[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r13372 - gnunet/src/monkey/seaspider/org/gnunet/seaspider
From: |
gnunet |
Subject: |
[GNUnet-SVN] r13372 - gnunet/src/monkey/seaspider/org/gnunet/seaspider |
Date: |
Fri, 22 Oct 2010 16:28:51 +0200 |
Author: safey
Date: 2010-10-22 16:28:51 +0200 (Fri, 22 Oct 2010)
New Revision: 13372
Added:
gnunet/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
Log:
Handle to deal with Expression Database
Added:
gnunet/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
===================================================================
---
gnunet/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
(rev 0)
+++
gnunet/src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
2010-10-22 14:28:51 UTC (rev 13372)
@@ -0,0 +1,75 @@
+package org.gnunet.seaspider.parser;
+
+import java.io.File;
+
+import org.tmatesoft.sqljet.core.SqlJetException;
+import org.tmatesoft.sqljet.core.SqlJetTransactionMode;
+import org.tmatesoft.sqljet.core.table.ISqlJetTable;
+import org.tmatesoft.sqljet.core.table.SqlJetDb;
+
+public class ExpressionDatabaseHandler {
+
+ private static SqlJetDb db = null;
+
+ public static void createExpressionDatabase(String databasePath) {
+ String createTableQuery = "CREATE TABLE Expression ( expr_ID
INT NOT NULL PRIMARY KEY , " +
+ "file_name TEXT NOT NULL , expr_syntax TEXT NOT NULL ," +
+ " start_lineno INT NOT NULL , end_lineno INT NOT NULL , " +
+ "scope_start_lineno INT NOT NULL , scope_end_lineno INT NOT
NULL)";
+
+ File dbFile = new File(databasePath + "/GNUnetExpressions.db");
+ dbFile.delete();/* Delete it if already existent */
+
+ /* Create Expressions database */
+ try {
+ db = SqlJetDb.open(dbFile, true);
+ db.getOptions().setAutovacuum(true);
+ db.beginTransaction(SqlJetTransactionMode.WRITE);
+ try {
+ db.getOptions().setUserVersion(1);/* Sets the
user's cookie */
+ } finally {
+ db.commit();
+ }
+ /* Create table Expression */
+ db.createTable(createTableQuery);
+ }
+ catch (SqlJetException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public static void closeDatabase()
+ {
+ try {
+ db.close();
+ } catch (SqlJetException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public static void insertIntoExpressionTable(String fileName, String
expressionSyntax,
+
int startLineNo, int endLineNo, int scopeStartLineNo,
+
int scopeEndLineNo)
+ {
+ if (db == null) {
+ System.out.println("Error:Database handle is not
initialized. Program will exit now!");
+ System.exit(1);
+ }
+
+ ISqlJetTable table;
+ try {
+ table = db.getTable("Expression");
+ db.beginTransaction(SqlJetTransactionMode.WRITE);
+ try {
+ table.insert(fileName, expressionSyntax,
startLineNo, endLineNo, scopeStartLineNo, scopeEndLineNo);
+ } finally {
+ db.commit();
+ }
+ }
+ catch (SqlJetException e) {
+ e.printStackTrace();
+ }
+ }
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r13372 - gnunet/src/monkey/seaspider/org/gnunet/seaspider,
gnunet <=