Author: arminw
Date: Tue Feb  6 15:38:30 2007
New Revision: 504369

URL: http://svn.apache.org/viewvc?view=rev&rev=504369
Log:
add support for attribute 'state-detection' used by odmg-api
add support to specify PersistentField implementation class on ClassDescriptor 
and FieldDescriptor level

Modified:
    
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
    
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
    
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
    
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java
    
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java
    
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository.dtd

Modified: 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java?view=diff&rev=504369&r1=504368&r2=504369
==============================================================================
--- 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
 (original)
+++ 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
 Tue Feb  6 15:38:30 2007
@@ -194,6 +194,12 @@
      */
     private boolean acceptLocks = true;
     /**
+     * If the used API supports object state detection, this attribute
+     * indicate wether or not class should be included in object
+     * state detection.
+     */
+    private boolean stateDetection = true;
+    /**
      * if true instances of this class are always refreshed
      * even if they are already in the cache.
      * false by default.
@@ -880,6 +886,7 @@
     /**
      *
      * @return this classes FieldDescriptor's as well as it's parents and so 
on and so on
+     * @deprecated
      */
     public FieldDescriptor[] getFieldDescriptorsInHeirarchy()
     {
@@ -1068,7 +1075,7 @@
             {
                 FieldDescriptor[] fields;
                 // 1.b if not an interface The classdescriptor must have 
FieldDescriptors
-                fields = getFieldDescriptions();
+                fields = getFieldDescriptor(false);
                 // now collect all PK fields
                 for (int i = 0; i < fields.length; i++)
                 {
@@ -1117,7 +1124,7 @@
     {
         if (m_RwFieldDescriptors == null)
         {
-            FieldDescriptor[] fields = getFieldDescriptions();
+            FieldDescriptor[] fields = getFieldDescriptor(false);
             Collection rwFields = new ArrayList();
 
             for (int i = 0; i < fields.length; i++)
@@ -1377,23 +1384,23 @@
 
         // proxy is optional
         if (theProxyClass != null)
-       {
-           if (isDynamicProxy())   // tomdz: What about VirtualProxy ?
+           {
+            if (isDynamicProxy())   // tomdz: What about VirtualProxy ?
             {
-               result.append( "    ");
+                result.append( "    ");
                 result.append( tags.getAttribute(CLASS_PROXY, DYNAMIC_STR));
                 result.append( eol );
-           }
+            }
             else
-           {
-               result.append( "    ");
-            result.append( tags.getAttribute(CLASS_PROXY, 
this.getProxyClassName()));
-            result.append( eol );
+            {
+                result.append( "    ");
+                result.append( tags.getAttribute(CLASS_PROXY, 
this.getProxyClassName()));
+                result.append( eol );
             }
             result.append( "        ");
-        result.append( tags.getAttribute(PROXY_PREFETCHING_LIMIT, "" + 
this.getProxyPrefetchingLimit()));
-        result.append( eol );
-       }
+            result.append( tags.getAttribute(PROXY_PREFETCHING_LIMIT, "" + 
this.getProxyPrefetchingLimit()));
+            result.append( eol );
+           }
 
         // schema is optional
         if (this.getSchema() != null)
@@ -2291,5 +2298,31 @@
     public ClassDescriptor getTopLevelClassDescriptor()
     {
         return getRepository().getTopLevelDescriptor(getClassOfObject());
+    }
+
+    /**
+     * Returns whether or not this class should be included in
+     * object state detection. Default state is <em>true</em>.
+     *
+     * @return If <em>true</em> the class will be included in
+     * automatic object state detection.
+     * @see #setStateDetection(boolean)
+     */
+    public boolean isStateDetection()
+    {
+        return stateDetection;
+    }
+
+    /**
+     * If the used API supports object state detection (e.g. ODMG-api does),
+     * this attribute indicate whether or not this class should be included in 
object
+     * state detection (automatic check for changed object fields).
+     *
+     * @param stateDetection Set <em>true</em> if automatic state detection 
should
+     * be enabled.
+     */
+    public void setStateDetection(boolean stateDetection)
+    {
+        this.stateDetection = stateDetection;
     }
 }

Modified: 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java?view=diff&rev=504369&r1=504368&r2=504369
==============================================================================
--- 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
 (original)
+++ 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
 Tue Feb  6 15:38:30 2007
@@ -61,6 +61,12 @@
      */
     private int defaultIsolationLevel = IsolationLevels.IL_DEFAULT;
     /**
+     * If the used API supports object state detection, this attribute
+     * indicate wether or not mapped classes should be included in object
+     * state detection.
+     */
+    private boolean stateDetection = true;
+    /**
      * This table holds all known Mapping descriptions.
      * Key values are the respective Class objects
      */
@@ -916,6 +922,32 @@
             }
         }
         return tableNamesSet;
+    }
+
+    /**
+     * Returns whether or not mapped classes should be included in
+     * object state detection. Default state is <em>true</em>.
+     *
+     * @return If <em>true</em> the classes will be included in
+     * automatic object state detection.
+     * @see #setStateDetection(boolean)
+     */
+    public boolean isStateDetection()
+    {
+        return stateDetection;
+    }
+
+    /**
+     * If the used API supports object state detection (e.g. ODMG-api does),
+     * this attribute indicate whether or not this mapped classes should be
+     * included in object state detection (automatic check for changed object 
fields).
+     *
+     * @param stateDetection Set <em>true</em> if automatic state detection 
should
+     * be enabled.
+     */
+    public void setStateDetection(boolean stateDetection)
+    {
+        this.stateDetection = stateDetection;
     }
 
     protected void finalize() throws Throwable

Modified: 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java?view=diff&rev=504369&r1=504368&r2=504369
==============================================================================
--- 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
 (original)
+++ 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
 Tue Feb  6 15:38:30 2007
@@ -79,6 +79,12 @@
     // if false then it is the responsibility of the
     // dbms to update all lock columns eg using triggers
     private boolean updateLock = true;
+    /**
+     * If the used API supports object state detection, this attribute
+     * indicate wether or not this field should be included in object
+     * state detection.
+     */
+    private boolean stateDetection = true;
     private String m_access;
     private SequenceDescriptor sequenceDescriptor;
 
@@ -558,6 +564,31 @@
     public boolean isLobFieldType()
     {
         return getJdbcType().getFieldType().isLobField();
+    }
+
+    /**
+     * Returns whether or not this field should be included in
+     * object state detection. Default state is <em>true</em>.
+     *
+     * @return If <em>true</em> the field will be included in
+     * automatic object state detection.
+     * @see #setStateDetection(boolean)
+     */
+    public boolean isStateDetection()
+    {
+        return stateDetection;
+    }
+
+    /**
+     * If the used API supports object state detection (e.g. ODMG-api does),
+     * this attribute indicate whether or not this field should be included in 
object
+     * state detection (automatic check for changed object fields).
+     *
+     * @param stateDetection
+     */
+    public void setStateDetection(boolean stateDetection)
+    {
+        this.stateDetection = stateDetection;
     }
 
 

Modified: 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java?view=diff&rev=504369&r1=504368&r2=504369
==============================================================================
--- 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java
 (original)
+++ 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java
 Tue Feb  6 15:38:30 2007
@@ -87,6 +87,8 @@
     public static final int PRECISION = 53;
     public static final int SCALE = 54;
     public static final int ACCESS = 99;
+    public static final int STATE_DETECTION = 117;
+    public static final int FIELD_CLASS = 118;
 
     public static final int CON_MAX_ACTIVE = 55;
     public static final int CON_MAX_IDLE = 56;
@@ -145,7 +147,7 @@
     public static final int PROXY_PREFETCHING_LIMIT = 114;
 
     // maintain a next id to keep track where we are
-    static final int _NEXT = 117;
+    static final int _NEXT = 119;
 
     // String constants
     public static final String TAG_ACCESS = "access";

Modified: 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java?view=diff&rev=504369&r1=504368&r2=504369
==============================================================================
--- 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java
 (original)
+++ 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java
 Tue Feb  6 15:38:30 2007
@@ -159,6 +159,8 @@
         table.put("attribute-value", new Integer(ATTRIBUTE_VALUE));
         table.put("documentation", new Integer(DOCUMENTATION));
         table.put("accept-locks", new Integer(ACCEPT_LOCKS));
+        table.put("state-detection", new Integer(STATE_DETECTION));
+        table.put("field-class", new Integer(FIELD_CLASS));
 
         table.put("sequence-manager", new Integer(SEQUENCE_MANAGER));
         table.put("className", new Integer(SEQUENCE_MANAGER_CLASS));

Modified: 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java?view=diff&rev=504369&r1=504368&r2=504369
==============================================================================
--- 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java
 (original)
+++ 
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java
 Tue Feb  6 15:38:30 2007
@@ -21,6 +21,7 @@
 import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
 import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldFactory;
 import org.apache.ojb.broker.util.ClassHelper;
+import org.apache.ojb.broker.util.ConvertHelper;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 import org.xml.sax.Attributes;
@@ -173,6 +174,15 @@
                                     version+". Please update your 
repository.dtd and your repository.xml"+
                                     " version attribute entry");
                         }
