brj 2005/04/27 12:21:52
Modified: src/java/org/apache/ojb/broker/accesslayer/sql
SqlGeneratorDefaultImpl.java
SqlSelectStatement.java SqlGenerator.java
src/java/org/apache/ojb/broker/accesslayer
ProxyRsIterator.java JdbcAccessImpl.java
JdbcAccess.java RsQueryObject.java
src/java/org/apache/ojb/broker/accesslayer/batch
BatchManagerImpl.java
src/java/org/apache/ojb/broker/core
QueryReferenceBroker.java
. release-notes.txt
Added: src/java/org/apache/ojb/broker/accesslayer/sql
SqlSelectPkStatement.java
Log:
select the pk-columns only when querying for proxies.
Revision Changes Path
1.30 +17 -5
db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java
Index: SqlGeneratorDefaultImpl.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- SqlGeneratorDefaultImpl.java 24 Apr 2005 16:29:10 -0000 1.29
+++ SqlGeneratorDefaultImpl.java 27 Apr 2005 19:21:52 -0000 1.30
@@ -180,14 +180,13 @@
}
/**
- * generate a prepared SELECT-Statement for the Class
- * described by cld
+ * generate a prepared SELECT-Statement for the Class described by cld
* @param cld the ClassDescriptor
*/
public String getPreparedSelectByPkStatement(ClassDescriptor cld)
{
ProcedureDescriptor pd = cld.getSelectByPKProcedure();
- SqlStatement sql;
+ SqlStatement sql;
if (pd == null)
{
@@ -215,7 +214,7 @@
public String getPreparedSelectStatement(Query query, ClassDescriptor
cld)
{
ProcedureDescriptor pd = cld.getSelectByFKProcedure();
- SqlStatement sql;
+ SqlStatement sql;
if ((query instanceof QueryByExample) && (pd != null))
{
@@ -232,6 +231,19 @@
}
/**
+ * generate a select pk-columns only statement according to query
+ * @param query the Query
+ * @param cld the ClassDescriptor
+ */
+ public String getPreparedSelectPkStatement(Query query, ClassDescriptor
cld)
+ {
+ SqlStatement sql;
+ sql = new SqlSelectPkStatement(m_platform, m_logger, cld, query);
+
+ return sql.getStatement();
+ }
+
+ /**
* generate a prepared DELETE-Statement according to query
* @param query the Query
* @param cld the ClassDescriptor
1.38 +17 -7
db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java
Index: SqlSelectStatement.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- SqlSelectStatement.java 1 Apr 2005 20:28:09 -0000 1.37
+++ SqlSelectStatement.java 27 Apr 2005 19:21:52 -0000 1.38
@@ -38,7 +38,6 @@
*/
public class SqlSelectStatement extends SqlQueryStatement
{
-
/**
* Constructor for SqlSelectStatement.
* @param aPlatform
@@ -68,10 +67,6 @@
/**
* Appends to the statement a comma separated list of column names.
*
- * MBAIRD: if the object being queried on has multiple classes mapped to
the table,
- * then we will get all the fields that are a unique set across all
those classes so if we need to
- * we can materialize an extent
- *
* DO NOT use this if order of columns is important. The row readers
build reflectively and look up
* column names to find values, so this is safe. In the case of update,
you CANNOT use this as the
* order of columns is important.
@@ -81,7 +76,7 @@
*/
protected List appendListOfColumnsForSelect(ClassDescriptor cld,
StringBuffer buf)
{
- FieldDescriptor[] fieldDescriptors =
cld.getRepository().getFieldDescriptorsForMultiMappedTable(cld);
+ FieldDescriptor[] fieldDescriptors = getFieldsForSelect(cld);
int fieldDescriptorLength = fieldDescriptors.length;
ArrayList columnList = new ArrayList();
int i = 0;
@@ -103,6 +98,21 @@
}
/**
+ * Return the Fields to be selected.
+ *
+ * MBAIRD: if the object being queried on has multiple classes mapped to
the table,
+ * then we will get all the fields that are a unique set across all
those classes so if we need to
+ * we can materialize an extent
+ *
+ * @param cld the ClassDescriptor
+ * @return
+ */
+ protected FieldDescriptor[] getFieldsForSelect(ClassDescriptor cld)
+ {
+ return
cld.getRepository().getFieldDescriptorsForMultiMappedTable(cld);
+ }
+
+ /**
* Appends to the statement a comma separated list of column names.
*
* @param columns defines the columns to be selected (for reports)
1.12 +8 -1
db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenerator.java
Index: SqlGenerator.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenerator.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SqlGenerator.java 22 Nov 2004 20:55:23 -0000 1.11
+++ SqlGenerator.java 27 Apr 2005 19:21:52 -0000 1.12
@@ -58,6 +58,13 @@
public String getPreparedSelectStatement(Query query, ClassDescriptor
cld);
/**
+ * generate a select pk-columns only statement according to query
+ * @param query the Query
+ * @param cld the ClassDescriptor
+ */
+ public String getPreparedSelectPkStatement(Query query, ClassDescriptor
cld);
+
+ /**
* generate a select-Statement according to query
* @param query the Query
* @param cld the ClassDescriptor
1.1
db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectPkStatement.java
Index: SqlSelectPkStatement.java
===================================================================
package org.apache.ojb.broker.accesslayer.sql;
/* 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.
*/
import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.metadata.FieldDescriptor;
import org.apache.ojb.broker.platforms.Platform;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.util.logging.Logger;
/**
* Select the pk-columns only.
* This statement is useful when querying for proxies.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jakob Braeuchi</a>
* @version $Id: SqlSelectPkStatement.java,v 1.1 2005/04/27 19:21:52 brj Exp $
*/
public class SqlSelectPkStatement extends SqlSelectStatement
{
/**
* @param aPlatform
* @param aLogger
* @param aCld
* @param aQuery
*/
public SqlSelectPkStatement(Platform aPlatform, Logger aLogger,
ClassDescriptor aCld, Query aQuery)
{
super(aPlatform, aLogger, aCld, aQuery);
}
/**
* @param parent
* @param pf
* @param cld
* @param query
* @param logger
*/
public SqlSelectPkStatement(SqlQueryStatement parent, Platform pf,
ClassDescriptor cld, Query query, Logger logger)
{
super(parent, pf, cld, query, logger);
}
/**
* Return the Fields to be selected.
*
* @param cld the ClassDescriptor
* @return
*/
protected FieldDescriptor[] getFieldsForSelect(ClassDescriptor cld)
{
return cld.getPkFields();
}
}
1.2 +2 -2
db-ojb/src/java/org/apache/ojb/broker/accesslayer/ProxyRsIterator.java
Index: ProxyRsIterator.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ProxyRsIterator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProxyRsIterator.java 24 Apr 2005 11:54:04 -0000 1.1
+++ ProxyRsIterator.java 27 Apr 2005 19:21:52 -0000 1.2
@@ -64,7 +64,7 @@
*/
protected ResultSetAndStatement executeQuery(RsQueryObject queryObject,
PersistenceBrokerInternal broker)
{
- return queryObject.performQuery(broker.serviceJdbcAccess());
+ return queryObject.performPkQuery(broker.serviceJdbcAccess());
}
}
1.32 +43 -13
db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
Index: JdbcAccessImpl.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- JdbcAccessImpl.java 6 Apr 2005 14:45:42 -0000 1.31
+++ JdbcAccessImpl.java 27 Apr 2005 19:21:52 -0000 1.32
@@ -332,11 +332,32 @@
/**
* performs a SELECT operation against RDBMS.
- * @param query the query string.
+ * @param query the query.
* @param cld ClassDescriptor providing JDBC information.
*/
public ResultSetAndStatement executeQuery(Query query, ClassDescriptor
cld) throws PersistenceBrokerException
{
+ return executeQuery(query, cld, false);
+ }
+
+ /**
+ * performs a SELECT pk-columns operation against RDBMS.
+ * @param query the query.
+ * @param cld ClassDescriptor providing JDBC information.
+ */
+ public ResultSetAndStatement executePkQuery(Query query, ClassDescriptor
cld) throws PersistenceBrokerException
+ {
+ return executeQuery(query, cld, true);
+ }
+
+ /**
+ * performs a SELECT operation against RDBMS.
+ * @param query the query.
+ * @param cld ClassDescriptor providing JDBC information.
+ * @param selectPkOnly true selects pk-columns only
+ */
+ protected ResultSetAndStatement executeQuery(Query query,
ClassDescriptor cld, boolean selectPkOnly) throws PersistenceBrokerException
+ {
if (logger.isDebugEnabled())
{
logger.debug("executeQuery: " + query);
@@ -346,7 +367,15 @@
ResultSetAndStatement retval = null;
try
{
- String sql =
broker.serviceSqlGenerator().getPreparedSelectStatement(query, cld);
+ String sql;
+ if (selectPkOnly)
+ {
+ sql =
broker.serviceSqlGenerator().getPreparedSelectPkStatement(query, cld);
+ }
+ else
+ {
+ sql =
broker.serviceSqlGenerator().getPreparedSelectStatement(query, cld);
+ }
PreparedStatement stmt =
broker.serviceStatementManager().getPreparedStatement(sql, scrollable);
ResultSet rs;
@@ -376,11 +405,11 @@
{
logger.error("PersistenceBrokerException during the execution of
the query: " + e.getMessage(), e);
/*
- * MBAIRD: error condition could result in our
- * ResultSetAndStatement not being returned, and not
being closed
- * since it is opened before the try loop, we should
release it if
- * there is a problem.
- */
+ * MBAIRD: error condition could result in our
+ * ResultSetAndStatement not being returned, and not being closed
+ * since it is opened before the try loop, we should release it
if
+ * there is a problem.
+ */
if (retval != null)
{
retval.close();
@@ -394,11 +423,11 @@
+ "): " + e.getMessage();
logger.error(msg, e);
/*
- * MBAIRD: error condition could result in our
- * ResultSetAndStatement not being returned, and not
being closed
- * since it is opened before the try loop, we should
release it if
- * there is a problem.
- */
+ * MBAIRD: error condition could result in our
+ * ResultSetAndStatement not being returned, and not being closed
+ * since it is opened before the try loop, we should release it
if
+ * there is a problem.
+ */
if (retval != null)
{
retval.close();
@@ -407,6 +436,7 @@
}
}
+
public ResultSetAndStatement executeSQL(String sqlStatement, boolean
scrollable)
throws PersistenceBrokerException
{
1.37 +9 -2
db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccess.java
Index: JdbcAccess.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccess.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- JdbcAccess.java 20 Sep 2004 14:33:14 -0000 1.36
+++ JdbcAccess.java 27 Apr 2005 19:21:52 -0000 1.37
@@ -124,8 +124,15 @@
/**
* performs a SELECT operation against RDBMS.
- * @param query the query string.
+ * @param query the query.
* @param cld ClassDescriptor providing JDBC information.
*/
public ResultSetAndStatement executeQuery(Query query, ClassDescriptor
cld) throws PersistenceBrokerException;
+
+ /**
+ * performs a SELECT of pk-columns operation against RDBMS.
+ * @param query the query.
+ * @param cld ClassDescriptor providing JDBC information.
+ */
+ public ResultSetAndStatement executePkQuery(Query query, ClassDescriptor
cld) throws PersistenceBrokerException;
}
1.8 +18 -1
db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java
Index: RsQueryObject.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- RsQueryObject.java 1 Apr 2005 20:28:09 -0000 1.7
+++ RsQueryObject.java 27 Apr 2005 19:21:52 -0000 1.8
@@ -63,6 +63,12 @@
//*******************************************
// public methods
//*******************************************
+
+ /**
+ * Execute the Query. Select all columns.
+ * @param jdbcAccess
+ * @return
+ */
public ResultSetAndStatement performQuery(JdbcAccess jdbcAccess)
{
if (isSQLBased())
@@ -75,6 +81,17 @@
}
}
+ /**
+ * Execute the Query. Select the pk-columns only.
+ * This is an optimization when using proxies.
+ * @param jdbcAccess
+ * @return
+ */
+ public ResultSetAndStatement performPkQuery(JdbcAccess jdbcAccess)
+ {
+ return jdbcAccess.executePkQuery(query, cld);
+ }
+
public boolean usePaging()
{
return query.usePaging();
1.4 +6 -1
db-ojb/src/java/org/apache/ojb/broker/accesslayer/batch/BatchManagerImpl.java
Index: BatchManagerImpl.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/batch/BatchManagerImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BatchManagerImpl.java 20 Sep 2004 14:33:14 -0000 1.3
+++ BatchManagerImpl.java 27 Apr 2005 19:21:52 -0000 1.4
@@ -508,6 +508,11 @@
return jdbcAccess.executeQuery(query, cld);
}
+ public ResultSetAndStatement executePkQuery(Query query, ClassDescriptor
cld) throws PersistenceBrokerException
+ {
+ return jdbcAccess.executePkQuery(query, cld);
+ }
+
public String toString()
{
ToStringBuilder buf = new ToStringBuilder(this);
1.37 +5 -1
db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java
Index: QueryReferenceBroker.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- QueryReferenceBroker.java 24 Apr 2005 16:29:10 -0000 1.36
+++ QueryReferenceBroker.java 27 Apr 2005 19:21:52 -0000 1.37
@@ -839,6 +839,10 @@
}
}
+ /**
+ * Return the Class to be prefetched.
+ * @return Class or null
+ */
public Class getClassToPrefetch()
{
return classToPrefetch;
1.79 +3 -1 db-ojb/release-notes.txt
Index: release-notes.txt
===================================================================
RCS file: /home/cvs/db-ojb/release-notes.txt,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- release-notes.txt 14 Apr 2005 19:56:57 -0000 1.78
+++ release-notes.txt 27 Apr 2005 19:21:52 -0000 1.79
@@ -11,6 +11,8 @@
Release 1.1_alpha
---------------------------------------------------------------------
NEW FEATURES:
+- When querying for Proxies the select statement contains the pk-columns
only.
+ This feature may help to solve memory problems.
- Proxy generation is now pluggable with two implementations (standard Java
proxies,
CGLib proxies)
- Better support for attributes containing expressions ie. sum(0.9 * price *
stock).
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]