X-Git-Url: http://git.sourceforge.jp/view?p=neighbornote%2FNeighborNote.git;a=blobdiff_plain;f=src%2Fcx%2Ffbn%2Fnevernote%2Fsql%2FDatabaseConnection.java;h=72caf26797eb61caeacfb7b2c1cbe6fcf430529b;hp=2315180d17b5596e69ccb8a7fb53d1b3e49a6265;hb=4f64dbba0a56c86271272d9809a5df97bd955815;hpb=a93fe0f00adf0bf60cafd728d6b3e34de537ee36 diff --git a/src/cx/fbn/nevernote/sql/DatabaseConnection.java b/src/cx/fbn/nevernote/sql/DatabaseConnection.java index 2315180..72caf26 100644 --- a/src/cx/fbn/nevernote/sql/DatabaseConnection.java +++ b/src/cx/fbn/nevernote/sql/DatabaseConnection.java @@ -1,6 +1,7 @@ /* - * This file is part of NixNote + * This file is part of NixNote/NeighborNote * Copyright 2009 Randy Baumgarte + * Copyright 2013 Yuki Takahashi * * This file may be licensed under the terms of of the * GNU General Public License Version 2 (the ``GPL''). @@ -43,18 +44,27 @@ public class DatabaseConnection { private InkImagesTable inkImagesTable; private SyncTable syncTable; private SystemIconTable systemIconTable; + // ICHANGED + private HistoryTable historyTable; + private ExcludedTable excludedTable; + private StaredTable staredTable; + private final ApplicationLogger logger; private Connection conn; private Connection indexConn; private Connection resourceConn; + // ICHANGED + private Connection behaviorConn; + int throttle; int id; - - public DatabaseConnection(ApplicationLogger l, String url, String iurl, String rurl, String userid, String password, String cypherPassword, int throttle) { + // ICHANGED String burlを追加 + public DatabaseConnection(ApplicationLogger l, String url, String iurl, String rurl, String burl, String userid, String password, String cypherPassword, int throttle) { logger = l; this.throttle = throttle; - dbSetup(url, iurl, rurl, userid, password, cypherPassword); + // ICHANGED burlを追加 + dbSetup(url, iurl, rurl, burl, userid, password, cypherPassword); } private void setupTables() { @@ -71,6 +81,11 @@ public class DatabaseConnection { sharedNotebookTable = new SharedNotebookTable(logger, this); systemIconTable = new SystemIconTable(logger, this); inkImagesTable = new InkImagesTable(logger, this); + // ICHANGED + historyTable = new HistoryTable(logger, this); + excludedTable = new ExcludedTable(logger, this); + staredTable = new StaredTable(logger, this); + } @@ -80,7 +95,8 @@ public class DatabaseConnection { } // Initialize the database connection - public void dbSetup(String url,String indexUrl, String resourceUrl, String userid, String userPassword, String cypherPassword) { + // ICHANGED String behaviorUrlを追加 + public void dbSetup(String url,String indexUrl, String resourceUrl, String behaviorUrl, String userid, String userPassword, String cypherPassword) { logger.log(logger.HIGH, "Entering DatabaseConnection.dbSetup " +id); @@ -101,6 +117,9 @@ public class DatabaseConnection { boolean indexDbExists = f.exists(); f = Global.getFileManager().getDbDirFile(Global.resourceDatabaseName + ".h2.db"); boolean resourceDbExists = f.exists(); + // ICHANGED + f = Global.getFileManager().getDbDirFile(Global.behaviorDatabaseName + ".h2.db"); + boolean behaviorDbExists = f.exists(); logger.log(logger.HIGH, "Entering RDatabaseConnection.dbSetup"); @@ -121,6 +140,9 @@ public class DatabaseConnection { } indexConn = DriverManager.getConnection(indexUrl,userid,passwordString); resourceConn = DriverManager.getConnection(resourceUrl,userid,passwordString); + // ICHANGED + behaviorConn = DriverManager.getConnection(behaviorUrl, userid, passwordString); + // conn = DriverManager.getConnection(url+";AUTO_SERVER=TRUE",userid,passwordString); } catch (SQLException e) { e.printStackTrace(); @@ -151,6 +173,14 @@ public class DatabaseConnection { executeSql("Update note set indexneeded='true'"); } + // ICHANGED + // 操作履歴テーブルと除外ノートテーブルとスター付きノートテーブルを作る + if (!behaviorDbExists) { + createHistoryTables(); + createExcludedTables(); + createStaredTables(); + } + // If we encrypted/decrypted it the last time, we need to reconnect the tables. // if (Global.relinkTables) { // NSqlQuery query = new NSqlQuery(conn); @@ -179,62 +209,6 @@ public class DatabaseConnection { } public void upgradeDb(String version) { - if (version.equals("0.85")) { - executeSql("alter table note add column titleColor integer"); - executeSql("alter table note add column thumbnail blob"); - executeSql("alter table note add column thumbnailneeded boolean"); - executeSql("Update note set thumbnailneeded = true;"); - executeSql("create index NOTE_NOTEBOOK_INDEX on note (notebookguid, guid);"); - executeSql("create index NOTETAGS_TAG_INDEX on notetags (tagguid, noteguid);"); - 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 Boolean"); - 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 notebook add column readOnly boolean"); - executeSql("alter table notebook add column linked boolean"); - - executeSql("alter table tag add column realname varchar"); - executeSql("alter table tag add column linked boolean"); - executeSql("alter table tag add column icon blob"); - executeSql("alter table tag add column notebookguid varchar"); - 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 TAG_NOTEBOOK_INDEX on tag (notebookGuid);"); - - executeSql("update note set thumbnailneeded=true, thumbnail=null;"); - executeSql("update notebook set publishingUri='', " + - "publishingAscending=false, stack='', readonly=false, publishingOrder=1, " + - "publishingPublicDescription='', linked=false"); - executeSql("update tag set linked=false, realname='', notebookguid=''"); - - sharedNotebookTable.createTable(); - linkedNotebookTable.createTable(); - systemIconTable.createTable(); - inkImagesTable.createTable(); - - version = "0.95"; - executeSql("Insert into Sync (key, value) values ('FullNotebookSync', 'true')"); - executeSql("Insert into Sync (key, value) values ('FullLinkedNotebookSync', 'true')"); - executeSql("Insert into Sync (key, value) values ('FullSharedNotebookSync', 'true')"); - executeSql("Insert into Sync (key, value) values ('FullInkNoteImageSync', 'true')"); - Global.setDatabaseVersion(version); - } - if (version.equals("0.95")) { - if (dbTableExists("words")) - executeSql("Drop table words;"); - if (dbTableExists("NoteResources")) - executeSql("Drop table NoteResources;"); - } if (!dbTableColumnExists("NOTE", "ORIGINAL_GUID")) { executeSql("alter table note add column ORIGINAL_GUID VarChar"); executeSql("create index NOTE_ORIGINAL_GUID_INDEX on note (original_guid, guid);"); @@ -252,8 +226,14 @@ public class DatabaseConnection { executeSql("alter table notebook add column NARROW_SORT_COLUMN integer"); executeSql("update notebook set NARROW_SORT_COLUMN = -1"); } - - + if (!dbTableColumnExists("NOTE", "PINNED")) { + executeSql("alter table note add column pinned integer"); + executeSql("update note set pinned = 0"); + } + if (!dbTableColumnExists("NOTE", "ATTRIBUTECONTENTCLASS")) { + executeSql("alter table note add column attributeContentClass VarChar"); + executeSql("update note set attributeContentClass = ''"); + } } public void executeSql(String sql) { @@ -303,6 +283,21 @@ public class DatabaseConnection { noteTable.noteResourceTable.createTable(); } + // ICHANGED + public void createHistoryTables() { + historyTable.createTable(); + } + + // ICHANGED + public void createExcludedTables() { + excludedTable.createTable(); + } + + // ICHANGED + public void createStaredTables() { + staredTable.createTable(); + } + public Connection getConnection() { return conn; } @@ -313,6 +308,11 @@ public class DatabaseConnection { return resourceConn; } + // ICHANGED + public Connection getBehaviorConnection() { + return behaviorConn; + } + //*************************************************************** //* Table get methods //*************************************************************** @@ -355,6 +355,21 @@ public class DatabaseConnection { public InkImagesTable getInkImagesTable() { return inkImagesTable; } + + // ICHANGED + public HistoryTable getHistoryTable() { + return historyTable; + } + + // ICHANGED + public ExcludedTable getExcludedTable() { + return excludedTable; + } + + // ICHANGED + public StaredTable getStaredTable() { + return staredTable; + } //**************************************************************** //* Begin/End transactions