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/sequence SequenceManagerTest.java
Date Wed, 26 Feb 2003 00:30:29 GMT
arminw      2003/02/25 16:30:29

  Modified:    src/java/org/apache/ojb/broker/metadata
                        ConnectionDescriptorXmlHandler.java
                        DescriptorRepository.java
                        JdbcConnectionDescriptor.java
                        RepositoryXmlHandler.java SequenceDescriptor.java
               src/test/org/apache/ojb/broker/metadata
                        CustomAttributesTest.java MetadataTest.java
               src/test/org/apache/ojb/broker/sequence
                        SequenceManagerTest.java
  Log:
  add support for custom attributes
  to JdbcConnectionDescriptor and
  DescriptorRepository, update test cases,
  add new test cases
  
  Revision  Changes    Path
  1.4       +32 -11    db-ojb/src/java/org/apache/ojb/broker/metadata/ConnectionDescriptorXmlHandler.java
  
  Index: ConnectionDescriptorXmlHandler.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ConnectionDescriptorXmlHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConnectionDescriptorXmlHandler.java	9 Jan 2003 23:53:11 -0000	1.3
  +++ ConnectionDescriptorXmlHandler.java	26 Feb 2003 00:30:28 -0000	1.4
  @@ -85,6 +85,7 @@
       private JdbcConnectionDescriptor m_CurrentJCD;
       private SequenceDescriptor currentSequenceDescriptor;
       private List conDesList;
  +    private AttributeContainer currentAttributeContainer;
       private boolean defaultConnectionFound = false;
   
       /**
  @@ -148,6 +149,8 @@
                       {
                           if (isDebug) logger.debug("   > " + tags.getTagById(JDBC_CONNECTION_DESCRIPTOR));
                           JdbcConnectionDescriptor newJcd = new JdbcConnectionDescriptor();
  +                        currentAttributeContainer = newJcd;
  +
                           conDesList.add(newJcd);
                           m_CurrentJCD = newJcd;
   
  @@ -240,9 +243,6 @@
                           if (isDebug) logger.debug("     " + tags.getTagById(IGNORE_AUTOCOMMIT_EXCEPTION)
+ ": " + ignoreAutoCommitExceptions);
                           m_CurrentJCD.setIgnoreAutoCommitExceptions(Boolean.valueOf(ignoreAutoCommitExceptions).booleanValue());
   
  -
  -
  -
                           break;
                       }
                   case CONNECTION_POOL:
  @@ -319,6 +319,7 @@
                           if(checkString(className))
                           {
                               this.currentSequenceDescriptor = new SequenceDescriptor(this.m_CurrentJCD);
  +                            this.currentAttributeContainer = currentSequenceDescriptor;
                               this.m_CurrentJCD.setSequenceDescriptor(this.currentSequenceDescriptor);
                               if (isDebug) logger.debug("    > " + tags.getTagById(SEQUENCE_MANAGER));
                               if (isDebug) logger.debug("     " + tags.getTagById(SEQUENCE_MANAGER_CLASS)
+ ": " + className);
  @@ -328,26 +329,34 @@
                       }
                   case ATTRIBUTE:
                       {
  +                        //handle custom attributes
  +                        String attributeName = atts.getValue(tags.getTagById(ATTRIBUTE_NAME));
  +                        String attributeValue = atts.getValue(tags.getTagById(ATTRIBUTE_VALUE));
  +
                           // If we have a container to store this attribute in, then do so.
  -                        if (this.currentSequenceDescriptor != null)
  +                        if (this.currentAttributeContainer != null)
                           {
  -                            //handle custom sequence manager attributes
  -                            String attributeName = atts.getValue(tags.getTagById(ATTRIBUTE_NAME));
  -                            String attributeValue = atts.getValue(tags.getTagById(ATTRIBUTE_VALUE));
  +
                               if (checkString(attributeName))
                               {
                                   if (isDebug) logger.debug("    > " + tags.getTagById(ATTRIBUTE));
                                   if (isDebug) logger.debug("     " + tags.getTagById(ATTRIBUTE_NAME)
+ ": " + attributeName);
                                   if (isDebug) logger.debug("     " + tags.getTagById(ATTRIBUTE_VALUE)
+ ": " + attributeValue);
  -                                this.currentSequenceDescriptor.addConfigurationProperty(attributeName,
attributeValue);
  +                                this.currentAttributeContainer.addAttribute(attributeName,
attributeValue);
  +//                                logger.info("attribute ["+attributeName+"="+attributeValue+"]
add to "+currentAttributeContainer.getClass());
                               }
                               else
                               {
  -                                logger.info("Found 'null' or 'empty' attribute object for
sequence-manager element."+
  +                                logger.info("Found 'null' or 'empty' attribute object for
element "+currentAttributeContainer.getClass() +
                                           " attribute-name=" + attributeName + ", attribute-value="
+ attributeValue+
                                           " See jdbc-connection-descriptor with jcdAlias
'"+m_CurrentJCD.getJcdAlias()+"'");
                               }
                           }
  +//                        else
  +//                        {
  +//                            logger.info("Found attribute (name="+attributeName+", value="+attributeValue+
  +//                                    ") but I could not assign them to a descriptor");
  +//                        }
   
                           break;
                       }
  @@ -400,16 +409,27 @@
           {
               switch (getLiteralId(qName))
               {
  +                case MAPPING_REPOSITORY:
  +                    {
  +                        currentAttributeContainer = null;
  +                        break;
  +                    }
  +                case CLASS_DESCRIPTOR:
  +                    {
  +                        currentAttributeContainer = null;
  +                        break;
  +                    }
                   case JDBC_CONNECTION_DESCRIPTOR:
                       {
                           logger.debug("   < " + tags.getTagById(JDBC_CONNECTION_DESCRIPTOR));
                           m_CurrentJCD = null;
  +                        currentAttributeContainer = null;
                           break;
                       }
                   case CONNECTION_POOL:
                       {
                           logger.debug("   < " + tags.getTagById(CONNECTION_POOL));
  -
  +                        currentAttributeContainer = m_CurrentJCD;
                           break;
                       }
                   case SEQUENCE_MANAGER:
  @@ -417,6 +437,7 @@
                           if (isDebug) logger.debug("    < " + tags.getTagById(SEQUENCE_MANAGER));
                           // set to null at the end of the tag!!
                           this.currentSequenceDescriptor = null;
  +                        currentAttributeContainer = m_CurrentJCD;
                           break;
                       }
                   case ATTRIBUTE:
  
  
  
  1.33      +3 -2      db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
  
  Index: DescriptorRepository.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- DescriptorRepository.java	19 Feb 2003 21:13:27 -0000	1.32
  +++ DescriptorRepository.java	26 Feb 2003 00:30:28 -0000	1.33
  @@ -79,7 +79,8 @@
    * @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz<a>
    * @version $Id$
    */
  -public final class DescriptorRepository implements Serializable, XmlCapable, IsolationLevels
  +public final class DescriptorRepository extends DescriptorBase
  +                                        implements Serializable, XmlCapable, IsolationLevels
   {
       /**
        * The version identifier of the Repository.
  
  
  
  1.23      +4 -2      db-ojb/src/java/org/apache/ojb/broker/metadata/JdbcConnectionDescriptor.java
  
  Index: JdbcConnectionDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/JdbcConnectionDescriptor.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- JdbcConnectionDescriptor.java	18 Feb 2003 10:51:14 -0000	1.22
  +++ JdbcConnectionDescriptor.java	26 Feb 2003 00:30:28 -0000	1.23
  @@ -74,7 +74,7 @@
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @version $Id$
    */
  -public class JdbcConnectionDescriptor implements Serializable, XmlCapable
  +public class JdbcConnectionDescriptor extends DescriptorBase implements Serializable, XmlCapable
   {
       private Logger logger = LoggerFactory.getLogger(JdbcConnectionDescriptor.class);
   
  @@ -484,6 +484,8 @@
           }
   
   		strReturn += "  >" + eol+eol;
  +
  +
           strReturn += this.getConnectionPoolDescriptor().toXML()+eol;
           if(this.getSequenceDescriptor() != null) strReturn += this.getSequenceDescriptor().toXML()+eol;
           strReturn += "  " + tags.getClosingTagById(JDBC_CONNECTION_DESCRIPTOR) + eol;
  
  
  
  1.31      +18 -7     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.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- RepositoryXmlHandler.java	31 Jan 2003 17:55:55 -0000	1.30
  +++ RepositoryXmlHandler.java	26 Feb 2003 00:30:28 -0000	1.31
  @@ -174,6 +174,7 @@
               {
                   case MAPPING_REPOSITORY:
                       {
  +                        this.m_CurrentAttrContainer = m_repository;
                           String defIso = atts.getValue(tags.getTagById(ISOLATION_LEVEL));
                           if (defIso != null)
                           {
  @@ -644,13 +645,19 @@
                           //handle custom attributes
                           String attributeName = atts.getValue(tags.getTagById(ATTRIBUTE_NAME));
                           String attributeValue = atts.getValue(tags.getTagById(ATTRIBUTE_VALUE));
  -                        if (isDebug) logger.debug("    > " + tags.getTagById(ATTRIBUTE));
  -                        if (isDebug) logger.debug("     " + tags.getTagById(ATTRIBUTE_NAME)
+ ": " + attributeName);
  -                        if (isDebug) logger.debug("     " + tags.getTagById(ATTRIBUTE_VALUE)
+ ": " + attributeValue);
                           // If we have a container to store this attribute in, then do so.
                           if (this.m_CurrentAttrContainer != null)
                           {
  +                            if (isDebug) logger.debug("    > " + tags.getTagById(ATTRIBUTE));
  +                            if (isDebug) logger.debug("     " + tags.getTagById(ATTRIBUTE_NAME)
+ ": " + attributeName);
  +                            if (isDebug) logger.debug("     " + tags.getTagById(ATTRIBUTE_VALUE)
+ ": " + attributeValue);
                               this.m_CurrentAttrContainer.addAttribute(attributeName, attributeValue);
  +//                            logger.info("attribute ["+attributeName+"="+attributeValue+"]
add to "+m_CurrentAttrContainer.getClass());
  +                        }
  +                        else
  +                        {
  +                            logger.info("Found attribute (name="+attributeName+", value="+attributeValue+
  +                                    ") but I could not assign them to a descriptor");
                           }
                       }
                   default :
  @@ -686,13 +693,14 @@
                   case MAPPING_REPOSITORY:
                       {
                           if (isDebug) logger.debug(" < " + tags.getTagById(MAPPING_REPOSITORY));
  +                        this.m_CurrentAttrContainer = null;
                           break;
                       }
                   case CLASS_DESCRIPTOR:
                       {
                           if (isDebug) logger.debug("  < " + tags.getTagById(CLASS_DESCRIPTOR));
                           m_CurrentCLD = null;
  -                        m_CurrentAttrContainer = null;
  +                        this.m_CurrentAttrContainer = null;
                           break;
                       }
                   case CLASS_EXTENT:
  @@ -757,17 +765,20 @@
                       }
                   case SEQUENCE_MANAGER:
                       {
  -                        if (isDebug) logger.debug("    < " + tags.getTagById(DOCUMENTATION));
  +                        // if (isDebug) logger.debug("    < " + tags.getTagById(DOCUMENTATION));
  +                        this.m_CurrentAttrContainer = null;
                           break;
                       }
                   case CONNECTION_POOL:
                       {
  -                        if (isDebug) logger.debug("    < " + tags.getTagById(DOCUMENTATION));
  +                        // if (isDebug) logger.debug("    < " + tags.getTagById(DOCUMENTATION));
  +                        this.m_CurrentAttrContainer = null;
                           break;
                       }
                   case JDBC_CONNECTION_DESCRIPTOR:
                       {
                           if (isDebug) logger.debug("    < " + tags.getTagById(DOCUMENTATION));
  +                        this.m_CurrentAttrContainer = null;
                           break;
                       }
   
  
  
  
  1.4       +14 -7     db-ojb/src/java/org/apache/ojb/broker/metadata/SequenceDescriptor.java
  
  Index: SequenceDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/SequenceDescriptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SequenceDescriptor.java	31 Jan 2003 17:03:32 -0000	1.3
  +++ SequenceDescriptor.java	26 Feb 2003 00:30:28 -0000	1.4
  @@ -17,12 +17,12 @@
    * All sequence manager implementation specific configuration
    * attributes are represented by key/value pairs in a
    * <code>Properties</code> object and could be reached via
  - * {@link #getConfigurationProperties} or {@link #getConfigurationProperty(String key)}.
  + * {@link #getConfigurationProperties} or {@link #getAttribute(String key)}.
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class SequenceDescriptor implements Serializable, XmlCapable
  +public class SequenceDescriptor implements Serializable, XmlCapable, AttributeContainer
   {
       private Logger logger = LoggerFactory.getLogger(SequenceDescriptor.class);
   
  @@ -62,14 +62,21 @@
           this.sequenceManagerClass = sequenceManagerClass;
       }
   
  -    public void addConfigurationProperty(String key, String value)
  +    public void addAttribute(String attributeName, String attributeValue)
       {
  -        configurationProperties.setProperty(key, value);
  +        configurationProperties.setProperty(attributeName, attributeValue);
       }
   
  -    public String getConfigurationProperty(String key)
  +    public String getAttribute(String key)
       {
  -        return configurationProperties.getProperty(key);
  +        return getAttribute(key, null);
  +    }
  +
  +    public String getAttribute(String attributeName, String defaultValue)
  +    {
  +        String result = configurationProperties.getProperty(attributeName);
  +        if(result == null) result = defaultValue;
  +        return result;
       }
   
       public Properties getConfigurationProperties()
  
  
  
  1.5       +36 -2     db-ojb/src/test/org/apache/ojb/broker/metadata/CustomAttributesTest.java
  
  Index: CustomAttributesTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/metadata/CustomAttributesTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CustomAttributesTest.java	20 Jan 2003 16:13:34 -0000	1.4
  +++ CustomAttributesTest.java	26 Feb 2003 00:30:29 -0000	1.5
  @@ -3,6 +3,7 @@
   import junit.framework.TestCase;
   
   import org.apache.ojb.broker.Article;
  +import org.apache.ojb.broker.PBKey;
   
   /**
    * This TestClass tests the RepositoryPersitors facilities for
  @@ -45,8 +46,41 @@
   
   	}
   
  +    public void testCustomAttributesDescriptorRepository()
  +    {
  +        String repositoryAttribute_1 = "attribute-repository-1";
  +        String repositoryAttribute_2 = "attribute-repository-2";
  +        MetadataManager mm = MetadataManager.getInstance();
  +
  +        DescriptorRepository dr = mm.readDescriptorRepository(MetadataTest.TEST_REPOSITORY);
  +        String res_1 = dr.getAttribute(repositoryAttribute_1);
  +        String res_2 = dr.getAttribute(repositoryAttribute_2);
  +        assertNotNull("No attributes found", res_1);
  +        assertNotNull("No attributes found", res_2);
  +        assertEquals("Found attribute does not match", "attribute-repository-test-value-1",
res_1);
  +        assertEquals("Found attribute does not match", "attribute-repository-test-value-2",
res_2);
  +
  +    }
  +
  +    public void testCustomAttributesConnectionDescriptor()
  +    {
  +        String connectionAttribute_1 = "attribute-connection-1";
  +        String connectionAttribute_2 = "attribute-connection-2";
  +
  +        MetadataManager mm = MetadataManager.getInstance();
  +        ConnectionRepository cr = mm.readConnectionRepository(MetadataTest.TEST_CONNECTION_DESCRIPTOR);
  +        JdbcConnectionDescriptor jcd = cr.getDescriptor(new PBKey("runtime"));
  +        String res_1 = jcd.getAttribute(connectionAttribute_1);
  +        String res_2 = jcd.getAttribute(connectionAttribute_2);
  +        assertNotNull("No attributes found", res_1);
  +        assertNotNull("No attributes found", res_2);
  +        assertEquals("Found attribute does not match", "attribute-connection-test-value-1",
res_1);
  +        assertEquals("Found attribute does not match", "attribute-connection-test-value-2",
res_2);
  +    }
  +
  +
   	/** Test storing repository.*/
  -	public void testReadCustomAttributes()
  +	public void testCustomAttributesClassDescriptor()
   	{
   		DescriptorRepository repository = MetadataManager.getInstance().getRepository();
   
  @@ -66,7 +100,7 @@
   	}
   
       /** Test using attributes on serialized/deserialized repository*/
  -	public void testSerializedReadCustomAttributes()
  +	public void testSerializedCustomAttributesClassDescriptor()
   	{
           DescriptorRepository repository = MetadataManager.getInstance().copyOfGlobalRepository();
   
  
  
  
  1.6       +9 -13     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MetadataTest.java	11 Feb 2003 19:34:44 -0000	1.5
  +++ MetadataTest.java	26 Feb 2003 00:30:29 -0000	1.6
  @@ -27,13 +27,9 @@
    */
   public class MetadataTest extends TestCase
   {
  -    /**
  -     * Path used by the test case to find some test
  -     * repository files.
  -     */
  -    private static final String pathToTestDir = "";
  -    private static final String TEST_REPOSITORY_DESCRIPTOR = "Test_ClassDescriptor.xml";
  -    private static final String TEST_REPOSITORY_CONNECTION = "Test_ConnectionDescriptor.xml";
  +    public static final String TEST_CLASS_DESCRIPTOR = "Test_ClassDescriptor.xml";
  +    public static final String TEST_CONNECTION_DESCRIPTOR = "Test_ConnectionDescriptor.xml";
  +    public static final String TEST_REPOSITORY = "Test_Repository.xml";
   
       /**
        * A persistent object class
  @@ -76,7 +72,7 @@
       {
   
           MetadataManager mm = MetadataManager.getInstance();
  -        ConnectionRepository cr = mm.readConnectionRepository(TEST_REPOSITORY_CONNECTION);
  +        ConnectionRepository cr = mm.readConnectionRepository(TEST_CONNECTION_DESCRIPTOR);
           mm.mergeConnectionRepository(cr);
   
           ConnectionRepository mergedCR = mm.connectionRepository();
  @@ -87,7 +83,7 @@
       public void testRuntimeMergeDescriptorRepository() throws Exception
       {
           MetadataManager mm = MetadataManager.getInstance();
  -        DescriptorRepository dr = mm.readDescriptorRepository(TEST_REPOSITORY_DESCRIPTOR);
  +        DescriptorRepository dr = mm.readDescriptorRepository(TEST_CLASS_DESCRIPTOR);
           mm.mergeDescriptorRepository(dr);
   
           DescriptorRepository mergedDR = mm.getRepository();
  @@ -327,11 +323,11 @@
           SequenceDescriptor seq = jcd.getSequenceDescriptor();
           assertEquals(SequenceManagerHighLowImpl.class.getName(), seq.getSequenceManagerClass().getName());
   
  -        assertNotNull(seq.getConfigurationProperty("key1"));
  -        assertEquals("value1", seq.getConfigurationProperty("key1"));
  +        assertNotNull(seq.getAttribute("key1"));
  +        assertEquals("value1", seq.getAttribute("key1"));
   
  -        assertNotNull(seq.getConfigurationProperty("key2"));
  -        assertEquals("value2", seq.getConfigurationProperty("key2"));
  +        assertNotNull(seq.getAttribute("key2"));
  +        assertEquals("value2", seq.getAttribute("key2"));
       }
   
   
  
  
  
  1.16      +2 -2      db-ojb/src/test/org/apache/ojb/broker/sequence/SequenceManagerTest.java
  
  Index: SequenceManagerTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/SequenceManagerTest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SequenceManagerTest.java	5 Feb 2003 20:03:43 -0000	1.15
  +++ SequenceManagerTest.java	26 Feb 2003 00:30:29 -0000	1.16
  @@ -94,7 +94,7 @@
               if(sm instanceof SequenceManagerSeqHiLoImpl || sm instanceof SequenceManagerHighLowImpl)
               {
                   SequenceDescriptor sd = broker.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor();
  -                String strSize = sd.getConfigurationProperty(SequenceManagerHighLowImpl.PROPERTY_GRAB_SIZE);
  +                String strSize = sd.getAttribute(SequenceManagerHighLowImpl.PROPERTY_GRAB_SIZE);
                   if(strSize != null)
                   {
                       seqGrabSize = new Integer(strSize).intValue();
  
  
  

Mime
View raw message