1 package org.gnunet.seaspider.parser;
5 import org.tmatesoft.sqljet.core.SqlJetException;
6 import org.tmatesoft.sqljet.core.SqlJetTransactionMode;
7 import org.tmatesoft.sqljet.core.table.ISqlJetTable;
8 import org.tmatesoft.sqljet.core.table.SqlJetDb;
10 public class ExpressionDatabaseHandler {
12 private static SqlJetDb db = null;
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)";
20 File dbFile = new File(databasePath + "/GNUnetExpressions.db");
21 dbFile.delete();/* Delete it if already existent */
23 /* Create Expressions database */
25 db = SqlJetDb.open(dbFile, true);
26 db.getOptions().setAutovacuum(true);
27 db.beginTransaction(SqlJetTransactionMode.WRITE);
29 db.getOptions().setUserVersion(1);/* Sets the user's cookie */
33 /* Create table Expression */
34 db.createTable(createTableQuery);
36 catch (SqlJetException e) {
42 public static void closeDatabase()
46 } catch (SqlJetException e) {
52 public static void insertIntoExpressionTable(String fileName, String expressionSyntax,
53 int startLineNo, int endLineNo, int scopeStartLineNo,
57 System.out.println("Error:Database handle is not initialized. Program will exit now!");
63 table = db.getTable("Expression");
64 db.beginTransaction(SqlJetTransactionMode.WRITE);
66 table.insert(fileName, expressionSyntax, startLineNo, endLineNo, scopeStartLineNo, scopeEndLineNo);
71 catch (SqlJetException e) {