proper transactions
authorChristian Grothoff <christian@grothoff.org>
Wed, 27 Oct 2010 14:41:20 +0000 (14:41 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 27 Oct 2010 14:41:20 +0000 (14:41 +0000)
src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
src/monkey/seaspider/org/gnunet/seaspider/Seaspider.java

index 5886fc90b10807ea7995b6a68a7a7a2d09816933..a94f63e77af7e3dc56b15c96706497df420c40a6 100644 (file)
@@ -8,8 +8,13 @@ import org.tmatesoft.sqljet.core.table.ISqlJetTable;
 import org.tmatesoft.sqljet.core.table.SqlJetDb;
 
 public class ExpressionDatabaseHandler {
-       
-       private static SqlJetDb db = null;
+
+       private static final boolean DEBUG = false;
+               
+       private static SqlJetDb db;
+
+       private static ISqlJetTable table;
+
        
        public static void createExpressionDatabase(String databasePath) {
                String createTableQuery = "CREATE TABLE Expression ( expr_ID INT NOT NULL PRIMARY KEY , " +
@@ -31,6 +36,8 @@ public class ExpressionDatabaseHandler {
                        }
                        /* Create table Expression */
                        db.createTable(createTableQuery);
+                       db.beginTransaction(SqlJetTransactionMode.WRITE);
+                       table = db.getTable("Expression");
                }
                catch (SqlJetException e) {
                        e.printStackTrace();
@@ -41,6 +48,7 @@ public class ExpressionDatabaseHandler {
        public static void closeDatabase()
        {
                try {
+                       db.commit();
                        db.close();
                } catch (SqlJetException e) {
                        e.printStackTrace();
@@ -55,24 +63,15 @@ public class ExpressionDatabaseHandler {
                        return;
                if (expressionSyntax.startsWith("\""))
                        return;
-               if (false)
+               if (DEBUG)
                        System.out.println (fileName  + ":[" + startLineNo + "-" + endLineNo + "]: " + expressionSyntax);
-               if (true)
-                       return;
                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);
-                       } finally {
-                               db.commit();
-                       }
+                       table.insert(fileName, expressionSyntax, startLineNo, endLineNo);
                }
                catch (SqlJetException e) {
                        e.printStackTrace();
index f074136572a926bb1508c37e562eb048e24a7b31..15ad2571c8468dcef17fe0241edbf729639fb06b 100644 (file)
@@ -38,11 +38,11 @@ public class Seaspider {
          }
      };
      
-     /* File filter to get only source and header files */
+     /* File filter to get only source files and no test cases */
      FileFilter sourceFilter = new FileFilter() {
        public boolean accept(File file) {
                String fileName = file.getName();
-               return fileName.endsWith(".c");
+               return fileName.endsWith(".c") && ! fileName.startsWith("test_");
        }
      };