mkalen 2005/04/06 07:45:42
Modified: src/java/org/apache/ojb/broker/accesslayer
JdbcAccessImpl.java StatementManager.java
StatementsForClassImpl.java
src/java/org/apache/ojb/broker/platforms Platform.java
PlatformDefaultImpl.java PlatformHsqldbImpl.java
PlatformOracle9iImpl.java PlatformOracleImpl.java
Log:
Merge with OJB_1_0_RELEASE branch. Includes OJB-6: Patch by Vadim Gritsenko -
Support for stored procedures returning ResultSet.
Revision Changes Path
1.31 +96 -25
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.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- JdbcAccessImpl.java 1 Apr 2005 20:21:12 -0000 1.30
+++ JdbcAccessImpl.java 6 Apr 2005 14:45:42 -0000 1.31
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.accesslayer;
-/* Copyright 2003-2004 The Apache Software Foundation
+/* Copyright 2003-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.
@@ -55,6 +55,17 @@
public class JdbcAccessImpl implements JdbcAccess
{
private static final String SQL_STATE_KEY_VIOLATED = "23000";
+ private static final String SQL_STATE_FK_VIOLATED = "23505";
+ /*
+ X/OPEN codes within class 23:
+ 23000 INTEGRITY CONSTRAINT VIOLATION
+ 23001 RESTRICT VIOLATION
+ 23502 NOT NULL VIOLATION
+ 23503 FOREIGN KEY VIOLATION
+ 23505 UNIQUE VIOLATION
+ 23514 CHECK VIOLATION
+ */
+
/**
* The logger used.
*/
@@ -83,7 +94,9 @@
}
/**
- * Answer the Platform.
+ * Helper Platform accessor method
+ *
+ * @return Platform for the current broker connection manager.
*/
private Platform getPlatform()
{
@@ -97,7 +110,10 @@
*/
public void executeDelete(ClassDescriptor cld, Object obj) throws
PersistenceBrokerException
{
- if(logger.isDebugEnabled()) logger.safeDebug("executeDelete", obj);
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("executeDelete: " + obj);
+ }
PreparedStatement stmt = null;
try
@@ -160,7 +176,10 @@
*/
public void executeDelete(Query query, ClassDescriptor cld) throws
PersistenceBrokerException
{
- if(logger.isDebugEnabled()) logger.safeDebug("executeDelete (by
Query)", query);
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("executeDelete (by Query): " + query);
+ }
PreparedStatement stmt = null;
@@ -196,7 +215,10 @@
*/
public void executeInsert(ClassDescriptor cld, Object obj) throws
PersistenceBrokerException
{
- if(logger.isDebugEnabled()) logger.safeDebug("executeInsert", obj);
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("executeInsert: " + obj);
+ }
PreparedStatement stmt = null;
try
@@ -231,6 +253,7 @@
}
catch (SQLException e)
{
+ final String stateCode = e.getSQLState();
// Build a detailed error message
StringBuffer msg = new StringBuffer("SQL failure while insert
object data for class ");
try
@@ -246,7 +269,8 @@
.append(fields[i].getPersistentField().get(obj));
}
msg.append("], object was " + obj);
- msg.append(", exception message is [" + e.getMessage() +
"]");
+ msg.append(", exception message is
[").append(e.getMessage()).append("]");
+ msg.append(", SQL code [").append(stateCode).append("]");
}
catch (Exception ignore)
{
@@ -256,7 +280,9 @@
/**
* throw a specific type of runtime exception for a key
constraint.
*/
- if (SQL_STATE_KEY_VIOLATED.equals(e.getSQLState()))
+ if (SQL_STATE_KEY_VIOLATED.equals(stateCode)
+ ||
+ SQL_STATE_FK_VIOLATED.equals(stateCode))
{
throw new KeyConstraintViolatedException(msg.toString(), e);
}
@@ -297,7 +323,7 @@
*/
if (qbc.getPrefetchedRelationships() != null &&
!qbc.getPrefetchedRelationships().isEmpty())
{
- scrollable = true;
+ scrollable = true;
}
}
}
@@ -311,21 +337,37 @@
*/
public ResultSetAndStatement executeQuery(Query query, ClassDescriptor
cld) throws PersistenceBrokerException
{
- if (logger.isDebugEnabled()) logger.safeDebug("executeQuery", query);
-
- boolean scrollable = isScrollable(query);
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("executeQuery: " + query);
+ }
+
+ final boolean scrollable = isScrollable(query);
ResultSetAndStatement retval = null;
-
try
{
String sql =
broker.serviceSqlGenerator().getPreparedSelectStatement(query, cld);
PreparedStatement stmt =
broker.serviceStatementManager().getPreparedStatement(sql, scrollable);
- broker.serviceStatementManager().bindStatement(stmt, query, cld,
1);
- if (logger.isDebugEnabled())
- logger.debug("executeQuery: " + stmt);
-
- ResultSet rs = stmt.executeQuery();
+ ResultSet rs;
+ if (getPlatform().isCallableStatement(stmt))
+ {
+ // Query implemented as a stored procedure, which must
return a result set.
+ // Query sytax is: { ?= call PROCEDURE_NAME(?,...,?)}
+ getPlatform().registerOutResultSet((CallableStatement) stmt,
1);
+ broker.serviceStatementManager().bindStatement(stmt, query,
cld, 2);
+ if (logger.isDebugEnabled())
+ logger.debug("executeQuery: " + stmt);
+ stmt.execute();
+ rs = (ResultSet) ((CallableStatement) stmt).getObject(1);
+ }
+ else
+ {
+ broker.serviceStatementManager().bindStatement(stmt, query,
cld, 1);
+ if (logger.isDebugEnabled())
+ logger.debug("executeQuery: " + stmt);
+ rs = stmt.executeQuery();
+ }
retval = new ResultSetAndStatement(getPlatform(), stmt, rs);
return retval;
@@ -387,8 +429,23 @@
try
{
PreparedStatement stmt =
stmtMan.getPreparedStatement(sqlStatement, scrollable);
- stmtMan.bindValues(stmt, values, 1);
- ResultSet rs = stmt.executeQuery();
+
+ ResultSet rs;
+ if (getPlatform().isCallableStatement(stmt))
+ {
+ // Query implemented as a stored procedure, which must
return a result set.
+ // Query sytax is: { ?= call PROCEDURE_NAME(?,...,?)}
+ getPlatform().registerOutResultSet((CallableStatement) stmt,
1);
+ stmtMan.bindValues(stmt, values, 2);
+ stmt.execute();
+ rs = (ResultSet) ((CallableStatement) stmt).getObject(1);
+ }
+ else
+ {
+ stmtMan.bindValues(stmt, values, 1);
+ rs = stmt.executeQuery();
+ }
+
// 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.)
retval = new ResultSetAndStatement(getPlatform(), stmt, rs);
@@ -497,7 +554,10 @@
*/
public void executeUpdate(ClassDescriptor cld, FieldDescriptor[]
fieldsToUpdate, Object obj) throws PersistenceBrokerException
{
- if(logger.isDebugEnabled()) logger.safeDebug("executeUpdate", obj);
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("executeUpdate: " + obj);
+ }
PreparedStatement stmt = null;
@@ -637,11 +697,22 @@
throw new PersistenceBrokerException("getSelectByPKStatement
returned a null statement");
}
broker.serviceStatementManager().bindSelect(stmt, oid, cld);
- rs = stmt.executeQuery();
+
+ if (getPlatform().isCallableStatement(stmt))
+ {
+ // If this is a stored procedure call, first argument is
ResultSet
+ stmt.execute();
+ rs = (ResultSet) ((CallableStatement) stmt).getObject(1);
+ }
+ else
+ {
+ rs = stmt.executeQuery();
+ }
+
// data available read object, else return null
if (rs.next())
{
- Map row = new HashMap();
+ Map row = new HashMap();
RowReader rowReader = broker.getRowReaderFor(cld);
rowReader.readObjectArrayFrom(rs, row);
@@ -711,10 +782,9 @@
PreparedStatement stmt)
throws PersistenceBrokerSQLException
{
-
// If the procedure descriptor is null or has no return values or
// if the statement is not a callable statment, then we're done.
- if ((proc == null) || (!proc.hasReturnValues()) || (!(stmt
instanceof CallableStatement)))
+ if ((proc == null) || (!proc.hasReturnValues()) ||
(!getPlatform().isCallableStatement(stmt)))
{
return;
}
@@ -798,4 +868,5 @@
throw new PersistenceBrokerSQLException(msg, e);
}
}
+
}
1.58 +47 -68
db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java
Index: StatementManager.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- StatementManager.java 1 Apr 2005 20:28:09 -0000 1.57
+++ StatementManager.java 6 Apr 2005 14:45:42 -0000 1.58
@@ -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.
@@ -109,7 +109,7 @@
{
for (; i < pkValues.length; i++)
{
- m_platform.setObjectForStatement(stmt, i + 1, pkValues[i],
pkFields[i].getJdbcType().getType());
+ setObjectForStatement(stmt, i + 1, pkValues[i],
pkFields[i].getJdbcType().getType());
}
}
catch (SQLException e)
@@ -140,13 +140,13 @@
values = getKeyValues(cld, obj);
for (int i = 0; i < values.length; i++)
{
- m_platform.setObjectForStatement(stmt, index,
values[i].getValue(), values[i].getJdbcType().getType());
+ setObjectForStatement(stmt, index, values[i].getValue(),
values[i].getJdbcType().getType());
index++;
}
if (discriminatorFd != null && !discriminatorFd.isPrimaryKey())
{
- m_platform.setObjectForStatement(stmt, index,
cld.getDiscriminatorValue(), discriminatorFd.getJdbcType().getType());
+ setObjectForStatement(stmt, index,
cld.getDiscriminatorValue(), discriminatorFd.getJdbcType().getType());
index++;
}
@@ -154,7 +154,7 @@
values = currentLockingValues;
for (int i = 0; i < values.length; i++)
{
- m_platform.setObjectForStatement(stmt, index,
values[i].getValue(), values[i].getJdbcType().getType());
+ setObjectForStatement(stmt, index, values[i].getValue(),
values[i].getJdbcType().getType());
index++;
}
}
@@ -462,25 +462,19 @@
for (int i = 0; i < values.length; i++)
{
ValueContainer val = values[i];
- if (val.getValue() != null)
- {
- m_platform.setObjectForStatement(stmt, i + 1,
val.getValue(), val.getJdbcType().getType());
- }
- else
- {
- m_platform.setNullForStatement(stmt, i + 1,
val.getJdbcType().getType());
- }
+ setObjectForStatement(stmt, i + 1, val.getValue(),
val.getJdbcType().getType());
}
}
}
/**
- * binds the Identities Primary key values to the statement
+ * Binds the Identities Primary key values to the statement.
*/
public void bindSelect(PreparedStatement stmt, Identity oid,
ClassDescriptor cld) throws SQLException
{
ValueContainer[] values = null;
int i = 0;
+ int j = 0;
if (cld == null)
{
@@ -488,18 +482,18 @@
}
try
{
+ if (m_platform.isCallableStatement(stmt))
+ {
+ // First argument is the result set
+ m_platform.registerOutResultSet((CallableStatement) stmt, 1);
+ j++;
+ }
+
values = getKeyValues(cld, oid);
- for (i = 0; i < values.length; i++)
+ for (/*void*/; i < values.length; i++, j++)
{
ValueContainer valContainer = values[i];
- if (valContainer.getValue() != null)
- {
- m_platform.setObjectForStatement(stmt, i + 1,
valContainer.getValue(), valContainer.getJdbcType().getType());
- }
- else
- {
- m_platform.setNullForStatement(stmt, i + 1,
valContainer.getJdbcType().getType());
- }
+ setObjectForStatement(stmt, j + 1, valContainer.getValue(),
valContainer.getJdbcType().getType());
}
}
catch (SQLException e)
@@ -531,29 +525,14 @@
// parameters for SET-clause
for (int i = 0; i < values.length; i++)
{
- if (values[i].getValue() != null)
- {
- m_platform.setObjectForStatement(stmt, index,
values[i].getValue(), values[i].getJdbcType().getType());
- }
- else
- {
- m_platform.setNullForStatement(stmt, index,
values[i].getJdbcType().getType());
- }
-
+ setObjectForStatement(stmt, index, values[i].getValue(),
values[i].getJdbcType().getType());
index++;
}
// parameters for WHERE-clause pk
values = getKeyValues(cld, obj);
for (int i = 0; i < values.length; i++)
{
- if (values[i].getValue() != null)
- {
- m_platform.setObjectForStatement(stmt, index,
values[i].getValue(), values[i].getJdbcType().getType());
- }
- else
- {
- m_platform.setNullForStatement(stmt, index,
values[i].getJdbcType().getType());
- }
+ setObjectForStatement(stmt, index, values[i].getValue(),
values[i].getJdbcType().getType());
index++;
}
// parameters for WHERE-clause locking
@@ -561,14 +540,7 @@
values = valuesSnapshot;
for (int i = 0; i < values.length; i++)
{
- if (values[i].getValue() != null)
- {
- m_platform.setObjectForStatement(stmt, index,
values[i].getValue(), values[i].getJdbcType().getType());
- }
- else
- {
- m_platform.setNullForStatement(stmt, index,
values[i].getJdbcType().getType());
- }
+ setObjectForStatement(stmt, index, values[i].getValue(),
values[i].getJdbcType().getType());
index++;
}
}
@@ -597,15 +569,7 @@
// parameters for SET-clause
for (int i = 0; i < values.length; i++)
{
- if (values[i].getValue() != null)
- {
- m_platform.setObjectForStatement(stmt, index,
values[i].getValue(), values[i].getJdbcType().getType());
- }
- else
- {
- m_platform.setNullForStatement(stmt, index,
values[i].getJdbcType().getType());
- }
-
+ setObjectForStatement(stmt, index, values[i].getValue(),
values[i].getJdbcType().getType());
index++;
}
// parameters for WHERE-clause pk
@@ -651,7 +615,7 @@
{
for (int i = 0; i < values.length; i++)
{
- m_platform.setObjectForStatement(stmt, index,
values[i].getValue(), values[i].getJdbcType().getType());
+ setObjectForStatement(stmt, index, values[i].getValue(),
values[i].getJdbcType().getType());
index++;
}
}
@@ -863,7 +827,7 @@
// Figure out if we are using a callable statement. If we are, then
we
// will need to register one or more output parameters.
CallableStatement callable = null;
- if (stmt instanceof CallableStatement)
+ if (m_platform.isCallableStatement(stmt))
{
callable = (CallableStatement) stmt;
}
@@ -884,14 +848,7 @@
ArgumentDescriptor arg = (ArgumentDescriptor) iterator.next();
Object val = arg.getValue(obj);
int jdbcType = arg.getJdbcType();
- if (val != null)
- {
- m_platform.setObjectForStatement(stmt, valueSub + 1, val,
jdbcType);
- }
- else
- {
- m_platform.setNullForStatement(stmt, valueSub + 1, jdbcType);
- }
+ setObjectForStatement(stmt, valueSub + 1, val, jdbcType);
if ((arg.getIsReturnedByProcedure()) && (callable != null))
{
callable.registerOutParameter(valueSub + 1, jdbcType);
@@ -899,4 +856,26 @@
valueSub++;
}
}
+
+ /**
+ * Sets object for statement at specific index, adhering to platform-
and null-rules.
+ * @param stmt the statement
+ * @param index the current parameter index
+ * @param value the value to set
+ * @param sqlType the JDBC SQL-type of the value
+ * @throws SQLException on platform error
+ */
+ private void setObjectForStatement(PreparedStatement stmt, int index,
Object value, int sqlType)
+ throws SQLException
+ {
+ if (value == null)
+ {
+ m_platform.setNullForStatement(stmt, index, sqlType);
+ }
+ else
+ {
+ m_platform.setObjectForStatement(stmt, index, value, sqlType);
+ }
+ }
+
}
1.27 +6 -3
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.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- StatementsForClassImpl.java 2 Apr 2005 09:44:39 -0000 1.26
+++ StatementsForClassImpl.java 6 Apr 2005 14:45:42 -0000 1.27
@@ -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.
@@ -42,6 +42,8 @@
{
private Logger log =
LoggerFactory.getLogger(StatementsForClassImpl.class);
+ private static final String CALL = "{ ?= call";
+
/**
* sets the escape processing mode
*/
@@ -171,7 +173,8 @@
PreparedStatement stmt = null;
try
{
- stmt = prepareStatement(con, sql, scrollable, true);
+ // TODO: Vadim Gritsenko FIXME: Improve check for stored
procedure call syntax
+ stmt = prepareStatement(con, sql, scrollable,
!sql.toLowerCase().startsWith(CALL));
}
catch (java.sql.SQLException ex)
{
1.26 +20 -2
db-ojb/src/java/org/apache/ojb/broker/platforms/Platform.java
Index: Platform.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/Platform.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Platform.java 22 Nov 2004 20:55:24 -0000 1.25
+++ Platform.java 6 Apr 2005 14:45:42 -0000 1.26
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.platforms;
-/* 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.
@@ -233,4 +233,22 @@
*/
public String quoteName(String aString);
+ /**
+ * Determines whether statement is [EMAIL PROTECTED] CallableStatement}
or not.
+ *
+ * @param stmt the statement
+ * @return true if statement is [EMAIL PROTECTED] CallableStatement}.
+ */
+ public boolean isCallableStatement(PreparedStatement stmt);
+
+ /**
+ * Registers call argument at <code>position</code> as returning
+ * a [EMAIL PROTECTED] ResultSet} value.
+ *
+ * @param stmt the statement
+ * @param position argument position
+ */
+ public void registerOutResultSet(CallableStatement stmt, int position)
+ throws SQLException;
+
}
1.31 +25 -3
db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
Index: PlatformDefaultImpl.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- PlatformDefaultImpl.java 25 Nov 2004 17:31:34 -0000 1.30
+++ PlatformDefaultImpl.java 6 Apr 2005 14:45:42 -0000 1.31
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.platforms;
-/* 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.
@@ -222,7 +222,7 @@
public void setObjectForStatement(PreparedStatement ps, int index,
Object value, int sqlType)
throws SQLException
{
- if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
+ if ((sqlType == Types.LONGVARCHAR) && (value instanceof String))
{
String s = (String) value;
ps.setCharacterStream(index, new StringReader(s), s.length());
@@ -249,6 +249,11 @@
}
else
{
+ if (log.isDebugEnabled()) {
+ log.debug("Default setObjectForStatement, sqlType=" +
sqlType +
+ ", value class=" + (value == null ? "NULL!" :
value.getClass().getName())
+ + ", value=" + value);
+ }
ps.setObject(index, value, sqlType);
}
}
@@ -468,4 +473,21 @@
return result;
}
+ /**
+ * @see
org.apache.ojb.broker.platforms.Platform#isCallableStatement(java.sql.PreparedStatement)
+ */
+ public boolean isCallableStatement(PreparedStatement stmt)
+ {
+ return stmt instanceof CallableStatement;
+ }
+
+ /**
+ * @see
org.apache.ojb.broker.platforms.Platform#registerOutResultSet(java.sql.CallableStatement,
int)
+ */
+ public void registerOutResultSet(CallableStatement stmt, int position)
+ throws SQLException
+ {
+ stmt.registerOutParameter(position, Types.OTHER);
+ }
+
}
1.9 +14 -2
db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformHsqldbImpl.java
Index: PlatformHsqldbImpl.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformHsqldbImpl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- PlatformHsqldbImpl.java 12 Nov 2004 18:18:35 -0000 1.8
+++ PlatformHsqldbImpl.java 6 Apr 2005 14:45:42 -0000 1.9
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.platforms;
-/* 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,6 +15,8 @@
* limitations under the License.
*/
+import java.sql.PreparedStatement;
+
/**
* This class extends <code>PlatformDefaultImpl</code> and defines specific
* behavior for the Hsqldb platform.
@@ -90,4 +92,14 @@
return "DROP SEQUENCE " + sequenceName;
}
+ /**
+ * HSQLDB does not implement CallableStatement.
+ *
+ * @see
org.apache.ojb.broker.platforms.Platform#isCallableStatement(java.sql.PreparedStatement)
+ */
+ public boolean isCallableStatement(PreparedStatement stmt)
+ {
+ return false;
+ }
+
}
1.21 +8 -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.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- PlatformOracle9iImpl.java 17 Mar 2005 23:57:00 -0000 1.20
+++ PlatformOracle9iImpl.java 6 Apr 2005 14:45:42 -0000 1.21
@@ -164,11 +164,10 @@
/**
* Default constructor.
- * Runs static init needed for Oracle-extensions and large BLOB/CLOB
support to function.
*/
public PlatformOracle9iImpl()
{
- initOracleReflectedVars();
+ super();
}
/**
@@ -541,7 +540,12 @@
return null;
}
- protected static void initOracleReflectedVars() {
+ /**
+ * Initializes static variables needed for Oracle-extensions and large
BLOB/CLOB support.
+ */
+ protected void initOracleReflectedVars()
+ {
+ super.initOracleReflectedVars();
try
{
/*
1.24 +53 -3
db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformOracleImpl.java
Index: PlatformOracleImpl.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformOracleImpl.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- PlatformOracleImpl.java 11 Mar 2005 17:12:28 -0000 1.23
+++ PlatformOracleImpl.java 6 Apr 2005 14:45:42 -0000 1.24
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.platforms;
-/* 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.
@@ -32,6 +32,7 @@
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
+import org.apache.ojb.broker.util.ClassHelper;
/**
* This class is a concrete implementation of <code>Platform</code>.
Provides an implementation
@@ -59,10 +60,24 @@
" can only be inserted using Oracle9i platform in an unmanaged" +
" environment or oracle platform with Oracle OCI driver";
+ /**
+ * Field value of <code>oracle.jdbc.OracleTypes.CURSOR</code>.
+ * @see #initOracleReflectedVars
+ */
+ protected static int ORACLE_JDBC_TYPE_CURSOR = -10;
+
private Logger logger =
LoggerFactory.getLogger(PlatformOracleImpl.class);
/**
- * Method prepareNextValProcedureStatement implementation
+ * Default constructor.
+ */
+ public PlatformOracleImpl()
+ {
+ initOracleReflectedVars();
+ }
+
+ /**
+ * Method prepareNextValProcedureStatement implementation
* is simply copied over from PlatformMsSQLServerImpl class.
* @see
org.apache.ojb.broker.platforms.Platform#prepareNextValProcedureStatement(java.sql.Connection,
java.lang.String, java.lang.String)
*/
@@ -249,6 +264,15 @@
}
/**
+ * @see
org.apache.ojb.broker.platforms.Platform#registerOutResultSet(java.sql.CallableStatement,
int)
+ */
+ public void registerOutResultSet(CallableStatement stmt, int position)
+ throws SQLException
+ {
+ stmt.registerOutParameter(position, ORACLE_JDBC_TYPE_CURSOR);
+ }
+
+ /**
* Returns the JDBC URL used for the specified connection.
* @param conn the database connection for which to check JDBC URL
* @return the JDBC URL or an empty String on error
@@ -290,4 +314,30 @@
return dbUrl != null && dbUrl.startsWith(OCI_URL_PREFIX);
}
+ /**
+ * Initializes static variables needed for getting Oracle-specific JDBC
types.
+ */
+ protected void initOracleReflectedVars()
+ {
+ try
+ {
+ // Check for Oracle-specific Types class
+ final Class oracleTypes =
ClassHelper.getClass("oracle.jdbc.OracleTypes", false);
+ final Field cursorField = oracleTypes.getField("CURSOR");
+ ORACLE_JDBC_TYPE_CURSOR = cursorField.getInt(null);
+ }
+ catch (ClassNotFoundException e)
+ {
+ logger.warn("PlatformOracleImpl could not find Oracle JDBC
classes");
+ }
+ catch (NoSuchFieldException e)
+ {
+ logger.warn("PlatformOracleImpl could not find Oracle JDBC type
fields");
+ }
+ catch (IllegalAccessException e)
+ {
+ logger.warn("PlatformOracleImpl could not get Oracle JDBC type
values");
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]