db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r422228 [1/2] - in /db/ojb/trunk: ./ src/java/org/apache/ojb/broker/accesslayer/ src/java/org/apache/ojb/broker/accesslayer/conversions/ src/java/org/apache/ojb/broker/accesslayer/sql/
Date Sat, 15 Jul 2006 14:17:30 GMT
Author: arminw
Date: Sat Jul 15 07:17:29 2006
New Revision: 422228

URL: http://svn.apache.org/viewvc?rev=422228&view=rev
Log:
merge trunk with 1.0.x

Modified:
    db/ojb/trunk/build-torque.xml
    db/ojb/trunk/build.properties
    db/ojb/trunk/build.xml
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/PlainPrefetcher.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ReferencePrefetcher.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReader.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/FieldConversion.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/IntList2VarcharFieldConversion.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/StringList2VarcharFieldConversion.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/StringVector2VarcharFieldConversion.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/TimeList2VarcharFieldConversion.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlExistStatement.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlInsertStatement.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectByPkStatement.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java

Modified: db/ojb/trunk/build-torque.xml
URL: http://svn.apache.org/viewvc/db/ojb/trunk/build-torque.xml?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/build-torque.xml (original)
+++ db/ojb/trunk/build-torque.xml Sat Jul 15 07:17:29 2006
@@ -1,5 +1,21 @@
 <project name="Torque" default="main" basedir=".">
   <!--
+#/* Copyright 2002-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+-->
+  <!--
     Note - You should not have to edit this file.
 
     Instead, if calling build-torque.xml directly, edit the build.properties
@@ -22,7 +38,7 @@
   <property file="${torque.contextProperties}"/>
   <property name="lib.dir" value="lib"/>
   <property name="torque.lib.dir" value="${lib.dir}"/>
-  <property name="torque.jar" value="torque-gen-3.1.jar"/>
+
 
   <!--
     Build the classpath. Specifically point to each file we're including to avoid
@@ -33,14 +49,6 @@
   -->
   <path id="torque-classpath">
     <fileset dir="${torque.lib.dir}">
-      <include name="**/commons-collections-2.1.jar"/>
-      <include name="**/commons-lang-1.0.1.jar"/>
-      <include name="**/log4j-1.2.8.jar"/>
-      <include name="**/${torque.jar}"/>
-      <include name="**/velocity-1.3.1.jar"/>
-      <include name="**/village-2.0-dev-20030825.jar"/>
-      <include name="**/xercesImpl-2.0.2.jar"/>
-      <include name="**/xmlParserAPIs-2.0.2.jar"/>
       <include name="**/*.jar"/>
     </fileset>
   </path>

Modified: db/ojb/trunk/build.properties
URL: http://svn.apache.org/viewvc/db/ojb/trunk/build.properties?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/build.properties (original)
+++ db/ojb/trunk/build.properties Sat Jul 15 07:17:29 2006
@@ -22,7 +22,6 @@
 # implemented profiles:
 #
 profile=hsqldb
-
 # use the mssqldb-JSQLConnect profile for Microsoft SQL Server and
 # you will automatically JSQLConnect driver, from http://www.j-netdirect.com/
 # MBAIRD: This is my driver of preference for MS SQL Server, I find the OEM'd
@@ -32,7 +31,6 @@
 #profile=mssqldb-ms
 #profile=mysql
 #profile=db2
-#profile=derby
 #profile=oracle
 #profile=oracle9i
 #profile=msaccess
@@ -41,6 +39,7 @@
 #profile=sybase
 #profile=sapdb
 #profile=maxdb
+#profile=derby
 #profile=mckoi
 #profile=firebird
 
@@ -145,10 +144,10 @@
 org.apache.ojb.broker.accesslayer,\
 org.apache.ojb.broker.accesslayer.conversions,\
 org.apache.ojb.broker.core.*,\
-org.apache.ojb.broker.dirty,\
 org.apache.ojb.broker.metadata,\
 org.apache.ojb.broker.metadata.fieldaccess,\
 org.apache.ojb.broker.cache,\
+org.apache.ojb.broker.lob,\
 org.apache.ojb.broker.locking,\
 org.apache.ojb.broker.util,\
 org.apache.ojb.broker.util.logging,\
@@ -164,20 +163,21 @@
 org.apache.ojb.junit,\
 org.apache.ojb.performance
 
-copyright=(C) 2002 - 2006 Apache Software Foundation <br>All rights reserved. Published under the Apache License 2.0. <br> <a href="http://db.apache.org/ojb">http://db.apache.org/ojb</a>
-icon=<img src="../images/ojb-200.png" alt="ObJectRelationalBridge">
-br=<br>
-hr=<hr>
+copyright=(C) 2002 - 2006 Apache Software Foundation \
+<br/>All rights reserved. Published under the Apache License 2.0. \
+<br/><a href="http://db.apache.org/ojb">http://db.apache.org/ojb</a>
+icon=<img src="../images/ojb-400-white.png" alt="ObJectRelationalBridge">
+br=<br/>
 
 
 # project name and version info
 name=ObJectRelationalBridge
 project-name=db-ojb
-major=1
-minor=1
+major=2
+minor=0
 build=0
 version=${major}.${minor}.${build}
-versiondate=2005-10-15
+versiondate=2006-XX-XX
 ojb-filename-prefix=${project-name}-${version}
 
 #

Modified: db/ojb/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/ojb/trunk/build.xml?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/build.xml (original)
+++ db/ojb/trunk/build.xml Sat Jul 15 07:17:29 2006
@@ -17,11 +17,6 @@
  */
 -->
 <!-- @version $Id$ -->
-<!--
-     ObJectRelationalBridge ANT build configuration.
-     initial author: Thomas Mahler
-     contains modifications by Chris Greenlee and others.
--->
 
 <project name="ObJectRelationalBridge" default="all" basedir=".">
 
@@ -64,6 +59,13 @@
         <path refid="compilation-classpath"/>
     </path>
 
+    <!-- classpath used for OJB's test suite -->
+    <path id="junit-classpath">
+        <path refid="runtime-classpath"/>
+        <!-- this jar was used in OJB's test suite -->
+        <pathelement path="${build.test}/tmp/test-res.jar"/>
+    </path>
+
     <property name="runtime.classpath" refid="runtime-classpath"/>
 
 
@@ -395,19 +397,6 @@
     </target>
 
     <!-- ================================================================== -->
-    <!-- dump testdb using torque                                        -->
-    <!-- ================================================================== -->
-    <target name="dump-testdb"
-            description="dump testdb using torque">
-        <ant dir="."
-             antfile="${torque.buildFile}"
-             target="project-datadtd-classpath"/>
-        <ant dir="."
-             antfile="${torque.buildFile}"
-             target="project-datadump-classpath"/>
-    </target>
-
-    <!-- ================================================================== -->
     <!-- prepare testdb using DdlUtils                                      -->
     <!-- ================================================================== -->
     <target name="prepare-testdb-ddlutils"
@@ -468,6 +457,19 @@
     </target>
 
     <!-- ================================================================== -->
+    <!-- dump testdb using torque                                        -->
+    <!-- ================================================================== -->
+    <target name="dump-testdb"
+            description="dump testdb using torque">
+        <ant dir="."
+             antfile="${torque.buildFile}"
+             target="project-datadtd-classpath"/>
+        <ant dir="."
+             antfile="${torque.buildFile}"
+             target="project-datadump-classpath"/>
+    </target>
+
+    <!-- ================================================================== -->
     <!-- Build the JAR file using main-opt                                  -->
     <!-- ================================================================== -->
 
@@ -589,17 +591,7 @@
         <!-- 3. additional jar files -->
         <copy todir="${build.servlet}/WEB-INF/lib">
             <fileset dir="${lib}">
-                <include name="**/*.jar"/>
-                <exclude name="jdo*.jar"/>
-                <exclude name="ant-*.jar"/>
-                <exclude name="xerces*.jar"/>
-                <exclude name="xml-*.jar"/>
-                <exclude name="xalan*.jar"/>
-                <exclude name="jakarta-regexp*.jar"/>
-                <exclude name="torque*.jar"/>
-                <exclude name="velocity*.jar"/>
-                <exclude name="xdoclet*.jar"/>
-                <exclude name="xjava*.jar"/>
+                <include name="commons-*.jar"/>
             </fileset>
         </copy>
 
@@ -1151,6 +1143,35 @@
            basedir="${build.mavendist}"/>
   </target> 
  
