db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r398752 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker: accesslayer/JdbcAccessImpl.java accesslayer/RsIterator.java core/PersistenceBrokerImpl.java metadata/ClassDescriptor.java
Date Tue, 02 May 2006 00:26:45 GMT
Author: arminw
Date: Mon May  1 17:26:42 2006
New Revision: 398752

URL: http://svn.apache.org/viewcvs?rev=398752&view=rev
Log:
add initial LOB field support

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java?rev=398752&r1=398751&r2=398752&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
Mon May  1 17:26:42 2006
@@ -581,6 +581,10 @@
                 Map row = new HashMap();
                 cld.getRowReader().readObjectArrayFrom(rs_stmt, row);
                 result = cld.getRowReader().readObjectFrom(row);
+
+                // TODO: Wrap LOB-fields in RowReader in next major version
+                // wrap LOB fields
+                broker.serviceLobHelper().wrapLobFields(cld, result);
             }
             // close resources
             rs_stmt.close();

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java?rev=398752&r1=398751&r2=398752&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
Mon May  1 17:26:42 2006
@@ -488,6 +488,11 @@
                             // Maps ReferenceDescriptors to HashSets of owners
                             pb.getReferenceBroker().retrieveReferences(result, cld, unforced);
                             pb.getReferenceBroker().retrieveCollections(result, cld, unforced);
+
+                            // TODO: Wrap LOB-fields in RowReader in next major version
+                            // wrap LOB fields
+                            pb.serviceLobHelper().wrapLobFields(cld, result);
+
                             getCache().disableMaterializationCache();
                         }
                         catch(RuntimeException e)
@@ -509,6 +514,15 @@
                     // map all field values from the current result set
                     rowReader.readObjectArrayFrom(getRsAndStmt(), row);
                     rowReader.refreshObject(result, row);
+
+                    // TODO: Wrap LOB-fields in RowReader in next major version
+                    // wrap LOB fields
+                    pb.serviceLobHelper().wrapLobFields(cld, result);
+                }
+                else
+                {
+                    // refresh LOB fields
+                    pb.serviceLobHelper().internalAutoRefresh(result, cld);
                 }
                 pb.checkRefreshRelationships(result, oid, cld);
             }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java?rev=398752&r1=398751&r2=398752&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
Mon May  1 17:26:42 2006
@@ -25,6 +25,8 @@
 import java.util.Set;
 
 import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.ojb.broker.Identity;
 import org.apache.ojb.broker.IdentityFactory;
 import org.apache.ojb.broker.ManageableCollection;
@@ -37,6 +39,10 @@
 import org.apache.ojb.broker.TransactionInProgressException;
 import org.apache.ojb.broker.TransactionNotInProgressException;
 import org.apache.ojb.broker.TransientObjectException;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
+import org.apache.ojb.broker.PersistenceBroker;
+import org.apache.ojb.broker.lob.LobHelper;
+import org.apache.ojb.broker.lob.LobHelperImpl;
 import org.apache.ojb.broker.accesslayer.ChainingIterator;
 import org.apache.ojb.broker.accesslayer.ConnectionManagerFactory;
 import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
@@ -74,6 +80,9 @@
 import org.apache.ojb.broker.util.BrokerHelper;
 import org.apache.ojb.broker.util.IdentityArrayList;
 import org.apache.ojb.broker.util.ObjectModification;
