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 ar...@apache.org on 2006/05/02 02:10:43 UTC
svn commit: r398746 -
/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java
Author: arminw
Date: Mon May 1 17:10:41 2006
New Revision: 398746
URL: http://svn.apache.org/viewcvs?rev=398746&view=rev
Log:
use new Platform method to set statement values
improve exception handling
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java?rev=398746&r1=398745&r2=398746&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java Mon May 1 17:10:41 2006
@@ -20,7 +20,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.sql.Types;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
@@ -222,14 +221,8 @@
}
else
{
- if (value != null)
- {
- stmt.setObject(index, value);
- }
- else
- {
- stmt.setNull(index, Types.NULL);
- }
+ // no field defined, use common method call
+ m_platform.setObjectForStatement(stmt, index,value);
}
return ++index; // increment before return
@@ -476,17 +469,21 @@
setObjectForStatement(stmt, j + 1, values[i].getValue(), values[i].getJdbcType().getType());
}
}
- catch (SQLException e)
+ catch (Exception e)
{
- m_log.error("bindSelect failed for: " + oid.toString() + ", PK: " + i + ", value: " + values[i]);
- throw e;
+ String msg = "bindSelect failed for Identity: " + oid + ", performing PK: " + i
+ + ((values != null && i < values.length) ? ", value: " + values[i] : "");
+ m_log.error(msg);
+ if(e instanceof SQLException) throw (SQLException) e;
+ else if(e instanceof RuntimeException) throw (RuntimeException) e;
+ else throw new PersistenceBrokerException(msg, e);
}
}
/**
* binds the values of the object obj to the statements parameters
*/
- public void bindUpdate(PreparedStatement stmt, ClassDescriptor cld, Object obj) throws java.sql.SQLException
+ public void bindUpdate(PreparedStatement stmt, ClassDescriptor cld, Object obj) throws SQLException
{
if (cld.getUpdateProcedure() != null)
{
@@ -713,19 +710,12 @@
{
callable = (CallableStatement) stmt;
}
- catch(Exception e)
+ catch(ClassCastException e)
{
- m_log.error("Error while bind values for class '" + (cld != null ? cld.getClassNameOfObject() : null)
+ m_log.error("Unexpected error while cast statement to 'CallableStatement' for class '"
+ + (cld != null ? cld.getClassNameOfObject() : null)
+ "', using stored procedure: "+ proc, e);
- if(e instanceof SQLException)
- {
- throw (SQLException) e;
- }
- else
- {
- throw new PersistenceBrokerException("Unexpected error while bind values for class '"
- + (cld != null ? cld.getClassNameOfObject() : null) + "', using stored procedure: "+ proc);
- }
+ throw e;
}
// If we have a return value, then register it.
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org