db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r562142 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb: broker/metadata/ odmg/
Date Thu, 02 Aug 2007 15:38:48 GMT
Author: arminw
Date: Thu Aug  2 08:38:47 2007
New Revision: 562142

URL: http://svn.apache.org/viewvc?view=rev&rev=562142
Log:
use new StateDetection enum class

Added:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/StateDetection.java
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/RepositoryXmlHandler.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/ObjectEnvelope.java

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=562142&r1=562141&r2=562142
==============================================================================
--- 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
Thu Aug  2 08:38:47 2007
@@ -198,7 +198,7 @@
      * indicate wether or not class should be included in object
      * state detection.
      */
-    private boolean stateDetection = true;
+    private StateDetection stateDetection = StateDetection.INHERIT;
     /**
      * if true instances of this class are always refreshed
      * even if they are already in the cache.
@@ -2042,27 +2042,35 @@
     }
 
     /**
-     * Returns whether or not this class should be included in
-     * object state detection. Default state is <em>true</em>.
+     * Returns the state detection status. Default state is <code>StateDetection.INHERIT</code>.
      *
-     * @return If <em>true</em> the class will be included in
-     * automatic object state detection.
-     * @see #setStateDetection(boolean)
+     * @return The state detection status.
      */
-    public boolean isStateDetection()
+    public StateDetection getStateDetection()
     {
         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).
+     * this attribute indicate whether or not the mapped class is
+     * included in object state detection (automatic check for changed object fields).
      *
-     * @param stateDetection Set <em>true</em> if automatic state detection should
-     * be enabled.
+     * @param name Set the status of the {@link StateDetection}.
      */
-    public void setStateDetection(boolean stateDetection)
+    public void setStateDetection(String name)
+    {
+        this.stateDetection = StateDetection.getEnum(name);
+    }
+
+    /**
+     * If the used API supports object state detection (e.g. ODMG-api does),
+     * this attribute indicate whether or not the mapped class is
+     * included in object state detection (automatic check for changed object fields).
+     *
+     * @param stateDetection Set the status of the {@link StateDetection}.
+     */
+    public void setStateDetection(StateDetection 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=562142&r1=562141&r2=562142
==============================================================================
--- 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
Thu Aug  2 08:38:47 2007
@@ -64,7 +64,7 @@
      * indicate wether or not mapped classes should be included in object
      * state detection.
      */
-    private boolean stateDetection = true;
+    private StateDetection stateDetection = StateDetection.ON;
     /**
      * This table holds all known Mapping descriptions.
      * Key values are the respective Class objects
@@ -960,29 +960,37 @@
     }
 
     /**
-     * Returns whether or not mapped classes should be included in
-     * object state detection. Default state is <em>true</em>.
+     * Returns the state detection status. Default state is <code>StateDetection.ON</code>.
      *
-     * @return If <em>true</em> the classes will be included in
-     * automatic object state detection.
-     * @see #setStateDetection(boolean)
+     * @return The state detection status.
      */
-    public boolean isStateDetection()
+    public StateDetection getStateDetection()
     {
         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
+     * this attribute indicate whether or not the mapped classes are
      * included in object state detection (automatic check for changed object fields).
      *
-     * @param stateDetection Set <em>true</em> if automatic state detection should
-     * be enabled.
+     * @param stateDetection Set the status of the {@link StateDetection}.
      */
-    public void setStateDetection(boolean stateDetection)
+    public void setStateDetection(StateDetection stateDetection)
     {
         this.stateDetection = stateDetection;
+    }
+
+    /**
+     * If the used API supports object state detection (e.g. ODMG-api does),
+     * this attribute indicate whether or not the mapped classes are
+     * included in object state detection (automatic check for changed object fields).
+     *
+     * @param name Set the status of the {@link StateDetection}.
+     */
+    public void setStateDetection(String name)
+    {
+        this.stateDetection = StateDetection.getEnum(name);
     }
 
     /**

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=562142&r1=562141&r2=562142
==============================================================================
--- 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
Thu Aug  2 08:38:47 2007
@@ -85,7 +85,7 @@
      * indicate wether or not this field should be included in object
      * state detection.
      */
-    private boolean stateDetection = true;
+    private StateDetection stateDetection = StateDetection.INHERIT;
     private String m_access;
     private SequenceDescriptor sequenceDescriptor;
 
@@ -628,13 +628,11 @@
 
     /**
      * Returns whether or not this field should be included in
-     * object state detection. Default state is <em>true</em>.
+     * object state detection. Default state is <code>StateDetection.INHERIT</code>.
      *
-     * @return If <em>true</em> the field will be included in
-     * automatic object state detection.
-     * @see #setStateDetection(boolean)
+     * @return The state detection status.
      */
-    public boolean isStateDetection()
+    public StateDetection getStateDetection()
     {
         return stateDetection;
     }
@@ -644,9 +642,21 @@
      * this attribute indicate whether or not this field should be included in object
      * state detection (automatic check for changed object fields).
      *
-     * @param stateDetection
+     * @param name Set the status of the {@link StateDetection}.
      */
-    public void setStateDetection(boolean stateDetection)
+    public void setStateDetection(String name)
+    {
+        this.stateDetection = StateDetection.getEnum(name);
+    }
+
+    /**
+     * 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 Set the status of the {@link StateDetection}.
+     */
+    public void setStateDetection(StateDetection stateDetection)
     {
         this.stateDetection = stateDetection;
     }

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=562142&r1=562141&r2=562142
==============================================================================
--- 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
Thu Aug  2 08:38:47 2007
@@ -178,9 +178,8 @@
                         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);
+                            if (isDebug) logger.debug("     " + tags.getTagById(STATE_DETECTION)
+ ": " + stateDetectionStr);
+                            m_repository.setStateDetection(stateDetectionStr);
                         }
 
                         break;
