OSDN Git Service

NixNoteのUpgradeDbメソッドを不要部分を削除。
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / sql / DatabaseConnection.java
index 21b852a..72caf26 100644 (file)
@@ -1,6 +1,7 @@
 /*
- * This file is part of NeverNote 
+ * 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,68 +209,31 @@ 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);");
                }
+               if (!dbTableColumnExists("NOTEBOOK", "NARROW_SORT_ORDER")) {
+                       executeSql("alter table notebook add column NARROW_SORT_ORDER integer");
+                       executeSql("update notebook set NARROW_SORT_ORDER = -1");
 
-               
+                       executeSql("alter table notebook add column WIDE_SORT_ORDER integer");
+                       executeSql("update notebook set WIDE_SORT_ORDER = -1");
+                       
+                       executeSql("alter table notebook add column WIDE_SORT_COLUMN integer");
+                       executeSql("update notebook set WIDE_SORT_COLUMN = -1");
+                       
+                       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) {
@@ -290,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;
        }
@@ -300,6 +308,11 @@ public class DatabaseConnection {
                return resourceConn;
        }
        
+       // ICHANGED
+       public Connection getBehaviorConnection() {
+               return behaviorConn;
+       }
+       
        //***************************************************************
        //* Table get methods
        //***************************************************************
@@ -342,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