+import org.apache.ojb.broker.util.ClassHelper;
+import org.apache.ojb.broker.util.configuration.Configuration;
+import org.apache.ojb.broker.util.configuration.ConfigurationException;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 import org.apache.ojb.broker.util.sequence.SequenceManager;
@@ -97,6 +106,15 @@
 {
     private Logger logger = LoggerFactory.getLogger(PersistenceBrokerImpl.class);
 
+    /**
+     * A stack trace of this broker user.
+     * Used when broker leak detection is enabled.
+     */
+    protected String brokerStackTrace;
+    /**
+     * Returns <em>true</em> if broker leak detection is enabled.
+     */
+    protected boolean brokerLeakDetection;
     protected PersistenceBrokerFactoryIF pbf;
     protected BrokerHelper brokerHelper;
     protected MtoNBroker mtoNBroker;
@@ -131,6 +149,7 @@
     private IdentityFactory identityFactory;
     private RelationshipPrefetcherFactory relationshipPrefetcherFactory;
     private ProxyFactory proxyFactory;
+    private LobHelper lobHelper;
     private PBKey pbKey;
 
     /**
@@ -208,11 +227,34 @@
                         connectionManager.getSupportedPlatform());
         mtoNBroker = new MtoNBroker(this);
         referencesBroker = new QueryReferenceBroker(this);
-        identityFactory = new IdentityFactoryImpl(this);
         relationshipPrefetcherFactory = new RelationshipPrefetcherFactory(this);
         proxyFactory = AbstractProxyFactory.getProxyFactory();
     }
 
+    public void configure(Configuration pConfig) throws ConfigurationException
+    {
+        super.configure(pConfig);
+        brokerLeakDetection = pConfig.getBoolean("BrokerLeakDetection", false);
+        Class lobHelperClass = pConfig.getClass("LobHelperClass", LobHelperImpl.class);
+        Class identityFactoryClass = pConfig.getClass("IdentityFactoryClass", IdentityFactoryImpl.class);
+        boolean lobAutoRefresh = pConfig.getBoolean("LobAutoRefresh", false);
+        try
+        {
+            lobHelper = (LobHelper) ClassHelper.newInstance(lobHelperClass, PersistenceBrokerInternal.class,
this);
+            identityFactory = (IdentityFactory) ClassHelper.newInstance(identityFactoryClass,
PersistenceBroker.class, this);
+            lobHelper.setLobAutoRefresh(lobAutoRefresh);
+        }
+        catch(Exception e)
+        {
+            throw new PersistenceBrokerException("Can't configure this instance", e);
+        }
+    }
+
+    public LobHelper serviceLobHelper()
+    {
+        return lobHelper;
+    }
+
     public MaterializationCache getInternalCache()
     {
         return objectCache;
@@ -281,6 +323,11 @@
         if(!closed)
         {
             refresh();
+            if(brokerLeakDetection)
+            {
+                brokerStackTrace = ExceptionUtils.getFullStackTrace(
+                        new Exception("PersistenceBroker caller stack"));
+            }
         }
         this.isClosed = closed;
     }
@@ -1731,7 +1778,7 @@
         {
             obj = getDBObject(id);
         }
-        else
+        else // cache match
         {
             ClassDescriptor cld = getClassDescriptor(obj.getClass());
             // if specified in the ClassDescriptor the instance must be refreshed
@@ -1739,6 +1786,11 @@
             {
                 refreshInstance(obj, id, cld);
             }
+            else
+            {
+                // refresh LOB-fields
+                serviceLobHelper().internalAutoRefresh(obj, cld);
+            }
             // now refresh all references
             checkRefreshRelationships(obj, id, cld);
         }
@@ -1807,8 +1859,8 @@
             if(oid.isTransient())
             {
                 if(logger.isEnabledFor(Logger.INFO)) logger.info(
-                        "The object to query was detected as transient, will only lookup
the cache for object instance. Identity="
-                        + oid + ", the query object was " + query);
+                        "The object to query was detected as transient, will only lookup
the cache for object" +
+                                " instance. Identity=" + oid + ", the query object was "
+ query);
                 result = this.objectCache.lookup(oid);
             }
             else
@@ -2228,9 +2280,19 @@
         try
         {
             super.finalize();
+            // if not closed ==> broker leak detected
             if (!isClosed)
             {
-                logger.warn("Garbage collection: Unclosed PersistenceBroker instance detected,
check code for PB leaks");
+                String msg = "Garbage collection: Unclosed PersistenceBroker instance detected,
check code for PB leaks.";
+                if(brokerLeakDetection)
+                {
+                    logger.error(msg + " Broker caller stack is: "
+                            + SystemUtils.LINE_SEPARATOR + brokerStackTrace);
+                }
+                else
+                {
+                    logger.warn(msg);
+                }
                 close();
             }
         }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java?rev=398752&r1=398751&r2=398752&view=diff
==============================================================================
--- 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
Mon May  1 17:26:42 2006
@@ -135,6 +135,10 @@
      */
     private Class factoryClass;
     private int useIdentityColumn = 0;
+    /**
+     * Indicate whether or not this class has LOB fields.
+     */
+    private Boolean hasLobField;
 
     private String baseClass = null;
     /**
@@ -432,6 +436,7 @@
         m_lockingFieldDescriptors = null;
         m_RwFieldDescriptors = null;
         m_RwNonPkFieldDescriptors = null;
+        hasLobField = null;
     }
 
     public boolean removeFieldDescriptor(FieldDescriptor fld)
@@ -449,6 +454,7 @@
         m_lockingFieldDescriptors = null;
         m_RwFieldDescriptors = null;
         m_RwNonPkFieldDescriptors = null;
+        hasLobField = null;
         return result;
     }
 
@@ -2227,5 +2233,27 @@
     public SuperReferenceDescriptor getSuperReference()
     {
         return (SuperReferenceDescriptor) getObjectReferenceDescriptorByName(SuperReferenceDescriptor.SUPER_FIELD_INTERNAL_NAME);
+    }
+
+    /**
+     * Returns <em>true</em> if this class has one or more LOB fields (Blob,
Clob).
+     */
+    public boolean hasLobField()
+    {
+        if(hasLobField == null)
+        {
+            hasLobField = Boolean.FALSE;
+            FieldDescriptor[] fields = getFieldDescriptor(true);
+            for(int i = 0; i < fields.length; i++)
+            {
+                FieldDescriptor field = fields[i];
+                if(field.isLobFieldType())
+                {
+                    hasLobField = Boolean.TRUE;
+                    break;
+                }
+            }
+        }
+        return hasLobField.booleanValue();
     }
 }



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