+                        // set state-detection attribute
+                        String stateDetectionStr = 
atts.getValue(tags.getTagById(STATE_DETECTION));
+                        if (stateDetectionStr != null)
+                        {
+                            boolean stateDetection = 
ConvertHelper.toBooleanPrimitiv(stateDetectionStr);
+                            if (isDebug) logger.debug("     " + 
tags.getTagById(STATE_DETECTION) + ": " + stateDetection);
+                            m_repository.setStateDetection(stateDetection);
+                        }
+
                         break;
                     }
                 case CLASS_DESCRIPTOR:
@@ -307,15 +317,29 @@
 
                         // set refresh attribute
                         String refresh = 
atts.getValue(tags.getTagById(REFRESH));
-                        if (isDebug) logger.debug("     " + 
tags.getTagById(REFRESH) + ": " + refresh);
-                        b = (Boolean.valueOf(refresh)).booleanValue();
-                        m_CurrentCLD.setAlwaysRefresh(b);
-
-                        // TODO: remove this or make offical feature
-                        // persistent field
-                                               String pfClassName = 
atts.getValue("persistent-field-class");
-                                               if (isDebug) logger.debug("     
persistent-field-class: " + pfClassName);
-                                               
m_CurrentCLD.setPersistentFieldClassName(pfClassName);
+                        if(refresh != null)
+                        {
+                            if (isDebug) logger.debug("     " + 
tags.getTagById(REFRESH) + ": " + refresh);
+                            b = (Boolean.valueOf(refresh)).booleanValue();
+                            m_CurrentCLD.setAlwaysRefresh(b);
+                        }
+
+                        // persistent field class name
+                                               String pfClassName = 
atts.getValue(tags.getTagById(FIELD_CLASS));
+                        if(pfClassName != null)
+                        {
+                            if (isDebug) logger.debug("     field-class: " + 
pfClassName);
+                            
m_CurrentCLD.setPersistentFieldClassName(pfClassName);
+                        }
+
+                        // set state-detection attribute
+                        String stateDetectionStr = 
atts.getValue(tags.getTagById(STATE_DETECTION));
+                        if (stateDetectionStr != null)
+                        {
+                            boolean stateDetection = 
ConvertHelper.toBooleanPrimitiv(stateDetectionStr);
+                            if (isDebug) logger.debug("     " + 
tags.getTagById(STATE_DETECTION) + ": " + stateDetection);
+                            m_CurrentCLD.setStateDetection(stateDetection);
+                        }
 
                         // put cld to the metadata repository
                         m_repository.put(classname, m_CurrentCLD);
@@ -359,14 +383,32 @@
                         m_lastId = (strId == null ? m_lastId + 1 : 
Integer.parseInt(strId));
 
                         String strAccess = 
atts.getValue(tags.getTagById(ACCESS));
+                        String fieldName = 
atts.getValue(tags.getTagById(FIELD_NAME));
+                        if (isDebug) logger.debug("     " + 
tags.getTagById(FIELD_NAME) + ": " + fieldName);
 
                         if 
(RepositoryElements.TAG_ACCESS_ANONYMOUS.equalsIgnoreCase(strAccess))
                         {
-                            m_CurrentFLD = new 
AnonymousFieldDescriptor(m_CurrentCLD, m_lastId);
+                            AnonymousFieldDescriptor anonymous = new 
AnonymousFieldDescriptor(m_CurrentCLD, m_lastId);
+                            anonymous.setPersistentField(null,fieldName);
+                            m_CurrentFLD = anonymous;
                         }
                         else
                         {
                             m_CurrentFLD = new FieldDescriptor(m_CurrentCLD, 
m_lastId);
+                            // set the PersistentField
+                            String persistentFieldClassName = 
atts.getValue(tags.getTagById(FIELD_CLASS));
+                            if (persistentFieldClassName != null)
+                            {
+                                if (isDebug) logger.debug("     " + 
tags.getTagById(FIELD_CLASS) + ": " + persistentFieldClassName);
+                            }
+                            else
+                            {
+                                persistentFieldClassName = 
m_CurrentCLD.getPersistentFieldClassName();
+                            }
+                            Class objectClass = 
m_CurrentCLD.getClassOfObject();
+                            PersistentField pf = 
PersistentFieldFactory.createPersistentField(
+                                    persistentFieldClassName, objectClass, 
fieldName);
+                            m_CurrentFLD.setPersistentField(pf);
                         }
                         m_CurrentFLD.setAccess(strAccess);
                         m_CurrentCLD.addFieldDescriptor(m_CurrentFLD);
@@ -374,21 +416,6 @@
                         // prepare for custom attributes
                         this.m_CurrentAttrContainer = this.m_CurrentFLD;
 
-                        String fieldName = 
atts.getValue(tags.getTagById(FIELD_NAME));
-                        if (isDebug) logger.debug("     " + 
tags.getTagById(FIELD_NAME) + ": " + fieldName);
-
-                        if 
(RepositoryElements.TAG_ACCESS_ANONYMOUS.equalsIgnoreCase(strAccess))
-                        {
-                                                       
AnonymousFieldDescriptor anonymous = (AnonymousFieldDescriptor) m_CurrentFLD;
-                            anonymous.setPersistentField(null,fieldName);
-                        }
-                        else
-                        {
-                            String classname = 
m_CurrentCLD.getClassNameOfObject();
-                                                       PersistentField pf = 
PersistentFieldFactory.createPersistentField(m_CurrentCLD.getPersistentFieldClassName(),ClassHelper.getClass(classname),fieldName);
-                            m_CurrentFLD.setPersistentField(pf);
-                        }
-
                         String columnName = 
atts.getValue(tags.getTagById(COLUMN_NAME));
                         if (isDebug) logger.debug("     " + 
tags.getTagById(COLUMN_NAME) + ": " + columnName);
                         m_CurrentFLD.setColumnName(columnName);
@@ -479,6 +506,15 @@
                             if (isDebug) logger.debug("     " + 
tags.getTagById(SCALE) + ": " + i);
                             m_CurrentFLD.setScale(i);
                             m_CurrentFLD.setScaleSpecified(true);
+                        }
+
+                        // set state-detection attribute
+                        String stateDetectionStr = 
atts.getValue(tags.getTagById(STATE_DETECTION));
+                        if (stateDetectionStr != null)
+                        {
+                            boolean stateDetection = 
ConvertHelper.toBooleanPrimitiv(stateDetectionStr);
+                            if (isDebug) logger.debug("     " + 
tags.getTagById(STATE_DETECTION) + ": " + stateDetection);
+                            m_CurrentFLD.setStateDetection(stateDetection);
                         }
 
                         break;

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository.dtd
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository.dtd?view=diff&rev=504369&r1=504368&r2=504369
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository.dtd 
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository.dtd Tue 
Feb  6 15:38:30 2007
@@ -50,12 +50,17 @@
     by OJB's pessimistic locking api. All jdbc-connection-descriptor or 
