Author: jflesch
Date: 2006-10-18 18:37:20 +0000 (Wed, 18 Oct 2006)
New Revision: 10670

Modified:
   trunk/apps/Thaw/src/thaw/plugins/index/File.java
   trunk/apps/Thaw/src/thaw/plugins/index/Index.java
   trunk/apps/Thaw/src/thaw/plugins/index/Link.java
Log:
Fix index loading (yes, again.)

Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/File.java    2006-10-18 06:05:57 UTC 
(rev 10669)
+++ trunk/apps/Thaw/src/thaw/plugins/index/File.java    2006-10-18 18:37:20 UTC 
(rev 10670)
@@ -278,6 +278,39 @@
                }
        }

+
+       public boolean isInTheDatabase() {
+               if (parent == null) {
+                       Logger.notice(this, "isInTheDatabase(): No parent !");
+                       return false;
+               }
+
+               try {
+                       PreparedStatement st;
+
+                       st = db.getConnection().prepareStatement("SELECT 
publicKey from files WHERE publicKey = ? AND indexParent = ?");
+
+                       if(publicKey != null)
+                               st.setString(1, publicKey);
+                       else
+                               st.setString(1, fileName);
+
+                       st.setInt(2, getParent().getId());
+
+                       if(st.execute()) {
+                               ResultSet result = st.getResultSet();
+                               if (result != null && result.next()) {
+                                       return true;
+                               }
+                       }
+
+               } catch(SQLException e) {
+
+               }
+               
+               return false;
+       }
+

        public void update(java.util.Observable o, Object param) {
                if(o == transfer) {

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2006-10-18 06:05:57 UTC 
(rev 10669)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2006-10-18 18:37:20 UTC 
(rev 10670)
@@ -372,7 +372,7 @@
                        publicKey = sskGenerator.getPublicKey();
                        privateKey = sskGenerator.getPrivateKey();

-                       Logger.debug(this, "Index public key: "+publicKey);
+                       Logger.debug(this, "Index public key: " +publicKey);
                        Logger.debug(this, "Index private key: "+privateKey);

                }
@@ -526,12 +526,15 @@
         */
        public void addFile(thaw.plugins.index.File file) {
                file.setParent(this);
-               file.insert();

-               addFileToList(file);
+               if (!file.isInTheDatabase()) {
+                       file.insert();

-               setChanged();
-               notifyObservers(file);
+                       addFileToList(file);
+
+                       setChanged();
+                       notifyObservers(file);
+               }
        }


@@ -572,13 +575,16 @@

        public void addLink(Link link) {
                link.setParent(this);
-               link.insert();

-               if (linkList != null) {
-                       linkList.add(link);
+               if (!link.isInTheDatabase()) {
+                       link.insert();

-                       setChanged();
-                       notifyObservers(link);
+                       if (linkList != null) {
+                               linkList.add(link);
+
+                               setChanged();
+                               notifyObservers(link);
+                       }
                }

        }
@@ -633,7 +639,7 @@
                                while(results.next()) {
                                        try {
                                                Link link = new Link(db, 
results, this);
-                                               linkList.add(link);
+                                               addLink(link);
                                        } catch(Exception e) {
                                                Logger.warning(this, "Unable to 
add index '"+publicKey+"' to the list because: "+e.toString());
                                        }
@@ -889,7 +895,7 @@
                                Element e = (Element)list.item(i);

                                thaw.plugins.index.File file = new 
thaw.plugins.index.File(db, e, this);        
-                               addFileToList(file);
+                               addFile(file);
                        }
                }


Modified: trunk/apps/Thaw/src/thaw/plugins/index/Link.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Link.java    2006-10-18 06:05:57 UTC 
(rev 10669)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Link.java    2006-10-18 18:37:20 UTC 
(rev 10670)
@@ -119,6 +119,37 @@

        }

+
+       public boolean isInTheDatabase() {
+               if (parent == null) {
+                       Logger.notice(this, "isInTheDatabase(): No parent !");
+                       return false;
+               }
+
+               try {
+                       PreparedStatement st;
+
+                       st = db.getConnection().prepareStatement("SELECT 
publicKey from links WHERE publicKey = ? AND indexParent = ?");
+
+                       st.setString(1, key);
+
+                       st.setInt(2, getParent().getId());
+
+                       if(st.execute()) {
+                               ResultSet result = st.getResultSet();
+                               if (result != null && result.next()) {
+                                       return true;
+                               }
+                       }
+
+               } catch(SQLException e) {
+                       Logger.error(this, "Unable to check if link '"+key+"' 
exists because: "+e.toString());
+               }
+               
+               return false;
+       }
+
+
        public void delete() {
                try {
                        PreparedStatement st;


Reply via email to