Querying by a ByteArrayWrapper works for you? Really?

On Thursday 04 September 2008 15:38, batosai at freenetproject.org wrote:
> Author: batosai
> Date: 2008-09-04 14:38:32 +0000 (Thu, 04 Sep 2008)
> New Revision: 22409
> 
> Modified:
>    trunk/apps/WoT/src/plugins/WoT/Identity.java
>    trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java
> Log:
> Switched to ByteArrayWrapper as suggested by Nextgens.
> 
> Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
> ===================================================================
> --- trunk/apps/WoT/src/plugins/WoT/Identity.java      2008-09-04 14:23:27 UTC 
(rev 22408)
> +++ trunk/apps/WoT/src/plugins/WoT/Identity.java      2008-09-04 14:38:32 UTC 
(rev 22409)
> @@ -17,6 +17,7 @@
>  import com.db4o.query.Query;
>  
>  import freenet.keys.FreenetURI;
> +import freenet.support.ByteArrayWrapper;
>  
>  /**
>   * An identity as handled by the WoT (a USK)
> @@ -27,7 +28,7 @@
>  public class Identity {
>  
>       @SuppressWarnings("unused")
> -     private String id;
> +     private ByteArrayWrapper id;
>       private FreenetURI requestURI;
>       
>       private Date lastChange;
> @@ -45,10 +46,7 @@
>               props = new HashMap<String, String>();
>               contexts = new ArrayList<String>();
>               contexts.add(context);
> -             
> -             int start = getRequestURI().toString().indexOf(',');
> -             int end = getRequestURI().toString().indexOf(',', start + 1);
> -             id = getRequestURI().toString().substring(start, end);
> +             id = new ByteArrayWrapper(getRequestURI().getRoutingKey());
>       }
>  
>       public Identity (String requestURI, String nickName, String 
publishTrustList, String context) throws InvalidParameterException, 
MalformedURLException {
> @@ -58,7 +56,7 @@
>  
>       
>       @SuppressWarnings("unchecked")
> -     public static Identity getById (ObjectContainer db, String id) throws 
DuplicateIdentityException, UnknownIdentityException {
> +     public static Identity getById (ObjectContainer db, ByteArrayWrapper 
> id) 
throws DuplicateIdentityException, UnknownIdentityException {
>  
>               Query query = db.query();
>               query.constrain(Identity.class);
> @@ -70,15 +68,12 @@
>               return result.next();
>       }
>       
> -     public static Identity getByURI (ObjectContainer db, String uri) throws 
UnknownIdentityException, DuplicateIdentityException {
> -             int start = uri.indexOf(',');
> -             int end = uri.indexOf(',', start + 1);
> -
> -             return getById(db, uri.substring(start,end));
> +     public static Identity getByURI (ObjectContainer db, String uri) throws 
UnknownIdentityException, DuplicateIdentityException, MalformedURLException {
> +             return getByURI(db, new FreenetURI(uri));
>       }
>       
>       public static Identity getByURI (ObjectContainer db, FreenetURI uri) 
throws UnknownIdentityException, DuplicateIdentityException {
> -             return getByURI(db, uri.toString());
> +             return getById(db, new ByteArrayWrapper(uri.getRoutingKey()));
>       }
>       
>       
> 
> Modified: trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java
> ===================================================================
> --- trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java   2008-09-04 14:23:27 UTC 
(rev 22408)
> +++ trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java   2008-09-04 14:38:32 UTC 
(rev 22409)
> @@ -36,6 +36,7 @@
>  import com.db4o.query.Query;
>  
>  import freenet.keys.FreenetURI;
> +import freenet.support.ByteArrayWrapper;
>  
>  /**
>   * A local Identity (it belongs to the user)
> @@ -60,7 +61,7 @@
>       
>       
>       @SuppressWarnings("unchecked")
> -     public static OwnIdentity getById (ObjectContainer db, String id) 
> throws 
UnknownIdentityException, DuplicateIdentityException {
> +     public static OwnIdentity getById (ObjectContainer db, ByteArrayWrapper 
id) throws UnknownIdentityException, DuplicateIdentityException {
>               Query query = db.query();
>               query.constrain(OwnIdentity.class);
>               query.descend("id").constrain(id);
> @@ -71,16 +72,12 @@
>               return result.next();
>       }
>       
> -     public static OwnIdentity getByURI (ObjectContainer db, String uri) 
> throws 
UnknownIdentityException, DuplicateIdentityException {
> -             int start = uri.indexOf(',');
> -             int end = uri.indexOf(',', start + 1);
> -
> -             return getById(db, uri.substring(start,end));
> -
> +     public static OwnIdentity getByURI (ObjectContainer db, String uri) 
> throws 
UnknownIdentityException, DuplicateIdentityException, MalformedURLException {
> +             return getByURI(db, new FreenetURI(uri));
>       }
>  
>       public static OwnIdentity getByURI (ObjectContainer db, FreenetURI uri) 
throws UnknownIdentityException, DuplicateIdentityException {
> -             return getByURI(db, uri.toString());
> +             return getById(db, new ByteArrayWrapper(uri.getRoutingKey()));
>       }
>       
>               
> 
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20080906/8fa5ff6b/attachment.pgp>

Reply via email to