class-descriptor
     that do not define a specific isolation level will use this.
     Note: This does NOT touch the jdbc-level of the connection.
+
+    The state-detection attribute is used by API's supporting automatic state 
detection
+       of persistence capable objects. The attribute indicate whether or not 
mapped classes should
+       be included in object state detection (automatic detection of changed 
object fields).
   -->
 <!ATTLIST descriptor-repository
        version (1.0) #REQUIRED
        isolation-level (read-uncommitted | read-committed | repeatable-read |
                         serializable | optimistic | none) "read-uncommitted"
        proxy-prefetching-limit CDATA "50"
+       state-detection (true | false) "true"
 >
 
 <!--
@@ -476,6 +481,13 @@
 
        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.
+
+       The state-detection attribute is used by API's supporting automatic 
state detection
+       of persistence capable objects. The attribute indicate whether or not 
this class should
+       be included in object state detection (automatic detection of changed 
object fields).
+
+       The field-class attribute can be used to override the 
<code>PersistentField</code>
+    implementation class.
   -->
 <!ATTLIST class-descriptor
        class ID #REQUIRED
@@ -492,6 +504,8 @@
        factory-class CDATA #IMPLIED
        factory-method CDATA #IMPLIED
        refresh (true | false) "false"
+       state-detection (true | false) "true"
+       field-class CDATA #IMPLIED
 >
 
 
@@ -602,6 +616,15 @@
        corresponding Java attribute. Hence the name of such a field does not
        refer to a Java attribute of the class, but is used as a unique
        identifier only.
+
+       The state-detection attribute is used by API's supporting automatic 
state detection
+       of persistence capable objects. The attribute indicate whether or not 
this field should
+       be included in object state detection (automatic detection of changed 
object fields).
+       If in the <em>state-detection</em> is generally disabled or in the 
associated
+    class-descriptor, this setting will (normally) be ignored.
+
+    The field-class attribute can be used to override the 
<code>PersistentField</code>
+    implementation class.
   -->
 <!ATTLIST field-descriptor
        id CDATA #IMPLIED
@@ -627,6 +650,8 @@
        precision CDATA #IMPLIED
        scale CDATA #IMPLIED
        access (readonly | readwrite | anonymous) "readwrite"
+       state-detection (true | false) "true"
+       field-class CDATA #IMPLIED
 >
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to