You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ma...@apache.org on 2003/06/26 21:07:50 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer StatementsForClassImpl.java
mattbaird 2003/06/26 12:07:50
Modified: src/java/org/apache/ojb/broker/util/batch
PreparedStatementInvocationHandler.java
src/java/org/apache/ojb/broker/platforms
PlatformOracle9iImpl.java
src/java/org/apache/ojb/broker/accesslayer
StatementsForClassImpl.java
Added: profile oracle9i-Seropto.profile
Log:
support for further Oracle 9i optimizations: row prefetching and statement caching. Fixed a batching bug
Revision Changes Path
1.1 db-ojb/profile/oracle9i-Seropto.profile
Index: oracle9i-Seropto.profile
===================================================================
# location of jar that you will be using for testing
# so that it can be copied into the dist/lib directory.
torque.testDatabaseJar = ${lib.repo}/oracle.jar
torque.idMethod = idbroker
torque.defaultDatabase = OJB
# -------------------------------------------------------------------
#
# T O R Q U E C O N F I G U R A T I O N F I L E
#
# -------------------------------------------------------------------
project = ojbtest
# -------------------------------------------------------------------
#
# T A R G E T D A T A B A S E
#
# -------------------------------------------------------------------
database = oracle
database.manual.creation = true
# -------------------------------------------------------------------
#
# O B J E C T M O D E L I N F O R M A T I O N
#
# -------------------------------------------------------------------
# These settings will allow you to customize the way your
# Peer-based object model is created.
# -------------------------------------------------------------------
# addSaveMethod=true adds tracking code to determine how to save objects
#
# addGetByNameMethod=true adds methods to get fields by name/position
#
# complexObjectModel=true generates an om with collection support
#
# addTimeStamp=true puts time stamps in generated files
#
# addIntakeRetrievable=implement Intake's Retrievable interface
# -------------------------------------------------------------------
targetPackage=org.apache.torque.test
basePrefix=Base
addSaveMethod=true
addGetByNameMethod=true
complexObjectModel=true
addTimeStamp=true
addIntakeRetrievable=false
useManagers=true
# -------------------------------------------------------------------
#
# D A T A B A S E S E T T I N G S
#
# -------------------------------------------------------------------
# JDBC connection settings. This is used by the JDBCToXML task that
# will create an XML database schema from JDBC metadata. These
# settings are also used by the SQL Ant task to initialize your
# Turbine system with the generated SQL.
# -------------------------------------------------------------------
dbmsName = Oracle9i
jdbcLevel = 2.0
urlProtocol = jdbc
urlSubprotocol = inetora
#urlDbalias = oci8:@(description=(address=(host=127.0.0.1)(protocol=tcp)(port=1521))(connect_data=(sid=orcl)))
urlDbalias = plqaibm2:1521:QADBI2
createDatabaseUrl = ${urlProtocol}:${urlSubprotocol}:${urlDbalias}
buildDatabaseUrl = ${urlProtocol}:${urlSubprotocol}:${urlDbalias}
databaseUrl = ${urlProtocol}:${urlSubprotocol}:${urlDbalias}
databaseDriver = com.inet.ora.OraDriver
databaseUser = mbaird
databasePassword = mbaird
databaseHost = plqaibm2
# Tells JDBC task that javaName attribute for the tables and columns
# should be made same as SQL name.
sameJavaName=false
# -------------------------------------------------------------------
#
# D O C U M E N T A T I O S E T T I N G S
#
# -------------------------------------------------------------------
# These settings will allow you to customize the way your schema
# documentation is created.
# Valid formats are: html, anakia (for use with jakarta-site2)
# -------------------------------------------------------------------
documentationFormat=html
# -------------------------------------------------------------------
# You should NOT have to edit anything below here.
# -------------------------------------------------------------------
# -------------------------------------------------------------------
#
# T E M P L A T E P A T H
#
# -------------------------------------------------------------------
templatePath = ../templates
# -------------------------------------------------------------------
#
# C O N T R O L T E M P L A T E S
#
# -------------------------------------------------------------------
SQLControlTemplate = sql/base/Control.vm
OMControlTemplate = om/Control.vm
idTableControlTemplate = sql/id-table/Control.vm
DataDTDControlTemplate = data/Control.vm
DataDumpControlTemplate = data/dump/Control.vm
DataSQLControlTemplate = sql/load/Control.vm
DocControlTemplate = doc/Control.vm
# -------------------------------------------------------------------
#
# O U T P U T D I R E C T O R Y
#
# -------------------------------------------------------------------
outputDirectory=src
# -------------------------------------------------------------------
#
# S C H E M A D I R E C T O R Y
#
# -------------------------------------------------------------------
schemaDirectory=schema
1.6 +15 -0 db-ojb/src/java/org/apache/ojb/broker/util/batch/PreparedStatementInvocationHandler.java
Index: PreparedStatementInvocationHandler.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/batch/PreparedStatementInvocationHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PreparedStatementInvocationHandler.java 26 Jun 2003 01:04:10 -0000 1.5
+++ PreparedStatementInvocationHandler.java 26 Jun 2003 19:07:50 -0000 1.6
@@ -177,6 +177,21 @@
stmt = conn.prepareStatement(_sql);
try
{
+ m_platform.afterStatementCreate(stmt);
+ }
+ catch (PlatformException e)
+ {
+ if (e.getCause() instanceof SQLException)
+ {
+ throw (SQLException)e.getCause();
+ }
+ else
+ {
+ throw new SQLException(e.getMessage());
+ }
+ }
+ try
+ {
m_platform.beforeBatch(stmt);
}
catch (PlatformException e)
1.4 +140 -4 db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java
Index: PlatformOracle9iImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PlatformOracle9iImpl.java 26 Jun 2003 01:04:10 -0000 1.3
+++ PlatformOracle9iImpl.java 26 Jun 2003 19:07:50 -0000 1.4
@@ -54,13 +54,16 @@
* <http://www.apache.org/>.
*/
+import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.sql.Statement;
/**
* This class is a concrete implementation of <code>Platform</code>. Provides
@@ -68,9 +71,14 @@
* Oracle 9i's Thin driver in particular.
*
* Optimization: Oracle Batching (not standard JDBC batching)
- *
* see http://technet.oracle.com/products/oracle9i/daily/jun07.html
*
+ * Optimization: Oracle Prefetching
+ * see http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/advanced/RowPrefetchSample/Readme.html
+ *
+ * Optimization: Oracle Statement Caching
+ * see http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/jdbc30/StmtCacheSample/Readme.html
+ *
* TODO: Optimization: use ROWNUM to minimize the effects of not having server side cursors
*
* see http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:127412348064
@@ -82,11 +90,133 @@
{
private Logger logger = LoggerFactory.getLogger(PlatformOracle9iImpl.class);
private static final Object[] BATCH_SIZE = {new Integer(10)};
- private static final Class[] PARAM_TYPE = {Integer.TYPE};
+ private static final Class[] PARAM_TYPE_INTEGER = {Integer.TYPE};
+ private static final Class[] PARAM_TYPE_BOOLEAN = {Boolean.TYPE};
+ private static boolean STATEMENT_CACHING_SUPPORTED = true;
private static boolean SET_EXECUTE_BATCH_METHOD_EXISTS = true;
private static boolean SEND_BATCH_METHOD_EXISTS = true;
private static Method SET_EXECUTE_BATCH = null;
private static Method SEND_BATCH = null;
+ private static Method SET_STATEMENT_CACHING_ENABLE = null;
+ private static Method SET_IMPLICIT_CACHING_ENABLED = null;
+ private static boolean ROW_PREFETCH_SUPPORTED = true;
+ private static Method SET_ROW_PREFETCH = null;
+ private static final int STATEMENT_CACHE_SIZE = 100;
+ private static final int ROW_PREFETCH_SIZE = 100;
+
+
+ /**
+ * enable oracle statement caching
+ *
+ * see http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/jdbc30/StmtCacheSample/Readme.html
+ *
+ * @param jcd
+ * @param conn
+ * @throws PlatformException
+ */
+ public void initializeJdbcConnection(JdbcConnectionDescriptor jcd, Connection conn) throws PlatformException
+ {
+ /**
+ * do all the generic initialization first
+ */
+ super.initializeJdbcConnection(jcd, conn);
+
+ if (SET_STATEMENT_CACHING_ENABLE == null && SET_IMPLICIT_CACHING_ENABLED == null && STATEMENT_CACHING_SUPPORTED)
+ {
+ try
+ {
+ SET_STATEMENT_CACHING_ENABLE = conn.getClass().getMethod("setStatementCacheSize", PARAM_TYPE_INTEGER);
+ SET_IMPLICIT_CACHING_ENABLED = conn.getClass().getMethod("setImplicitCachingEnabled", PARAM_TYPE_BOOLEAN);
+ }
+ catch (NoSuchMethodException e)
+ {
+ STATEMENT_CACHING_SUPPORTED = false;
+ }
+ catch (SecurityException e)
+ {
+ STATEMENT_CACHING_SUPPORTED = false;
+ throw new PlatformException(e.getMessage(), e);
+ }
+ }
+ if (STATEMENT_CACHING_SUPPORTED)
+ {
+ try
+ {
+ SET_STATEMENT_CACHING_ENABLE.invoke(conn, new Object[]{new Integer(STATEMENT_CACHE_SIZE)}); // use a 100 item cache
+ SET_IMPLICIT_CACHING_ENABLED.invoke(conn, new Object[]{new Boolean(true)}); // use implicit caching
+ }
+ catch (IllegalAccessException e)
+ {
+ STATEMENT_CACHING_SUPPORTED = false;
+ throw new PlatformException(e.getMessage(), e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ STATEMENT_CACHING_SUPPORTED = false;
+ throw new PlatformException(e.getMessage(), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ STATEMENT_CACHING_SUPPORTED = false;
+ throw new PlatformException(e.getMessage(), e);
+ }
+ }
+ }
+
+ /**
+ *
+ * doesn't seem to improve performance.
+ *
+ * support for oracle prefetching
+ *
+ * see http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/advanced/RowPrefetchSample/Readme.html
+ *
+ * @param stmt
+ * @throws PlatformException
+ */
+ public void XXXXafterStatementCreate(Statement stmt) throws PlatformException
+ {
+ super.afterStatementCreate(stmt);
+ if (ROW_PREFETCH_SUPPORTED && SET_ROW_PREFETCH == null)
+ {
+ try
+ {
+ SET_ROW_PREFETCH = stmt.getClass().getMethod("setRowPrefetch", PARAM_TYPE_INTEGER);
+ }
+ catch (NoSuchMethodException e)
+ {
+ ROW_PREFETCH_SUPPORTED = false;
+ }
+ catch (SecurityException e)
+ {
+ ROW_PREFETCH_SUPPORTED = false;
+ throw new PlatformException(e.getMessage(), e);
+ }
+ }
+ if (ROW_PREFETCH_SUPPORTED)
+ {
+ try
+ {
+ SET_ROW_PREFETCH.invoke(stmt, new Object[]{new Integer(ROW_PREFETCH_SIZE)}); // use a 100 item cache
+ }
+ catch (IllegalAccessException e)
+ {
+ STATEMENT_CACHING_SUPPORTED = false;
+ throw new PlatformException(e.getMessage(), e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ STATEMENT_CACHING_SUPPORTED = false;
+ throw new PlatformException(e.getMessage(), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ STATEMENT_CACHING_SUPPORTED = false;
+ throw new PlatformException(e.getMessage(), e);
+ }
+ }
+ }
+
/**
* don't bind to the Oracle drivers and thus have to cast, rather do the
* reflection to find out if we can use the setExecuteBatch method with this
@@ -103,20 +233,23 @@
{
if (SET_EXECUTE_BATCH == null)
{
- SET_EXECUTE_BATCH = stmt.getClass().getMethod("setExecuteBatch", PARAM_TYPE);
+ SET_EXECUTE_BATCH = stmt.getClass().getMethod("setExecuteBatch", PARAM_TYPE_INTEGER);
}
SET_EXECUTE_BATCH.invoke(stmt, BATCH_SIZE);
}
catch (IllegalAccessException e)
{
+ SET_EXECUTE_BATCH_METHOD_EXISTS = false;
throw new PlatformException(e.getMessage(), e);
}
catch (IllegalArgumentException e)
{
+ SET_EXECUTE_BATCH_METHOD_EXISTS = false;
throw new PlatformException(e.getMessage(), e);
}
catch (InvocationTargetException e)
{
+ SET_EXECUTE_BATCH_METHOD_EXISTS = false;
throw new PlatformException(e.getMessage(), e);
}
catch (NoSuchMethodException e)
@@ -166,7 +299,7 @@
public int[] executeBatch(PreparedStatement stmt) throws PlatformException
{
int[] retval = null;
- if (SET_EXECUTE_BATCH_METHOD_EXISTS && SEND_BATCH_METHOD_EXISTS)
+ if (SEND_BATCH_METHOD_EXISTS)
{
try
{
@@ -183,14 +316,17 @@
}
catch (IllegalAccessException e)
{
+ SEND_BATCH_METHOD_EXISTS = false;
throw new PlatformException(e.getMessage(), e);
}
catch (IllegalArgumentException e)
{
+ SEND_BATCH_METHOD_EXISTS = false;
throw new PlatformException(e.getMessage(), e);
}
catch (InvocationTargetException e)
{
+ SEND_BATCH_METHOD_EXISTS = false;
throw new PlatformException(e.getMessage(), e);
}
catch (NoSuchMethodException e)
1.14 +7 -2 db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java
Index: StatementsForClassImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- StatementsForClassImpl.java 8 Apr 2003 20:19:29 -0000 1.13
+++ StatementsForClassImpl.java 26 Jun 2003 19:07:50 -0000 1.14
@@ -59,6 +59,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.lang.reflect.Proxy;
import org.apache.ojb.broker.PersistenceBrokerSQLException;
import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
@@ -71,6 +72,7 @@
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
+import org.apache.ojb.broker.util.ProxyHelper;
/**
* This class serves as a cache for Statements that are
@@ -272,7 +274,10 @@
}
try
{
- platform.afterStatementCreate(result);
+ if (!(result instanceof Proxy))
+ {
+ platform.afterStatementCreate(result);
+ }
}
catch (PlatformException e)
{