db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb repository.dtd
Date Fri, 02 May 2003 12:24:33 GMT
thma        2003/05/02 05:24:33

  Modified:    src/java/org/apache/ojb/broker/metadata RepositoryTags.java
                        ClassDescriptor.java RepositoryXmlHandler.java
                        CollectionDescriptor.java
                        ObjectReferenceDescriptor.java
                        RepositoryElements.java
               src/java/org/apache/ojb/broker/accesslayer RsIterator.java
                        RowReaderDefaultImpl.java RowReader.java
                        CollectionProxy.java
               xdocs    repository.xml
               src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/test/org/apache/ojb repository.dtd
  Log:
  OJB159: provide a new feature that allows to force refresh of all objects retrieved from
cache.
  the feature can be switched on by a new attribute refresh="true" on the class-descriptor
level.
  
  Revision  Changes    Path
  1.28      +1 -1      db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java
  
  Index: RepositoryTags.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- RepositoryTags.java	3 Apr 2003 20:35:26 -0000	1.27
  +++ RepositoryTags.java	2 May 2003 12:24:29 -0000	1.28
  @@ -152,7 +152,7 @@
           table.put("jdbc-level", new Integer(JDBC_LEVEL));
           table.put("locking", new Integer(LOCKING));
           table.put("update-lock", new Integer(UPDATE_LOCK));
  -        table.put("refresh", new Integer(REFRESH_REFERENCE));
  +        table.put("refresh", new Integer(REFRESH));
           table.put("proxy", new Integer(PROXY_REFERENCE));
           table.put("sort", new Integer(SORT));
   
  
  
  
  1.57      +34 -1     db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
  
  Index: ClassDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- ClassDescriptor.java	21 Apr 2003 08:03:48 -0000	1.56
  +++ ClassDescriptor.java	2 May 2003 12:24:30 -0000	1.57
  @@ -236,6 +236,13 @@
   	private Map m_fieldDescriptorNameMap = new HashMap();
   	private Map m_collectionDescriptorNameMap = new HashMap();
   	private Map m_objectReferenceDescriptorsNameMap = new HashMap();
  +	
  +	/**
  +	 * if true instances of this class are always refreshed
  +	 * even if they are already in the cache.
  +	 * false by default.
  +	 */
  +	private boolean alwaysRefresh = false;
   
   	/**
   	 * optional method to be invoked after instance fields are initialized
  @@ -1285,6 +1292,13 @@
   			result += "    " + tags.getAttribute(INITIALIZATION_METHOD, this.getInitializationMethod().getName())
+ eol;
   		}
   
  +        //reference refresh is optional, disabled by default
  +        if (isAlwaysRefresh())
  +        {
  +            result += "    " + tags.getAttribute(REFRESH, "true") + eol;
  +        }
  +
  +
   		result += "  >" + eol;
   
   		// end of attributes
  @@ -1636,5 +1650,24 @@
   	{
   		return this.initializationMethod;
   	}
  +
  +    /**
  +     * if true instances of this class are always refreshed
  +	 * even if they are already in the cache.
  +     * @return boolean
  +     */
  +    public boolean isAlwaysRefresh()
  +    {
  +        return alwaysRefresh;
  +    }
  +
  +    /**
  +     * Sets the alwaysRefresh parameter.
  +     * @param alwaysRefresh The value to set
  +     */
  +    public void setAlwaysRefresh(boolean alwaysRefresh)
  +    {
  +        this.alwaysRefresh = alwaysRefresh;
  +    }
   
   }
  
  
  
  1.41      +12 -5     db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java
  
  Index: RepositoryXmlHandler.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- RepositoryXmlHandler.java	18 Apr 2003 11:15:58 -0000	1.40
  +++ RepositoryXmlHandler.java	2 May 2003 12:24:30 -0000	1.41
  @@ -300,6 +300,13 @@
                               m_CurrentCLD.setInitializationMethod(initializationMethod);
                           }
   
  +                        // set refresh attribute
  +                        String refresh = atts.getValue(tags.getTagById(REFRESH));
  +                        if (isDebug) logger.debug("     " + tags.getTagById(REFRESH) +
": " + refresh);
  +                        b = (new Boolean(refresh)).booleanValue();
  +                        m_CurrentCLD.setAlwaysRefresh(b);
  +
  +
                           break;
                       }
   
  @@ -473,8 +480,8 @@
                           m_CurrentORD.setLazy(b);
   
                           // set refresh attribute
  -                        String refresh = atts.getValue(tags.getTagById(REFRESH_REFERENCE));
  -                        if (isDebug) logger.debug("     " + tags.getTagById(REFRESH_REFERENCE)
+ ": " + refresh);
  +                        String refresh = atts.getValue(tags.getTagById(REFRESH));
  +                        if (isDebug) logger.debug("     " + tags.getTagById(REFRESH) +
": " + refresh);
                           b = (new Boolean(refresh)).booleanValue();
                           m_CurrentORD.setRefresh(b);
   
  @@ -580,8 +587,8 @@
                           m_CurrentCOD.setLazy(b);
   
                           // set refresh attribute
  -                        String refresh = atts.getValue(tags.getTagById(REFRESH_REFERENCE));
  -                        if (isDebug) logger.debug("     " + tags.getTagById(REFRESH_REFERENCE)
+ ": " + refresh);
  +                        String refresh = atts.getValue(tags.getTagById(REFRESH));
  +                        if (isDebug) logger.debug("     " + tags.getTagById(REFRESH) +
": " + refresh);
                           b = (new Boolean(refresh)).booleanValue();
                           m_CurrentCOD.setRefresh(b);
   
  
  
  
  1.19      +2 -2      db-ojb/src/java/org/apache/ojb/broker/metadata/CollectionDescriptor.java
  
  Index: CollectionDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/CollectionDescriptor.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- CollectionDescriptor.java	26 Feb 2003 19:46:13 -0000	1.18
  +++ CollectionDescriptor.java	2 May 2003 12:24:31 -0000	1.19
  @@ -309,7 +309,7 @@
           //reference refresh is optional, disabled by default
           if (isRefresh())
           {
  -             result       += "        " + tags.getAttribute(REFRESH_REFERENCE,"true") +
eol;
  +             result       += "        " + tags.getAttribute(REFRESH,"true") + eol;
           }
   
           //auto retrieve is optional, enabled by default
  
  
  
  1.24      +1 -1      db-ojb/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java
  
  Index: ObjectReferenceDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- ObjectReferenceDescriptor.java	8 Apr 2003 20:19:30 -0000	1.23
  +++ ObjectReferenceDescriptor.java	2 May 2003 12:24:31 -0000	1.24
  @@ -379,7 +379,7 @@
           //reference refresh is optional, disabled by default
           if (isRefresh())
           {
  -            result += "        " + tags.getAttribute(REFRESH_REFERENCE, "true") + eol;
  +            result += "        " + tags.getAttribute(REFRESH, "true") + eol;
           }
   
           //auto retrieve is optional, enabled by default
  
  
  
  1.27      +1 -1      db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java
  
  Index: RepositoryElements.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- RepositoryElements.java	11 Apr 2003 20:58:02 -0000	1.26
  +++ RepositoryElements.java	2 May 2003 12:24:31 -0000	1.27
  @@ -113,7 +113,7 @@
       public static final int JDBC_LEVEL = 45;
       public static final int LOCKING = 46;
       public static final int UPDATE_LOCK = 98;
  -    public static final int REFRESH_REFERENCE = 47;
  +    public static final int REFRESH = 47;
       public static final int PROXY_REFERENCE = 48;
       public static final int ISOLATION_LEVEL = 34;
       public static final int FOREIGN_KEY = 49;
  
  
  
  1.35      +8 -2      db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
  
  Index: RsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- RsIterator.java	26 Apr 2003 23:18:25 -0000	1.34
  +++ RsIterator.java	2 May 2003 12:24:31 -0000	1.35
  @@ -448,15 +448,21 @@
                       }
                   }
               }
  -            else
  +            else // Object is in cache
               {
                   ClassDescriptor cld = m_cld.getRepository().getDescriptorFor(result.getClass());
  +                // if refresh is required, update the cache instance from the db
  +                if (cld.isAlwaysRefresh())
  +                {
  +                	m_cld.getRowReader().refreshObject(result, m_row);
  +                }
                   m_broker.refreshRelationships(result, cld);
               }
   
               return result;
           }
       }
  +
   
       /**
        * Reads primary key information from current RS row and generates a
  
  
  
  1.18      +20 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
  
  Index: RowReaderDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- RowReaderDefaultImpl.java	16 Mar 2003 12:04:32 -0000	1.17
  +++ RowReaderDefaultImpl.java	2 May 2003 12:24:32 -0000	1.18
  @@ -296,4 +296,23 @@
       {
           return cld;
       }
  +    
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.RowReader#refreshObject(Object, Map)
  +     */
  +    public void refreshObject(Object instance, Map row)
  +    {
  +    	// 1. select target ClassDescriptor
  +    	ClassDescriptor targetClassDescriptor = selectClassDescriptor(row);
  +        // 2. fill all scalar attributes of the existing object
  +        FieldDescriptor[] fields = targetClassDescriptor.getFieldDescriptions();
  +        FieldDescriptor fmd;
  +        for (int i = 0; i < fields.length; i++)
  +        {
  +            fmd = fields[i];
  +            fmd.getPersistentField().set(instance, row.get(fmd.getColumnName()));
  +        }
  +    	
  +    }
  +
   }
  
  
  
  1.6       +13 -4     db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReader.java
  
  Index: RowReader.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReader.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RowReader.java	19 Jan 2003 12:22:05 -0000	1.5
  +++ RowReader.java	2 May 2003 12:24:32 -0000	1.6
  @@ -65,12 +65,21 @@
   public interface RowReader extends Serializable
   {
       /**
  -     * materialize a single object of a type described by cld,
  -     * from the first row of the ResultSet rs.
  +     * materialize a single object from the values of the Map row.
        * the implementor of this class must not care for materializing
  -     *  references or collection attributes, this is done later!
  +     * references or collection attributes, this is done later!
  +     * @param row the Map containing the new values
  +     * @return a properly created instance.
        */
       public Object readObjectFrom(Map row);
  +
  +    /**
  +     * refresh an existing instance from the values of the Map row.
  +     * @param instance the instance to refresh
  +     * @param row the Map containing the new values
  +     */
  +    public void refreshObject(Object instance, Map row);
  +
   
   	/**
   	 * Read all fields from the current ResultRow into the Object[] row.#
  
  
  
  1.18      +1 -2      db-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionProxy.java
  
  Index: CollectionProxy.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionProxy.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- CollectionProxy.java	1 May 2003 17:23:58 -0000	1.17
  +++ CollectionProxy.java	2 May 2003 12:24:32 -0000	1.18
  @@ -66,7 +66,6 @@
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.core.PersistenceBrokerThreadMapping;
   import org.apache.ojb.broker.query.Query;
  -import org.apache.ojb.broker.util.collections.ManageableVector;
   import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
   
   /**
  
  
  
  1.18      +4 -0      db-ojb/xdocs/repository.xml
  
  Index: repository.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/xdocs/repository.xml,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- repository.xml	1 Apr 2003 14:06:11 -0000	1.17
  +++ repository.xml	2 May 2003 12:24:32 -0000	1.18
  @@ -416,6 +416,9 @@
   	The optional factory-method specifies a static no-argument method
   	that is to be used instead of a no argument constructor.<br/>
   	Important note: this feature is not yet implemented.
  +<br/><br/>	
  +	The refresh attribute can be set to true to force OJB to refresh
  +	instances when loaded from cache. It's set to false by default.
   </p>
   <source><![CDATA[
   <!ATTLIST class-descriptor
  @@ -430,6 +433,7 @@
   	accept-locks (true | false) "true"
   	initialization-method CDATA #IMPLIED
   	factory-method CDATA #IMPLIED
  +	refresh (true | false) "false"
   >
   ]]></source>
   
  
  
  
  1.3       +33 -2     db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PersistenceBrokerImpl.java	1 May 2003 17:23:58 -0000	1.2
  +++ PersistenceBrokerImpl.java	2 May 2003 12:24:32 -0000	1.3
  @@ -91,7 +91,6 @@
   import org.apache.ojb.broker.util.BrokerHelper;
   import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.ProxyHelper;
  -import org.apache.ojb.broker.util.collections.ManageableVector;
   import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
   import org.apache.ojb.broker.util.configuration.Configuration;
   import org.apache.ojb.broker.util.configuration.ConfigurationException;
  @@ -1671,6 +1670,12 @@
           else
           {
               ClassDescriptor cld = descriptorRepository.getDescriptorFor(obj.getClass());
  +            // if specified in the ClassDescriptor the instance must be refreshed
  +            if (cld.isAlwaysRefresh())
  +            {
  +            	refreshInstance(obj, id, cld);	
  +            }
  +            // now refresh all references
               refreshRelationships(obj, cld);
           }
   
  @@ -1682,6 +1687,32 @@
           return obj;
       }
   
  +	/**
  +	 * refresh all primitive typed attributes of a cached instance
  +	 * with the current values from the database.
  +	 * refreshing of reference and collection attributes is not done
  +	 * here.
  +	 * @param cachedInstance the cached instance to be refreshed
  +	 * @param oid the Identity of the cached instance
  +	 * @param cld the ClassDescriptor of cachedInstance 
  +	 */
  +	private void refreshInstance(Object cachedInstance, Identity oid, ClassDescriptor cld)
  +	{
  +		// read in fresh copy from the db
  +		Object freshInstance = getDBObject(oid);
  +				
  +		// update all primitive typed attributes
  +		FieldDescriptor[] fields = cld.getFieldDescriptions();
  +        FieldDescriptor fmd;
  +        PersistentField fld;
  +        for (int i = 0; i < fields.length; i++)
  +        {
  +            fmd = fields[i];
  +            fld = fmd.getPersistentField();            
  +            fld.set(cachedInstance, fld.get(freshInstance));
  +        }
  +	} 
  +	
       /**
        * retrieve an Object by query
        * I.e perform a SELECT ... FROM ... WHERE ...  in an RDBMS
  
  
  
  1.41      +5 -0      db-ojb/src/test/org/apache/ojb/repository.dtd
  
  Index: repository.dtd
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository.dtd,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- repository.dtd	3 Apr 2003 20:35:27 -0000	1.40
  +++ repository.dtd	2 May 2003 12:24:32 -0000	1.41
  @@ -319,6 +319,10 @@
   	The optional factory-method specifies a static no-argument method
   	that is to be used instead of a no argument constructor.
   	Important note: this feature is not yet implemented.
  +	
  +	The refresh attribute can be set to true to force OJB to refresh
  +	instances when loaded from cache. It's set to false by default.
  +
     -->
   <!ATTLIST class-descriptor
   	class ID #REQUIRED
  @@ -332,6 +336,7 @@
   	accept-locks (true | false) "true"
   	initialization-method CDATA #IMPLIED
   	factory-method CDATA #IMPLIED
  +	refresh (true | false) "false"
   >
   
   
  
  
  

Mime
View raw message