User: starksm Date: 01/09/11 11:35:00 Modified: src/main/org/jboss/ejb/plugins/cmp/jdbc JDBCCommand.java JDBCCommandFactory.java JDBCDestroyCommand.java JDBCInsertRelationsCommand.java JDBCRelationInterceptor.java JDBCStartCommand.java JDBCUtil.java Log: Convert all logging to org.jboss.logging.Logger which is a subclass of org.apache.log4j.Category. Revision Changes Path 1.4 +3 -3 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCCommand.java Index: JDBCCommand.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCCommand.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- JDBCCommand.java 2001/09/01 22:03:15 1.3 +++ JDBCCommand.java 2001/09/11 18:35:00 1.4 @@ -11,7 +11,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; -import org.jboss.logging.Log; +import org.jboss.logging.Logger; import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge; import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCEntityMetaData; @@ -24,7 +24,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a> * @author <a href="mailto:[EMAIL PROTECTED]">Dirk Zimmermann</a> - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ public abstract class JDBCCommand { // Attributes ---------------------------------------------------- @@ -32,7 +32,7 @@ protected JDBCStoreManager manager; protected JDBCEntityBridge entity; protected JDBCEntityMetaData entityMetaData; - protected Log log; + protected Logger log; // Command name, used for debug trace protected String name; 1.6 +1 -2 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCCommandFactory.java Index: JDBCCommandFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCCommandFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JDBCCommandFactory.java 2001/09/01 22:03:15 1.5 +++ JDBCCommandFactory.java 2001/09/11 18:35:00 1.6 @@ -33,7 +33,6 @@ import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData; -import org.jboss.logging.Log; /** * JDBCCommandFactory creates all required CMP command and some JDBC @@ -43,7 +42,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a> * @author <a href="[EMAIL PROTECTED]">danch (Dan Christopherson</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ public class JDBCCommandFactory implements CommandFactory { 1.6 +2 -2 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCDestroyCommand.java Index: JDBCDestroyCommand.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCDestroyCommand.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JDBCDestroyCommand.java 2001/09/01 22:03:15 1.5 +++ JDBCDestroyCommand.java 2001/09/11 18:35:00 1.6 @@ -22,7 +22,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a> * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a> * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ public class JDBCDestroyCommand extends JDBCUpdateCommand implements DestroyCommand { // Constructors -------------------------------------------------- @@ -73,7 +73,7 @@ manager.getContainer().getTransactionManager().begin (); jdbcExecute("DROP TABLE " + tableName); manager.getContainer().getTransactionManager().commit (); - log.log("Dropped table '" + tableName + "' successfully."); + log.info("Dropped table '" + tableName + "' successfully."); } catch (Exception e) { log.debug("Could not drop table " + tableName + ": " + e.getMessage()); try { 1.5 +4 -3 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCInsertRelationsCommand.java Index: JDBCInsertRelationsCommand.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCInsertRelationsCommand.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JDBCInsertRelationsCommand.java 2001/09/01 22:03:15 1.4 +++ JDBCInsertRelationsCommand.java 2001/09/11 18:35:00 1.5 @@ -10,19 +10,20 @@ import java.sql.PreparedStatement; import java.util.Iterator; import javax.ejb.EJBException; + import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMPFieldBridge; import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge; -import org.jboss.logging.Log; +import org.jboss.logging.Logger; /** * Inserts relations into a relation table. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class JDBCInsertRelationsCommand { protected JDBCStoreManager manager; - protected Log log; + protected Logger log; // Command name, used for debug trace protected String name; 1.5 +3 -2 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCRelationInterceptor.java Index: JDBCRelationInterceptor.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCRelationInterceptor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JDBCRelationInterceptor.java 2001/09/01 22:03:15 1.4 +++ JDBCRelationInterceptor.java 2001/09/11 18:35:00 1.5 @@ -34,13 +34,14 @@ * relationship. This interceptor also manages the relation table data. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> -* @version $Revision: 1.4 $ +* @version $Revision: 1.5 $ */ public class JDBCRelationInterceptor extends AbstractInterceptor { // Constants ----------------------------------------------------- protected static final Method GET_RELATED_ID; protected static final Method ADD_RELATION; protected static final Method REMOVE_RELATION; + protected static Logger log = Logger.create(JDBCRelationInterceptor.class); static { try { @@ -233,7 +234,7 @@ } } } catch (Exception e) { - Logger.exception(e); + log.error("ex", e); // Store failed -> rollback! try { 1.6 +5 -5 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java Index: JDBCStartCommand.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JDBCStartCommand.java 2001/09/01 22:03:15 1.5 +++ JDBCStartCommand.java 2001/09/11 18:35:00 1.6 @@ -23,7 +23,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a> * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a> * @author <a href="mailto:[EMAIL PROTECTED]">Michel de Groot</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ public class JDBCStartCommand extends JDBCUpdateCommand implements StartCommand { // Constructors -------------------------------------------------- @@ -63,7 +63,7 @@ DatabaseMetaData dmd = con.getMetaData(); rs = dmd.getTables(con.getCatalog(), null, tableName, null); if (rs.next ()) { - log.log("Table '" + tableName + "' already exists"); + log.info("Table '" + tableName + "' already exists"); return; } } finally { @@ -78,13 +78,13 @@ manager.getContainer().getTransactionManager().commit (); // Create successful, log this - log.log("Created table '" + tableName + "' successfully."); + log.info("Created table '" + tableName + "' successfully."); } catch (Exception e) { - log.debug("Could not create table " + tableName + ": " + e.getMessage()); + log.debug("Could not create table " + tableName, e); try { manager.getContainer().getTransactionManager().rollback (); } catch (Exception _e) { - log.error("Could not roll back transaction: "+ _e.getMessage()); + log.error("Could not roll back transaction: ", e); } } } 1.6 +294 -200 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCUtil.java Index: JDBCUtil.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCUtil.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JDBCUtil.java 2001/09/01 22:03:15 1.5 +++ JDBCUtil.java 2001/09/11 18:35:00 1.6 @@ -35,8 +35,6 @@ import javax.ejb.EJBObject; import javax.ejb.Handle; -// TODO this needs to be replaced with the log4j logging -import org.jboss.logging.Log; import org.jboss.logging.Logger; /** @@ -45,110 +43,144 @@ * parameters and loading query results. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ -public class JDBCUtil { - public static void safeClose(Connection con) { - if(con != null) { - try { +public class JDBCUtil +{ + static Logger log = Logger.create(JDBCUtil.class); + + public static void safeClose(Connection con) + { + if(con != null) + { + try + { con.close(); - } catch(SQLException e) { - Logger.debug(e); + } catch(SQLException e) + { + log.debug("SQL error", e); + } + } + } + + public static void safeClose(ResultSet rs) + { + if(rs != null) + { + try + { + rs.close(); + } catch(SQLException e) + { + log.debug("SQL error", e); + } + } + } + + public static void safeClose(Statement statement) + { + if(statement != null) + { + try + { + statement.close(); + } catch(SQLException e) + { + log.debug("SQL error", e); + } + } + } + + public static void safeClose(InputStream in) + { + if(in != null) + { + try + { + in.close(); + } catch(IOException e) + { + log.debug("SQL error", e); + } + } + } + + public static void safeClose(OutputStream out) + { + if(out != null) + { + try + { + out.close(); + } catch(IOException e) + { + log.debug("SQL error", e); } } } - - public static void safeClose(ResultSet rs) { - if(rs != null) { - try { - rs.close(); - } catch(SQLException e) { - Logger.debug(e); - } - } - } - - public static void safeClose(Statement statement) { - if(statement != null) { - try { - statement.close(); - } catch(SQLException e) { - Logger.debug(e); - } - } - } - - public static void safeClose(InputStream in) { - if(in != null) { - try { - in.close(); - } catch(IOException e) { - Logger.debug(e); - } - } - } - - public static void safeClose(OutputStream out) { - if(out != null) { - try { - out.close(); - } catch(IOException e) { - Logger.debug(e); - } - } - } - - - /** - * Sets a parameter in this Command's PreparedStatement. - * Handles null values, and provides tracing. - * - * @param ps the PreparedStatement whose parameter needs to be set. - * @param index the index (1-based) of the parameter to be set. - * @param jdbcType the JDBC type of the parameter. - * @param value the value which the parameter is to be set to. - * @throws SQLException if parameter setting fails. - */ - public static void setParameter(Log log, PreparedStatement ps, int index, int jdbcType, Object value) throws SQLException { - if(JDBCCommand.debug) { + + + /** + * Sets a parameter in this Command's PreparedStatement. + * Handles null values, and provides tracing. + * + * @param ps the PreparedStatement whose parameter needs to be set. + * @param index the index (1-based) of the parameter to be set. + * @param jdbcType the JDBC type of the parameter. + * @param value the value which the parameter is to be set to. + * @throws SQLException if parameter setting fails. + */ + public static void setParameter(Logger log, PreparedStatement ps, int index, int jdbcType, Object value) throws SQLException + { + if(JDBCCommand.debug) + { log.debug("Set parameter: " + - "index=" + index + ", " + - "jdbcType=" + getJDBCTypeName(jdbcType) + ", " + - "value=" + ((value == null) ? "NULL" : value)); - } - - if (value == null) { + "index=" + index + ", " + + "jdbcType=" + getJDBCTypeName(jdbcType) + ", " + + "value=" + ((value == null) ? "NULL" : value)); + } + + if (value == null) + { ps.setNull(index, jdbcType); - } else { + } else + { // convert to valid SQL data types (for DATE, TIME, TIMESTAMP) value = convertToSQLType(jdbcType, value); - - if(isBinaryJDBCType(jdbcType)) { + + if(isBinaryJDBCType(jdbcType)) + { byte[] bytes = convertObjectToByteArray(value); setBinaryParameter(ps, index, bytes); - } else { + } else + { ps.setObject(index, value, jdbcType); } } } - - private static void setBinaryParameter(PreparedStatement ps, int index, byte[] bytes) throws SQLException { + + private static void setBinaryParameter(PreparedStatement ps, int index, byte[] bytes) throws SQLException + { // it's more efficient to use setBinaryStream for large // streams, and causes problems if not done on some DBMS // implementations - if (bytes.length < 2000) { + if (bytes.length < 2000) + { ps.setBytes(index, bytes); - } else { + } else + { InputStream in = null; - try { + try + { in = new ByteArrayInputStream(bytes); ps.setBinaryStream(index, in, bytes.length); - } finally { + } finally + { safeClose(in); } } } - + /** * Used for all retrieval of results from <code>ResultSet</code>s. * Implements tracing, and allows some tweaking of returned types. @@ -157,126 +189,158 @@ * @param index index of the result column. * @param destination The class of the variable this is going into */ - public static Object getResult(Log log, ResultSet rs, int index, Class destination) throws SQLException { + public static Object getResult(Logger log, ResultSet rs, int index, Class destination) throws SQLException + { Object[] returnValue = new Object[1]; - if(getNonBinaryResult(rs, index, destination, returnValue)) { - if(JDBCCommand.debug) { - log.debug("Get result: index=" + index + ", javaType=" + destination.getName() + ", S value=" + returnValue[0]); + if(getNonBinaryResult(rs, index, destination, returnValue)) + { + if(JDBCCommand.debug) + { + log.debug("Get result: index=" + index + ", javaType=" + destination.getName() + ", S value=" + returnValue[0]); } return returnValue[0]; - } else if(getObjectResult(rs, index, destination, returnValue)) { - if(JDBCCommand.debug) { - log.debug("Get result: index=" + index + ", javaType=" + destination.getName() + ", O value=" + returnValue[0]); + } else if(getObjectResult(rs, index, destination, returnValue)) + { + if(JDBCCommand.debug) + { + log.debug("Get result: index=" + index + ", javaType=" + destination.getName() + ", O value=" + returnValue[0]); } return returnValue[0]; - } else if(getBinaryResult(rs, index, destination, returnValue)) { - if(JDBCCommand.debug) { - log.debug("Get result: index=" + index + ", javaType=" + destination.getName() + ", B value=" + returnValue[0]); + } else if(getBinaryResult(rs, index, destination, returnValue)) + { + if(JDBCCommand.debug) + { + log.debug("Get result: index=" + index + ", javaType=" + destination.getName() + ", B value=" + returnValue[0]); } return returnValue[0]; } throw new SQLException("Unable to load a ResultSet column into a variable of type '" + destination.getName() + "'"); } - - private static boolean getNonBinaryResult(ResultSet rs, int index, Class destination, Object returnValue[]) throws SQLException { + + private static boolean getNonBinaryResult(ResultSet rs, int index, Class destination, Object returnValue[]) throws SQLException + { Method method = (Method)rsTypes.get(destination.getName()); - if(method != null) { - try { - Object value = method.invoke(rs, new Object[]{new Integer(index)}); - if(rs.wasNull()) { + if(method != null) + { + try + { + Object value = method.invoke(rs, new Object[] + {new Integer(index)}); + if(rs.wasNull()) + { returnValue[0] = null; - } else { + } else + { if(value instanceof String && - (destination.isAssignableFrom(Character.class) || - destination.isAssignableFrom(Character.TYPE) )) { + (destination.isAssignableFrom(Character.class) || + destination.isAssignableFrom(Character.TYPE) )) + { value = new Character(((String)value).charAt(0)); } returnValue[0] = value; } return true; - } catch(IllegalAccessException e) { - // What-ever, I guess non-binary will not work for this field. - } catch(InvocationTargetException e) { - // What-ever, I guess non-binary will not work for this field. + } catch(IllegalAccessException e) + { + // What-ever, I guess non-binary will not work for this field. + } catch(InvocationTargetException e) + { + // What-ever, I guess non-binary will not work for this field. } } return false; } - - private static boolean getObjectResult(ResultSet rs, int index, Class destination, Object returnValue[]) throws SQLException { + + private static boolean getObjectResult(ResultSet rs, int index, Class destination, Object returnValue[]) throws SQLException + { // // I think this method is very dangerous, and we should consider removing it. // Some lesser databases only allow you to read a column once and if the // object based stratege fails, we have to read the column again with getBytes. Object value = rs.getObject(index); - if(value == null) { + if(value == null) + { returnValue[0] = null; return true; } - + return convertToJavaType(value, destination, returnValue); } - - private static boolean getBinaryResult(ResultSet rs, int index, Class destination, Object returnValue[]) throws SQLException { + + private static boolean getBinaryResult(ResultSet rs, int index, Class destination, Object returnValue[]) throws SQLException + { byte[] bytes = rs.getBytes(index); - if( bytes == null ) { + if( bytes == null ) + { returnValue[0] = null; return true; } - + Object value = convertByteArrayToObject(bytes); return convertToJavaType(value, destination, returnValue); - } - - private static boolean convertToJavaType(Object value, Class destination, Object returnValue[]) throws SQLException { - try { + } + + private static boolean convertToJavaType(Object value, Class destination, Object returnValue[]) throws SQLException + { + try + { // Was the object double marshalled? - if(value instanceof MarshalledObject && !destination.equals(MarshalledObject.class)) { + if(value instanceof MarshalledObject && !destination.equals(MarshalledObject.class)) + { value = ((MarshalledObject)value).get(); } - + // ejb-reference: get the object back from the handle - if(value instanceof Handle) { + if(value instanceof Handle) + { value = ((Handle)value).getEJBObject(); - if(destination.isAssignableFrom(value.getClass())) { + if(destination.isAssignableFrom(value.getClass())) + { returnValue[0] = value; return true; - } else { + } else + { throw new SQLException("Got a " + value.getClass().getName() + ": '" + value + "' while looking for a " + destination.getName()); } } - + // Are we done yet? - if(destination.isAssignableFrom(value.getClass())) { + if(destination.isAssignableFrom(value.getClass())) + { returnValue[0] = value; return true; } - + // Ok is this a primitive wrapper - if(destination.isPrimitive()) { + if(destination.isPrimitive()) + { if((destination.equals(Byte.TYPE) && value instanceof Byte) || - (destination.equals(Short.TYPE) && value instanceof Short) || - (destination.equals(Character.TYPE) && value instanceof Character) || - (destination.equals(Boolean.TYPE) && value instanceof Boolean) || - (destination.equals(Integer.TYPE) && value instanceof Integer) || - (destination.equals(Long.TYPE) && value instanceof Long) || - (destination.equals(Float.TYPE) && value instanceof Float) || - (destination.equals(Double.TYPE) && value instanceof Double) - ) { + (destination.equals(Short.TYPE) && value instanceof Short) || + (destination.equals(Character.TYPE) && value instanceof Character) || + (destination.equals(Boolean.TYPE) && value instanceof Boolean) || + (destination.equals(Integer.TYPE) && value instanceof Integer) || + (destination.equals(Long.TYPE) && value instanceof Long) || + (destination.equals(Float.TYPE) && value instanceof Float) || + (destination.equals(Double.TYPE) && value instanceof Double) + ) + { returnValue[0] = value; return true; } } - } catch (RemoteException e) { + } catch (RemoteException e) + { throw new SQLException("Unable to load EJBObject back from Handle: " +e); - } catch(IOException e) { + } catch(IOException e) + { throw new SQLException("Unable to load to deserialize result: "+e); - } catch (ClassNotFoundException e) { + } catch (ClassNotFoundException e) + { throw new SQLException("Unable to load to deserialize result: "+e); } return false; } - + /** * Returns true if the JDBC type should be (de-)serialized as a * binary stream and false otherwise. @@ -284,103 +348,125 @@ * @param jdbcType the JDBC type * @return true if binary type, false otherwise */ - public static boolean isBinaryJDBCType(int jdbcType) { + public static boolean isBinaryJDBCType(int jdbcType) + { return (Types.BINARY == jdbcType || - Types.BLOB == jdbcType || - Types.CLOB == jdbcType || - Types.JAVA_OBJECT == jdbcType || - Types.LONGVARBINARY == jdbcType || - Types.OTHER == jdbcType || - Types.STRUCT == jdbcType || - Types.VARBINARY == jdbcType); - } - - private static Object convertToSQLType(int jdbcType, Object value) { - if(jdbcType == Types.DATE) { - if(value.getClass().getName().equals("java.util.Date")) { - return new java.sql.Date(((java.util.Date)value).getTime()); - } - } else if(jdbcType == Types.TIME) { - if(value.getClass().getName().equals("java.util.Date")) { - return new java.sql.Time(((java.util.Date)value).getTime()); - } - } else if(jdbcType == Types.TIMESTAMP) { - if(value.getClass().getName().equals("java.util.Date")) { - return new java.sql.Timestamp(((java.util.Date)value).getTime()); + Types.BLOB == jdbcType || + Types.CLOB == jdbcType || + Types.JAVA_OBJECT == jdbcType || + Types.LONGVARBINARY == jdbcType || + Types.OTHER == jdbcType || + Types.STRUCT == jdbcType || + Types.VARBINARY == jdbcType); + } + + private static Object convertToSQLType(int jdbcType, Object value) + { + if(jdbcType == Types.DATE) + { + if(value.getClass().getName().equals("java.util.Date")) + { + return new java.sql.Date(((java.util.Date)value).getTime()); + } + } else if(jdbcType == Types.TIME) + { + if(value.getClass().getName().equals("java.util.Date")) + { + return new java.sql.Time(((java.util.Date)value).getTime()); + } + } else if(jdbcType == Types.TIMESTAMP) + { + if(value.getClass().getName().equals("java.util.Date")) + { + return new java.sql.Timestamp(((java.util.Date)value).getTime()); } } return value; } - - private static byte[] convertObjectToByteArray(Object value) throws SQLException { + + private static byte[] convertObjectToByteArray(Object value) throws SQLException + { // Do we already have a byte array? - if (value instanceof byte[]) { + if (value instanceof byte[]) + { return (byte[])value; } - + ByteArrayOutputStream baos = null; ObjectOutputStream oos = null; - try { + try + { // ejb-reference: store the handle - if (value instanceof EJBObject) { - value = ((EJBObject)value).getHandle(); + if (value instanceof EJBObject) + { + value = ((EJBObject)value).getHandle(); } - + // return the serialize the value baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); - + // Marshall the object and write it oos.writeObject(new MarshalledObject(value)); return baos.toByteArray(); - } catch(RemoteException e) { + } catch(RemoteException e) + { throw new SQLException("Cannot get Handle of EJBObject: "+e); - } catch(IOException e) { + } catch(IOException e) + { throw new SQLException("Can't serialize binary object: " + e); - } finally { + } finally + { safeClose(oos); safeClose(baos); } } - - private static Object convertByteArrayToObject(byte[] bytes) throws SQLException { + + private static Object convertByteArrayToObject(byte[] bytes) throws SQLException + { ByteArrayInputStream bais = null; ObjectInputStream ois = null; - - try { + + try + { Object value; - + // deserialize result bais = new ByteArrayInputStream(bytes); ois = new ObjectInputStream(bais); value = ois.readObject(); - + // de-marshall value value = ((MarshalledObject)value).get(); - + // ejb-reference: get the object back from the handle - if(value instanceof Handle) { - value = ((Handle)value).getEJBObject(); + if(value instanceof Handle) + { + value = ((Handle)value).getEJBObject(); } return value; - } catch (RemoteException e) { + } catch (RemoteException e) + { throw new SQLException("Unable to load EJBObject back from Handle: " +e); - } catch (IOException e) { + } catch (IOException e) + { throw new SQLException("Unable to load to deserialize result: "+e); - } catch (ClassNotFoundException e) { + } catch (ClassNotFoundException e) + { throw new SQLException("Unable to load to deserialize result: "+e); - } finally { + } finally + { safeClose(ois); safeClose(bais); } } - + // // Simple helper methods // private static Map jdbcTypeNames; private final static Map rsTypes; - + /** * Gets the JDBC type name corresponding to the given type code. * Only used in debug log messages. @@ -389,17 +475,21 @@ * @return the JDBC type name. * @see Types */ - private static String getJDBCTypeName(int jdbcType) { + private static String getJDBCTypeName(int jdbcType) + { return (String)jdbcTypeNames.get(new Integer(jdbcType)); } - - static { + + static + { // Initialize the mapping between non-binary java result set // types and the method on ResultSet that is used to retrieve // a value of the java type. rsTypes = new HashMap(); - Class[] arg = new Class[]{Integer.TYPE}; - try { + Class[] arg = new Class[] + {Integer.TYPE}; + try + { rsTypes.put(java.util.Date.class.getName(), ResultSet.class.getMethod("getTimestamp", arg)); rsTypes.put(java.sql.Date.class.getName(), ResultSet.class.getMethod("getDate", arg)); rsTypes.put(java.sql.Time.class.getName(), ResultSet.class.getMethod("getTime", arg)); @@ -423,23 +513,27 @@ rsTypes.put(Float.TYPE.getName(), ResultSet.class.getMethod("getFloat", arg)); rsTypes.put(java.lang.Double.class.getName(), ResultSet.class.getMethod("getDouble", arg)); rsTypes.put(Double.TYPE.getName(), ResultSet.class.getMethod("getDouble", arg)); - } catch(NoSuchMethodException e) { + } catch(NoSuchMethodException e) + { // Should never happen - Logger.debug(e); + log.debug("SQL error", e); } - + // Initializes the map between jdbcType (int) and the name of the type. // This map is used to print meaningful debug and error messages. jdbcTypeNames = new HashMap(); Field[] fields = Types.class.getFields(); - for(int i = 0; i < fields.length; i++) { - try { - jdbcTypeNames.put(fields[i].get(null), fields[i].getName()); - } catch (IllegalAccessException e) { - // Should never happen - Logger.debug(e); + for(int i = 0; i < fields.length; i++) + { + try + { + jdbcTypeNames.put(fields[i].get(null), fields[i].getName()); + } catch (IllegalAccessException e) + { + // Should never happen + log.debug("SQL error", e); } } } - + } _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development