/*
- * 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'').
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;
- int throttle=0;
+ // 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() {
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);
+
}
}
// 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);
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");
}
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();
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);
+// query.exec("Drop table NoteResources;");
+// String linkcmd = "create linked table NoteResources "
+// +"('org.h2.Driver', '"+url+"', '"+userid+"', '"+passwordString+ "', 'NoteResources')";
+// System.out.println(linkcmd);
+// query.exec(linkcmd);
+// System.err.println(query.lastError());
+// Global.relinkTables = false;
+// }
+
+
logger.log(logger.HIGH, "Leaving DatabaseConnection.dbSetup" +id);
}
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) {
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;
}
return resourceConn;
}
+ // ICHANGED
+ public Connection getBehaviorConnection() {
+ return behaviorConn;
+ }
+
//***************************************************************
//* Table get methods
//***************************************************************
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
else
return false;
}
+
+ //****************************************************************
+ //* Check if a row in a table exists
+ //****************************************************************
+ public boolean dbTableColumnExists(String tableName, String columnName) {
+ NSqlQuery query = new NSqlQuery(getConnection());
+ query.prepare("select TABLE_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=:name and COLUMN_NAME=:column");
+ query.bindValue(":name", tableName.toUpperCase());
+ query.bindValue(":column", columnName);
+ query.exec();
+ if (query.next())
+ return true;
+ else
+ return false;
+ }
}