X-Git-Url: http://git.sourceforge.jp/view?p=neighbornote%2FNeighborNote.git;a=blobdiff_plain;f=src%2Fcx%2Ffbn%2Fnevernote%2Fsql%2FDatabaseConnection.java;h=47a611301d927c799f2d063df2e6717800841ea7;hp=c046b2add9f83b7254ae294ad67fabd982e55ece;hb=e0ca12f9a3252642d3e4632f580b368965830e94;hpb=a45def57488852d6c41e1f809ceac748b6a92322 diff --git a/src/cx/fbn/nevernote/sql/DatabaseConnection.java b/src/cx/fbn/nevernote/sql/DatabaseConnection.java index c046b2a..47a6113 100644 --- a/src/cx/fbn/nevernote/sql/DatabaseConnection.java +++ b/src/cx/fbn/nevernote/sql/DatabaseConnection.java @@ -40,6 +40,8 @@ public class DatabaseConnection { private SavedSearchTable searchTable; private WatchFolderTable watchFolderTable; private InvalidXMLTable invalidXMLTable; + private LinkedNotebookTable linkedNotebookTable; + private SharedNotebookTable sharedNotebookTable; private SyncTable syncTable; private final ApplicationLogger logger; private Connection conn; @@ -61,6 +63,8 @@ public class DatabaseConnection { invalidXMLTable = new InvalidXMLTable(logger, this); wordsTable = new WordsTable(logger, this); syncTable = new SyncTable(logger, this); + linkedNotebookTable = new LinkedNotebookTable(logger, this); + sharedNotebookTable = new SharedNotebookTable(logger, this); } @@ -83,16 +87,11 @@ public class DatabaseConnection { QJdbc.initialize(); + setupTables(); + File f = Global.getFileManager().getDbDirFile(Global.databaseName + ".h2.db"); boolean dbExists = f.exists(); - // If it doesn't exist and we are the main thread, then we need to create stuff. - if (!dbExists) { - createTables(); - Global.setAutomaticLogin(false); - } - setupTables(); - logger.log(logger.HIGH, "Entering RDatabaseConnection.dbSetup"); @@ -109,9 +108,11 @@ public class DatabaseConnection { return; } - logger.log(logger.HIGH, "Leaving RDatabaseConnection.dbSetup"); - - + // If it doesn't exist and we are the main thread, then we need to create stuff. + if (!dbExists) { + createTables(); + Global.setAutomaticLogin(false); + } logger.log(logger.HIGH, "Leaving DatabaseConnection.dbSetup" +id); } @@ -138,6 +139,34 @@ public class DatabaseConnection { version = "0.86"; Global.setDatabaseVersion(version); } + if (version.equals("0.86")) { + + executeSql("alter table notebook add column publishingUri VarChar"); + executeSql("alter table notebook add column publishingOrder Integer"); + executeSql("alter table notebook add column publishingAscending VarChar"); + executeSql("alter table notebook add column publishingPublicDescription varchar"); + executeSql("alter table notebook add column stack varchar"); + executeSql("alter table notebook add column icon blob"); + executeSql("alter table tag add column icon blob"); + executeSql("alter table SavedSearch add column icon blob"); + + executeSql("create index NOTE_THUMBNAIL_INDEX on note (thumbnailneeded, guid);"); + executeSql("create index NOTE_EXPUNGED_INDEX on note (isExpunged, guid);"); + executeSql("create index NOTE_DUEDATE_INDEX on note (attributeSubjectDate, guid);"); + executeSql("create index RESOURCES_GUID_INDEX on noteresources (noteGuid, guid);"); + executeSql("update note set thumbnailneeded=true, thumbnail=null;"); + executeSql("update notebook set publishingUri='', " + + "publishingAscending='', stack='', publishingOrder=1, " + + "publishingPublicDescription=''"); + + sharedNotebookTable.createTable(); + linkedNotebookTable.createTable(); + + version = "0.95"; + executeSql("Insert into Sync (key, value) values ('FullLinkedNotebookSync', 'true')"); + executeSql("Insert into Sync (key, value) values ('FullSharedNotebookSync', 'true')"); + Global.setDatabaseVersion(version); + } } public void executeSql(String sql) { @@ -149,6 +178,9 @@ public class DatabaseConnection { if (!Global.getDatabaseVersion().equals("0.86")) { upgradeDb(Global.getDatabaseVersion()); } + if (!Global.getDatabaseVersion().equals("0.95")) { + upgradeDb(Global.getDatabaseVersion()); + } } @@ -171,8 +203,7 @@ public class DatabaseConnection { watchFolderTable.createTable(); invalidXMLTable.createTable(); wordsTable.createTable(); - syncTable.createTable(); - + syncTable.createTable(); } public Connection getConnection() { @@ -209,4 +240,10 @@ public class DatabaseConnection { public SyncTable getSyncTable() { return syncTable; } + public LinkedNotebookTable getLinkedNotebookTable() { + return linkedNotebookTable; + } + public SharedNotebookTable getSharedNotebookTable() { + return sharedNotebookTable; + } }