OSDN Git Service

Correct java cast exceptions when doing a getUserInformation.
authorRandy Baumgarte <randy@fbn.cx>
Sun, 10 Jul 2011 19:57:07 +0000 (15:57 -0400)
committerRandy Baumgarte <randy@Centauri.(none)>
Tue, 12 Jul 2011 22:38:06 +0000 (18:38 -0400)
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/sql/DatabaseConnection.java

index 0665fab..b0da172 100644 (file)
@@ -273,21 +273,37 @@ public class Global {
     public static User getUserInformation() {\r
        User user = new User();\r
        settings.beginGroup("User");\r
     public static User getUserInformation() {\r
        User user = new User();\r
        settings.beginGroup("User");\r
-       user.setId((Integer)settings.value("id", 0));\r
+       try {   \r
+               user.setId((Integer)settings.value("id", 0));                   \r
+       } catch  (java.lang.ClassCastException e) {\r
+               user.setId(new Integer((String)settings.value("id", "0")));\r
+       }\r
                String username = (String)settings.value("username", "");\r
                String email = (String)settings.value("email", "");\r
                String name = (String)settings.value("name", "");\r
                String timezone = (String)settings.value("timezone", "");\r
                String username = (String)settings.value("username", "");\r
                String email = (String)settings.value("email", "");\r
                String name = (String)settings.value("name", "");\r
                String timezone = (String)settings.value("timezone", "");\r
-               Integer privilege = (Integer)settings.value("privilege", "");\r
-\r
-               String date = (String)settings.value("created", "0");\r
-               user.setCreated(new Long(date));\r
+               Integer privilege = 0;\r
+               try {   \r
+                       privilege = new Integer((String)settings.value("privilege", "0"));                      \r
+               } catch (java.lang.ClassCastException e) {\r
+                       privilege = (Integer)settings.value("privilege", 0);\r
+               }\r
 \r
 \r
-               date = (String)settings.value("updated", "0");\r
-               user.setUpdated(new Long(date));\r
-               \r
-               date = (String)settings.value("deleted", "0");\r
-               user.setDeleted(new Long(date));\r
+               try {   \r
+                       String date = (String)settings.value("created", "0");\r
+                       user.setCreated(new Long(date));\r
+                       date = (String)settings.value("updated", "0");\r
+                       user.setUpdated(new Long(date));\r
+                       date = (String)settings.value("deleted", "0");\r
+                       user.setDeleted(new Long(date));\r
+               } catch (java.lang.ClassCastException e) {\r
+                       Long date = (Long)settings.value("created", 0);\r
+                       user.setCreated(date);\r
+                       date = (Long)settings.value("updated", 0);\r
+                       user.setUpdated(date);\r
+                       date = (Long)settings.value("deleted", 0);\r
+                       user.setDeleted(date);\r
+               }\r
 \r
                String shard = (String)settings.value("shard", "");\r
        settings.endGroup();\r
 \r
                String shard = (String)settings.value("shard", "");\r
        settings.endGroup();\r
index 07342b6..f1cf5ae 100644 (file)
@@ -861,6 +861,8 @@ public class NeverNote extends QMainWindow{
                                QMessageBox.StandardButton.No) == StandardButton.Yes.value()) {
                        ChangeFileEncryption.execute(dbPath, dbName, encryptCipher, null, Global.cipherPassword.toCharArray(), true);
                        Global.setDatabaseUrl(Global.getDatabaseUrl() + ";CIPHER="+encryptCipher);
                                QMessageBox.StandardButton.No) == StandardButton.Yes.value()) {
                        ChangeFileEncryption.execute(dbPath, dbName, encryptCipher, null, Global.cipherPassword.toCharArray(), true);
                        Global.setDatabaseUrl(Global.getDatabaseUrl() + ";CIPHER="+encryptCipher);
+                       Global.setDatabaseUrl(Global.getIndexDatabaseUrl() + ";CIPHER="+encryptCipher);
+                       Global.setDatabaseUrl(Global.getResourceDatabaseUrl() + ";CIPHER="+encryptCipher);
                        QMessageBox.information(this, tr("Encryption Complete"), tr("Encryption is complete"));
                }
         } catch (SQLException e) {
                        QMessageBox.information(this, tr("Encryption Complete"), tr("Encryption is complete"));
                }
         } catch (SQLException e) {
index 7486246..d117f5a 100644 (file)
@@ -151,6 +151,15 @@ public class DatabaseConnection {
                        executeSql("Update note set indexneeded='true'");
                }
                
                        executeSql("Update note set indexneeded='true'");
                }
                
+               // Drop the note resource table & re-connect it in case it was recently encrypted.
+/*             NSqlQuery query = new NSqlQuery(conn);
+               query.exec("drop table NoteResources;");
+               String linkcmd = "create linked table NoteResources "
+                       +"('org.h2.Driver', '"+url+"', '"+userid+"', '"+passwordString+ "', 'NoteResources')";
+               query.exec(linkcmd);
+               System.err.println(query.lastError());
+*/             
+               
                logger.log(logger.HIGH, "Leaving DatabaseConnection.dbSetup" +id);
        }
        
                logger.log(logger.HIGH, "Leaving DatabaseConnection.dbSetup" +id);
        }