+    <!-- =================================================================== -->
+	<!-- create jar resource for a specific test in OJB's test-suite         -->
+	<!-- =================================================================== -->
+    <target name="prepare-test-suite" description="Prepare OJB's test suite">
+        <property name="res.src" value="${src.test}/org/apache/ojb"/>
+        <property name="res.tmp.dir" value="${build.test}/tmp"/>
+        <property name="res.jar.name" value="test-res.jar" />
+        <property name="res.jar.dir" value="${res.tmp.dir}" />
+
+        <delete dir="${res.tmp.dir}" />
+        <mkdir dir="${res.tmp.dir}" />
+        <mkdir dir="${res.tmp.dir}/tmp" />
+
+        <copy todir="${res.tmp.dir}/tmp">
+            <fileset dir="${res.src}">
+              <include name="repository.dtd Test_Repository_Renamed_DTD.xml"/>
+            </fileset>
+        </copy>
+        <copy file="${res.src}/repository.dtd" tofile="${res.jar.dir}/tmp/test_renamed_repository.dtd"/>
+        <copy file="${res.src}/Test_Repository_Renamed_DTD.xml" todir="${res.jar.dir}/tmp"/>
+
+        <jar jarfile="${res.jar.dir}/tmp/${res.jar.name}"
+            basedir="${res.jar.dir}/tmp">
+        </jar>
+
+        <copy file="${res.jar.dir}/tmp/${res.jar.name}" todir="${res.jar.dir}"/>
+        <delete dir="${res.tmp.dir}/tmp" />
+    </target>
+
     <!-- ================================================================== -->
     <!-- Perform JUnit Tests                                                -->
     <!-- ================================================================== -->
@@ -1163,10 +1184,10 @@
     	description="Performs all JUnit regression tests."/>
 
     <!-- property 'test.package' has to be set at command line -->
-    <target name="run-test" depends="junit-environment-check, prepare-repository, copy-testdb">
+    <target name="run-test" depends="junit-environment-check, prepare-repository, copy-testdb, prepare-test-suite">
         <junit printsummary="yes" showoutput="true" fork="yes" dir="${build.test}/ojb">
         	<jvmarg value="-DOJB.bootLogLevel=INFO" />
-            <classpath refid="runtime-classpath"/>
+            <classpath refid="junit-classpath"/>
             <formatter type="plain" />
             <test name="${test.package}"
                   haltonfailure="no"
@@ -1177,7 +1198,7 @@
     </target>
 
     <target name="junit-no-compile"
-    	    depends="junit-environment-check,prepare,prepare-testdb,junit-no-compile-no-prepare,junit-no-compile-no-prepare-selected"
+    	    depends="junit-environment-check,prepare,prepare-testdb, prepare-test-suite, junit-no-compile-no-prepare,junit-no-compile-no-prepare-selected"
     />
 
     <target name="junit-no-compile-no-prepare"
@@ -1185,7 +1206,7 @@
         <junit printsummary="yes" fork="yes" dir="${build.test}/ojb">
         	<jvmarg value="-DOJB.bootLogLevel=INFO" />
             <jvmarg value="-DOJB.skip.issues=${OJB.skip.issues}" />
-            <classpath refid="runtime-classpath"/>
+            <classpath refid="junit-classpath"/>
             <formatter type="plain" />
             <formatter type="xml" />
 
@@ -1198,15 +1219,15 @@
                   haltonfailure="no"
                   outfile="target/test/tests-odmg" >
             </test>
-            <test name="org.apache.ojb.soda.AllTests"
-                  haltonfailure="no"
-                  outfile="target/test/tests-soda" >
-            </test>
-
-            <test name="org.apache.ojb.otm.AllTests"
-                  haltonfailure="no"
-                  outfile="target/test/tests-otm" >
-            </test>
+            <!--<test name="org.apache.ojb.soda.AllTests"-->
+                  <!--haltonfailure="no"-->
+                  <!--outfile="target/test/tests-soda" >-->
+            <!--</test>-->
+<!---->
+            <!--<test name="org.apache.ojb.otm.AllTests"-->
+                  <!--haltonfailure="no"-->
+                  <!--outfile="target/test/tests-otm" >-->
+            <!--</test>-->
 
         </junit>
     </target>
@@ -1217,7 +1238,7 @@
             <jvmarg value="-DOJB.bootLogLevel=INFO" />
             <jvmarg value="-DOJB.skip.issues=${OJB.skip.issues}" />
 <!--            <jvmarg value="-Xrunyjpagent:alloc,onexit=memory"/> -->
-            <classpath refid="runtime-classpath"/>
+            <classpath refid="junit-classpath"/>
             <formatter type="plain" />
             <formatter type="xml" />
 
@@ -1251,7 +1272,7 @@
         <junit printsummary="yes" fork="yes" dir="${build.test}/ojb">
             <jvmarg value="-DOJB.bootLogLevel=INFO"/>
             <jvmarg value="-DOJB.skip.issues=${OJB.skip.issues}"/>
-            <classpath refid="runtime-classpath"/>
+            <classpath refid="junit-classpath"/>
             <formatter type="plain"/>
             <formatter type="xml"/>
             <test name="org.apache.ojb.broker.sqlcount.AllTests"
@@ -1273,6 +1294,7 @@
     <target name="copy-testdb" depends="prepare">
     	<delete file="${build.test}/OJB.properties"/>
     	<delete file="${build.test}/OJB.script"/>
+    	<delete file="${build.test}/OJB.log"/>
     	<copy file="${src.test}/org/apache/ojb/quick-db/OJB.properties" tofile="${build.test}/OJB.properties"/>
     	<copy file="${src.test}/org/apache/ojb/quick-db/OJB.script" tofile="${build.test}/OJB.script"/>
 
@@ -1289,7 +1311,7 @@
         <java fork="yes" classname="org.apache.ojb.compare.CompareApiPerformanceTests"
               dir="${build.test}/ojb" taskname="ojb" failonerror="true" >
             <classpath refid="runtime-classpath"/>
-            <arg value="2500"/>
+            <arg value="1500"/>
             <arg value="3"/>
             <jvmarg value="-Xms128m"/>
             <jvmarg value="-Xmx256m"/>
@@ -1326,13 +1348,13 @@
             <arg value=
             "org.apache.ojb.compare.OJBPerfTest$JdbcPerfTest,
             org.apache.ojb.compare.OJBPerfTest$PBPerfTest,
-            org.apache.ojb.compare.OJBPerfTest$ODMGPerfTest,
-            org.apache.ojb.compare.OJBPerfTest$OTMPerfTest"
+            org.apache.ojb.compare.OJBPerfTest$ODMGPerfTest"
             />
             <arg value="6"/> <!-- test loops, default was 6 -->
             <arg value="12"/> <!-- performed threads, default was 12 -->
 			<arg value="500"/> <!-- number of managed objects per thread, default was 500 -->
             <arg value="false"/> <!-- if 'false' we use performance mode, 'true' we do run in stress mode -->
+            <arg value="true"/> <!-- if 'true' all log messages will be print -->
             <jvmarg value="-Xms128m"/>
             <jvmarg value="-Xmx256m"/>
         </java>
@@ -1340,8 +1362,8 @@
         <ant target="copy-testdb"/>
     </target>
 
+    <!-- compile perf classes -->
     <target name="perf-test-jar" depends="init">
-        <!-- compile perf classes -->
         <javac srcdir="${build.srctest}"
             includes="**/performance/*"
 			destdir="${build.desttest}"

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java Sat Jul 15 07:17:29 2006
@@ -43,7 +43,6 @@
 /**
  * Relationship Prefetcher for Collections.
  *
- * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
  * @version $Id$
  */
 public class CollectionPrefetcher extends RelationshipPrefetcherImpl