@@ -336,9 +335,8 @@
                         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);
+                            if (isDebug) logger.debug("     " + tags.getTagById(STATE_DETECTION)
+ ": " + stateDetectionStr);
+                            m_CurrentCLD.setStateDetection(stateDetectionStr);
                         }
 
                         // put cld to the metadata repository
@@ -512,9 +510,8 @@
                         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);
+                            if (isDebug) logger.debug("     " + tags.getTagById(STATE_DETECTION)
+ ": " + stateDetectionStr);
+                            m_CurrentFLD.setStateDetection(stateDetectionStr);
                         }
 
                         break;

Added: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/StateDetection.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/StateDetection.java?view=auto&rev=562142
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/StateDetection.java
(added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/StateDetection.java
Thu Aug  2 08:38:47 2007
@@ -0,0 +1,112 @@
+package org.apache.ojb.broker.metadata;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Locale;
+
+import org.apache.commons.lang.enums.Enum;
+
+/**
+ * This class represents the state detection status.
+ *
+ * @version $Id$
+ */
+public class StateDetection extends Enum
+{
+    /**
+     * Enable state detection.
+     */
+    public static final StateDetection ON = new StateDetection("on");
+    /**
+     * Disable state detection.
+     */
+    public static final StateDetection OFF = new StateDetection("off");
+    /**
+     * Inherit state detection status.
+     */
+    public static final StateDetection INHERIT = new StateDetection("inherit");
+
+    private StateDetection(String name)
+    {
+        super(name);
+    }
+
+    /**
+     * Returns <em>true</em> if status is 'ON'.
+     * @return The status match result.
+     */
+    public boolean isOn()
+    {
+        return this.equals(ON);
+    }
+
+    /**
+     * Returns <em>true</em> if status is 'OFF'.
+     * @return The status match result.
+     */
+    public boolean isOff()
+    {
+        return this.equals(OFF);
+    }
+
+    /**
+     * Returns <em>true</em> if status is 'INHERIT'.
+     * @return The status match result.
+     */
+    public boolean isInherit()
+    {
+        return this.equals(INHERIT);
+    }
+
+    /**
+     * Get the state detection. Valid names are: on, off, inherit.
+     *
+     * @param name The name of the state detection status.
+     * @return The resolved {@link org.apache.ojb.broker.metadata.StateDetection}.
+     */
+    public static StateDetection getEnum(String name)
+    {
+        StateDetection result = (StateDetection) getEnum(StateDetection.class, name.toLowerCase(Locale.ENGLISH));
+        if(result == null)
+        {
+            throw new MetadataException("Specified state-dection status '" + name
+                    + "' doesn't exist, valid settings are: " + getEnumList());
+        }
+        return result;
+    }
+
+    public static Map getEnumMap()
+    {
+        return getEnumMap(StateDetection.class);
+    }
+
+    public static List getEnumList()
+    {
+        return getEnumList(StateDetection.class);
+    }
+
+    public static Iterator iterator()
+    {
+        return iterator(StateDetection.class);
+    }
+}

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/ObjectEnvelope.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/ObjectEnvelope.java?view=diff&rev=562142&r1=562141&r2=562142
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/ObjectEnvelope.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/ObjectEnvelope.java Thu Aug
 2 08:38:47 2007
@@ -443,7 +443,7 @@
 
     private void buildImageForFields(Map imageMap, ClassDescriptor cld)
     {
-        if(cld.isStateDetection() && cld.getRepository().isStateDetection())
+        if(!cld.getStateDetection().isOff() && cld.getRepository().getStateDetection().isOn())
         {
             // register all non reference fields of object (with inherited fields)
             FieldDescriptor[] fieldDescs = cld.getFieldDescriptor(true);
@@ -458,7 +458,7 @@
     {
         // register copies of all fields, except the fields with
         // disbaled state detection
-        if(fld.isStateDetection())
+        if(!fld.getStateDetection().isOff())
         {
             Object value = fld.getCopyOfValue(getRealObject());
             imageMap.put(fld.getPersistentField().getName(), new Image.Field(fld.getJdbcType().getFieldType(),
value));



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