db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r430926 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata: ConnectionPoolDescriptor.java DescriptorBase.java IndexDescriptor.java JdbcConnectionDescriptor.java ObjectCacheDescriptor.java SequenceDescriptor.java
Date Sat, 12 Aug 2006 00:07:40 GMT
Author: arminw
Date: Fri Aug 11 17:07:39 2006
New Revision: 430926

URL: http://svn.apache.org/viewvc?rev=430926&view=rev
Log:
harmonize custom attributes handling

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ConnectionPoolDescriptor.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorBase.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/IndexDescriptor.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/JdbcConnectionDescriptor.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ObjectCacheDescriptor.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/SequenceDescriptor.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ConnectionPoolDescriptor.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ConnectionPoolDescriptor.java?rev=430926&r1=430925&r2=430926&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ConnectionPoolDescriptor.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ConnectionPoolDescriptor.java
Fri Aug 11 17:07:39 2006
@@ -190,11 +190,13 @@
         buf.append("         <!-- ");
         buf.append(eol);
         buf.append("         Add JDBC-level properties here, like fetchSize.");
+        buf.append(eol);
         buf.append("         Attributes with name prefix \"jdbc.\" are passed directly to
the JDBC driver.");
         buf.append(eol);
         buf.append("         e.g. <attribute attribute-name=\"fetchSize\" attribute-value=\"100\"/>");
         buf.append(eol);
         buf.append("         -->");
+        buf.append(eol);
         XmlHelper.appendSerializedAttributes(buf, "         ", this);
 
         buf.append("      ").append(tags.getClosingTagById(CONNECTION_POOL)).append(eol);

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorBase.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorBase.java?rev=430926&r1=430925&r2=430926&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorBase.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorBase.java
Fri Aug 11 17:07:39 2006
@@ -18,22 +18,26 @@
 import java.io.Serializable;
 import java.util.*;
 
+import org.apache.ojb.broker.util.logging.LoggerFactory;
+
 /**
  * base class for all Descriptors. It is used to implement the AttributeContainer
  * interface which provides mechanics for user defined attributes.
- * @author Thomas Mahler
+ *
+ * @version $Id: $
  */
 class DescriptorBase implements AttributeContainer, Serializable
 {
-	static final long serialVersionUID = 713914612744155925L;
+    static final long serialVersionUID = 713914612744155925L;
     /** holds user defined attributes */
-    private Map attributeMap = null;
+    private Properties attributeMap;
 
     /**
      * Constructor for DescriptorBase.
      */
     public DescriptorBase()
     {
+        attributeMap = new Properties();
     }
 
     /**
@@ -42,17 +46,16 @@
     public void addAttribute(String attributeName, String attributeValue)
     {
         // Don't allow null attribute names.
-        if (attributeName == null)
+        if (attributeName == null || attributeValue == null)
         {
+            LoggerFactory.getDefaultLogger().error(
+                    "[" + this.getClass().getName()
+                            + "] Illegal Attribute add - value or key is null: key="
+                            + attributeName + " value=" + attributeValue);
             return;
         }
-        // Set up the attribute list
-        if (attributeMap == null)
-        {
-            attributeMap = new HashMap();
-        }
         // Add the entry.
-        attributeMap.put(attributeName, attributeValue);
+        attributeMap.setProperty(attributeName, attributeValue);
     }
 
     /**
@@ -60,14 +63,10 @@
      */
     public String getAttribute(String attributeName, String defaultValue)
     {
-        String result = defaultValue;
-        if (attributeMap != null)
+        String result = attributeMap.getProperty(attributeName);
+        if (result == null)
         {
-            result = (String) attributeMap.get(attributeName);
-            if (result == null)
-            {
-                result = defaultValue;
-            }
+            result = defaultValue;
         }
         return result;
     }
@@ -92,6 +91,29 @@
     }
 
     /**
+     * Return the custom/configuration properties.
+     *
+     * @return The current properties.
+     */
+    public Properties getProperties()
+    {
+        return attributeMap;
+    }
+
+    /**
+     * Set the custom/configuration properties.
+     *
+     * @param properties Set the properties, <em>null</em> will be ignored.
+     */
+    public void setProperties(Properties properties)
+    {
+        if(properties != null)
+        {
+            this.attributeMap = properties;
+        }
+    }
+
+    /**
      * Returns an array of the names of all atributes of this descriptor.
      * 
      * @return The list of attribute names (will not be <code>null</code>)
@@ -104,7 +126,7 @@
         keys.toArray(result);
         return result;
     }
-    
+
     public String toString()
     {
         StringBuffer buf = new StringBuffer();

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/IndexDescriptor.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/IndexDescriptor.java?rev=430926&r1=430925&r2=430926&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/IndexDescriptor.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/IndexDescriptor.java
Fri Aug 11 17:07:39 2006
@@ -15,19 +15,19 @@
  * limitations under the License.
  */
 
-import org.apache.commons.lang.SystemUtils;
-
 import java.util.Vector;
-import java.io.Serializable;
+
+import org.apache.commons.lang.SystemUtils;
+import org.apache.ojb.broker.util.XmlHelper;
 
 /**
  *
  *
  * @version $Id$
  */
-public class IndexDescriptor implements XmlCapable, Serializable
+public class IndexDescriptor extends DescriptorBase implements XmlCapable
 {
-	private static final long serialVersionUID = -1722513568634970108L;
+    private static final long serialVersionUID = -1722513568634970108L;
     private String name;
     private boolean unique;
     private Vector indexColumns = new Vector();
@@ -98,6 +98,16 @@
         }
 
         // closing tag
+        result.append( "      " );
+        result.append( "         <!-- " );
+        result.append( eol );
+        result.append( "         Add custom index properties here, using custom attributes"
);
+        result.append( eol );
+        result.append( "         e.g. <attribute attribute-name=\"myKey\" attribute-value=\"myValue\"/>"
);
+        result.append( eol );
+        result.append( "         -->" );
+        result.append( eol );
+        XmlHelper.appendSerializedAttributes(result, "         ", getProperties());
         result.append( "      " );
         result.append( tags.getClosingTagById( INDEX_DESCRIPTOR ) );
         result.append( " " );

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/JdbcConnectionDescriptor.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/JdbcConnectionDescriptor.java?rev=430926&r1=430925&r2=430926&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/JdbcConnectionDescriptor.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/JdbcConnectionDescriptor.java
Fri Aug 11 17:07:39 2006
@@ -16,11 +16,13 @@
  */
 
 import java.io.Serializable;
+import java.util.Properties;
 
 import javax.sql.DataSource;
 
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
+import org.apache.ojb.broker.util.XmlHelper;
 import org.apache.ojb.broker.PBKey;
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
@@ -530,6 +532,22 @@
         strReturn.append( eol );
         strReturn.append( eol );
 
+        strReturn.append("         <!-- ");
+        strReturn.append(eol);
+        strReturn.append("         Add custom connection properties here.");
+        strReturn.append(eol);
+        strReturn.append("         e.g. <attribute attribute-name=\"myKey\" attribute-value=\"myValue\"/>");
+        strReturn.append(eol);
+        strReturn.append("         -->");
+        strReturn.append(eol);
+        XmlHelper.appendSerializedAttributes(strReturn, "         ", getProperties());
+        strReturn.append( eol );
+        strReturn.append( eol );
+
+        if( this.getObjectCacheDescriptor() != null )
+        {
+            strReturn.append( this.getObjectCacheDescriptor().toXML() );
+        }
         strReturn.append( this.getConnectionPoolDescriptor().toXML() );
         strReturn.append( eol );
         if( this.getSequenceDescriptor() != null )

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ObjectCacheDescriptor.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ObjectCacheDescriptor.java?rev=430926&r1=430925&r2=430926&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ObjectCacheDescriptor.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ObjectCacheDescriptor.java
Fri Aug 11 17:07:39 2006
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-import java.io.Serializable;
 import java.util.Properties;
 
 import org.apache.commons.lang.SystemUtils;
@@ -36,16 +35,14 @@
  * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
-public class ObjectCacheDescriptor implements Serializable, XmlCapable, AttributeContainer
+public class ObjectCacheDescriptor extends DescriptorBase implements XmlCapable
 {
 	private static final long serialVersionUID = 2583853027407750053L;
     private static final Class DEF_OBJECT_CACHE = ObjectCacheEmptyImpl.class;
     private Class objectCache;
-    private Properties configurationProperties;
 
     public ObjectCacheDescriptor()
     {
-        this.configurationProperties = new Properties();
         this.objectCache = DEF_OBJECT_CACHE;
     }
 
@@ -65,31 +62,14 @@
         this.objectCache = objectCache;
     }
 
-    public void addAttribute(String attributeName, String attributeValue)
-    {
-        configurationProperties.setProperty(attributeName, attributeValue);
-    }
-
-    public String getAttribute(String 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()
     {
-        return configurationProperties;
+        return getProperties();
     }
 
     public void setConfigurationProperties(Properties configurationProperties)
     {
-        this.configurationProperties = configurationProperties;
+        setProperties(configurationProperties);
     }
 
     public String toString()

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/SequenceDescriptor.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/SequenceDescriptor.java?rev=430926&r1=430925&r2=430926&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/SequenceDescriptor.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/SequenceDescriptor.java
Fri Aug 11 17:07:39 2006
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-import java.io.Serializable;
 import java.util.Properties;
 
 import org.apache.commons.lang.SystemUtils;
@@ -35,18 +34,16 @@
  * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
-public class SequenceDescriptor implements Serializable, XmlCapable, AttributeContainer
+public class SequenceDescriptor extends  DescriptorBase implements XmlCapable
 {
 
 	private static final long serialVersionUID = -5161713731380949398L;
     private JdbcConnectionDescriptor jcd;
     private Class sequenceManagerClass;
-    private Properties configurationProperties;
 
     public SequenceDescriptor(JdbcConnectionDescriptor jcd)
     {
         this.jcd = jcd;
-        this.configurationProperties = new Properties();
     }
 
     public SequenceDescriptor(JdbcConnectionDescriptor jcd, Class sequenceManagerClass)
@@ -75,31 +72,14 @@
         this.sequenceManagerClass = sequenceManagerClass;
     }
 
-    public void addAttribute(String attributeName, String attributeValue)
-    {
-        configurationProperties.setProperty(attributeName, attributeValue);
-    }
-
-    public String getAttribute(String 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()
     {
-        return configurationProperties;
+        return getProperties();
     }
 
     public void setConfigurationProperties(Properties configurationProperties)
     {
-        this.configurationProperties = configurationProperties;
+        setProperties(configurationProperties);
     }
 
     public String toString()



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