@@ -68,7 +67,6 @@
     protected Query[] buildPrefetchQueries(Collection owners, Collection children)
     {
         PersistenceBroker pb = getBroker();
-        IdentityFactory idFactory = pb.serviceIdentity();
         ClassDescriptor cld = getOwnerClassDescriptor();
         Class topLevelClass = pb.getTopLevelClass(cld.getClassOfObject());
         Collection queries = new ArrayList(owners.size());
@@ -83,7 +81,7 @@
             owner = iter.next();
             fkValues = getFkTargetValuesForObject(owner);
             
-            id = idFactory.buildIdentity(null, topLevelClass, fkValues);
+            id = pb.serviceIdentity().buildIdentity(null, topLevelClass, fkValues);
             idsSubset.add(id);
             if (idsSubset.size() == pkLimit)
             {
@@ -114,11 +112,11 @@
         {
             String EOL = SystemUtils.LINE_SEPARATOR;
             String msg = EOL + "Can't build prefetch query for collection descriptor belonging to '"
-                    + (cds != null ? cds.getClassDescriptor().getClassNameOfObject() : null) + "', "
-                    + EOL + "field name '" + (cds != null ? cds.getPersistentField().getName() : null) + "', "
+                    + (cds.getClassDescriptor().getClassNameOfObject()) + "', "
+                    + EOL + "field name '" + (cds.getPersistentField().getName()) + "', "
                     + EOL + "item class was '" + (itemCld != null ? itemCld.getClassNameOfObject() : null) + "', "
                     + EOL + "because the length of FK fields was '0'!! Check metadata configuration."
-                    + EOL + " Descriptor: " + (cds != null ? cds.toXML() : null);
+                    + EOL + " Descriptor: " + (cds.toXML());
             throw new OJBRuntimeException(msg);
         }
         QueryByCriteria query = buildPrefetchQuery(ids, fields);

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java Sat Jul 15 07:17:29 2006
@@ -23,6 +23,7 @@
 import org.apache.commons.dbcp.AbandonedConfig;
 import org.apache.commons.dbcp.AbandonedObjectPool;
 import org.apache.commons.dbcp.DriverManagerConnectionFactory;
+import org.apache.commons.dbcp.PoolableConnection;
 import org.apache.commons.dbcp.PoolableConnectionFactory;
 import org.apache.commons.dbcp.PoolingDataSource;
 import org.apache.commons.pool.KeyedObjectPoolFactory;
@@ -38,8 +39,8 @@
 import org.apache.ojb.broker.util.pooling.PoolConfiguration;
 
 /**
- * ConnectionFactory implementation using jakarta-DBCP
- * to pool driver based connections.
+ * ConnectionFactory implementation using Commons DBCP and Commons Pool API
+ * to pool connections.
  *
  * (based on a proposal of Dirk Verbeek - Thanks).
  *
@@ -91,7 +92,12 @@
         try
         {
             // We are using datasources, thus close returns connection to pool
-            con.close();
+
+            // we have to check 'isClosed', because otherwise method
+            // org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.checkOpen
+            // will throw an unexpected exception (see javadoc for Coonection.close()) when
+            // con.close() is called several times.
+            if(!con.isClosed()) con.close();
         }
         catch (SQLException e)
         {
@@ -111,6 +117,11 @@
                 if(connectionPool != null)
                 {
                     log.warn("Release connection pool: " + connectionPool);
+                    if(connectionPool instanceof GenericObjectPool)
+                    {
+                        // deactivates the idle evictor thread
+                        ((GenericObjectPool) connectionPool).setTimeBetweenEvictionRunsMillis(-1);
+                    }
                     connectionPool.close();
                     connectionPool = null;
                     dataSource = null;
@@ -218,7 +229,7 @@
         // the classes that implement the pooling functionality.
         //
         final PoolableConnectionFactory poolableConnectionFactory;
-        poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
+        poolableConnectionFactory = new OJBPoolableConnectionFactory(connectionFactory,
                 connectionPool,
                 statementPoolFactory,
                 validationQuery,
@@ -232,11 +243,14 @@
                                               AbandonedConfig ac)
     {
         final GenericObjectPool connectionPool;
-        final boolean doRemoveAbandoned = ac != null && ac.getRemoveAbandoned() == true;
+        final boolean doRemoveAbandoned = ac != null && ac.getRemoveAbandoned();
 
-        if (doRemoveAbandoned) {
+        if(doRemoveAbandoned)
+        {
             connectionPool = new AbandonedObjectPool(null, ac);
-        } else {
+        }
+        else
+        {
             connectionPool = new GenericObjectPool();
         }
         connectionPool.setMaxActive(config.maxActive);
@@ -256,7 +270,7 @@
     {
         final JdbcConnectionDescriptor jcd = getJcd();
         final String platform = jcd.getDbms();
-        if (platform.startsWith("Oracle9i"))
+        if(platform.startsWith("Oracle9i"))
         {
             // mkalen: let the platform set Oracle-specific statement pooling
             return null;
@@ -266,23 +280,21 @@
         GenericKeyedObjectPoolFactory statementPoolFactory = null;
         final Properties properties = jcd.getConnectionFactoryDescriptor().getDbcpProperties();
         final String poolStmtParam = properties.getProperty(PARAM_NAME_POOL_STATEMENTS);
-        if (poolStmtParam != null && Boolean.valueOf(poolStmtParam).booleanValue())
+        if(poolStmtParam != null && Boolean.valueOf(poolStmtParam).booleanValue())
         {
-            final String maxOpenPrepStmtString;
-
             int maxOpenPreparedStatements = GenericKeyedObjectPool.DEFAULT_MAX_TOTAL;
-            maxOpenPrepStmtString = properties.getProperty(PARAM_NAME_STATEMENT_POOL_MAX_TOTAL);
-            if (maxOpenPrepStmtString != null)
+            final String maxOpenPrepStmtString = properties.getProperty(PARAM_NAME_STATEMENT_POOL_MAX_TOTAL);
+            if(maxOpenPrepStmtString != null)
             {
                 maxOpenPreparedStatements = Integer.parseInt(maxOpenPrepStmtString);
             }
             // Use the same values as Commons DBCP BasicDataSource
             statementPoolFactory = new GenericKeyedObjectPoolFactory(null,
-                        -1, // unlimited maxActive (per key)
-                        GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL,
-                        0, // maxWait
-                        1, // maxIdle (per key)
-                        maxOpenPreparedStatements);
+                    -1, // unlimited maxActive (per key)
+                    GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL,
+                    0, // maxWait
+                    1, // maxIdle (per key)
+                    maxOpenPreparedStatements);
         }
         return statementPoolFactory;
     }
@@ -309,22 +321,16 @@
             final Properties properties = jcd.getConnectionFactoryDescriptor().getDbcpProperties();
             final String allowConnectionUnwrapParam;
             allowConnectionUnwrapParam = properties.getProperty(PARAM_NAME_UNWRAP_ALLOWED);
-            if (allowConnectionUnwrapParam != null &&
-                Boolean.valueOf(allowConnectionUnwrapParam).booleanValue())
-            {
-                allowConnectionUnwrap = true;
-            }
-            else
-            {
-                allowConnectionUnwrap = false;
-            }
+            //allow access to underlying resource by default if property is not set
+            allowConnectionUnwrap = allowConnectionUnwrapParam == null || Boolean.valueOf(allowConnectionUnwrapParam).booleanValue();
         }
         final PoolingDataSource dataSource;
         dataSource = new PoolingDataSource(connectionPool);
         dataSource.setAccessToUnderlyingConnectionAllowed(allowConnectionUnwrap);
 
         final AbandonedConfig ac = buildAbandonedConfiguration(jcd);
-        if (ac.getRemoveAbandoned() && ac.getLogAbandoned()) {
+        if(ac.getRemoveAbandoned() && ac.getLogAbandoned())
+        {
             final LoggerWrapperPrintWriter loggerPiggyBack;
             loggerPiggyBack = new LoggerWrapperPrintWriter(log, Logger.ERROR);
             dataSource.setLogWriter(loggerPiggyBack);
@@ -371,134 +377,6 @@
         return result;
     }
 
-    // ----- deprecated methods, to be removed -----
-
-//    /**
-//     * mkalen: Left for binary API-compatibility with OJB 1.0.3 (don't break users' factories)
-//     * @deprecated since OJB 1.0.4,
-//     * please use {@link #createConnectionPool(org.apache.commons.pool.impl.GenericObjectPool.Config, org.apache.commons.dbcp.AbandonedConfig)}
-//     */
-//    protected ObjectPool createObjectPool(GenericObjectPool.Config config)
-//    {
-//        return createConnectionPool(config, null);
-//    }
-
-//    /**
-//     * mkalen: Left for binary API-compatibility with OJB 1.0.3 (don't break users' factories)
-//     * @deprecated since OJB 1.0.4,
-//     * please use {@link #wrapAsDataSource(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor, org.apache.commons.pool.ObjectPool)}
-//     */
-//    protected PoolingDataSource createPoolingDataSource(ObjectPool connectionPool)
-//    {
-//        // mkalen: not a nice cast but we do not want to break signature and it is safe
-//        // since any new implementations will not be based on this method and the wrapper-
-//        // call here goes to code we control (where we know it's PoolingDataSource)
-//        return (PoolingDataSource) wrapAsDataSource(null, connectionPool);
-//    }
-
-    // ----- end deprecated methods -----
-
-//    protected ObjectPool createConnectionPool(GenericObjectPool.Config config,
-//                                              AbandonedConfig ac)
-//    {
-//        final GenericObjectPool connectionPool;
-//        final boolean doRemoveAbandoned = ac != null && ac.getRemoveAbandoned();
-//
-//        if (doRemoveAbandoned) {
-//            connectionPool = new AbandonedObjectPool(null, ac);
-//        } else {
-//            connectionPool = new GenericObjectPool();
-//        }
-//        connectionPool.setMaxActive(config.maxActive);
-//        connectionPool.setMaxIdle(config.maxIdle);
-//        connectionPool.setMinIdle(config.minIdle);
-//        connectionPool.setMaxWait(config.maxWait);
-//        connectionPool.setTestOnBorrow(config.testOnBorrow);
-//        connectionPool.setTestOnReturn(config.testOnReturn);
-//        connectionPool.setTimeBetweenEvictionRunsMillis(config.timeBetweenEvictionRunsMillis);
-//        connectionPool.setNumTestsPerEvictionRun(config.numTestsPerEvictionRun);
-//        connectionPool.setMinEvictableIdleTimeMillis(config.minEvictableIdleTimeMillis);
-//        connectionPool.setTestWhileIdle(config.testWhileIdle);
-//        return connectionPool;
-//    }
-//
-//    private GenericObjectPool.Config buildPoolConfiguration(JdbcConnectionDescriptor jcd)
-//    {
-//        PoolConfiguration poolConf = new PoolConfiguration();
-//        // read all attributes from descriptor and add them to ..Conf class
-//        poolConf.putAll(jcd.getConnectionFactoryDescriptor().getAttributes());
-//
-//        GenericObjectPool.Config conf = poolConf.getObjectPoolConfig();
-//        return conf;
-//    }
-//
-//    private AbandonedConfig buildAbandonedConfig(JdbcConnectionDescriptor jcd)
-//    {
-//        PoolConfiguration poolConf = new PoolConfiguration();
-//        // read all attributes from descriptor and add them to ..Conf class
-//        poolConf.putAll(jcd.getConnectionFactoryDescriptor().getAttributes());
-//
-//        AbandonedConfig ac = poolConf.getAbandonedConfig();
-//        return ac;
-//    }
-//
-//    protected ObjectPool createObjectPool(GenericObjectPool.Config config)
-//    {
-//        // We'll use a GenericObjectPool instance, although
-//        // any ObjectPool implementation will suffice.
-//        return new GenericObjectPool(null, config);
-//    }
-//
-//    protected KeyedObjectPoolFactory createStatementPoolFactory(JdbcConnectionDescriptor jcd)
-//    {
-//        final String platform = jcd.getDbms();
-//        if (platform.equals("Oracle9i"))
-//        {
-//            // mkalen: let the platform set Oracle-specific statement pooling
-//            return null;
-//        }
-//
-//        final KeyedPoolableObjectFactory objectFactory = getStatementCacheObjectFactory();
-//        final GenericKeyedObjectPool.Config factoryConfig = buildStatementCacheFactoryConfig(jcd);
-//        final KeyedObjectPoolFactory stmtPoolFactory;
-//        stmtPoolFactory = new GenericKeyedObjectPoolFactory(objectFactory, factoryConfig);
-//        return stmtPoolFactory;
-//    }
-//
-//    protected KeyedPoolableObjectFactory getStatementCacheObjectFactory()
-//    {
-//        return null;
-//    }
-//
-//    protected GenericKeyedObjectPool.Config buildStatementCacheFactoryConfig(JdbcConnectionDescriptor jcd)
-//    {
-//        GenericKeyedObjectPool.Config factoryConfig;
-//
-//        // TODO: mkalen: find a way to specify PreparedStatement pooling params
-//        factoryConfig = new GenericKeyedObjectPool.Config();
-//        /*
-//        // We can not use this as that would set Connection pool params on PS-cache...
-//        PoolConfiguration poolConf = new PoolConfiguration();
-//        // read all attributes from descriptor and add them to ..Conf class
-//        poolConf.putAll(jcd.getConnectionFactoryDescriptor().getAttributes());
-//        poolConf.getKeyedObjectPoolConfig();
-//        factoryConfig = poolConf.getKeyedObjectPoolConfig();
-//        */
-//        return factoryConfig;
-//    }
-//
-//    protected PoolingDataSource createPoolingDataSource(ObjectPool pool)
-//    {
-//        PoolingDataSource ds = new PoolingDataSource(pool);
-//        // allow user to access underlying (real) connection
-//        ds.setAccessToUnderlyingConnectionAllowed(true);
-//        return ds;
-//    }
-//
-//    protected org.apache.commons.dbcp.ConnectionFactory createConnectionFactory(JdbcConnectionDescriptor jcd)
-//    {
-//        return new ConPoolFactory(jcd);
-//    }
 
     //**************************************************************************************
     // Inner classes
@@ -520,13 +398,13 @@
         public Connection createConnection() throws SQLException
         {
             final Connection conn = super.createConnection();
-            if (conn != null)
+            if(conn != null)
             {
                 try
                 {
                     initializeJdbcConnection(conn);
                 }
-                catch (LookupException e)
+                catch(LookupException e)
                 {
                     log.error("Platform dependent initialization of connection failed", e);
                 }
@@ -534,6 +412,138 @@
             return conn;
         }
 
+    }
+
+    /**
+     * Specific OJB version of {@link org.apache.commons.dbcp.PoolableConnectionFactory}. This is
+     * needed because the DBCP version cause some unexpected behavior - see overridden methods
+     * {@link #passivateObject(Object)}, {@link #activateObject(Object)} and {@link #makeObject()}.
+     */
+    static class OJBPoolableConnectionFactory extends PoolableConnectionFactory
+    {
+        public OJBPoolableConnectionFactory(org.apache.commons.dbcp.ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit)
+        {
+            super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit);
+}
+
+        public OJBPoolableConnectionFactory(org.apache.commons.dbcp.ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation)
+        {
+            super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation);
+        }
+
+        public OJBPoolableConnectionFactory(org.apache.commons.dbcp.ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, AbandonedConfig config)
+        {
+            super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, config);
+        }
+
+        public OJBPoolableConnectionFactory(org.apache.commons.dbcp.ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, AbandonedConfig config)
+        {
+            super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, config);
+        }
+
+        public OJBPoolableConnectionFactory(org.apache.commons.dbcp.ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, String defaultCatalog, AbandonedConfig config)
+        {
+            super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, defaultCatalog, config);
+        }
+
+        public OJBPoolableConnectionFactory(org.apache.commons.dbcp.ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, Boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation, String defaultCatalog, AbandonedConfig config)
+        {
+            super(connFactory, pool, stmtPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, defaultCatalog, config);
+        }
+
+        /**
+         * Don't change autocommit state - This is handled by OJB.
+         */
+        public void passivateObject(final Object obj) throws Exception
+        {
+            if(obj instanceof OJBPoolableConnection)
+            {
+                OJBPoolableConnection conn = (OJBPoolableConnection) obj;
+                conn.clearWarnings();
+                // do not change, will be managed by OJB
+                //conn.setAutoCommit(true);
+
+                conn.passivate();
+            }
+            else
+            {
+                super.passivateObject(obj);
+            }
+        }
+
+        /**
+         * Don't change autocommit state, don't rollback connection when autocommit
+         * is set false and connection is not readonly - This is handled by OJB.
+         */
+        public void activateObject(final Object obj) throws Exception
+        {
+            if(obj instanceof OJBPoolableConnection)
+            {
+                OJBPoolableConnection conn = (OJBPoolableConnection) obj;
+                conn.activate();
+                // do not change, will be managed by OJB
+                // conn.setAutoCommit(_defaultAutoCommit);
+                if(_defaultTransactionIsolation != -1 && _defaultTransactionIsolation != conn.getTransactionIsolation())
+                {
+                    conn.setTransactionIsolation(_defaultTransactionIsolation);
+                }
+                if(_defaultReadOnly.booleanValue() != conn.isReadOnly())
+                {
+                    conn.setReadOnly(_defaultReadOnly.booleanValue());
+                }
+                if(_defaultCatalog != null)
+                {
+                    conn.setCatalog(_defaultCatalog);
+                }
+            }
+            else
+            {
+                super.activateObject(obj);
+            }
+        }
+
+        /**
+         * Wraps the {@link org.apache.commons.dbcp.PoolableConnection} with
+         * {@link org.apache.ojb.broker.accesslayer.ConnectionFactoryDBCPImpl.OJBPoolableConnection}
+         * to allow access to protected methods.
+         */
+        synchronized public Object makeObject() throws Exception
+        {
+            PoolableConnection con = (PoolableConnection) super.makeObject();
+            return new OJBPoolableConnection(con, _pool, _config);
+        }
+    }
+
+    /**
+     * Needed to allow usage of methods {@link #activate()} and {@link #passivate()}
+     * in class {@link org.apache.ojb.broker.accesslayer.ConnectionFactoryDBCPImpl.OJBPoolableConnectionFactory}.
+     */
+    static class OJBPoolableConnection extends PoolableConnection
+    {
+        public OJBPoolableConnection(final Connection conn, final ObjectPool pool)
+        {
+            super(conn, pool);
+        }
+
+        public OJBPoolableConnection(final Connection conn, final ObjectPool pool, final AbandonedConfig config)
+        {
+            super(conn, pool, config);
+        }
+
+        protected void activate()
+        {
+            super.activate();
+        }
+
+        protected void passivate() throws SQLException
+        {
+            super.passivate();
+        }
+
+        public synchronized void close() throws SQLException
+        {
+            if(!isClosed()) super.close();
+        }
     }
 
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java Sat Jul 15 07:17:29 2006
@@ -36,6 +36,7 @@
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.broker.PersistenceBrokerSQLException;
+import org.apache.ojb.broker.lob.LobHandle;
 import org.apache.ojb.broker.accesslayer.batch.BatchInfo;
 import org.apache.ojb.broker.accesslayer.batch.BatchManager;
 import org.apache.ojb.broker.accesslayer.sql.SelectStatement;
