db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess AnonymousPersistentField.java AbstractPersistentField.java
Date Wed, 28 Jan 2004 20:04:50 GMT
arminw      2004/01/28 12:04:50

  Modified:    src/java/org/apache/ojb/broker/metadata/fieldaccess
                        AnonymousPersistentField.java
                        AbstractPersistentField.java
  Log:
  minor improvement
  
  Revision  Changes    Path
  1.11      +6 -10     db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentField.java
  
  Index: AnonymousPersistentField.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentField.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AnonymousPersistentField.java	27 Jan 2004 19:42:45 -0000	1.10
  +++ AnonymousPersistentField.java	28 Jan 2004 20:04:50 -0000	1.11
  @@ -71,8 +71,6 @@
   {
       private static final long serialVersionUID = 3989863424358352941L;
   
  -    private static final String NULL_VALUE = "ojbNullValue";
  -
       private transient Map fkCache;
       private String fieldname;
   
  @@ -124,19 +122,17 @@
               if (fkCache == null)
               {
                   fkCache = new ReferenceMap (ReferenceMap.WEAK, ReferenceMap.HARD, 10, 0.75f,
true);
  -                // fkCache = new WeakHashMap();
               }
  -            // thus we can't put 'null' as value, we use a replacement
  -            if(value == null) value = NULL_VALUE;
  -            fkCache.put(key, value);
  +            if (value != null)
  +                 fkCache.put(key, value);
  +             else
  +                 fkCache.remove (key);
           }
       }
   
       protected Object getFromFieldCache(Object key)
       {
  -        Object obj = (key != null && fkCache != null) ? fkCache.get(key) : null;
  -        if(obj == NULL_VALUE) obj = null;
  -        return obj;
  +        return (key != null && fkCache != null) ? fkCache.get(key) : null;
       }
   
       /**
  
  
  
  1.12      +18 -13    db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AbstractPersistentField.java
  
  Index: AbstractPersistentField.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AbstractPersistentField.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AbstractPersistentField.java	23 Jan 2004 23:45:38 -0000	1.11
  +++ AbstractPersistentField.java	28 Jan 2004 20:04:50 -0000	1.12
  @@ -282,11 +282,14 @@
       {
           Object result = null;
           int index = aFieldName.indexOf(PATH_TOKEN);
  +        // make sure not to use a proxy object
  +        Object realObj = ProxyHelper.getRealObject(obj);
  +        Class realClass = ProxyHelper.getRealClass(obj);
           if (index >= 0)
           {
               String name = aFieldName.substring(0, index);
  -            PersistentField pField = createInternPersistentField(ProxyHelper.getRealClass(obj),
name);
  -            Object attrib = pField.get(ProxyHelper.getRealObject(obj));
  +            PersistentField pField = createInternPersistentField(realClass, name);
  +            Object attrib = pField.get(realObj);
   
               if (attrib != null)
               {
  @@ -296,8 +299,8 @@
           }
           else
           {
  -            PersistentField pField = createInternPersistentField(ProxyHelper.getRealClass(obj),
aFieldName);
  -            result = pField.get(ProxyHelper.getRealObject(obj));
  +            PersistentField pField = createInternPersistentField(realClass, aFieldName);
  +            result = pField.get(realObj);
           }
           return result;
       }
  @@ -311,11 +314,13 @@
       protected void setNestedObject(Object obj, String fieldName, Object value)
       {
           int index = fieldName.indexOf(PATH_TOKEN);
  +        Class realClass = ProxyHelper.getRealClass(obj);
  +        Object realObj = ProxyHelper.getRealObject(obj);
           if (index >= 0)
           {
               String name = fieldName.substring(0, index);
  -            PersistentField pField = createInternPersistentField(ProxyHelper.getRealClass(obj),
name);
  -            Object attrib = pField.get(ProxyHelper.getRealObject(obj));
  +            PersistentField pField = createInternPersistentField(realClass, name);
  +            Object attrib = pField.get(realObj);
   
               if (attrib != null || value != null)
               {
  @@ -328,12 +333,12 @@
                       catch (InstantiationException e)
                       {
                           throw new MetadataException("Error instantiate field: "
  -                                + name + " in object:" + obj.getClass().getName(), e);
  +                                + name + " in object:" + realClass.getName(), e);
                       }
                       catch (IllegalAccessException e)
                       {
                           throw new MetadataException("Error getting field:"
  -                                + name + " in object:" + obj.getClass().getName(), e);
  +                                + name + " in object:" + realClass.getName(), e);
                       }
   
                       /*
  @@ -342,11 +347,11 @@
                       */
                       if (pField instanceof AbstractPersistentField)
                       {
  -                        ((AbstractPersistentField) pField).doSet(ProxyHelper.getRealObject(obj),
attrib);
  +                        ((AbstractPersistentField) pField).doSet(realObj, attrib);
                       }
                       else
                       {
  -                        pField.set(ProxyHelper.getRealObject(obj), attrib);
  +                        pField.set(realObj, attrib);
                       }
                   }
                   String nestedName = fieldName.substring(index + PATH_TOKEN.length());
  @@ -355,8 +360,8 @@
           }
           else
           {
  -            PersistentField pField = createInternPersistentField(ProxyHelper.getRealClass(obj),
fieldName);
  -            pField.set(ProxyHelper.getRealObject(obj), value);
  +            PersistentField pField = createInternPersistentField(realClass, fieldName);
  +            pField.set(realObj, value);
           }
   
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message