Author: batosai
Date: 2008-09-05 09:09:22 +0000 (Fri, 05 Sep 2008)
New Revision: 22441

Modified:
   trunk/apps/WoT/src/plugins/WoT/Identity.java
   trunk/apps/WoT/src/plugins/WoT/WoT.java
   trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
Refactor : query Trust objects with SODA.

Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-09-04 22:07:09 UTC 
(rev 22440)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-09-05 09:09:22 UTC 
(rev 22441)
@@ -114,8 +114,24 @@
                else return result.next();
        }

+       @SuppressWarnings("unchecked")
+       public ObjectSet<Trust> getReceivedTrusts(ObjectContainer db) {
+               Query query = db.query();
+               query.constrain(Trust.class);
+               query.descend("trustee").constrain(this);
+               return query.execute();
+       }

+       @SuppressWarnings("unchecked")
+       public ObjectSet<Trust> getGivenTrusts(ObjectContainer db) {
+               Query query = db.query();
+               query.constrain(Trust.class);
+               query.descend("truster").constrain(this);
+               return query.execute();
+       }
+

+       
        public void setRequestURI(FreenetURI requestURI) throws 
InvalidParameterException {
                if(requestURI.getKeyType().equals("SSK")) requestURI = 
requestURI.setKeyType("USK");
                if(!requestURI.getKeyType().equals("USK")) throw new 
InvalidParameterException("Key type not supported");

Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java     2008-09-04 22:07:09 UTC (rev 
22440)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java     2008-09-05 09:09:22 UTC (rev 
22441)
@@ -126,7 +126,7 @@
                if(trust != null && trust.getValue() <= 0) hasNegativeTrust = 
true;

                // We get get all trust received by the identity
-               ObjectSet<Trust> trusters = getTrusters(identity);
+               ObjectSet<Trust> trusters = identity.getReceivedTrusts(db);
                while(trusters.hasNext()) {

                        Trust trusterTrust = trusters.next();
@@ -191,7 +191,7 @@
                Logger.debug(this, score.toString());

                if(oldCapacity != newCapacity) { // If the capacity has 
changed, we have to update all identities this one trusts 
-                       ObjectSet<Trust> trustees = getTrustees(identity);
+                       ObjectSet<Trust> trustees = identity.getGivenTrusts(db);
                        while(trustees.hasNext()) {
                                updateScore(treeOwner, 
trustees.next().getTrustee());
                        }
@@ -239,21 +239,5 @@
                // Same problem here
                return query.execute();
        }
-       
-       public ObjectSet<Trust> getTrusters (String identity) throws 
Db4oIOException, DatabaseClosedException, MalformedURLException, 
InvalidParameterException, UnknownIdentityException, DuplicateIdentityException 
{
-               return getTrusters(Identity.getByURI(db, identity));
-       }
-       
-       private ObjectSet<Trust> getTrusters (Identity identity) throws 
Db4oIOException, DatabaseClosedException, InvalidParameterException {
-               return db.queryByExample(new Trust(null, identity, 0));
-       }
-
-       public ObjectSet<Trust> getTrustees (String identity) throws 
Db4oIOException, DatabaseClosedException, MalformedURLException, 
InvalidParameterException, UnknownIdentityException, DuplicateIdentityException 
{ 
-               return getTrustees(Identity.getByURI(db, identity));
-       }
-
-       private ObjectSet<Trust> getTrustees (Identity identity) throws 
Db4oIOException, DatabaseClosedException, InvalidParameterException { 
-               return db.queryByExample(new Trust(identity, null, 0));
-       }
 }


Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java       2008-09-04 22:07:09 UTC 
(rev 22440)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java       2008-09-05 09:09:22 UTC 
(rev 22441)
@@ -543,7 +543,7 @@

                sfs.putAppend("Message", "Identities");

-               ObjectSet<Trust> result = 
wot.getTrusters(params.get("Identity"));
+               ObjectSet<Trust> result = Identity.getByURI(db, 
params.get("Identity")).getReceivedTrusts(db);

                for(int i = 1 ; result.hasNext() ; i++) {
                        Trust trust = result.next();
@@ -565,7 +565,7 @@

                sfs.putAppend("Message", "Identities");

-               ObjectSet<Trust> result = 
wot.getTrustees(params.get("Identity"));
+               ObjectSet<Trust> result = Identity.getByURI(db, 
params.get("Identity")).getGivenTrusts(db);

                for(int i = 1 ; result.hasNext() ; i++) {
                        Trust trust = result.next();


Reply via email to