google-code-export / sqljet

Automatically exported from code.google.com/p/sqljet
0 stars 1 forks source link

Using SQLJet in a Processing library #145

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I want to create a Processing library to record events on a multi-touch 
interface (MacOSX 10.6.5). I'm trying to achieve this by using SQLJet to easily 
record events on an SQLite database.

I'm using the Processing library template (20100507) for Eclipse 
(20090619-0625), and I've imported the OSGi bundle with SQLJet (1.0.3.b914) as 
an external JAR. I'm testing this simple code that only creates a database:

package TUIrecorder; 

import java.io.File;

import org.tmatesoft.sqljet.core.SqlJetException; 
import org.tmatesoft.sqljet.core.SqlJetTransactionMode; 
import org.tmatesoft.sqljet.core.table.ISqlJetTransaction; 
import org.tmatesoft.sqljet.core.table.SqlJetDb; 

import processing.core.*; 

public class TUIrecorder { 
   // myParent is a reference to the parent sketch 
   PApplet myParent; 
   File dbFile; 

   /** 
   * Constructor, called in the setup() method in the Processing sketch to start the library. 
   * 
   * @example TUIrecExample 
   * @param theParent 
   */ 
   public TUIrecorder(PApplet theParent) { 
      myParent = theParent; 

      try { 
         createDB(); 
      } catch (Exception e) { 
         System.out.println("Failed to create the database."); 
      } 
   }

   /**
   * Prepares a table in the database to record pick ups and drop downs 
   * 
   * @example TUIrecExample 
   * @throws SqlJetException 
   */ 
   private void createDB() throws SqlJetException { 
      dbFile = new File("db.interaction"); 
      dbFile.delete(); 
      // create database, table and two indices 
      SqlJetDb db = SqlJetDb.open(dbFile, true); 
      // set DB option that have to be set before running any transactions 
      db.getOptions().setAutovacuum(true); 
      // set DB option that have to be set in a transaction
      db.runTransaction(new ISqlJetTransaction() { 
         public Object run(SqlJetDb db) throws SqlJetException { 
            db.getOptions().setUserVersion(1); 
            return true; 
         } 
      }, SqlJetTransactionMode.WRITE); 

      // close DB 
      db.close(); 
   }
}

When I try to run it from Processing (1.2.1):

import TUIrecorder.*; 

TUIrecorder tuiRec; 

void setup() { 
   size(400,400); 
   smooth(); 

   tuiRec = new TUIrecorder(this);
}

void draw() {
   background(0);
}

I'm getting the following errors:

processing.app.debug.RunnerException: NoClassDefFoundError: 
org/antlr/runtime/RecognitionException 
at processing.app.Sketch.placeException(Sketch.java:1543) 
at processing.app.debug.Runner.findException(Runner.java:583) 
at processing.app.debug.Runner.reportException(Runner.java:558) 
at processing.app.debug.Runner.exception(Runner.java:498) 
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367) 
at processing.app.debug.EventThread.handleEvent(EventThread.java:255) 
at processing.app.debug.EventThread.run(EventThread.java:89) 

Exception in thread "Animation Thread" java.lang.NoClassDefFoundError: 
org/antlr/runtime/RecognitionException 
at org.tmatesoft.sqljet.core.table.SqlJetDb$2.runWithLock(SqlJetDb.java:247) 
at org.tmatesoft.sqljet.core.table.SqlJetDb.runWithLock(SqlJetDb.java:305) 
at org.tmatesoft.sqljet.core.table.SqlJetDb.readSchema(SqlJetDb.java:242) 
at org.tmatesoft.sqljet.core.table.SqlJetDb.getOptions(SqlJetDb.java:509) 
at TUIrecorder.TUIrecorder.createDB(Unknown Source) 
at TUIrecorder.TUIrecorder.(Unknown Source) 
at TUIrecExample.setup(TUIrecExample.java:30) 
at processing.core.PApplet.handleDraw(PApplet.java:1583) 
at processing.core.PApplet.run(PApplet.java:1503) at 
java.lang.Thread.run(Thread.java:680) 

Caused by: java.lang.ClassNotFoundException: 
org.antlr.runtime.RecognitionException 
at java.net.URLClassLoader$1.run(URLClassLoader.java:202) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(URLClassLoader.java:190) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:307) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 
... 10 more

Original issue reported on code.google.com by augusto...@gmail.com on 9 Dec 2010 at 11:19

GoogleCodeExporter commented 9 years ago

Original comment by sergey.s...@gmail.com on 9 Dec 2010 at 10:58

GoogleCodeExporter commented 9 years ago
Fixed it by manually adding the antlr-runtime-3.1.3.jar that comes in the 
SQLJet OSGi bundle as an external JAR.

Original comment by augusto...@gmail.com on 9 Dec 2010 at 11:50

GoogleCodeExporter commented 9 years ago
I'm not expert in OSGi, so if you could tell something about improving our 
bundle's packaging, please, don't hesitate. Thanks.

Original comment by sergey.s...@gmail.com on 9 Dec 2010 at 11:58

GoogleCodeExporter commented 9 years ago
Is it compulsory to add antlr-runtime-3.1.3.jar, however I thought that this is 
a "Pure Java" SQLite. Why this dependency is needed for a single 
org/antlr/runtime/RecognitionException exception, can't it be replaced with 
SqlJetException?

Original comment by ahmetalp...@gmail.com on 19 Feb 2011 at 11:07

GoogleCodeExporter commented 9 years ago
The 'antlr-runtime-3.1.3.jar' is required not only for 'RecognitionException'. 
All parsing of SQL statements is implemented using ANTLR library. At now SQL is 
parsed for database schema definitions. You could look to classes 
'org.tmatesoft.sqljet.core.internal.lang.SqlLexer' or 
'org.tmatesoft.sqljet.core.internal.lang.SqlParser' which are generated by 
ANTLR in build time and inherit from 'org.antlr.runtime.Lexer' and 
'org.antlr.runtime.Parser' classes.

Original comment by sergey.s...@gmail.com on 19 Feb 2011 at 11:30

GoogleCodeExporter commented 9 years ago
Issue 167 has been merged into this issue.

Original comment by sergey.s...@gmail.com on 9 Apr 2012 at 5:59