@@ -65,9 +66,9 @@
 import org.apache.ojb.broker.util.sequence.SequenceManagerException;
 
 /**
- * JdbcAccess is responsible for establishing performing
- * SQL Queries against remote Databases.
- * It hides all knowledge about JDBC from the BrokerImpl
+ * JdbcAccess is responsible for establishing performing SQL Queries against remote
+ * Databases. It hides all knowledge about JDBC from the associated
+ * {@link org.apache.ojb.broker.PersistenceBroker}.
  *
  * @version $Id$
  */
@@ -191,6 +192,15 @@
 
         // BRJ : provide useful defaults for locking fields
         if(cld.isLocking()) updateLockingValues(cld, obj);
+        // perform application based autoincrement
+        try
+        {
+            preSequenceProcess(cld, obj);
+        }
+        catch(SequenceManagerException e)
+        {
+            throw new PersistenceBrokerException("Insert failed! Can't assign autoincrement field", e);
+        }
 
         if(isStoredProcedure)
         {
@@ -202,7 +212,7 @@
         }
         // if DB Identity columns are used for PK values, we can't use batch
         // updates for object insert
-        if(isInBatchMode(cld) && !cld.useIdentityColumnField())
+        if(isInBatchMode(cld))
         {
             BatchInfo info = new BatchInfo(sql, cld, BatchInfo.TYPE_OBJECT_INSERT);
             try
@@ -225,10 +235,8 @@
                 bindValues(stmt, values, 1, isStoredProcedure);
                 // TODO: return execution result int value in method
                 stmt.executeUpdate();
-
-                // if database Identity Columns are used, query the id from database
-                // other SequenceManager implementations will ignore this call
-                broker.serviceSequenceManager().afterStore(this, cld, obj);
+                // perform identity column based autoincrement
+                postSequenceProcess(cld, obj);
 
                 // Harvest any return values.
                 if(isStoredProcedure) harvestReturnValues(cld.getInsertProcedure(), obj, stmt);
@@ -239,7 +247,7 @@
             }
             catch(SequenceManagerException e)
             {
-                throw new PersistenceBrokerException("Can't lookup new database Identity Column value", e);
+                throw new PersistenceBrokerException("Insert failed! Can't assign value of database identity column", e);
             }
             catch(SQLException e)
             {
@@ -337,6 +345,24 @@
         final String sql = broker.serviceSqlGenerator().getPreparedUpdateStatement(cld, fieldsToUpdate).getStatement();
         final ValueContainer[] values;
         final boolean isStoredProcedure = useCallableUpdateStatement(cld);
+
+        // we can only update LOB content when it's associated with current tx
+        if(cld.hasLobField())
+        {
+            for(int i = 0; i < fieldsToUpdate.length; i++)
+            {
+                FieldDescriptor field = fieldsToUpdate[i];
+                if(field.isLobFieldType())
+                {
+                    Object o = field.getPersistentField().get(obj);
+                    if(o instanceof LobHandle)
+                    {
+                        ((LobHandle) o).checkActive();
+                    }
+                }
+            }
+        }
+
         if(isStoredProcedure)
         {
             /*
@@ -545,7 +571,7 @@
                 rs = stmt.executeQuery();
             }
 
-            return new ResultSetAndStatement(stmtManager, stmt, rs, sql);
+            return new ResultSetAndStatement(broker, stmt, rs, sql);
         }
         catch(PersistenceBrokerException e)
         {
@@ -605,7 +631,7 @@
             // as we return the resultset for further operations, we cannot release the statement yet.
             // that has to be done by the JdbcAccess-clients (i.e. RsIterator, ProxyRsIterator and PkEnumeration.)
             // arminw: use anonymous inner class to satisfy constructor of
-            return new ResultSetAndStatement(broker.serviceStatementManager(), stmt, rs, new SelectStatement(){
+            return new ResultSetAndStatement(broker, stmt, rs, new SelectStatement(){
                 public Query getQueryInstance()
                 {
                     return null;
@@ -688,7 +714,7 @@
                 rs = stmt.executeQuery();
             }
             // data available read object, else return null
-            ResultSetAndStatement rs_stmt = new ResultSetAndStatement(broker.serviceStatementManager(), stmt, rs, sql);
+            ResultSetAndStatement rs_stmt = new ResultSetAndStatement(broker, stmt, rs, sql);
             if (rs.next())
             {
                 Map row = new HashMap();
@@ -943,10 +969,11 @@
             // If we have a field descriptor, then we can harvest the return value.
             if(obj != null)
             {
-                // Get the value and convert it to it's appropriate java type.
-                Object value = fmd.getJdbcType().getObjectFromColumn(callable, index);
+                // Get the value and convert it to it's appropriate
+                // java type.
+                Object value = fmd.readValue(broker, callable, index, true);
                 // Set the value of the persistent field.
-                fmd.getPersistentField().set(obj, fmd.getFieldConversion().sqlToJava(value));
+                fmd.getPersistentField().set(obj, value);
             }
         }
         catch(SQLException e)
@@ -955,6 +982,46 @@
                     obj.getClass().getName() + ", field=" + fmd.getAttributeName() + ": " + e.getMessage();
             log.error(msg, e);
             throw new PersistenceBrokerSQLException(msg, e);
+        }
+    }
+
+    /**
+     * Perform assignment of application based autoincrement values
+     */
+    protected void preSequenceProcess(ClassDescriptor cld, Object target) throws SequenceManagerException
+    {
+        // TODO: refactor auto-increment handling, auto-increment should only be supported by PK fields?
+        // FieldDescriptor[] fields = cld.getPkFields();
+        FieldDescriptor[] fields = cld.getFieldDescriptor(false);
+        FieldDescriptor field;
+        for(int i = 0; i < fields.length; i++)
+        {
+            field = fields[i];
+            if(field.isAutoIncrement() && !field.isAccessReadOnly())
+            {
+                Object value = field.getPersistentField().get(target);
+                if(broker.serviceBrokerHelper().representsNull(field, value))
+                {
+                    Object id = broker.serviceSequenceManager().getUniqueValue(field);
+                    field.getPersistentField().set(target, id);
+                }
+            }
+        }
+    }
+
+    /**
+     * Perform assignment of database identity column based autoincrement values
+     */
+    protected void postSequenceProcess(ClassDescriptor cld, Object target) throws SequenceManagerException
+    {
+        // if database Identity Columns are used, query the id from database
+        // other SequenceManager implementations will ignore this call
+        if(cld.useIdentityColumnField())
+        {
+            // execute batch to ensure existance of new id
+            broker.serviceBatchManager().executeBatch();
+            // lookup identity column PK value from DB and set PK in persistent object
+            broker.serviceSequenceManager().afterStore(this, cld, target);
         }
     }
 

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java Sat Jul 15 07:17:29 2006
@@ -44,7 +44,6 @@
 /**
  * Relationship Prefetcher for MtoN-Collections.
  * 
- * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
  * @version $Id$
  */
 public class MtoNCollectionPrefetcher extends CollectionPrefetcher
@@ -236,8 +235,7 @@
         while (iter.hasNext())
         {
             owner = iter.next();
-            fkValues = helper.extractValueArray(helper.getKeyValues(cld, owner));
-            id = idFactory.buildIdentity(null, topLevelClass, fkValues);
+            id = idFactory.buildIdentity(cld, owner);
             idsSubset.add(id);
             if (idsSubset.size() == pkLimit)
             {

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/PlainPrefetcher.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/PlainPrefetcher.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/PlainPrefetcher.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/PlainPrefetcher.java Sat Jul 15 07:17:29 2006
@@ -31,7 +31,6 @@
 /**
  * Prefetcher for plain list of objects (no relations).
  *
- * @author <a href="mailto:olegnitz@apache.org">Oleg Nitz</a>
  * @version $Id$
  */
 public class PlainPrefetcher extends BasePrefetcher
@@ -64,13 +63,12 @@
         for (Iterator it = realSubjects.iterator(); it.hasNext(); )
         {
             realSubject = it.next();
-            realSubjectsMap.put(new Identity(realSubject, pb), realSubject);
+            realSubjectsMap.put(pb.serviceIdentity().buildIdentity(realSubject), realSubject);
         }
 
         for (Iterator it = proxies.iterator(); it.hasNext(); )
         {
             proxy = it.next();
-            //handler = ProxyHelper.getIndirectionHandler(proxy);
             handler = pb.getConfiguration().getOjb().getProxyFactory().getIndirectionHandler(proxy);
 
             if (handler == null)

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ReferencePrefetcher.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ReferencePrefetcher.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ReferencePrefetcher.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ReferencePrefetcher.java Sat Jul 15 07:17:29 2006
@@ -35,7 +35,6 @@
 /**
  * Relationship Prefetcher for References.
  *
- * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  * @version $Id$
  */
 public class ReferencePrefetcher extends RelationshipPrefetcherImpl
@@ -63,27 +62,31 @@
         Class topLevelClass = pb.getTopLevelClass(ord.getItemClass());
         HashMap childrenMap = new HashMap(children.size());
         IdentityFactory idFactory = pb.serviceIdentity();
+        Object owner;
+        Object relatedObject;
+        Object fkValues[];
+        Identity id;
 
 
         for (Iterator it = children.iterator(); it.hasNext(); )
         {
-            Object relatedObject = it.next();
+            relatedObject = it.next();
             Object[] targetValues = getFkTargetValuesForObject(relatedObject);
-            Identity id = idFactory.buildIdentity(null, topLevelClass, targetValues);
+            id = idFactory.buildIdentity(null, topLevelClass, targetValues);
             childrenMap.put(id, relatedObject);
         }
 
         for (Iterator it = owners.iterator(); it.hasNext(); )
         {
-            Object owner = it.next();
-            Object[] fkValues = getFkValuesForObject(owner);
+            owner = it.next();
+            fkValues = getFkValuesForObject(owner);
             if (isNull(fkValues))
             {
                 field.set(owner, null);
                 continue;
             }
-            Identity id = idFactory.buildIdentity(null, topLevelClass, fkValues);
-            Object relatedObject = childrenMap.get(id);
+            id = idFactory.buildIdentity(null, topLevelClass, fkValues);
+            relatedObject = childrenMap.get(id);
             field.set(owner, relatedObject);
         }
     }
@@ -122,7 +125,6 @@
         {
             owner = iter.next();
             fkValues = getFkValuesForObject(owner);
-            
             if (isNull(fkValues))
             {
                 continue;
@@ -155,10 +157,7 @@
     protected Query buildPrefetchQuery(Collection ids)
     {
         ClassDescriptor cld = getItemClassDescriptor();
-        FieldDescriptor fds[];
-        
-//        fds = cld.getPkFields();
-        fds = getObjectReferenceDescriptor().getForeignKeyTargetFieldDescriptors(cld);
+        FieldDescriptor fds[] = getObjectReferenceDescriptor().getForeignKeyTargetFieldDescriptors(cld);
         
         return buildPrefetchQuery(ids, fds);
     }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java Sat Jul 15 07:17:29 2006
@@ -1,6 +1,6 @@
 package org.apache.ojb.broker.accesslayer;
 
-/* Copyright 2002-2004 The Apache Software Foundation
+/* Copyright 2002-2005 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 
@@ -23,96 +22,64 @@
 import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
 import org.apache.ojb.broker.metadata.JdbcTypesHelper;
+import org.apache.ojb.broker.metadata.JdbcType;
 import org.apache.ojb.broker.query.ReportQuery;
 import org.apache.ojb.broker.query.ReportQueryByCriteria;
 
 /**
  * RsIterator for ReportQueries
  *
- * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
  * @version $Id$
  */
 public class ReportQueryRsIterator extends RsIterator
 {
-    private String[] m_attributes;
+
     private int m_attributeCount;
     private int[] m_jdbcTypes;
+
     /**
      * Constructor for ReportQueryRsIterator.
      */
     public ReportQueryRsIterator(RsQueryObject queryObject, PersistenceBrokerInternal broker)
     {
         super(queryObject, broker);
-        try
-        {
-            // BRJ: use only explicit attributes (columns) ! 
-            // ignore those automatically added for ordering or grouping 
-            ReportQuery q = (ReportQuery)queryObject.getQuery();
-            m_attributes = q.getAttributes();
-            m_attributeCount = q.getAttributes().length;
-            
-            init_jdbcTypes();
-        }
-        catch (SQLException e)
-        {
-            releaseDbResources();
-            throw new PersistenceBrokerException(e);
-        }
-    }
- 
-    /**
-     * get the jdbcTypes from the Query or the ResultSet if not available from the Query
-     * @throws SQLException
-     */
-    private void init_jdbcTypes() throws SQLException
-    {
-        ReportQuery q = (ReportQuery) getQueryObject().getQuery();
-        m_jdbcTypes = new int[m_attributeCount];
-        
-        // try to get jdbcTypes from Query
-        if (q.getJdbcTypes() != null)
-        {
-            m_jdbcTypes = q.getJdbcTypes();
-        }
-        else
-        {
-            ResultSetMetaData rsMetaData = getRsAndStmt().m_rs.getMetaData();
-            for (int i = 0; i < m_attributeCount; i++)
-            {
-                m_jdbcTypes[i] = rsMetaData.getColumnType(i + 1);
-            }
-            
-        }
+        // BRJ: use only explicit attributes (columns) !
+        // ignore those automatically added for ordering or grouping
+        ReportQuery q = (ReportQuery)queryObject.getQuery();
+        m_attributeCount = q.getAttributes().length;
     }
-    
+
     /**
      * returns an Object[] representing the columns of the current ResultSet
      * row. There is no OJB object materialization, Proxy generation etc.
-     * involved to maximize performance. 
-     * If a FieldDescriptor is available for the attribute, the retrieved value
-     * is passed to it's FieldConversion. 
+     * involved to maximize performance.
      */
     protected Object getObjectFromResultSet() throws PersistenceBrokerException
     {
         Object[] result = new Object[m_attributeCount];
-        ResultSet rs = getRsAndStmt().m_rs;
-        ReportQueryByCriteria q =(ReportQueryByCriteria) getQueryObject().getQuery();
-        
+        ReportQuery q =(ReportQuery) getQueryObject().getQuery();
         for (int i = 0; i < m_attributeCount; i++)
         {
             try
             {
-                int jdbcType = m_jdbcTypes[i];
-                String attr = m_attributes[i];
-                FieldDescriptor fld = (FieldDescriptor) q.getAttributeFieldDescriptors().get(attr);
-                Object value = JdbcTypesHelper.getObjectFromColumn(rs, new Integer(jdbcType), i + 1);
-                
-                if (fld != null && fld.getFieldConversion() != null)
+                FieldDescriptor fld = null;
+                String attr = q.getAttributes()[i];
+                if(q instanceof ReportQueryByCriteria)
+                fld = (FieldDescriptor) ((ReportQueryByCriteria)q).getAttributeFieldDescriptors().get(attr);
+                Object val;
+                if(fld != null)
                 {
-                    value = fld.getFieldConversion().sqlToJava(value);
+                    val = fld.readValue(getRsAndStmt(), i+1, true);
                 }
-
-                result[i] = value;
+                else
+                {
+                    // if we don't know the associated FieldDescriptor we have to use
+                    // basic methods to read in the value
+                    int jdbcType = extractJdbcType(i);
+                    JdbcType type = JdbcTypesHelper.getJdbcTypeByTypesIndex(new Integer(jdbcType));
+                    val = type.getObjectFromColumn(getRsAndStmt().m_rs, i + 1);
+                }
+                result[i] = val;
             }
             catch (SQLException e)
             {
@@ -121,4 +88,34 @@
         }
         return result;
     }
+
+    /**
+     * Extracts the jdbc type of the specified result set column index.
+     *
+     * @param rsIndex The result set column index.
+     * @return The jdbc {@link java.sql.Types} type.
+     * @throws SQLException
+     */
+    private int extractJdbcType(int rsIndex) throws SQLException
+    {
+        if(m_jdbcTypes == null)
+        {
+            ReportQuery q = (ReportQuery) getQueryObject().getQuery();
+            if(q.getJdbcTypes() != null)
+            {
+                m_jdbcTypes = q.getJdbcTypes();
+            }
+            else
+            {
+                m_jdbcTypes = new int[m_attributeCount];
+                ResultSetMetaData rsMetaData = getRsAndStmt().m_rs.getMetaData();
+                for (int i = 0; i < m_attributeCount; i++)
+                {
+                    m_jdbcTypes[i] = rsMetaData.getColumnType(i + 1);
+                }
+            }
+        }
+        return m_jdbcTypes[rsIndex];
+    }
+
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java Sat Jul 15 07:17:29 2006
@@ -18,18 +18,18 @@
 import java.sql.ResultSet;
 import java.sql.Statement;
 
+import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.broker.accesslayer.sql.SelectStatement;
+import org.apache.ojb.broker.platforms.Platform;
 
 /**
  * Intern used wrapper for {@link Statement} and {@link ResultSet} instances.
+ * Make sure that after use of this class method {@link #close()} was called.
  *
  * @version $Id$
  */
-final public class ResultSetAndStatement
+public final class ResultSetAndStatement
 {
-	// private static Logger log = LoggerFactory.getLogger(ResultSetAndStatement.class);
-
-	private final StatementManager manager;
     private boolean isClosed;
     /*
     arminw: declare final to avoid stmt/rs leaking in use
@@ -38,10 +38,13 @@
 	public final ResultSet m_rs;
 	public final Statement m_stmt;
     public final SelectStatement m_sql;
+    public final PersistenceBrokerInternal m_broker;
+    public final Platform m_platform;
 
-	public ResultSetAndStatement(StatementManager manager, Statement stmt, ResultSet rs, SelectStatement sql)
+    public ResultSetAndStatement(PersistenceBrokerInternal broker, Statement stmt, ResultSet rs, SelectStatement sql)
 	{
-		this.manager = manager;
+        this.m_broker = broker;
+        this.m_platform = broker.serviceConnectionManager().getSupportedPlatform();
         m_stmt = stmt;
         m_rs = rs;
         m_sql = sql;
@@ -49,7 +52,7 @@
 	}
 
 	/**
-	 * do a platform specific resource release.
+     * Do a platform specific resource release.
      * <br/>
      * Note: This method must be called after usage
      * of this class.
@@ -58,7 +61,7 @@
 	{
 		if(!isClosed)
         {
-            manager.closeResources(m_stmt, m_rs);
+            m_broker.serviceStatementManager().closeResources(m_stmt, m_rs);
             isClosed = true;
         }
     }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReader.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReader.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReader.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReader.java Sat Jul 15 07:17:29 2006
@@ -18,11 +18,18 @@
 import java.io.Serializable;
 import java.util.Map;
 
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+
 /**
+ * This class is responsible to map a query result set row to the specified
+ * {@link java.util.Map}.
+ *
  * @version $Id$
  */
 public interface RowReader extends Serializable
 {
+    static final long serialVersionUID = -1283322922537162249L;
+
     /**
      * Materialize a single object from the values of the Map row.
      * the implementor of this class must not care for materializing
@@ -35,44 +42,38 @@
     public Object readObjectFrom(Map row, Object enclosingObj);
 
     /**
-     * refresh an existing instance from the values of the Map row.
+     * Refresh an existing instance from the values of the Map row.
+     *
      * @param instance the instance to refresh
      * @param row the Map containing the new values
      */
     public void refreshObject(Object instance, Map row);
 
 
-//	/**
-//	 * Read all fields from the current ResultRow into the Object[] row.#
-//	 * ConversionStrategies are applied here!
-//	 */
-//	public void readObjectArrayFrom(ResultSet rs, Map row);
-
     /**
      * Read all fields from the current ResultRow into the Object[] row.#
      * ConversionStrategies are applied here!
+     *
+     * @param rs Current result set.
+     * @param row The target map.
      */
     public void readObjectArrayFrom(ResultSetAndStatement rs, Map row);
 
-//	/**
-//	 * Read primary key fields from the current ResultRow into the Object[] row.#
-//	 * ConversionStrategies are applied here!
-//	 */
-//	public void readPkValuesFrom(ResultSet rs, Map row);
-
     /**
      * Read primary key fields from the current ResultRow into the Object[] row.#
      * ConversionStrategies are applied here!
+     *
+     * @param rs Current result set.
+     * @param row The target map.
      */
     public void readPkValuesFrom(ResultSetAndStatement rs, Map row);
 
-//    /**
-//     * Set the descriptor this <i>RowReader</i> worked with.
-//     */
-//    public void setClassDescriptor(ClassDescriptor cld);
-//
-//    /**
-//     * Returns the associated {@link org.apache.ojb.broker.metadata.ClassDescriptor}
-//     */
-//    public ClassDescriptor getClassDescriptor();
+    /**
+     * Read the specified field into the row map.
+     *
+     * @param rs Current result set.
+     * @param row The target map.
+     * @param fields The fields to read from result set.
+     */
+    public void readValuesFrom(ResultSetAndStatement rs, Map row, FieldDescriptor[] fields);
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java Sat Jul 15 07:17:29 2006
@@ -154,7 +154,8 @@
                 }
                 catch (Exception ex)
                 {
-                    throw new PersistenceBrokerException("Unable to invoke initialization method:" + initializationMethod.getName() + " for class:" + classDescriptor.getClassOfObject(), ex);
+                    throw new PersistenceBrokerException("Unable to invoke initialization method:"
+                    + initializationMethod.getName() + " for class:" + classDescriptor.getClassOfObject(), ex);
                 }
             }
         }
@@ -277,8 +278,8 @@
             if(ojbDiscriminator != null)
             {
                 ClassDescriptor cld = classDescriptor.getRepository().getDescriptorForDiscriminator(classDescriptor,ojbDiscriminator);
-                fields = cld.getFieldDescriptor(true);
                 row.put(OJB_DISCRIMINATOR_KEY, cld.getClassOfObject());
+                fields = cld.getFieldDescriptor(true);
             }
             else
             {
@@ -320,21 +321,22 @@
         readValuesFrom(rs_stmt, row, pkFields);
     }
 
-    protected void readValuesFrom(ResultSetAndStatement rs_stmt, Map row, FieldDescriptor[] fields)
+    public void readValuesFrom(ResultSetAndStatement rs_stmt, Map row, FieldDescriptor[] fields)
     {
         int size = fields.length;
-        Object val;
         FieldDescriptor fld = null;
         try
         {
+            Object value;
             for (int j = 0; j < size; j++)
             {
                 fld = fields[j];
                 if(!row.containsKey(fld.getColumnName()))
                 {
-                    int idx = rs_stmt.m_sql.getColumnIndex(fld);
-                    val = fld.getJdbcType().getObjectFromColumn(rs_stmt.m_rs, null, fld.getColumnName(), idx);
-                    row.put(fld.getColumnName(), fld.getFieldConversion().sqlToJava(val));
+                    // Get the value and convert it to it's appropriate
+                    // java type.
+                    value = fld.readValue(rs_stmt, true);
+                    row.put(fld.getColumnName(), value);
                 }
             }
         }
@@ -349,34 +351,41 @@
 
     protected String extractOjbConcreteClass(ClassDescriptor cld, ResultSet rs, Map row)
     {
+        String result = null;
         FieldDescriptor discriminatorFD = classDescriptor.getDiscriminatorField();
-        if (discriminatorFD == null)
-        {
-            return null;
-        }
-        try
+        if (discriminatorFD != null)
         {
-            Object tmp = discriminatorFD.getJdbcType().getObjectFromColumn(rs, discriminatorFD.getColumnName());
-            // allow field-conversion for discriminator column too
-            String result = (String) discriminatorFD.getFieldConversion().sqlToJava(tmp);
-            result = result != null ? result.trim() : null;
-            if (result == null || result.length() == 0)
-            {
-                throw new PersistenceBrokerException("The discriminator field column for class "
-                        + cld.getClassNameOfObject() + " returned null or 0-length string, discriminator field was: "
-                        + discriminatorFD);
-            }
-
-            // arminw: Make sure that we don't read discriminator field twice from the ResultSet.
-            row.put(discriminatorFD.getColumnName(), result);
-            return result;
-        }
-        catch (SQLException e)
-        {
-            throw new PersistenceBrokerException("Unexpected error while try to read 'ojbConcretClass'"
-                    + " field from result set using column name " + discriminatorFD.getColumnName() + " main class"
-                    + " was " + classDescriptor.getClassNameOfObject(), e);
+            // First check for already existing entry to avoid multiple result set lookup
+            result = (String) row.get(discriminatorFD.getColumnName());
+            if(result == null)
+            {
+                try
+                {
+                    Object tmp = discriminatorFD.getJdbcType().getObjectFromColumn(rs, discriminatorFD.getColumnName());
+                    // allow field-conversion for discriminator column too
+                    result = (String) discriminatorFD.getFieldConversion().sqlToJava(tmp);
+                    result = result != null ? result.trim() : null;
+                    if (result == null || result.length() == 0)
+                    {
+                        throw new PersistenceBrokerException("The discriminator field column for class "
+                                + cld.getClassNameOfObject() + " returned null or 0-length string, discriminator field was: "
+                                + discriminatorFD);
+                    }
+                    else
+                    {
+                        // Make sure that we don't read discriminator field twice from the ResultSet.
+                        row.put(discriminatorFD.getColumnName(), result);
+                    }
+                }
+                catch (SQLException e)
+                {
+                    throw new PersistenceBrokerException("Unexpected error while try to read 'ojbConcretClass'"
+                            + " field from result set using column name " + discriminatorFD.getColumnName() + " main class"
+                            + " was " + classDescriptor.getClassNameOfObject(), e);
+                }
+            }
         }
+        return result;
     }
 
     /**

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java Sat Jul 15 07:17:29 2006
@@ -33,10 +33,13 @@
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.broker.PersistenceBrokerSQLException;
+import org.apache.ojb.broker.lob.LobHandle;
+import org.apache.ojb.broker.platforms.Platform;
 import org.apache.ojb.broker.cache.SessionCache;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.metadata.DescriptorRepository;
 import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
 import org.apache.ojb.broker.query.Query;
 import org.apache.ojb.broker.query.QueryByCriteria;
 import org.apache.ojb.broker.query.QueryBySQL;
@@ -142,12 +145,11 @@
      * done or not. Default is <tt>true</tt>.
      */
     private boolean autoRelease = true;
+    private ResourceWrapper resourceListener;
 
     /** if true do not fire PBLifeCycleEvent. */
     private boolean disableLifeCycleEvents = false;
 
-    private ResourceWrapper resourceListener;
-
     /**
      * RsIterator constructor.
      *
@@ -393,12 +395,14 @@
      */
     protected Object getObjectFromResultSet() throws PersistenceBrokerException
     {
-        getRow().clear();
+        Map row = getRow();
+        PersistenceBrokerInternal pb = getBroker();
+        row.clear();
 
+        RowReader reader = pb.getRowReaderFor(getQueryObject().getClassDescriptor());
         // we need the PK values of result set row
         // provide m_row with primary key data of current row
-        RowReader reader = getBroker().getRowReaderFor(getQueryObject().getClassDescriptor());
-        reader.readPkValuesFrom(getRsAndStmt(), getRow());
+        reader.readPkValuesFrom(getRsAndStmt(), row);
 
         // 1.read Identity
         Identity oid = getIdentityFromResultSet();
@@ -409,14 +413,14 @@
         if (result == null)
         {
             // map all field values from the current result set
-            reader.readObjectArrayFrom(getRsAndStmt(), getRow());
+            reader.readObjectArrayFrom(getRsAndStmt(), row);
 
             // 3. If Object is not in cache
             // materialize Object with primitive attributes filled from current row
             // we however have to first retrieve an enclosing class reference if one exists
-            Object enclosingObj = getBroker().materializeEnclosingClassReference(getQueryObject().getClassDescriptor(), getRow());
+            Object enclosingObj = pb.materializeEnclosingClassReference(getQueryObject().getClassDescriptor(), row);
 
-            result = reader.readObjectFrom(getRow(), enclosingObj);
+            result = reader.readObjectFrom(row, enclosingObj);
             // result may still be null!
             if (result != null)
             {
@@ -440,11 +444,11 @@
                          * actual class.
                          */
                         // fill reference and collection attributes
-                        ClassDescriptor cld = getBroker().getClassDescriptor(result.getClass());
+                        ClassDescriptor cld = pb.getClassDescriptor(result.getClass());
 
                         // don't force loading of reference
-                        getBroker().getReferenceBroker().retrieveReferences(result, cld, false);
-                        getBroker().getReferenceBroker().retrieveCollections(result, cld, false);
+                        pb.getReferenceBroker().retrieveReferences(result, cld, false);
+                        pb.getReferenceBroker().retrieveCollections(result, cld, false);
 
                         getCache().disableMaterializationCache();
                     }
@@ -460,16 +464,35 @@
         else
         // Object is in cache
         {
-            ClassDescriptor cld = getBroker().getClassDescriptor(result.getClass());
+            ClassDescriptor cld = pb.getClassDescriptor(result.getClass());
             // if refresh is required, read all values from the result set and
             // update the cache instance from the db
             if (cld.isAlwaysRefresh())
             {
                 // map all field values from the current result set
-                reader.readObjectArrayFrom(getRsAndStmt(), getRow());
-                reader.refreshObject(result, getRow());
+                reader.readObjectArrayFrom(getRsAndStmt(), row);
+                reader.refreshObject(result, row);
             }
-            getBroker().refreshRelationships(result, oid, cld);
+            else if(cld.hasLobField() && pb.serviceLobHelper().isLobAutoRefresh())
+            {
+                /*
+                If the object has LOB content we have to re-read the locator
+                object of cached objects
+                */
+                FieldDescriptor[] flds = cld.getLobFields();
+                for(int i = 0; i < flds.length; i++)
+                {
+                    FieldDescriptor fld = flds[i];
+                    LobHandle lob = (LobHandle) fld.getPersistentField().get(result);
+                    // if LOB content isn't active, we have to re-read content
+                    if(!lob.isActive())
+                    {
+                        reader.readValuesFrom(getRsAndStmt(), row, new FieldDescriptor[]{fld});
+                        fld.getPersistentField().set(result, row.get(fld.getColumnName()));
+                    }
+                }
+            }
+            pb.refreshRelationships(result, oid, cld);
         }
 
         return result;
@@ -478,7 +501,7 @@
     /**
      * with a new batch of JDBC 3.0 drivers coming out we can't just check for
      * begins with 2, we need to check the actual version and see if it's
-     * greater than or equal to 2
+     * greater than or equal to 2.
      */
     private boolean supportsAdvancedJDBCCursorControl()
     {
@@ -550,9 +573,7 @@
         {
             //ignore it
         }
-        if (!supportsAdvancedJDBCCursorControl()
-                || getBroker().serviceConnectionManager().getSupportedPlatform().useCountForResultsetSize()
-                || forwardOnly)
+        if (!supportsAdvancedJDBCCursorControl() || getPlatform().useCountForResultsetSize() || forwardOnly)
         {
             /**
              * MBAIRD: doesn't support the .last .getRow method, use the
@@ -622,7 +643,7 @@
      */
     public boolean absolute(int row) throws PersistenceBrokerException
     {
-        boolean retval = false;
+        boolean retval;
         if (supportsAdvancedJDBCCursorControl())
         {
             retval = absoluteAdvanced(row);
@@ -636,8 +657,6 @@
 
     /**
      * absolute for basicJDBCSupport
-     * @param row
-     * @return
      */
     private boolean absoluteBasic(int row)
     {
@@ -680,8 +699,6 @@
 
     /**
      * absolute for advancedJDBCSupport
-     * @param row
-     * @return
      */
     private boolean absoluteAdvanced(int row)
     {
@@ -847,6 +864,11 @@
     protected JdbcConnectionDescriptor getConnectionDescriptor()
     {
         return getBroker().serviceConnectionManager().getConnectionDescriptor();
+    }
+
+    protected Platform getPlatform()
+    {
+        return getBroker().serviceConnectionManager().getSupportedPlatform();
     }
 
     /**

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java Sat Jul 15 07:17:29 2006
@@ -25,7 +25,6 @@
 /**
  * Helper class for {@link RsIterator} queries.
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 class RsQueryObject

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/FieldConversion.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/FieldConversion.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/FieldConversion.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/FieldConversion.java Sat Jul 15 07:17:29 2006
@@ -24,7 +24,7 @@
  * conversion is needed. But if the persistent class attribute is of type <code>int[]</code> a
  * field conversion to a supported field type is needed - e.g. <code>int[] ---> String</code>.
  * <p/>
- * The default implementation {@link FieldConversionDefaultImpl} does not modify its input.
+ * The default implementation {@link #DEFAULT} does not modify its input.
  * OJB users can use predefined implementation and can also
  * build their own conversions that perform arbitrary mappings.
  * The mapping has to defined in the OJB mapping configuration file - more see documentation.
@@ -34,7 +34,6 @@
  */
 public interface FieldConversion extends Serializable
 {
-	static final long serialVersionUID = 2692919097691347845L;
     /**
      * Convert an object of the persistent class to a counterpart object
      * supported by the JDBC specification.
@@ -51,4 +50,22 @@
      * @return The converted Java object
      */
     public Object sqlToJava(Object source) throws ConversionException;
+
+    /**
+     * A default noop implementation of the {@link FieldConversion} interface.
+     */
+    public static final FieldConversion DEFAULT = new FieldConversionDefaultImpl();
+
+    static class FieldConversionDefaultImpl implements FieldConversion
+    {
+        public Object javaToSql(final Object source) throws ConversionException
+        {
+            return source;
+        }
+
+        public Object sqlToJava(final Object source) throws ConversionException
+        {
+            return source;
+        }
+    }
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/IntList2VarcharFieldConversion.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/IntList2VarcharFieldConversion.java?rev=422228&r1=422227&r2=422228&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/IntList2VarcharFieldConversion.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/conversions/IntList2VarcharFieldConversion.java Sat Jul 15 07:17:29 2006
@@ -15,114 +15,24 @@
  * limitations under the License.
  */
 
-import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.lang.StringUtils;
-
 /**
  * This implementation of the {@link FieldConversion} interface converts
  * between a {@link java.util.List} of {@link java.lang.Integer} objects and a database
  * <em>varchar</em> field.
  *
- * @author Guillaume Nodet
  * @version $Id$
  */
-public class IntList2VarcharFieldConversion implements FieldConversion
+public class IntList2VarcharFieldConversion extends AbstractList2VarcharConversion
 {
-
-    private static final String NULLVALUE = "#NULL#";
-    private static final String EMPTYCOLLEC = "#EMTPY#";
-
     public IntList2VarcharFieldConversion()
     {
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.ojb.broker.accesslayer.conversions.FieldConversion#javaToSql(java.lang.Object)
-     */
-    public Object javaToSql(Object source) throws ConversionException
-    {
-        if (source == null)
-        {
-            return NULLVALUE;
-        }
-
-        try
-        {
-            List intList = (List) source;
-            if (intList.isEmpty())
-            {
-                return EMPTYCOLLEC;
-            }
-
-            StringBuffer result = new StringBuffer();
-            for (int i = 0; i < intList.size(); i++)
-            {
-                Integer obj = (Integer) intList.get(i);
-                String newSt = obj.toString();
-                newSt = StringUtils.replace(newSt, "#", "##");
-                result.append(newSt);
-                result.append("#");
-            }
-            return result.toString();
-        }
-        catch (ClassCastException e)
-        {
-            throw new ConversionException("Object is not a List of Integer it is a"
-                    + source.getClass().getName());
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.ojb.broker.accesslayer.conversions.FieldConversion#sqlToJava(java.lang.Object)
-     */
-    public Object sqlToJava(Object source) throws ConversionException
+    protected void addEntryToList(List resultList, String strEntry)
     {
-
-        if (source == null)
-        {
-            return null;
-        }
-        if (!(source instanceof String))
-        {
-            throw new ConversionException("Object is not a String it is a"
-                    + source.getClass().getName());
-        }
-        if (source.toString().equals(NULLVALUE))
-        {
-            return null;
-        }
-        if (source.toString().equals(EMPTYCOLLEC))
-        {
-            return new ArrayList();
-        }
-
-        List v = new ArrayList();
-        String input = source.toString();
-        int pos = input.indexOf("#");
-
-        while (pos >= 0)
-        {
-            if (pos == 0)
-            {
-                v.add("");
-            }
-            else
-            {
-                v.add(Integer.valueOf(input.substring(0, pos)));
-            }
-
-            if (pos + 1 > input.length())
-            {
-                //# at end causes outof bounds
-                break;
-            }
-
-            input = input.substring(pos + 1, input.length());
-            pos = input.indexOf("#");
-        }
-        return v;
+        String value = checkResult(strEntry);
+        resultList.add(value != null ? Integer.valueOf(value) : null);
     }
-
 }



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