aboutsummaryrefslogtreecommitdiff
path: root/src/monkey
diff options
context:
space:
mode:
authorSafey A.Halim <safey.allah@gmail.com>2010-10-22 14:28:51 +0000
committerSafey A.Halim <safey.allah@gmail.com>2010-10-22 14:28:51 +0000
commit318468a976ec426f517663f7a244c969623df882 (patch)
tree20d0a359c50d96d3f75ce0b378768e668afec98e /src/monkey
parent1d915299939e745e75cdd9bca6f970eb1d6fb38a (diff)
downloadgnunet-318468a976ec426f517663f7a244c969623df882.tar.gz
gnunet-318468a976ec426f517663f7a244c969623df882.zip
Handle to deal with Expression Database
Diffstat (limited to 'src/monkey')
-rw-r--r--src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java b/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
new file mode 100644
index 000000000..36c34d1de
--- /dev/null
+++ b/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
@@ -0,0 +1,75 @@
1package org.gnunet.seaspider.parser;
2
3import java.io.File;
4
5import org.tmatesoft.sqljet.core.SqlJetException;
6import org.tmatesoft.sqljet.core.SqlJetTransactionMode;
7import org.tmatesoft.sqljet.core.table.ISqlJetTable;
8import org.tmatesoft.sqljet.core.table.SqlJetDb;
9
10public class ExpressionDatabaseHandler {
11
12 private static SqlJetDb db = null;
13
14 public static void createExpressionDatabase(String databasePath) {
15 String createTableQuery = "CREATE TABLE Expression ( expr_ID INT NOT NULL PRIMARY KEY , " +
16 "file_name TEXT NOT NULL , expr_syntax TEXT NOT NULL ," +
17 " start_lineno INT NOT NULL , end_lineno INT NOT NULL , " +
18 "scope_start_lineno INT NOT NULL , scope_end_lineno INT NOT NULL)";
19
20 File dbFile = new File(databasePath + "/GNUnetExpressions.db");
21 dbFile.delete();/* Delete it if already existent */
22
23 /* Create Expressions database */
24 try {
25 db = SqlJetDb.open(dbFile, true);
26 db.getOptions().setAutovacuum(true);
27 db.beginTransaction(SqlJetTransactionMode.WRITE);
28 try {
29 db.getOptions().setUserVersion(1);/* Sets the user's cookie */
30 } finally {
31 db.commit();
32 }
33 /* Create table Expression */
34 db.createTable(createTableQuery);
35 }
36 catch (SqlJetException e) {
37 e.printStackTrace();
38 }
39 }
40
41
42 public static void closeDatabase()
43 {
44 try {
45 db.close();
46 } catch (SqlJetException e) {
47 e.printStackTrace();
48 }
49 }
50
51
52 public static void insertIntoExpressionTable(String fileName, String expressionSyntax,
53 int startLineNo, int endLineNo, int scopeStartLineNo,
54 int scopeEndLineNo)
55 {
56 if (db == null) {
57 System.out.println("Error:Database handle is not initialized. Program will exit now!");
58 System.exit(1);
59 }
60
61 ISqlJetTable table;
62 try {
63 table = db.getTable("Expression");
64 db.beginTransaction(SqlJetTransactionMode.WRITE);
65 try {
66 table.insert(fileName, expressionSyntax, startLineNo, endLineNo, scopeStartLineNo, scopeEndLineNo);
67 } finally {
68 db.commit();
69 }
70 }
71 catch (SqlJetException e) {
72 e.printStackTrace();
73 }
74 }
75}