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/test/org/apache/ojb/broker/metadata MetadataTest.java
Date Wed, 17 Sep 2003 22:31:51 GMT
arminw      2003/09/17 15:31:51

  Modified:    src/test/org/apache/ojb Test_Repository.xml
                        repository_junit.xml repository_database.xml
                        repository.dtd OJB.properties
               src/test/org/apache/ojb/broker TreeTest.java
                        ObjectCacheTest.java
               src/test/org/apache/ojb/broker/metadata MetadataTest.java
  Removed:     src/test/org/apache/ojb/broker TreeGroup.java Tree.java
  Log:
  - add new cache tests
  - update test cases
  - add new property in OJB.properties file
  - add new element 'object-cache' in repository.dtd
  
  Revision  Changes    Path
  1.2       +32 -1     db-ojb/src/test/org/apache/ojb/Test_Repository.xml
  
  Index: Test_Repository.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/Test_Repository.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Test_Repository.xml	26 Feb 2003 00:00:15 -0000	1.1
  +++ Test_Repository.xml	17 Sep 2003 22:31:51 -0000	1.2
  @@ -26,7 +26,7 @@
       </attribute>
   
       <jdbc-connection-descriptor
  -        jcd-alias="runtime"
  +        jcd-alias="runtime_2"
           platform="Hsqldb"
           jdbc-level="2.0"
           driver="org.hsqldb.jdbcDriver"
  @@ -37,6 +37,11 @@
           password=""
           batch-mode="false"
       >
  +
  +        <object-cache class="org.apache.ojb.broker.cache.ObjectCacheEmptyImpl">
  +            <attribute attribute-name="attr_con" attribute-value="555"/>
  +        </object-cache>
  +
           <connection-pool
               maxActive="5"
               whenExhaustedAction="0"
  @@ -59,5 +64,31 @@
           </attribute>
   
       </jdbc-connection-descriptor>
  +
  +    <!-- test pc-class, this class is also declared in junit test metadata,
  +    so be careful in handle this metadata -->
  +    <class-descriptor
  +      class="org.apache.ojb.broker.metadata.MetadataTest$CacheObject"
  +      table="DO NOT USE"
  +    >
  +
  +        <object-cache class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
  +            <attribute attribute-name="attr_class" attribute-value="444"/>
  +        </object-cache>
  +
  +        <field-descriptor
  +         name="objId"
  +         column="OBJ_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +    </class-descriptor>
   
   </descriptor-repository>
  
  
  
  1.93      +15 -14    db-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.92
  retrieving revision 1.93
  diff -u -r1.92 -r1.93
  --- repository_junit.xml	17 Sep 2003 19:02:08 -0000	1.92
  +++ repository_junit.xml	17 Sep 2003 22:31:51 -0000	1.93
  @@ -1,4 +1,5 @@
   <!-- Mapping of classes used in junit tests and tutorials starts here -->
  +<!-- @version $Id$ -->
   
   <!-- Definitions for org.apache.ojb.ojb.broker.Article -->
      <class-descriptor
  @@ -1284,7 +1285,7 @@
   
   <!-- Definitions for org.apache.ojb.broker.Tree -->
      <class-descriptor
  -      class="org.apache.ojb.broker.Tree"
  +      class="org.apache.ojb.broker.TreeTest$Tree"
         table="TREE"
      >
         <field-descriptor
  @@ -1305,7 +1306,7 @@
         />
         <collection-descriptor
            name="childs"
  -         element-class-ref="org.apache.ojb.broker.Tree"
  +         element-class-ref="org.apache.ojb.broker.TreeTest$Tree"
            auto-retrieve="true"
            auto-update="true"
            auto-delete="true"
  @@ -1316,7 +1317,7 @@
   
   <!-- Definitions for org.apache.ojb.broker.TreeGroup -->
      <class-descriptor
  -      class="org.apache.ojb.broker.TreeGroup"
  +      class="org.apache.ojb.broker.TreeTest$TreeGroup"
         table="TREEGROUP"
      >
         <field-descriptor
  @@ -1342,19 +1343,19 @@
         />
         <reference-descriptor
            name="myParent"
  -         class-ref="org.apache.ojb.broker.TreeGroup"
  +         class-ref="org.apache.ojb.broker.TreeTest$TreeGroup"
         >
            <foreignkey field-ref="parentId"/>
         </reference-descriptor>
         <reference-descriptor
            name="myGroup"
  -         class-ref="org.apache.ojb.broker.TreeGroup"
  +         class-ref="org.apache.ojb.broker.TreeTest$TreeGroup"
         >
            <foreignkey field-ref="groupId"/>
         </reference-descriptor>
         <collection-descriptor
            name="children"
  -         element-class-ref="org.apache.ojb.broker.TreeGroup"
  +         element-class-ref="org.apache.ojb.broker.TreeTest$TreeGroup"
            auto-retrieve="true"
            auto-update="true"
            auto-delete="true"
  @@ -1363,7 +1364,7 @@
         </collection-descriptor>
         <collection-descriptor
            name="groupMembers"
  -         element-class-ref="org.apache.ojb.broker.TreeGroup"
  +         element-class-ref="org.apache.ojb.broker.TreeTest$TreeGroup"
            auto-retrieve="true"
            auto-update="true"
            auto-delete="true"
  @@ -3627,7 +3628,7 @@
       </class-descriptor>
   
       <class-descriptor
  -        class="org.apache.ojb.broker.ObjectCacheTest$CacheObject_2"
  +        class="org.apache.ojb.broker.ObjectCacheTest$CacheFilterObject"
           table="CACHE_TEST">
           <!-- when cache filtering is enabled this class was not cached -->
           <attribute
  @@ -3649,13 +3650,13 @@
       </class-descriptor>
   
   
  -<class-descriptor
  -        class="org.apache.ojb.broker.ObjectCacheTest$TestObject"
  +    <class-descriptor
  +        class="org.apache.ojb.broker.ObjectCacheTest$TestObjectEmptyCache"
           table="CACHE_TEST">
           <!-- declare a per class cache -->
  -        <attribute
  -            attribute-name="cacheClass"
  -            attribute-value="org.apache.ojb.broker.cache.ObjectCacheEmptyImpl"/>
  +        <object-cache class="org.apache.ojb.broker.cache.ObjectCacheEmptyImpl">
  +            <attribute attribute-name="test-attribute" attribute-value="test-value"/>
  +        </object-cache>
   
           <field-descriptor
            name="id"
  @@ -4625,7 +4626,7 @@
     		</reference-descriptor>
       </class-descriptor>
   
  - <class-descriptor
  +    <class-descriptor
           class="org.apache.ojb.broker.ObjectRepository$G"
           table="TABLE_G">
   
  
  
  
  1.15      +8 -2      db-ojb/src/test/org/apache/ojb/repository_database.xml
  
  Index: repository_database.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_database.xml,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- repository_database.xml	13 Sep 2003 14:52:28 -0000	1.14
  +++ repository_database.xml	17 Sep 2003 22:31:51 -0000	1.15
  @@ -13,7 +13,6 @@
   using the MetadataManager.
   -->
   
  -
       <!-- this connection was used as the default one within OJB -->
       <jdbc-connection-descriptor
      		jcd-alias="@JCD_ALIAS@"
  @@ -88,6 +87,7 @@
           password=""
           batch-mode="false"
       >
  +
           <connection-pool
               maxActive="6"
               whenExhaustedAction="0"
  @@ -124,6 +124,12 @@
           useAutoCommit="0"
           ignoreAutoCommitExceptions="true"
       >
  +
  +        <object-cache class="org.apache.ojb.broker.cache.ObjectCacheEmptyImpl">
  +            <attribute attribute-name="cacheKey1" attribute-value="cacheValue1"/>
  +            <attribute attribute-name="cacheKey2" attribute-value="cacheValue2"/>
  +        </object-cache>
  +
           <connection-pool
               maxActive="1"
               maxIdle="2"
  
  
  
  1.46      +49 -21    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.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- repository.dtd	9 Sep 2003 19:02:54 -0000	1.45
  +++ repository.dtd	17 Sep 2003 22:31:51 -0000	1.46
  @@ -2,6 +2,7 @@
   	ObJectRelationalBridge - Bridging Java objects and relational dabatases
   	This DTD describes the grammar of the Descriptor repository
   	Author: Thomas Mahler, (c) 2000, 2001, 2002, 2003
  +    @version $Id$
     -->
   
   <!--
  @@ -42,8 +43,6 @@
   -->
   <!ELEMENT documentation (#PCDATA)>
   
  -<!ELEMENT database-repository (jdbc-connection-descriptor*)>
  -
   <!--
   	The attribute element allows to add custom attributes.
   
  @@ -57,8 +56,7 @@
       define which sequence manager implementation should be used within
       the defined connection.
     -->
  -<!ELEMENT jdbc-connection-descriptor (documentation?, attribute*, connection-pool?, sequence-manager?)>
  -
  +<!ELEMENT jdbc-connection-descriptor (documentation?, attribute*, cache-object?, connection-pool?, sequence-manager?)>
   
   <!--
       The jcdAlias attribute is a shortcut name for the defined connection
  @@ -139,6 +137,36 @@
   
   
   <!--
  +    The object-cache element can be used to specify the ObjectCache
  +    implementation used by OJB. There are three levels for
  +    declaration:
  +        1. in OJB.properties file, to declare the standard (default)
  +        ObjectCache implementation.
  +        2. on jdbc-connection-descriptor level, to declare ObjectCache implementation
  +        on a per connection/user level
  +        3. on class-descriptor level, to declare ObjectCache implementation
  +        on a per class level
  +
  +    The priority of the declared object-cache elements are:
  +    per class > per jdbc descriptor > standard
  +
  +    E.g. if you declare ObjectCache 'cacheDef' as standard, set
  +    ObjectCache 'cacheA' in class-descriptor for class A and class B
  +    does not declare an object-cache element. Then OJB use cacheA as ObjectCache
  +    for class A and cacheDef for class B
  +-->
  +<!ELEMENT object-cache (documentation?, attribute*)>
  +
  +<!--
  +    Attribute 'class' specifies the full qualified class name of
  +    the used ObjectCache implementation.
  +-->
  +<!ATTLIST object-cache
  +    class                          CDATA #REQUIRED
  +>
  +
  +
  +<!--
   	The connection-pool element specifies the connection pooling
   	parameter.
   -->
  @@ -277,7 +305,7 @@
   	naming the derived classes.
   
   	A class-descriptor may contain user defined custom attribute elements.
  -    
  +
       The insert-procedure, update-procedure and delete-procedure elements
       identify the procedure/function that is defined in the database which
       will handle the insertion, update or deletion of an instance of this
  @@ -288,7 +316,7 @@
     -->
   <!ELEMENT class-descriptor
   	((documentation?, extent-class+, attribute*) |
  -	(documentation?, extent-class*, field-descriptor+,
  +	(documentation?, cache-object?, extent-class*, field-descriptor+,
   	 reference-descriptor*, collection-descriptor*,
        index-descriptor*, attribute*,
        insert-procedure?, update-procedure?, delete-procedure?))>
  @@ -330,7 +358,7 @@
   	also must be defined.
   	factory-method refers to a static no-argument method
   	of the factory-class class.
  -	
  +
   	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.
   
  @@ -397,7 +425,7 @@
   
   	The optional jdbc-type attribute specifies the JDBC type of the column.
   	If not specified OJB tries to identify the JDBC type by inspecting the
  -	Java attribute by reflection. 
  +	Java attribute by reflection.
   
   	The primarykey specifies if the column is a primary key column.
   
  @@ -459,7 +487,7 @@
   	jdbc-type (BIT | TINYINT | SMALLINT | INTEGER | BIGINT | DOUBLE |
   	           FLOAT | REAL | NUMERIC | DECIMAL | CHAR | VARCHAR |
   	           LONGVARCHAR | DATE | TIME | TIMESTAMP | BINARY |
  -	           VARBINARY | LONGVARBINARY | CLOB | BLOB) #IMPLIED
  +	           VARBINARY | LONGVARBINARY | CLOB | BLOB | BOOLEAN) #IMPLIED
   	primarykey (true | false) "false"
   	nullable (true | false) "true"
   	indexed (true | false) "false"
  @@ -645,7 +673,7 @@
       were set to true, but the auto-update and auto-delete attributes themself
       must be always set to false for use with OTM layer.
   
  -	
  +
     -->
   <!ATTLIST collection-descriptor
   	name CDATA #IMPLIED
  @@ -747,14 +775,14 @@
   
       The nested 'argument' elements define the argument list for the
       procedure/function as well as the source for each argument.
  -    
  +
       The name attribute identifies the name of the procedure/function to use
  -    
  +
       The return-field-ref identifies the field-descriptor that will receive
       the value that is returned by the procedure/function.  If the procedure/
       function does not include a return value, then do not specify a value
       for this attribute.
  -    
  +
       The include-all-fields attribute indicates if all field-descriptors in
       the corresponding class-descriptor are to be passed to the procedure/
       function.  If include-all-fields is 'true', any nested 'argument'
  @@ -779,14 +807,14 @@
   
       The nested 'argument' elements define the argument list for the
       procedure/function as well as the source for each argument.
  -    
  +
       The name attribute identifies the name of the procedure/function to use
  -    
  +
       The return-field-ref identifies the field-descriptor that will receive
       the value that is returned by the procedure/function.  If the procedure/
       function does not include a return value, then do not specify a value
       for this attribute.
  -    
  +
       The include-all-fields attribute indicates if all field-descriptors in
       the corresponding class-descriptor are to be passed to the procedure/
       function.  If include-all-fields is 'true', any nested 'argument'
  @@ -812,14 +840,14 @@
       The nested 'runtime-argument' and 'constant-argument' elements define
       the argument list for the procedure/function as well as the source
       for each argument.
  -    
  +
       The name attribute identifies the name of the procedure/function to use
  -    
  +
       The return-field-ref identifies the field-descriptor that will receive
       the value that is returned by the procedure/function.  If the procedure/
       function does not include a return value, then do not specify a value
       for this attribute.
  -    
  +
       The include-pk-only attribute indicates if all field-descriptors in
       the corresponding class-descriptor that are identified as being part of
       the primary key are to be passed to the procedure/function.  If
  @@ -841,7 +869,7 @@
   <!--
       Defines an argument that is passed to a procedure/function.  Each argument
       will be set to a value from a field-descriptor or null.
  -    
  +
       The field-ref attribute identifies the field-descriptor in the corresponding
       class-descriptor that provides the value for this argument.  If this attribute
       is unspecified, then this argument will be set to null.
  @@ -854,7 +882,7 @@
   >
   <!--
       Defines a constant value that is passed to a procedure/function.
  -    
  +
       The value attribute identifies the value that is passed to the procedure/
       function.
   -->
  
  
  
  1.58      +25 -11    db-ojb/src/test/org/apache/ojb/OJB.properties
  
  Index: OJB.properties
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/OJB.properties,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- OJB.properties	13 Sep 2003 21:28:15 -0000	1.57
  +++ OJB.properties	17 Sep 2003 22:31:51 -0000	1.58
  @@ -164,13 +164,27 @@
   #----------------------------------------------------------------------------------------
   # Object cache
   #----------------------------------------------------------------------------------------
  -# The ObjectCacheClass entry tells OJB which concrete instance Cache
  -# implementation is to be used.
  +# The ObjectCacheClass entry tells OJB which concrete ObjectCache
  +# implementation is to be used as standard cache.
  +# Its also possible to override this entry adding object-cache elements
  +# on jdbc-connection-descriptor level and
  +# per class-descriptor in repository file. More info see documentation.
  +#
   ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCacheDefaultImpl
   #ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCacheEmptyImpl
   #ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl
  -#ObjectCacheClass=org.apache.ojb.broker.cache.MetaObjectCacheJCSImpl
  -#ObjectCacheClass=org.apache.ojb.broker.cache.MetaObjectCachePerClassImpl
  +#ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCacheJCSPerClassImpl
  +#ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCachePerClassImpl
  +#
  +#
  +# This property is only relevant if the per class-descriptor object-cache
  +# declaration was used in conjunction with metadata runtime changes.
  +# If set 'flase' the class name of the object is used
  +# to find a per class ObjectCache implementation.
  +# If set 'true' the ObjectCacheDescriptor instance is used as key to
  +# find a per class ObjectCache, this enables to use different ObjectCache
  +# instances for the same class.
  +descriptorBasedCaches=false
   #
   #
   # Use CacheFilters to do filter operations before caching methods were
  @@ -256,8 +270,8 @@
   DEFAULT.LogLevel=WARN
   # Logger for PersistenceBrokerImpl class
   org.apache.ojb.broker.core.PersistenceBrokerImpl.LogLevel=WARN
  -# Logger for PersistenceBrokerFactory class
  -org.apache.ojb.broker.PersistenceBrokerFactory.LogLevel=WARN
  +# Logger for PersistenceBrokerFactory class PersistenceBrokerFactoryDefaultImpl
  +org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.LogLevel=WARN
   # Logger for RepositoryXmlHandler, useful for debugging parsing of repository.xml!
   org.apache.ojb.broker.metadata.RepositoryXmlHandler.LogLevel=WARN
   # Logger for JdbcAccess, useful for debugging JDBC related problems
  @@ -270,10 +284,10 @@
   org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.LogLevel=WARN
   # Logger for RepositoryPersistor
   org.apache.ojb.broker.metadata.RepositoryPersistor.LogLevel=WARN
  -# Logger for PersistenceBrokerFactoryDefaultImpl
  -org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.LogLevel=WARN
  -# Logger for ConnectionFactory
  -org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.LogLevel=ERROR
  +# Logger for ConnectionFactory base class
  +org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.LogLevel=WARN
  +# Logger for ConnectionManager
  +org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.LogLevel=WARN
   #
   # Special Logger categories used in test suite and tutorials
   #
  
  
  
  1.8       +514 -71   db-ojb/src/test/org/apache/ojb/broker/TreeTest.java
  
  Index: TreeTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/TreeTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TreeTest.java	8 Mar 2003 19:22:56 -0000	1.7
  +++ TreeTest.java	17 Sep 2003 22:31:51 -0000	1.8
  @@ -34,12 +34,11 @@
   	 * Insert the method's description here.
   	 * Creation date: (13.02.2001 18:50:29)
   	 * @return TestThreadsNLocks.org.apache.ojb.broker.Tree
  -	 * @param parent TestThreadsNLocks.org.apache.ojb.broker.Tree
   	 */
   	public TreeGroup createTreeGroup() throws Exception
   	{
   		TreeGroup result = new TreeGroup();
  -		
  +
   		FieldDescriptor idFld = broker.getClassDescriptor(Tree.class).getFieldDescriptorByName("id");
   		Integer idVal = (Integer) broker.serviceSequenceManager().getUniqueValue(idFld);
   
  @@ -64,7 +63,7 @@
   		{
   			FieldDescriptor idFld = broker.getClassDescriptor(Tree.class).getFieldDescriptorByName("id");
   			Integer idVal = (Integer) broker.serviceSequenceManager().getUniqueValue(idFld);
  -			
  +
   			result.setId(idVal.intValue());
   		}
   		catch (PersistenceBrokerException e)
  @@ -119,7 +118,7 @@
   			{
   				FieldDescriptor idFld = broker.getClassDescriptor(Tree.class).getFieldDescriptorByName("id");
   				Integer idVal = (Integer) broker.serviceSequenceManager().getUniqueValue(idFld);
  -			
  +
   				root.setId(idVal.intValue());
   			}
   			catch (PersistenceBrokerException e)
  @@ -170,81 +169,525 @@
   	}
   
   	/**
  +     *
   	 */
   	public void testTreeGroup() throws Exception
   	{
  -		try
  -		{
  -			TreeGroup root = createTreeGroup();
  -			root.setData("The Tree Group root: " + root.getId());
  -			TreeGroup green = createTreeGroup();
  -			green.setData("the GREEN group" + green.getId());
  -			TreeGroup red = createTreeGroup();
  -			red.setData("the RED group" + red.getId());
  -
  -			TreeGroup child;
  -			for (int i = 0; i < 3; i++)
  -			{
  -				child = createTreeGroup();
  -				root.addChild(child);
  -				green.addMember(child);
  -				child = createTreeGroup();
  -				root.addChild(child);
  -				red.addMember(child);
  -			}
  +        TreeGroup root = createTreeGroup();
  +        root.setData("The Tree Group root: " + root.getId());
  +        TreeGroup green = createTreeGroup();
  +        green.setData("the GREEN group " + green.getId());
  +        TreeGroup red = createTreeGroup();
  +        red.setData("the RED group " + red.getId());
  +
  +        TreeGroup child;
  +        for (int i = 0; i < 3; i++)
  +        {
  +            child = createTreeGroup();
  +            root.addChild(child);
  +            green.addMember(child);
  +            child = createTreeGroup();
  +            root.addChild(child);
  +            red.addMember(child);
  +        }
  +
  +        for (int i = 0; i < 6; i++)
  +        {
  +            child = root.getChild(i);
  +            child.addChild(createTreeGroup());
  +        }
  +
  +        //System.out.println("original TreeGroup:");
  +        //System.out.println(root);
  +        //System.out.println("GREEN TreeGroup:");
  +        //System.out.println(green);
  +        //System.out.println("RED TreeGroup:");
  +        //System.out.println(red);
  +        broker.beginTransaction();
  +        broker.store(root);
  +        broker.store(green);
  +        broker.store(red);
  +        broker.commitTransaction();
  +
  +        Identity oid = new Identity(root, broker);
  +
  +        broker.clearCache();
  +
  +        TreeGroup root_r = (TreeGroup) broker.getObjectByIdentity(oid);
  +        //System.out.println("tree after reading from db:");
  +        //System.out.println(root_r);
  +        assertNotNull(root_r);
  +        assertEquals(
  +            "tree should have same size after retrival",
  +            root.size(),
  +            root_r.size());
  +
  +        oid = new Identity(green, broker);
  +        TreeGroup green_r = (TreeGroup) broker.getObjectByIdentity(oid);
  +        //System.out.println("tree after reading from db:");
  +        //System.out.println(green_r);
  +        assertEquals(
  +            "tree should have same size after retrival",
  +            green.size(),
  +            green_r.size());
  +
  +        oid = new Identity(red, broker);
  +        TreeGroup red_r = (TreeGroup) broker.getObjectByIdentity(oid);
  +        //System.out.println("tree after reading from db:");
  +        //System.out.println(red_r);
  +        assertEquals(
  +            "tree should have same size after retrival",
  +            red.size(),
  +            red_r.size());
   
  -			for (int i = 0; i < 6; i++)
  -			{
  -				child = root.getChild(i);
  -				child.addChild(createTreeGroup());
  -			}
  -
  -			//System.out.println("original TreeGroup:");
  -			//System.out.println(root);
  -			//System.out.println("GREEN TreeGroup:");
  -			//System.out.println(green);
  -			//System.out.println("RED TreeGroup:");
  -			//System.out.println(red);
  -
  -			broker.store(root);
  -			broker.store(green);
  -			broker.store(red);
  +	}
   
  -			Identity oid = new Identity(root, broker);
   
  -			broker.clearCache();
   
  -			TreeGroup root_r = (TreeGroup) broker.getObjectByIdentity(oid);
  -			//System.out.println("tree after reading from db:");
  -			//System.out.println(root_r);
  -			assertEquals(
  -				"tree should have same size after retrival",
  -				root.size(),
  -				root_r.size());
  +    
  +    //*****************************************************************
  +    // inner classes - test objects
  +    //*****************************************************************
  +
  +    /**
  +     * Tree is  recursive type: a Tree element contains some data
  +     * and a Vector of child Tree elements.
  +     * This sample demonstrates what is needed to map such a data
  +     * structure on a DB table
  +     * @author Thomas Mahler
  +     */
  +    public static class Tree implements java.io.Serializable
  +    {
  +        private int id;
  +        private String data;
  +        private int parentId;
  +        private Vector childs;
  +
  +        /**
  +         * Tree constructor comment.
  +         */
  +        public Tree()
  +        {
  +            super();
  +        }
  +
  +        /**
  +         * Tree constructor comment.
  +         */
  +        public Tree(int id, String data, int parentid)
  +        {
  +            this.id = id;
  +            this.data = data;
  +            this.parentId = parentid;
  +        }
  +
  +        public void addChild(Tree newChild)
  +        {
  +            if (childs == null) childs = new Vector();
  +
  +            childs.add(newChild);
  +
  +        }
  +
  +        public Tree getChild(int index)
  +        {
  +            return (Tree) childs.get(index);
  +
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @return java.util.Vector
  +         */
  +        public java.util.Vector getChilds()
  +        {
  +            return childs;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @return java.lang.String
  +         */
  +        public java.lang.String getData()
  +        {
  +            return data;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @return int
  +         */
  +        public int getId()
  +        {
  +            return id;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @return int
  +         */
  +        public int getParentId()
  +        {
  +            return parentId;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @param newChilds java.util.Vector
  +         */
  +        public void setChilds(java.util.Vector newChilds)
  +        {
  +            childs = newChilds;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @param newData java.lang.String
  +         */
  +        public void setData(java.lang.String newData)
  +        {
  +            data = newData;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @param newId int
  +         */
  +        public void setId(int newId)
  +        {
  +            id = newId;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @param newParentId int
  +         */
  +        public void setParentId(int newParentId)
  +        {
  +            parentId = newParentId;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (14.02.2001 19:51:23)
  +         * @return int
  +         */
  +        public int size()
  +        {
  +            int result = 1;
  +            for (int i = 0; i < childs.size(); i++)
  +            {
  +                result += ((Tree) childs.get(i)).size();
  +            }
  +            return result;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:41)
  +         * @return java.lang.String
  +         */
  +        public String toString()
  +        {
  +
  +            return data + ((childs == null) ? "" : childs.toString());
  +        }
  +    }
  +
  +    /**
  +     * Tree is  recursive type: a Tree element contains some data
  +     * and a Vector of child Tree elements.
  +     * This sample demonstrates what is needed to map such a data
  +     * structure on a DB table
  +     * @author Thomas Mahler
  +     */
  +    public static class TreeGroup implements java.io.Serializable
  +    {
  +        private int id;
  +        private String data;
  +
  +        private int parentId;
  +        private Vector children;
  +        private TreeGroup myParent;
  +
  +        private int groupId;
  +        private Vector groupMembers;
  +        private TreeGroup myGroup;
  +
  +
  +        /**
  +         * Tree constructor comment.
  +         */
  +        public TreeGroup()
  +        {
  +            super();
  +        }
  +
  +        /**
  +         * Tree constructor comment.
  +         */
  +        public TreeGroup(int id, String data, int parentid, int groupid)
  +        {
  +            this.id = id;
  +            this.data = data;
  +            this.parentId = parentid;
  +            this.groupId = groupid;
  +        }
  +
  +        public void addChild(TreeGroup newChild)
  +        {
  +            if (children == null) children = new Vector();
  +
  +            children.add(newChild);
  +            newChild.setParentId(this.getId());
  +
  +        }
  +
  +        public void addMember(TreeGroup newMember)
  +        {
  +            if (groupMembers == null) groupMembers = new Vector();
  +
  +            groupMembers.add(newMember);
  +            newMember.setGroupId(this.getId());
  +
  +        }
  +
  +        public TreeGroup getChild(int index)
  +        {
  +            return (TreeGroup) children.get(index);
  +
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @return java.util.Vector
  +         */
  +        public Vector getChilds()
  +        {
  +            return children;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @return java.lang.String
  +         */
  +        public String getData()
  +        {
  +            return data;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @return int
  +         */
  +        public int getGroupId()
  +        {
  +            return groupId;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @return int
  +         */
  +        public int getId()
  +        {
  +            return id;
  +        }
  +
  +        public TreeGroup getMember(int index)
  +        {
  +            return (TreeGroup) groupMembers.get(index);
  +
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @return java.util.Vector
  +         */
  +        public Vector getMembers()
  +        {
  +            return groupMembers;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @return int
  +         */
  +        public int getParentId()
  +        {
  +            return parentId;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @param newChilds java.util.Vector
  +         */
  +        public void setChilds(java.util.Vector newChilds)
  +        {
  +            children = newChilds;
  +        }
  +
  +        /**
  +         * Sets the data.
  +         * @param data The data to set
  +         */
  +        public void setData(String data)
  +        {
  +            this.data = data;
  +        }
  +
  +        /**
  +         * Sets the groupId.
  +         * @param groupId The groupId to set
  +         */
  +        public void setGroupId(int groupId)
  +        {
  +            this.groupId = groupId;
  +        }
  +
  +        /**
  +         * Sets the id.
  +         * @param id The id to set
  +         */
  +        public void setId(int id)
  +        {
  +            this.id = id;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:02)
  +         * @param newMembers java.util.Vector
  +         */
  +        public void setMembers(java.util.Vector newMembers)
  +        {
  +            groupMembers = newMembers;
  +        }
  +
  +        /**
  +         * Sets the parentId.
  +         * @param parentId The parentId to set
  +         */
  +        public void setParentId(int parentId)
  +        {
  +            this.parentId = parentId;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (14.02.2001 19:51:23)
  +         * @return int
  +         */
  +        public int size()
  +        {
  +            int result = 1;
  +            if(children == null) return result;
  +            for (int i = 0; i < children.size(); i++)
  +            {
  +                result += ((TreeGroup) children.get(i)).size();
  +            }
  +            return result;
  +        }
  +
  +        /**
  +         * Insert the method's description here.
  +         * Creation date: (13.02.2001 18:33:41)
  +         * @return java.lang.String
  +         */
  +        public String toString()
  +        {
  +            return data
  +                    + ((children == null || (children.size() == 0)) ? "" : " children: " + children.toString())
  +                    + ((groupMembers == null || (groupMembers.size() == 0)) ? "" : " members: " + groupMembers.toString());
  +        }
  +        /**
  +         * Gets the children.
  +         * @return Returns a Vector
  +         */
  +        public Vector getChildren()
  +        {
  +            return children;
  +        }
  +
  +        /**
  +         * Sets the children.
  +         * @param children The children to set
  +         */
  +        public void setChildren(Vector children)
  +        {
  +            this.children = children;
  +        }
  +
  +        /**
  +         * Gets the groupMembers.
  +         * @return Returns a Vector
  +         */
  +        public Vector getGroupMembers()
  +        {
  +            return groupMembers;
  +        }
  +
  +        /**
  +         * Sets the groupMembers.
  +         * @param groupMembers The groupMembers to set
  +         */
  +        public void setGroupMembers(Vector groupMembers)
  +        {
  +            this.groupMembers = groupMembers;
  +        }
  +
  +        /**
  +         * Gets the myGroup.
  +         * @return Returns a TreeGroup
  +         */
  +        public TreeGroup getMyGroup()
  +        {
  +            return myGroup;
  +        }
  +
  +        /**
  +         * Sets the myGroup.
  +         * @param myGroup The myGroup to set
  +         */
  +        public void setMyGroup(TreeGroup myGroup)
  +        {
  +            this.myGroup = myGroup;
  +        }
  +
  +        /**
  +         * Gets the myParent.
  +         * @return Returns a TreeGroup
  +         */
  +        public TreeGroup getMyParent()
  +        {
  +            return myParent;
  +        }
  +
  +        /**
  +         * Sets the myParent.
  +         * @param myParent The myParent to set
  +         */
  +        public void setMyParent(TreeGroup myParent)
  +        {
  +            this.myParent = myParent;
  +        }
   
  -			oid = new Identity(green, broker);
  -			TreeGroup green_r = (TreeGroup) broker.getObjectByIdentity(oid);
  -			//System.out.println("tree after reading from db:");
  -			//System.out.println(green_r);
  -			assertEquals(
  -				"tree should have same size after retrival",
  -				green.size(),
  -				green_r.size());
  +    }
   
  -			oid = new Identity(red, broker);
  -			TreeGroup red_r = (TreeGroup) broker.getObjectByIdentity(oid);
  -			//System.out.println("tree after reading from db:");
  -			//System.out.println(red_r);
  -			assertEquals(
  -				"tree should have same size after retrival",
  -				red.size(),
  -				red_r.size());
   
  -		}
  -		catch (Throwable t)
  -		{
  -			System.out.println(t.getMessage());
  -			fail(t.getMessage());
  -		}
  -	}
   }
  
  
  
  1.8       +102 -50   db-ojb/src/test/org/apache/ojb/broker/ObjectCacheTest.java
  
  Index: ObjectCacheTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ObjectCacheTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ObjectCacheTest.java	5 Sep 2003 15:01:47 -0000	1.7
  +++ ObjectCacheTest.java	17 Sep 2003 22:31:51 -0000	1.8
  @@ -1,25 +1,27 @@
   package org.apache.ojb.broker;
   
  -import java.io.Serializable;
  -
   import junit.framework.TestCase;
  -
   import org.apache.ojb.broker.cache.CacheFilterClassImpl;
   import org.apache.ojb.broker.cache.CacheFilterPackageImpl;
  -import org.apache.ojb.broker.cache.MetaObjectCacheJCSImpl;
  -import org.apache.ojb.broker.cache.MetaObjectCachePerClassImpl;
   import org.apache.ojb.broker.cache.ObjectCache;
   import org.apache.ojb.broker.cache.ObjectCacheDefaultImpl;
   import org.apache.ojb.broker.cache.ObjectCacheFactory;
   import org.apache.ojb.broker.cache.ObjectCacheJCSImpl;
  +import org.apache.ojb.broker.cache.ObjectCacheJCSPerClassImpl;
   import org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl;
  +import org.apache.ojb.broker.cache.ObjectCachePerClassImpl;
  +import org.apache.ojb.broker.cache.ObjectCacheLocalDefaultImpl;
  +import org.apache.ojb.broker.metadata.ConnectionRepository;
   import org.apache.ojb.broker.metadata.MetadataManager;
  +import org.apache.ojb.broker.metadata.MetadataTest;
   import org.apache.ojb.broker.query.QueryByIdentity;
   import org.apache.ojb.broker.sequence.Repository;
   import org.apache.ojb.broker.util.GUID;
   import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
   import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
   
  +import java.io.Serializable;
  +
   /**
    * Do some basic tests using ObjectCache implementations.
    *
  @@ -35,10 +37,11 @@
       Class[] objectCacheImpls = new Class[]{
           // ObjectCacheEmptyImpl.class,
           ObjectCacheDefaultImpl.class,
  +        ObjectCacheLocalDefaultImpl.class,
           ObjectCachePerBrokerImpl.class,
           ObjectCacheJCSImpl.class,
  -        MetaObjectCacheJCSImpl.class,
  -        MetaObjectCachePerClassImpl.class
  +        ObjectCacheJCSPerClassImpl.class,
  +        ObjectCachePerClassImpl.class
       };
   
       String[] cacheFilter = new String[]{
  @@ -80,15 +83,25 @@
           return (OjbConfiguration) OjbConfigurator.getInstance().getConfigurationFor(null);
       }
   
  +    /**
  +     * Check base caching functions of some cache implementations.
  +     *
  +     * @throws Exception
  +     */
       public void testSimpleObjectCacheFunctions() throws Exception
       {
  -        for(int i=0;i<objectCacheImpls.length;i++)
  +        for (int i = 0; i < objectCacheImpls.length; i++)
           {
               ObjectCacheFactory.getInstance().setClassToServe(objectCacheImpls[i]);
               checkBaseFunctions();
           }
       }
   
  +    /**
  +     * This test check the CacheFilter feature and the two standard implementations
  +     * enable per class and per package out-filtering of objects.
  +     * @throws Exception
  +     */
       public void testCacheFilterFunctions() throws Exception
       {
           getConfig().setCacheFilters(cacheFilter);
  @@ -96,7 +109,7 @@
                   addAttribute(CacheFilterPackageImpl.EXCLUDE_PACKAGES, EXCLUDE_PACKAGE);
           MetadataManager.getInstance().connectionRepository().getDescriptor(TestHelper.DEF_KEY).
                   addAttribute(CacheFilterPackageImpl.EXCLUDE_PACKAGES, EXCLUDE_PACKAGE_NOT_EXIST);
  -        for(int i=0;i<objectCacheImpls.length;i++)
  +        for (int i = 0; i < objectCacheImpls.length; i++)
           {
               ObjectCacheFactory.getInstance().setClassToServe(objectCacheImpls[i]);
               PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  @@ -106,7 +119,7 @@
                   CacheObject obj = new CacheObject(null, "CacheObject persistent obj");
                   Identity oid = new Identity(obj, broker);
   
  -                CacheObject filterOutObject = new CacheObject_2(null, "CacheObject_2 persistent obj");
  +                CacheObject filterOutObject = new CacheFilterObject(null, "CacheFilterObject persistent obj");
                   Identity filterOutOid = new Identity(filterOutObject, broker);
   
                   Repository.SMKey filterOutPackageObject = new Repository.SMKey();
  @@ -115,11 +128,11 @@
   
                   Object result = null;
                   cache.clear();
  -                result = (CacheObject) cache.lookup(oid);
  +                result = cache.lookup(oid);
                   assertNull(result);
  -                result = (CacheObject) cache.lookup(filterOutOid);
  +                result = cache.lookup(filterOutOid);
                   assertNull(result);
  -                result = (CacheObject) cache.lookup(filterOutPackageOid);
  +                result = cache.lookup(filterOutPackageOid);
                   assertNull(result);
   
                   // cache it
  @@ -128,12 +141,12 @@
                   cache.cache(filterOutOid, filterOutObject);
   
                   // lookup things
  -                result = (CacheObject) cache.lookup(oid);
  +                result = cache.lookup(oid);
                   assertNotNull(result);
                   assertEquals(obj, result);
  -                result = (CacheObject) cache.lookup(filterOutOid);
  +                result = cache.lookup(filterOutOid);
                   assertNull(result);
  -                result = (Repository.SMKey) cache.lookup(filterOutPackageOid);
  +                result = cache.lookup(filterOutPackageOid);
                   assertNull(result);
               }
               finally
  @@ -143,14 +156,14 @@
           }
       }
   
  -	/**
  -	 * This test checks if the caches of two different brokers are properly isolated.
  -	 * changes made to an object in tx1 should not be visible in tx2 !
  -	 * TODO: once we work without global cache this test should pass!
  -	 */
  +    /**
  +     * This test checks if the caches of two different brokers are properly isolated.
  +     * changes made to an object in tx1 should not be visible in tx2 !
  +     * TODO: once we work without global cache only (e.g. intern temporary cache), this test should pass!
  +     */
       public void YYYtestCacheIsolation() throws Exception
       {
  -        Object[] pk = new Object[] { new Long(42)};
  +        Object[] pk = new Object[]{new Long(42)};
           Identity oid = new Identity(Article.class, InterfaceArticle.class, pk);
   
           GUID guid = new GUID();
  @@ -162,7 +175,7 @@
           String originalName = a1.getArticleName();
           a1.setArticleName(guid.toString());
   
  -        // start a second transaction
  +// start a second transaction
           PersistenceBroker broker2 = PersistenceBrokerFactory.defaultPersistenceBroker();
           broker2.beginTransaction();
   
  @@ -174,12 +187,17 @@
   
   
           broker1.commitTransaction();
  -		broker1.close();
  +        broker1.close();
   
           broker2.commitTransaction();
  -		broker2.close();
  +        broker2.close();
       }
   
  +    /**
  +     * Checks the base functions of the current ObjectCache implementation.
  +     *
  +     * @throws Exception
  +     */
       private void checkBaseFunctions() throws Exception
       {
           PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  @@ -191,21 +209,28 @@
               CacheObject obj2 = new CacheObject(null, "ObjectCache test 2");
               Identity oid2 = new Identity(obj2, broker);
               cache.clear();
  -            Object result = (CacheObject) cache.lookup(oid);
  +            Object result = cache.lookup(oid);
               assertNull(result);
   
               cache.cache(oid, obj);
               cache.cache(oid2, obj2);
  -            result = (CacheObject) cache.lookup(oid);
  +            result = cache.lookup(oid);
               assertNotNull(result);
               assertEquals(obj, result);
               assertNotSame(obj2, result);
  +System.out.println("## "+cache);
  +            cache.remove(oid);
  +            result = cache.lookup(oid);
  +            Object result2 = cache.lookup(oid2);
  +            assertNull(result);
  +            assertNotNull(result2);
   
               cache.clear();
  -            result = (CacheObject) cache.lookup(oid);
  +            result = cache.lookup(oid);
               assertNull(result);
  -            result = (CacheObject) cache.lookup(oid2);
  +            result = cache.lookup(oid2);
               assertNull(result);
  +            // cache.clear();
           }
           finally
           {
  @@ -214,17 +239,17 @@
       }
   
       /**
  -     * Test per class ObjectCache declaration. TestObject
  -     * metadata declare an 'empty ObjectCache' implementation
  +     * Test per class ObjectCache declaration. 'TestObjectEmptyCache'
  +     * class metadata declare an 'empty ObjectCache' implementation
        * as cache, CacheObject use the default ObjectCache implementation.
  -     * Thus we found CacheObject instance in cache, but NOT found
  -     * TestObject instance.
  +     * Thus we should found 'CacheObject' instance in cache, but NOT found
  +     * 'TestObjectEmptyCache' instance.
        */
  -    public void YYYtestPerClassCache()
  +    public void testPerClassCache() throws Exception
       {
           String name = "testPerClassCache_" + System.currentTimeMillis();
   
  -        TestObject obj = new TestObject();
  +        TestObjectEmptyCache obj = new TestObjectEmptyCache();
           obj.setName(name);
           CacheObject dummy = new CacheObject();
           dummy.setName(name);
  @@ -242,27 +267,46 @@
               ObjectCache cache = broker.serviceObjectCache();
               Object ret_obj = cache.lookup(obj_oid);
               Object ret_dummy = cache.lookup(dummy_oid);
  -            assertNull(ret_obj);
               assertNotNull(ret_dummy);
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -            if(broker != null && broker.isInTransaction()) broker.abortTransaction();
  +            assertNull(ret_obj);
           }
           finally
           {
  -            if(broker != null) broker.close();
  +            if (broker != null && broker.isInTransaction()) broker.abortTransaction();
  +            if (broker != null) broker.close();
           }
       }
   
  -    public void YYYtestPerDatabaseCache()
  +    /**
  +     * Read a specific jdbc-connction-descriptor at runtime, merge it with current
  +     * ConnectionRepository, lookup a specific PersistenceBroker instance, get ObjectCache.
  +     * This should be ObjectCacheEmptyImpl, because this is declared at jdbc-connection-descriptor
  +     * level.
  +     */
  +    public void testPerDatabaseCache()
       {
  +        ConnectionRepository cr = MetadataManager.getInstance()
  +                .readConnectionRepository(MetadataTest.TEST_REPOSITORY);
  +        MetadataManager.getInstance().mergeConnectionRepository(cr);
   
  +        PersistenceBroker pb = PersistenceBrokerFactory.createPersistenceBroker(new PBKey("runtime_2"));
  +        try
  +        {
  +            ObjectCache oc = pb.serviceObjectCache();
  +            CacheObject testObj = new CacheObject(null, "testPerDatabaseCache");
  +            Identity oid = new Identity(testObj, pb);
  +            oc.cache(oid, testObj);
  +            Object result = oc.lookup(oid);
  +            assertNull("We should not found this object in cache", result);
  +        }
  +        finally
  +        {
  +            if (pb != null && !pb.isClosed()) pb.close();
  +            MetadataManager.getInstance().connectionRepository().removeDescriptor(cr.getAllDescriptor().get(0));
  +        }
       }
   
   
  -
       // **********************************************************************
       // inner class
       // **********************************************************************
  @@ -302,24 +346,32 @@
           }
       }
   
  -    public static class CacheObject_2 extends CacheObject
  +    /**
  +     * in class-descriptor CacheFilter attribute 'cacheable=false'
  +     * is declared
  +     */
  +    public static class CacheFilterObject extends CacheObject
       {
  -        public CacheObject_2(Integer objId, String name)
  +        public CacheFilterObject(Integer objId, String name)
           {
               super(objId, name);
           }
   
  -        public CacheObject_2()
  +        public CacheFilterObject()
           {
           }
       }
   
  -    public static class TestObject
  +    /**
  +     * in class-descriptor ObjectCacheEmptyImpl class is declared
  +     * as cache implementation.
  +     */
  +    public static class TestObjectEmptyCache
       {
           private Integer id;
           private String name;
   
  -        public TestObject()
  +        public TestObjectEmptyCache()
           {
           }
   
  
  
  
  1.12      +66 -0     db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataTest.java
  
  Index: MetadataTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataTest.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- MetadataTest.java	13 Aug 2003 18:05:35 -0000	1.11
  +++ MetadataTest.java	17 Sep 2003 22:31:51 -0000	1.12
  @@ -6,6 +6,8 @@
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.TestHelper;
  +import org.apache.ojb.broker.cache.ObjectCacheEmptyImpl;
  +import org.apache.ojb.broker.cache.ObjectCacheDefaultImpl;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryFactory;
  @@ -258,6 +260,30 @@
           System.out.println("# Time to create a copy of " + descriptors + " class-descriptors: " + period / loop + " ms #");
       }
   
  +    public void testObjectCacheDeclarations()
  +    {
  +        DescriptorRepository dr = MetadataManager.getInstance()
  +                                    .readDescriptorRepository(TEST_REPOSITORY);
  +        ConnectionRepository cr = MetadataManager.getInstance().readConnectionRepository(TEST_REPOSITORY);
  +
  +        ObjectCacheDescriptor ocd;
  +        ocd = ((JdbcConnectionDescriptor)cr.getAllDescriptor().get(0)).getObjectCacheDescriptor();
  +        assertNotNull(ocd);
  +        assertNotNull(ocd.getObjectCache());
  +        assertEquals(ObjectCacheEmptyImpl.class, ocd.getObjectCache());
  +        assertNotNull(ocd.getAttribute("attr_con"));
  +        assertNull("Wrong custom attribute found", ocd.getAttribute("attr_class"));
  +        assertEquals("555", ocd.getAttribute("attr_con"));
  +
  +        ocd = dr.getDescriptorFor(CacheObject.class).getObjectCacheDescriptor();
  +        assertNotNull(ocd);
  +        assertNotNull(ocd.getObjectCache());
  +        assertEquals(ObjectCacheDefaultImpl.class, ocd.getObjectCache());
  +        assertNotNull(ocd.getAttribute("attr_class"));
  +        assertNull("Wrong custom attribute found", ocd.getAttribute("attr_con"));
  +        assertEquals("444", ocd.getAttribute("attr_class"));       
  +    }
  +
       public void testReadConnectionDescriptor()
       {
           JdbcConnectionDescriptor jcd = MetadataManager.getInstance().connectionRepository().
  @@ -280,6 +306,12 @@
           useAutoCommit="0"
           ignoreAutoCommitExceptions="true"
       >
  +
  +        <object-cache class="org.apache.ojb.broker.cache.ObjectCacheEmptyImpl">
  +            <attribute attribute-name="cacheKey1" attribute-value="cacheValue1"/>
  +            <attribute attribute-name="cacheKey2" attribute-value="cacheValue2"/>
  +        </object-cache>
  +
           <connection-pool
               maxActive="1"
               maxIdle="2"
  @@ -335,6 +367,14 @@
           assertEquals(0, jcd.getUseAutoCommit());
           assertEquals(true, jcd.isIgnoreAutoCommitExceptions());
   
  +        ObjectCacheDescriptor ocd = jcd.getObjectCacheDescriptor();
  +        assertNotNull(ocd);
  +        assertNotNull(ocd.getObjectCache());
  +        assertEquals(ocd.getObjectCache(), ObjectCacheEmptyImpl.class);
  +        assertNotNull(ocd.getAttribute("cacheKey1"));
  +        assertNotNull(ocd.getAttribute("cacheKey2"));
  +        assertEquals("cacheValue1", ocd.getAttribute("cacheKey1"));
  +        assertEquals("cacheValue2", ocd.getAttribute("cacheKey2"));
   
           ConnectionPoolDescriptor cpd = jcd.getConnectionPoolDescriptor();
           assertEquals(1, cpd.getMaxActive());
  @@ -392,6 +432,32 @@
           public void setId(int id)
           {
               this.id = id;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +    }
  +
  +    public static class CacheObject
  +    {
  +        Integer objId;
  +        String name;
  +
  +        public Integer getObjId()
  +        {
  +            return objId;
  +        }
  +
  +        public void setObjId(Integer objId)
  +        {
  +            this.objId = objId;
           }
   
           public String getName()
  
  
  

---------------------------------------------------------------------
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