Permalink
Browse files

use sqlite jdbc that supports foreign key

  • Loading branch information...
JPMoresmau committed Apr 30, 2012
1 parent 4ca8a7a commit 0b8fc992633c10e40a46a94285f0183b4cf33065
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry exported="true" kind="lib" path="lib/sqlitejdbc-v056.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/sqlite-jdbc-3.7.2.jar"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
@@ -19,5 +19,5 @@ Export-Package: net.sf.eclipsefp.haskell.buildwrapper,
net.sf.eclipsefp.haskell.buildwrapper.types,
net.sf.eclipsefp.haskell.buildwrapper.usage,
net.sf.eclipsefp.haskell.buildwrapper.util
-Bundle-ClassPath: lib/sqlitejdbc-v056.jar,
- .
+Bundle-ClassPath: .,
+ lib/sqlite-jdbc-3.7.2.jar
@@ -3,4 +3,4 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties,\
- lib/sqlitejdbc-v056.jar
+ lib/sqlite-jdbc-3.7.2.jar
Binary file not shown.
@@ -37,11 +37,18 @@ public void close(){
}
public void removeFile(IFile f){
- removeFile(f.getProject(),f.getProjectRelativePath().toOSString());
+ if (f!=null){
+ try {
+ db.removeFile(f);
+ db.commit();
+ } catch (SQLException sqle){
+ BuildWrapperPlugin.logError(BWText.error_db, sqle);
+ }
+ }
}
public void removeFile(IProject p, String relPath){
- //BuildWrapperPlugin.log(IStatus.INFO, "Removing "+p.getName()+"/"+relPath, null);
+ removeFile(p.getFile(relPath));
}
public void addFile(Component c,IFile f){
@@ -60,9 +67,11 @@ public void addFile(IProject p,Component c, String relPath){
try {
String pkg=formatPackage(arr.getString(0));
String module=formatModule(c, arr.getString(1));
- long fileID=db.getFileID(f);
- long moduleID=db.getModuleID(pkg, module, fileID);
- db.commit();
+ if (module!=null){
+ long fileID=db.getFileID(f);
+ long moduleID=db.getModuleID(pkg, module, fileID);
+ db.commit();
+ }
} catch (SQLException sqle){
BuildWrapperPlugin.logError(BWText.error_db, sqle);
} catch (JSONException je){
@@ -145,6 +154,9 @@ private String formatPackage(String pkg){
private String formatModule(Component c,String module){
String ret=module;
if("Main".equals(module)){
+ if (c.getName()==null){ // Main but a library, ignore
+ return null;
+ }
ret=module+" "+c.getName();
}
return ret;
@@ -16,15 +16,15 @@
import java.util.ArrayList;
import java.util.List;
+import net.sf.eclipsefp.haskell.buildwrapper.BuildWrapperPlugin;
+import net.sf.eclipsefp.haskell.buildwrapper.types.Module;
+import net.sf.eclipsefp.haskell.buildwrapper.util.BWText;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
-import net.sf.eclipsefp.haskell.buildwrapper.BuildWrapperPlugin;
-import net.sf.eclipsefp.haskell.buildwrapper.types.Module;
-import net.sf.eclipsefp.haskell.buildwrapper.util.BWText;
-
/**
* @author JP Moresmau
*
@@ -41,8 +41,14 @@ public UsageDB(){
Class.forName("org.sqlite.JDBC");
conn =
DriverManager.getConnection("jdbc:sqlite:"+f.getAbsolutePath());
+ conn.setAutoCommit(true);
+ Statement s=conn.createStatement();
+ try {
+ s.executeUpdate("PRAGMA foreign_keys = ON;");
+ } finally {
+ s.close();
+ }
conn.setAutoCommit(false);
-
setup();
} catch (Exception e){
BuildWrapperPlugin.logError(BWText.error_setup_db, e);
@@ -131,6 +137,37 @@ public long getFileID(IFile f) throws SQLException{
return fileID;
}
+ public void removeFile(IFile f) throws SQLException{
+ checkConnection();
+ PreparedStatement ps=conn.prepareStatement("select fileid from files where project=? and name=?");
+ Long fileID=null;
+ try {
+ ps.setString(1, f.getProject().getName());
+ ps.setString(2, f.getProjectRelativePath().toPortableString());
+ ResultSet rs=ps.executeQuery();
+ try {
+ if (rs.next()){
+ fileID=rs.getLong(1);
+ }
+ } finally {
+ rs.close();
+ }
+
+ } finally {
+ ps.close();
+ }
+ if (fileID!=null){
+ ps=conn.prepareStatement("delete from files where fileid=?");
+ try {
+ ps.setLong(1, fileID);
+ ps.executeUpdate();
+ } finally {
+ ps.close();
+ }
+
+ }
+ }
+
public long getModuleID(String pkg,String module,Long fileID) throws SQLException {
checkConnection();
PreparedStatement ps=conn.prepareStatement("select moduleid from modules where package=? and module=?");

0 comments on commit 0b8fc99

Please sign in to comment.