diff --git a/base/src/org/compiere/interfaces/Server.java b/base/src/org/compiere/interfaces/Server.java index eb6adf0904..4a11ef7921 100644 --- a/base/src/org/compiere/interfaces/Server.java +++ b/base/src/org/compiere/interfaces/Server.java @@ -56,6 +56,12 @@ public interface Server public int stmt_executeUpdate( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) throws java.rmi.RemoteException; + public org.compiere.util.ExecuteResult stmt_execute( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) + throws java.rmi.RemoteException; + + public org.compiere.util.CallableResult callable_execute( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) + throws java.rmi.RemoteException; + /** * Get next number for Key column = 0 is Error. * @param AD_Client_ID client @@ -78,9 +84,8 @@ public interface Server * Get Document No based on Document Type * @param C_DocType_ID document type * @param trxName optional Transaction Name - * @param definite is definite sequence * @return document no or null */ - public java.lang.String getDocumentNo( int C_DocType_ID, java.lang.String trxName, boolean definite ) + public java.lang.String getDocumentNo( int C_DocType_ID,java.lang.String trxName,boolean definite ) throws java.rmi.RemoteException; /** @@ -153,9 +158,10 @@ public interface Server * @param sql table name * @param displayType display type (i.e. BLOB/CLOB) * @param value the data + * @param trxName * @param token Security Token * @return true if updated */ - public boolean updateLOB( java.lang.String sql,int displayType,java.lang.Object value,org.compiere.util.SecurityToken token ) + public boolean updateLOB( java.lang.String sql,int displayType,java.lang.Object value,java.lang.String trxName,org.compiere.util.SecurityToken token ) throws java.rmi.RemoteException; /** diff --git a/base/src/org/compiere/interfaces/ServerLocal.java b/base/src/org/compiere/interfaces/ServerLocal.java index c4753b2e0b..49a1f68ce1 100644 --- a/base/src/org/compiere/interfaces/ServerLocal.java +++ b/base/src/org/compiere/interfaces/ServerLocal.java @@ -51,6 +51,10 @@ public interface ServerLocal * @return row count */ public int stmt_executeUpdate( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) ; + public org.compiere.util.ExecuteResult stmt_execute( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) ; + + public org.compiere.util.CallableResult callable_execute( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) ; + /** * Get next number for Key column = 0 is Error. * @param AD_Client_ID client @@ -71,9 +75,8 @@ public interface ServerLocal * Get Document No based on Document Type * @param C_DocType_ID document type * @param trxName optional Transaction Name - * @param definite is definite sequence * @return document no or null */ - public java.lang.String getDocumentNo( int C_DocType_ID,java.lang.String trxName, boolean definite ) ; + public java.lang.String getDocumentNo( int C_DocType_ID,java.lang.String trxName,boolean definite ) ; /** * Process Remote @@ -138,9 +141,10 @@ public interface ServerLocal * @param sql table name * @param displayType display type (i.e. BLOB/CLOB) * @param value the data + * @param trxName * @param token Security Token * @return true if updated */ - public boolean updateLOB( java.lang.String sql,int displayType,java.lang.Object value,org.compiere.util.SecurityToken token ) ; + public boolean updateLOB( java.lang.String sql,int displayType,java.lang.Object value,java.lang.String trxName,org.compiere.util.SecurityToken token ) ; /** * Describes the instance and its content for debugging purpose diff --git a/base/src/org/compiere/model/PO_LOB.java b/base/src/org/compiere/model/PO_LOB.java index 77d0756ecc..1184fde8b8 100644 --- a/base/src/org/compiere/model/PO_LOB.java +++ b/base/src/org/compiere/model/PO_LOB.java @@ -118,7 +118,7 @@ public class PO_LOB implements Serializable { if (server != null) { // See ServerBean - success = server.updateLOB (sql.toString(), m_displayType, m_value, SecurityToken.getInstance()); + success = server.updateLOB (sql.toString(), m_displayType, m_value, trxName, SecurityToken.getInstance()); if (CLogMgt.isLevelFinest()) log.fine("server.updateLOB => " + success); return success; diff --git a/base/src/org/compiere/util/CCallableStatement.java b/base/src/org/compiere/util/CCallableStatement.java index e77952a5c1..8a89f59798 100644 --- a/base/src/org/compiere/util/CCallableStatement.java +++ b/base/src/org/compiere/util/CCallableStatement.java @@ -31,10 +31,14 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.Calendar; import java.util.Map; import java.util.logging.Level; +import org.compiere.db.CConnection; +import org.compiere.interfaces.Server; + /** * Adempiere Callable Statement @@ -58,8 +62,11 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt super(resultSetType, resultSetConcurrency, sql, trxName); } - - /** + public CCallableStatement(CStatementVO vo) { + super(vo); + } + + /** * Initialise the prepared statement wrapper object */ protected void init() @@ -95,7 +102,11 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } } - + /** + * @param i + * @return Array + * @see java.sql.CallableStatement#getArray(int) + */ public Array getArray(int i) throws SQLException { if (p_stmt != null) @@ -105,7 +116,11 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt throw new java.lang.UnsupportedOperationException ("Method getArray() not yet implemented."); } - + /** + * @param parameterName + * @return Array + * @see java.sql.CallableStatement#getArray(String) + */ public Array getArray(String parameterName) throws SQLException { if (p_stmt != null) @@ -115,37 +130,72 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt throw new java.lang.UnsupportedOperationException ("Method getArray() not yet implemented."); } - + /** + * @param parameterIndex + * @return BigDecimal + * @see java.sql.CallableStatement#getBigDecimal(int) + */ public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { if (p_stmt != null) { return ((CallableStatement)p_stmt).getBigDecimal(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getBigDecimal() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? (BigDecimal)o.getValue() : null; } - + /** + * @param parameterName + * @return BigDecimal + * @see java.sql.CallableStatement#getBigDecimal(String) + */ public BigDecimal getBigDecimal(String parameterName) throws SQLException { if (p_stmt != null) { return ((CallableStatement)p_stmt).getBigDecimal(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getBigDecimal() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? (BigDecimal)o.getValue() : null; } - + /** + * @param parameterIndex + * @param scale + * @return BigDecimal + * @see java.sql.CallableStatement#getBigDecimal(int, int) + */ public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { if (p_stmt != null) { return ((CallableStatement)p_stmt).getBigDecimal(parameterIndex, scale); } - throw new java.lang.UnsupportedOperationException ("Method getBigDecimal() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? (BigDecimal)o.getValue() : null; } - + /** + * @param i + * @return Blob + * @see java.sql.CallableStatement#getBlob(int) + */ public Blob getBlob(int i) throws SQLException { if (p_stmt != null) @@ -155,7 +205,11 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt throw new java.lang.UnsupportedOperationException ("Method getBlob() not yet implemented."); } - + /** + * @param parameterName + * @return Blob + * @see java.sql.CallableStatement#getBlob(String) + */ public Blob getBlob(String parameterName) throws SQLException { if (p_stmt != null) @@ -165,67 +219,130 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt throw new java.lang.UnsupportedOperationException ("Method getBlob() not yet implemented."); } - + /** + * @param parameterIndex + * @return boolean + * @see java.sql.CallableStatement#getBoolean(int) + */ public boolean getBoolean(int parameterIndex) throws SQLException { if (p_stmt != null) { return ((CallableStatement)p_stmt).getBoolean(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getBoolean() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? (Boolean)o.getValue() : null; } - + /** + * @param parameterName + * @return boolean + * @see java.sql.CallableStatement#getBoolean(String) + */ public boolean getBoolean(String parameterName) throws SQLException { if (p_stmt != null) { return ((CallableStatement)p_stmt).getBoolean(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getBoolean() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? (Boolean)o.getValue() : null; } - + /** + * @param parameterIndex + * @see java.sql.CallableStatement#getByte(int) + */ public byte getByte(int parameterIndex) throws SQLException { if (p_stmt != null) { return ((CallableStatement)p_stmt).getByte(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getByte() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? (Byte)o.getValue() : null; } - + /** + * @param parameterName + * @return byte + * @see java.sql.CallableStatement#getByte(String) + */ public byte getByte(String parameterName) throws SQLException { if (p_stmt != null) { return ((CallableStatement)p_stmt).getByte(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getByte() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? (Byte)o.getValue() : null; } - + /** + * @param parameterIndex + * @return byte[] + * @see java.sql.CallableStatement#getBytes(int) + */ public byte[] getBytes(int parameterIndex) throws SQLException { if (p_stmt != null) { return ((CallableStatement)p_stmt).getBytes(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getBytes() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? (byte[])o.getValue() : null; } - + /** + * @param parameterName + * @return byte[] + * @see java.sql.CallableStatement#getBytes(String) + */ public byte[] getBytes(String parameterName) throws SQLException { if (p_stmt != null) { return ((CallableStatement)p_stmt).getBytes(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getBytes() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? (byte[])o.getValue() : null; } - + /** + * @param i + * @return Clob + * @see java.sql.CallableStatement#getClob(int) + */ public Clob getClob(int i) throws SQLException { if (p_stmt != null) @@ -235,7 +352,11 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt throw new java.lang.UnsupportedOperationException ("Method getClob() not yet implemented."); } - + /** + * @param parameterName + * @return @Clob + * @see java.sql.CallableStatement#getClob(String) + */ public Clob getClob(String parameterName) throws SQLException { if (p_stmt != null) @@ -245,14 +366,24 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt throw new java.lang.UnsupportedOperationException ("Method getClob() not yet implemented."); } - + /** + * @param parameterIndex + * @return Date + * @see java.sql.CallableStatement#getDate(int) + */ public Date getDate(int parameterIndex) throws SQLException { if (p_stmt != null) { return ((CallableStatement)p_stmt).getDate(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getDate() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? (Date)o.getValue() : null; } @@ -262,7 +393,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getDate(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getDate() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? (Date)o.getValue() : null; } @@ -272,7 +409,7 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getDate(parameterIndex, cal); } - throw new java.lang.UnsupportedOperationException ("Method getDate() not yet implemented."); + throw new java.lang.UnsupportedOperationException ("Method getDate(parameterIndex, calendar) not yet implemented."); } @@ -282,7 +419,7 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getDate(parameterName, cal); } - throw new java.lang.UnsupportedOperationException ("Method getDate() not yet implemented."); + throw new java.lang.UnsupportedOperationException ("Method getDate(parameterName, calendar) not yet implemented."); } @@ -292,7 +429,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getDouble(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getDouble() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? ((Number)o.getValue()).doubleValue() : 0; } @@ -302,7 +445,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getDouble(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getDouble() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? ((Number)o.getValue()).doubleValue() : 0; } @@ -312,7 +461,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getFloat(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getFloat() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? ((Number)o.getValue()).floatValue() : 0; } @@ -322,7 +477,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getFloat(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getFloat() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? ((Number)o.getValue()).floatValue() : 0; } @@ -332,7 +493,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getInt(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getInt() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? ((Number)o.getValue()).intValue() : 0; } @@ -342,7 +509,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getInt(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getInt() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? ((Number)o.getValue()).intValue() : 0; } @@ -352,7 +525,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getLong(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getLong() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? ((Number)o.getValue()).longValue() : 0; } @@ -362,7 +541,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getLong(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getLong() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? ((Number)o.getValue()).longValue() : 0; } @@ -372,7 +557,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getObject(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getObject() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? o.getValue() : null; } @@ -382,7 +573,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getObject(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getObject() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? o.getValue() : null; } @@ -392,7 +589,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getObject(i, map); } - throw new java.lang.UnsupportedOperationException ("Method getObject() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(i); + } + return o != null ? o.getValue() : null; } @@ -402,7 +605,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getObject(parameterName, map); } - throw new java.lang.UnsupportedOperationException ("Method getObject() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? o.getValue() : null; } @@ -432,7 +641,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getShort(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getShort() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? ((Number)o.getValue()).shortValue() : 0; } @@ -442,7 +657,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getShort(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getShort() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? ((Number)o.getValue()).shortValue() : 0; } @@ -452,7 +673,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getString(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getString() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? (o.getValue() != null ? o.getValue().toString() : null) : null; } @@ -462,7 +689,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getString(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getString() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? (o.getValue() != null ? o.getValue().toString() : null) : null; } @@ -472,7 +705,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getTime(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getTime() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? (Time)o.getValue() : null; } @@ -482,7 +721,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getTime(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getTime() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? (Time)o.getValue() : null; } @@ -512,7 +757,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getTimestamp(parameterIndex); } - throw new java.lang.UnsupportedOperationException ("Method getTimestamp() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getOrdinalOutput().get(parameterIndex); + } + return o != null ? (Timestamp)o.getValue() : null; } @@ -522,7 +773,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt { return ((CallableStatement)p_stmt).getTimestamp(parameterName); } - throw new java.lang.UnsupportedOperationException ("Method getTimestamp() not yet implemented."); + OutputParameter o = null; + if (executeResult != null) + { + CallableResult cr = (CallableResult)executeResult; + o = cr.getNamedOutput().get(parameterName); + } + return o != null ? (Timestamp)o.getValue() : null; } @@ -574,7 +831,7 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method registerOutParameter() not yet implemented."); + p_vo.registerOutParameter(parameterIndex, sqlType); } } @@ -587,7 +844,7 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method registerOutParameter() not yet implemented."); + p_vo.registerOutParameter(parameterName, sqlType); } } @@ -601,7 +858,7 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method registerOutParameter() not yet implemented."); + p_vo.registerOutParameter(parameterIndex, sqlType, scale); } } @@ -614,7 +871,7 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method registerOutParameter() not yet implemented."); + p_vo.registerOutParameter(paramIndex, sqlType, typeName); } } @@ -627,7 +884,7 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method registerOutParameter() not yet implemented."); + p_vo.registerOutParameter(parameterName, sqlType, scale); } } @@ -640,12 +897,45 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method registerOutParameter() not yet implemented."); + p_vo.registerOutParameter(parameterName, sqlType, typeName); } } + + @Override + protected boolean remote_execute() throws SQLException { + // Client -> remote sever + log.finest("server => " + p_vo + ", Remote=" + DB.isRemoteObjects()); + try + { + if (DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false)) + { + Server server = CConnection.get().getServer(); + if (server != null) + { + executeResult = server.callable_execute(p_vo, SecurityToken.getInstance()); + p_vo.clearParameters(); // re-use of result set + return executeResult.isFirstResult(); + } + log.log(Level.SEVERE, "AppsServer not found"); + } + throw new IllegalStateException("Remote Connection - Application server not available"); + } + catch (Exception ex) + { + log.log(Level.SEVERE, "AppsServer error", ex); + if (ex instanceof SQLException) + throw (SQLException)ex; + else if (ex instanceof RuntimeException) + throw (RuntimeException)ex; + else + throw new RuntimeException(ex); + } + } - - public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException + /** + * @see java.sql.CallableStatement#setAsciiStream(String, InputStream, int) + */ + public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException { if (p_stmt != null) { @@ -657,7 +947,9 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } } - + /** + * @see java.sql.CallableStatement#setBigDecimal(String, BigDecimal) + */ public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException { if (p_stmt != null) @@ -666,11 +958,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setBigDecimal() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setBinaryStream(String, InputStream, int) + */ public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException { if (p_stmt != null) @@ -684,7 +978,9 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } - + /** + * @see java.sql.CallableStatement#setBoolean(String, boolean) + */ public void setBoolean(String parameterName, boolean x) throws SQLException { if (p_stmt != null) @@ -693,11 +989,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setBoolean() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setByte(String, byte) + */ public void setByte(String parameterName, byte x) throws SQLException { if (p_stmt != null) @@ -706,11 +1004,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setByte() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setBytes(String, byte[]) + */ public void setBytes(String parameterName, byte[] x) throws SQLException { if (p_stmt != null) @@ -719,11 +1019,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setBytes() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setCharacterStream(String, Reader, int) + */ public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException { if (p_stmt != null) @@ -736,7 +1038,9 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } } - + /** + * @see java.sql.CallableStatement#setDate(String, Date) + */ public void setDate(String parameterName, Date x) throws SQLException { if (p_stmt != null) @@ -745,11 +1049,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setDate() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setDate(String, Date, Calendar) + */ public void setDate(String parameterName, Date x, Calendar cal) throws SQLException { if (p_stmt != null) @@ -762,7 +1068,9 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } } - + /** + * @see java.sql.CallableStatement#setDouble(String, double) + */ public void setDouble(String parameterName, double x) throws SQLException { if (p_stmt != null) @@ -771,11 +1079,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setDouble() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setFloat(String, float) + */ public void setFloat(String parameterName, float x) throws SQLException { if (p_stmt != null) @@ -784,11 +1094,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setFloat() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setLong(String, long) + */ public void setInt(String parameterName, int x) throws SQLException { if (p_stmt != null) @@ -797,11 +1109,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setInt() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setLong(String, long) + */ public void setLong(String parameterName, long x) throws SQLException { if (p_stmt != null) @@ -810,11 +1124,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setLong() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setNull(String, int) + */ public void setNull(String parameterName, int sqlType) throws SQLException { if (p_stmt != null) @@ -823,11 +1139,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setNull() not yet implemented."); + p_vo.setParameter(parameterName, new NullParameter(sqlType)); } } - + /** + * @see java.sql.CallableStatement#setNull(String, int, String) + */ public void setNull(String parameterName, int sqlType, String typeName) throws SQLException { if (p_stmt != null) @@ -836,11 +1154,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setNull() not yet implemented."); + p_vo.setParameter(parameterName, new NullParameter(sqlType)); } } - + /** + * @see java.sql.CallableStatement#setObject(String, Object) + */ public void setObject(String parameterName, Object x) throws SQLException { if (p_stmt != null) @@ -849,11 +1169,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setObject() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setObject(String, Object, int) + */ public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException { if (p_stmt != null) @@ -866,7 +1188,9 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } } - + /** + * @see java.sql.CallableStatement#setObject(String, Object, int, int) + */ public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException { if (p_stmt != null) @@ -879,7 +1203,9 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } } - + /** + * @see java.sql.CallableStatement#setShort(String, short) + */ public void setShort(String parameterName, short x) throws SQLException { if (p_stmt != null) @@ -888,11 +1214,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setShort() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setString(String, String) + */ public void setString(String parameterName, String x) throws SQLException { if (p_stmt != null) @@ -901,11 +1229,13 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setString() not yet implemented."); + p_vo.setParameter(parameterName, x); } } - + /** + * @see java.sql.CallableStatement#setTime(String, Time) + */ public void setTime(String parameterName, Time x) throws SQLException { if (p_stmt != null) @@ -914,11 +1244,14 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setTime() not yet implemented."); + p_vo.setParameter(parameterName, x); } } + /** + * @see java.sql.CallableStatement#setTime(String, Time, Calendar) + */ public void setTime(String parameterName, Time x, Calendar cal) throws SQLException { if (p_stmt != null) @@ -931,7 +1264,9 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } } - + /** + * @see java.sql.CallableStatement#setTime(String, Time) + */ public void setTimestamp(String parameterName, Timestamp x) throws SQLException { if (p_stmt != null) @@ -940,7 +1275,7 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } else { - throw new java.lang.UnsupportedOperationException ("Method setTimestamp() not yet implemented."); + p_vo.setParameter(parameterName, x); } } @@ -983,6 +1318,148 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt } } + @Override + public void fillParametersFromVO() { + try + { + //ordinal input parameters + ArrayList paramList = p_vo.getParameters(); + CallableStatement pstmt = (CallableStatement)p_stmt; + for (int i = 0; i < paramList.size(); i++) + { + Object o = paramList.get(i); + if (o == null) + { + throw new IllegalArgumentException ("Local - Null Parameter #" + i); + } + else if ( o instanceof OutputParameter) + { + OutputParameter op = (OutputParameter)o; + if (op.getScale() != -1 ) + pstmt.registerOutParameter(i+1, op.getSqlType(), op.getScale()); + else if (op.getTypeName() != null) + pstmt.registerOutParameter(i+1, op.getSqlType(), op.getTypeName()); + else + pstmt.registerOutParameter(i+1, op.getSqlType()); + } + else if (o instanceof NullParameter) + { + int type = ((NullParameter)o).getType(); + pstmt.setNull(i+1, type); + log.finest("#" + (i+1) + " - Null"); + } + else if (o instanceof Integer) + { + pstmt.setInt(i+1, ((Integer)o).intValue()); + log.finest("#" + (i+1) + " - int=" + o); + } + else if (o instanceof String) + { + pstmt.setString(i+1, (String)o); + log.finest("#" + (i+1) + " - String=" + o); + } + else if (o instanceof Timestamp) + { + pstmt.setTimestamp(i+1, (Timestamp)o); + log.finest("#" + (i+1) + " - Timestamp=" + o); + } + else if (o instanceof BigDecimal) + { + pstmt.setBigDecimal(i+1, (BigDecimal)o); + log.finest("#" + (i+1) + " - BigDecimal=" + o); + } + else if (o instanceof java.sql.Date) + { + pstmt.setDate(i+1, (java.sql.Date)o); + log.finest("#" + (i+1) + " - Date=" + o); + } + else if (o instanceof java.util.Date) + { + pstmt.setTimestamp(i+1, new Timestamp(((java.util.Date)o).getTime())); + log.finest("#" + (i+1) + " - Date=" + o); + } + else if (o instanceof Double) + { + pstmt.setDouble(i+1, (Double)o); + log.finest("#" + (i+1) + " - Double=" + o); + } + else if (o instanceof Float) + { + pstmt.setFloat(i+1, (Float)o); + log.finest("#" + (i+1) + " - Double=" + o); + } + else + throw new java.lang.UnsupportedOperationException ("Unknown Parameter Class=" + o.getClass()); + } + + //named input parameters + Map parameters = p_vo.getNamedParameters(); + for (Map.Entry e : parameters.entrySet()) + { + Object o = e.getValue(); + if (o == null) + throw new IllegalArgumentException ("Local - Null Parameter for " + e.getKey()); + else if (o instanceof NullParameter) + { + int type = ((NullParameter)o).getType(); + pstmt.setNull(e.getKey(), type); + log.finest("#" + e.getKey() + " - Null"); + } + else if (o instanceof Integer) + { + pstmt.setInt(e.getKey(), ((Integer)o).intValue()); + log.finest("#" + e.getKey() + " - int=" + o); + } + else if (o instanceof String) + { + pstmt.setString(e.getKey(), (String)o); + log.finest("#" + e.getKey() + " - String=" + o); + } + else if (o instanceof Timestamp) + { + pstmt.setTimestamp(e.getKey(), (Timestamp)o); + log.finest("#" + e.getKey() + " - Timestamp=" + o); + } + else if (o instanceof BigDecimal) + { + pstmt.setBigDecimal(e.getKey(), (BigDecimal)o); + log.finest("#" + e.getKey() + " - BigDecimal=" + o); + } + else if (o instanceof java.util.Date) + { + pstmt.setTimestamp(e.getKey(), new Timestamp(((java.util.Date)o).getTime())); + log.finest("#" + e.getKey() + " - Date=" + o); + } + else if (o instanceof java.sql.Date) + { + pstmt.setTimestamp(e.getKey(), new Timestamp(((java.sql.Date)o).getTime())); + log.finest("#" + e.getKey() + " - Date=" + o); + } + else + throw new java.lang.UnsupportedOperationException ("Unknown Parameter Class=" + o.getClass()); + } + + //named output parameters + Mapnamed = p_vo.getNamedOutput(); + for (Map.Entry e : named.entrySet()) + { + String oi = e.getKey(); + OutputParameter op = e.getValue(); + if (op.getScale() != -1 ) + pstmt.registerOutParameter(oi, op.getSqlType(), op.getScale()); + else if (op.getTypeName() != null) + pstmt.registerOutParameter(oi, op.getSqlType(), op.getTypeName()); + else + pstmt.registerOutParameter(oi, op.getSqlType()); + } + } + catch (SQLException ex) + { + log.log(Level.SEVERE, "fillParametersFromVO", ex); + } + } + + /* Java 6 support - teo_sarca BF [ 1806700 ] * public Reader getCharacterStream(int parameterIndex) throws SQLException { diff --git a/base/src/org/compiere/util/CPreparedStatement.java b/base/src/org/compiere/util/CPreparedStatement.java index 940c666c52..6306b3ad4c 100644 --- a/base/src/org/compiere/util/CPreparedStatement.java +++ b/base/src/org/compiere/util/CPreparedStatement.java @@ -243,7 +243,8 @@ public class CPreparedStatement extends CStatement implements PreparedStatement { if (p_stmt != null) return ((PreparedStatement)p_stmt).execute(); - throw new java.lang.UnsupportedOperationException ("Method execute() not yet implemented."); + + return remote_execute(); } @@ -769,35 +770,17 @@ public class CPreparedStatement extends CStatement implements PreparedStatement return "CPreparedStatement[" + p_vo + "]"; } // toString - /************************************************************************** - * Get Prepared Statement to create RowSet and set parameters. - * Method called on Remote to execute locally. - * @param dedicatedConnection if true gets new connection - if false gets anormal RO/RW connection - * @param trxName transaction - * @return Prepared Statement + /** + * */ - private PreparedStatement local_getPreparedStatement (boolean dedicatedConnection, String trxName) + public void fillParametersFromVO() { log.finest(p_vo.getSql()); - Connection conn = null; - Trx trx = trxName == null ? null : Trx.get(trxName, true); - if (trx != null) - conn = trx.getConnection(); - else - { - if (dedicatedConnection) - conn = DB.createConnection (false, Connection.TRANSACTION_READ_COMMITTED); - else - conn = local_getConnection (trxName); - } - if (conn == null) - throw new IllegalStateException("Local - No Connection"); - PreparedStatement pstmt = null; try { - pstmt = conn.prepareStatement(p_vo.getSql(), p_vo.getResultSetType(), p_vo.getResultSetConcurrency()); // Set Parameters ArrayList parameters = p_vo.getParameters(); + PreparedStatement pstmt = (PreparedStatement)p_stmt; for (int i = 0; i < parameters.size(); i++) { Object o = parameters.get(i); @@ -829,15 +812,25 @@ public class CPreparedStatement extends CStatement implements PreparedStatement pstmt.setBigDecimal(i+1, (BigDecimal)o); log.finest("#" + (i+1) + " - BigDecimal=" + o); } + else if (o instanceof java.sql.Date) + { + pstmt.setDate(i+1, (java.sql.Date)o); + log.finest("#" + (i+1) + " - Date=" + o); + } else if (o instanceof java.util.Date) { pstmt.setTimestamp(i+1, new Timestamp(((java.util.Date)o).getTime())); log.finest("#" + (i+1) + " - Date=" + o); - } - else if (o instanceof java.sql.Date) + } + else if (o instanceof Double) { - pstmt.setTimestamp(i+1, new Timestamp(((java.sql.Date)o).getTime())); - log.finest("#" + (i+1) + " - Date=" + o); + pstmt.setDouble(i+1, (Double)o); + log.finest("#" + (i+1) + " - Double=" + o); + } + else if (o instanceof Float) + { + pstmt.setFloat(i+1, (Float)o); + log.finest("#" + (i+1) + " - Double=" + o); } else throw new java.lang.UnsupportedOperationException ("Unknown Parameter Class=" + o.getClass()); @@ -845,210 +838,50 @@ public class CPreparedStatement extends CStatement implements PreparedStatement } catch (SQLException ex) { - log.log(Level.SEVERE, "local", ex); - if (pstmt != null) - { - try - { - pstmt.close(); - } - catch (Exception e) - { - log.log(Level.SEVERE, "Could not close prepared statement", e); - } - } - - if (conn != null && p_vo.getTrxName() == null) - { - try - { - conn.close(); - } - catch (Exception e) - { - log.log(Level.SEVERE, "Could not close connection", e); - } - } - - pstmt = null; + log.log(Level.SEVERE, "fillParametersFromVO", ex); } - return pstmt; } // local_getPreparedStatement - - /** - * Execute Query - * @return ResultSet or RowSet - * @throws SQLException - * @see java.sql.PreparedStatement#executeQuery() - */ - public RowSet getRowSet() - { - if (p_stmt != null) // local - return local_getRowSet(); - // - // Client -> remote sever - log.finest("server => " + p_vo + ", Remote=" + DB.isRemoteObjects()); - try - { - boolean remote = DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false); - if (remote && p_remoteErrors > 1) - remote = CConnection.get().isAppsServerOK(true); - if (remote) - { - Server server = CConnection.get().getServer(); - if (server != null) - { - RowSet rs = server.pstmt_getRowSet (p_vo, SecurityToken.getInstance()); - p_vo.clearParameters(); // re-use of result set - if (rs == null) - log.warning("RowSet is null - " + p_vo); - else - p_remoteErrors = 0; - return rs; - } - log.log(Level.SEVERE, "AppsServer not found"); - p_remoteErrors++; - } - } - catch (Exception ex) - { - log.log(Level.SEVERE, "AppsServer error", ex); - p_remoteErrors++; - if (ex instanceof RuntimeException) - throw (RuntimeException)ex; - else - throw new RuntimeException(ex); - } - throw new IllegalStateException("Remote Connection - Application server not available"); - } - /** * Get Result as RowSet for local system. * Note that connection is closed when closing Oracle CachedRowSet! - * @return result as RowSet - */ + * @return result as RowSet + **/ + @Override protected RowSet local_getRowSet() { - log.finest("local"); + log.finest("local_getRowSet"); RowSet rowSet = null; + ResultSet rs = null; PreparedStatement pstmt = (PreparedStatement)p_stmt; try { - // Set Parameters - ArrayList parameters = p_vo.getParameters(); - for (int i = 0; i < parameters.size(); i++) - { - Object o = parameters.get(i); - if (o == null) - throw new IllegalArgumentException ("Null Parameter #" + i); - else if (o instanceof NullParameter) - { - int type = ((NullParameter)o).getType(); - pstmt.setNull(i+1, type); - log.finest("#" + (i+1) + " - Null"); - } - else if (o instanceof Integer) - { - pstmt.setInt(i+1, ((Integer)o).intValue()); - log.finest("#" + (i+1) + " - int=" + o); - } - else if (o instanceof String) - { - pstmt.setString(i+1, (String)o); - log.finest("#" + (i+1) + " - String=" + o); - } - else if (o instanceof Timestamp) - { - pstmt.setTimestamp(i+1, (Timestamp)o); - log.finest("#" + (i+1) + " - Timestamp=" + o); - } - else if (o instanceof BigDecimal) - { - pstmt.setBigDecimal(i+1, (BigDecimal)o); - log.finest("#" + (i+1) + " - BigDecimal=" + o); - } - else if (o instanceof java.util.Date) - { - pstmt.setTimestamp(i+1, new Timestamp(((java.util.Date)o).getTime())); - log.finest("#" + (i+1) + " - Date=" + o); - } - else if (o instanceof java.sql.Date) - { - pstmt.setTimestamp(i+1, new Timestamp(((java.sql.Date)o).getTime())); - log.finest("#" + (i+1) + " - Date=" + o); - } - else - throw new java.lang.UnsupportedOperationException ("Unknown Parameter Class=" + o.getClass()); - } + fillParametersFromVO(); // - ResultSet rs = pstmt.executeQuery(); - rowSet = CCachedRowSet.getRowSet(rs); - rs.close(); + rs = pstmt.executeQuery(); + rowSet = CCachedRowSet.getRowSet(rs); } catch (Exception ex) { log.log(Level.SEVERE, p_vo.toString(), ex); throw new RuntimeException (ex); } + finally + { + DB.close(rs); + } return rowSet; } // local_getRowSet - - /************************************************************************* - * Execute Update. - * @return row count - */ - public int remote_executeUpdate() - { - log.finest("Update"); - PreparedStatement pstmt = null; - try - { - AdempiereDatabase db = CConnection.get().getDatabase(); - if (db == null) - throw new NullPointerException("Remote - No Database"); - // - pstmt = local_getPreparedStatement (false, p_vo.getTrxName()); - int result = pstmt.executeUpdate(); - // - return result; - } - catch (Exception ex) - { - log.log(Level.SEVERE, p_vo.toString(), ex); - throw new RuntimeException (ex); - } - finally - { - if (pstmt != null) - { - try - { - Connection conn = pstmt.getConnection(); - pstmt.close(); - if (p_vo.getTrxName() == null && !conn.isClosed()) - { - conn.close(); - } - } - catch (SQLException e) - { - log.log(Level.SEVERE, e.getMessage(), e); - } - pstmt = null; - } - } - } // remote_executeUpdate - - //remove this commnet if you want use JAVA 6 + - public void setAsciiStream(int parameterIndex, java.io.InputStream x, long length) - throws SQLException - { - - } - + public void setAsciiStream(int parameterIndex, java.io.InputStream x, long length) + throws SQLException + { + + } + + //uncomment the following methods to compile using jdk 6 //vpj-cd add support java 6 /* public void setBinaryStream(int parameterIndex, java.io.InputStream x, @@ -1141,9 +974,6 @@ public class CPreparedStatement extends CStatement implements PreparedStatement } - //In order to compile in Java 6 you must add these methods - - public void setSQLXML(int parameterIndex, java.sql.SQLXML xmlObject) throws SQLException { diff --git a/base/src/org/compiere/util/CStatement.java b/base/src/org/compiere/util/CStatement.java index d770b72f24..2a9a45d766 100644 --- a/base/src/org/compiere/util/CStatement.java +++ b/base/src/org/compiere/util/CStatement.java @@ -122,6 +122,8 @@ public class CStatement implements Statement protected CStatementVO p_vo = null; /** Remote Errors */ protected int p_remoteErrors = 0; + /** Object to hold remote execute result **/ + protected ExecuteResult executeResult; /** @@ -325,7 +327,8 @@ public class CStatement implements Statement p_vo.setSql(DB.getDatabase().convertStatement(sql0)); if (p_stmt != null) return p_stmt.execute(p_vo.getSql()); - throw new java.lang.UnsupportedOperationException ("Method execute() not yet implemented."); + + return remote_execute(); } /** @@ -341,7 +344,8 @@ public class CStatement implements Statement p_vo.setSql(DB.getDatabase().convertStatement(sql0)); if (p_stmt != null) return p_stmt.execute(p_vo.getSql(), autoGeneratedKeys); - throw new java.lang.UnsupportedOperationException ("Method execute() not yet implemented."); + + throw new java.lang.UnsupportedOperationException ("Method execute(sql, autoGeneratedKeys) not yet implemented."); } /** @@ -357,7 +361,7 @@ public class CStatement implements Statement p_vo.setSql(DB.getDatabase().convertStatement(sql0)); if (p_stmt != null) return p_stmt.execute(p_vo.getSql(), columnIndexes); - throw new java.lang.UnsupportedOperationException ("Method execute() not yet implemented."); + throw new java.lang.UnsupportedOperationException ("Method execute(sql, columnIndexes) not yet implemented."); } /** @@ -373,7 +377,7 @@ public class CStatement implements Statement p_vo.setSql(DB.getDatabase().convertStatement(sql0)); if (p_stmt != null) return p_stmt.execute(p_vo.getSql(), columnNames); - throw new java.lang.UnsupportedOperationException ("Method execute() not yet implemented."); + throw new java.lang.UnsupportedOperationException ("Method execute(sql, columnNames) not yet implemented."); } @@ -747,130 +751,41 @@ public class CStatement implements Statement } close = true; } // close - - /************************************************************************* - * Execute Update. - * @return row count + + /** + * + * @return boolean + * @throws SQLException */ - public int remote_executeUpdate() - { - log.finest(""); - Statement pstmt = null; + protected boolean remote_execute() throws SQLException { + // Client -> remote sever + log.finest("server => " + p_vo + ", Remote=" + DB.isRemoteObjects()); try { - AdempiereDatabase db = CConnection.get().getDatabase(); - if (db == null) - throw new NullPointerException("Remote - No Database"); - // - pstmt = local_getStatement (false, p_vo.getTrxName()); - int result = pstmt.executeUpdate(p_vo.getSql()); - // - return result; + if (DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false)) + { + Server server = CConnection.get().getServer(); + if (server != null) + { + executeResult = server.stmt_execute(p_vo, SecurityToken.getInstance()); + p_vo.clearParameters(); // re-use of result set + return executeResult.isFirstResult(); + } + log.log(Level.SEVERE, "AppsServer not found"); + } + throw new IllegalStateException("Remote Connection - Application server not available"); } catch (Exception ex) { - log.log(Level.SEVERE, p_vo.toString(), ex); - throw new RuntimeException (ex); - } - finally - { - if (pstmt != null) - { - try - { - Connection conn = pstmt.getConnection(); - pstmt.close(); - if (p_vo.getTrxName() == null && !conn.isClosed()) - { - conn.close(); - } - } - catch (SQLException e) - { - log.log(Level.SEVERE, e.getMessage(), e); - } - pstmt = null; - } - } - } // remote_executeUpdate - - /************************************************************************** - * Get Prepared Statement to create RowSet. - * Method called on Remote to execute locally. - * @param dedicatedConnection if true gets new connection - if false gets anormal RO/RW connection - * @param trxName transaction - * @return Prepared Statement - */ - private Statement local_getStatement (boolean dedicatedConnection, String trxName) - { - log.finest(""); - Connection conn = null; - Trx trx = trxName == null ? null : Trx.get(trxName, true); - if (trx != null) - conn = trx.getConnection(); - else - { - if (dedicatedConnection) - conn = DB.createConnection (false, Connection.TRANSACTION_READ_COMMITTED); + log.log(Level.SEVERE, "AppsServer error", ex); + if (ex instanceof SQLException) + throw (SQLException)ex; + else if (ex instanceof RuntimeException) + throw (RuntimeException)ex; else - conn = local_getConnection (trxName); + throw new RuntimeException(ex); } - Statement stmt = null; - try - { - stmt = conn.createStatement(p_vo.getResultSetType(), p_vo.getResultSetConcurrency()); - } - catch (SQLException ex) - { - log.log(Level.SEVERE, "local", ex); - if (stmt != null) - { - try - { - stmt.close(); - } - catch (Exception e) - { - log.log(Level.SEVERE, "Could not close statement", e); - } - stmt = null; - } - - if (conn != null && p_vo.getTrxName() == null) - { - try - { - conn.close(); - } - catch (Exception e) - { - log.log(Level.SEVERE, "Could not close connection", e); - } - } - } - return stmt; - } // local_getStatement - - /** - * Get Local Connection - * @param trxName transaction - * @return connection - */ - protected Connection local_getConnection(String trxName) - { - Connection conn = null; - Trx trx = trxName == null ? null : Trx.get(trxName, true); - if (trx != null) - conn = trx.getConnection(); - else - { - if (p_vo.getResultSetConcurrency () == ResultSet.CONCUR_UPDATABLE) - conn = DB.getConnectionRW (); - else - conn = DB.getConnectionRO (); - } - return conn; - } // local_getConnection + } /** * Execute Query @@ -926,22 +841,23 @@ public class CStatement implements Statement */ protected RowSet local_getRowSet() { - log.finest("remote"); - Statement pstmt = p_stmt; + log.finest("local_getRowSet"); RowSet rowSet = null; + ResultSet rs = null; try { - ResultSet rs = pstmt.executeQuery(p_vo.getSql()); - rowSet = CCachedRowSet.getRowSet(rs); - rs.close(); - pstmt.close(); - pstmt = null; + rs = p_stmt.executeQuery(p_vo.getSql()); + rowSet = CCachedRowSet.getRowSet(rs); } catch (Exception ex) { log.log(Level.SEVERE, p_vo.toString(), ex); throw new RuntimeException (ex); } + finally + { + DB.close(rs); + } return rowSet; } // local_getRowSet diff --git a/base/src/org/compiere/util/CStatementVO.java b/base/src/org/compiere/util/CStatementVO.java index d046f556ef..0cf8a6edb2 100644 --- a/base/src/org/compiere/util/CStatementVO.java +++ b/base/src/org/compiere/util/CStatementVO.java @@ -18,6 +18,8 @@ package org.compiere.util; import java.io.Serializable; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; /** * Adempiere Statement Value Object @@ -63,6 +65,10 @@ public class CStatementVO implements Serializable private ArrayList m_parameters = new ArrayList(); /** Transaction Name **/ private String m_trxName = null; + + private Map m_namedOutput = new HashMap(); + + private Mapm_namedParameters = new HashMap(); /** * String representation @@ -100,6 +106,18 @@ public class CStatementVO implements Serializable } else m_parameters.set(zeroIndex, element); + } // setParameter + + /** + * Set Parameter + * @param index1 1 based index + * @param element element + */ + public void setParameter (String name, Object element) + { + if (element != null && !(element instanceof Serializable)) + throw new java.lang.RuntimeException("setParameter not Serializable - " + element.getClass().toString()); + m_namedParameters.put(name, element); } // setParametsr /** @@ -108,17 +126,27 @@ public class CStatementVO implements Serializable public void clearParameters() { m_parameters = new ArrayList(); + m_namedParameters = new HashMap(); } // clearParameters /** * Get Parameters * @return arraylist */ - public ArrayList getParameters() + public ArrayList getParameters() { return m_parameters; } // getParameters + /*** + * get named parameters for callable statement + * @return map + */ + public Map getNamedParameters() + { + return m_namedParameters; + } + /** * Get Parameter Count * @return arraylist @@ -211,4 +239,53 @@ public class CStatementVO implements Serializable m_trxName = trxName; } + public void registerOutParameter(String parameterName, int sqlType, + int scale) + { + OutputParameter o = new OutputParameter(sqlType, scale, null); + m_namedOutput.put(parameterName, o); + } + + public void registerOutParameter(int paramIndex, int sqlType, + String typeName) + { + OutputParameter o = new OutputParameter(sqlType, -1, typeName); + this.setParameter(paramIndex, o); + } + + public void registerOutParameter(int parameterIndex, int sqlType, int scale) + { + OutputParameter o = new OutputParameter(sqlType, scale, null); + this.setParameter(parameterIndex, o); + + } + + public void registerOutParameter(String parameterName, int sqlType) + { + OutputParameter o = new OutputParameter(sqlType, -1, null); + m_namedOutput.put(parameterName, o); + } + + public void registerOutParameter(int parameterIndex, int sqlType) + { + OutputParameter o = new OutputParameter(sqlType, -1, null); + this.setParameter(parameterIndex, o); + } + + public void registerOutParameter(String parameterName, int sqlType, + String typeName) + { + OutputParameter o = new OutputParameter(sqlType, -1, typeName); + m_namedOutput.put(parameterName, o); + } + + public Map getNamedOutput() + { + return m_namedOutput; + } + + /* + public boolean hasOutputParameters() { + return m_ordinalOutput.size() > 0 || m_namedOutput.size() > 0; + }*/ } // CStatementVO diff --git a/base/src/org/compiere/util/CallableResult.java b/base/src/org/compiere/util/CallableResult.java new file mode 100644 index 0000000000..2f2ad093e1 --- /dev/null +++ b/base/src/org/compiere/util/CallableResult.java @@ -0,0 +1,25 @@ +package org.compiere.util; + +import java.util.Map; + +public class CallableResult extends ExecuteResult { + + private Map m_ordinalOutput = null; + private Map m_namedOutput = null; + + public Map getOrdinalOutput() { + return m_ordinalOutput; + } + public void setOrdinalOutput(Map ordinalOutput) { + m_ordinalOutput = ordinalOutput; + } + + public Map getNamedOutput() { + return m_namedOutput; + } + + public void setNamedOutput(Map namedOutput) { + m_namedOutput = namedOutput; + } + +} diff --git a/base/src/org/compiere/util/ExecuteResult.java b/base/src/org/compiere/util/ExecuteResult.java new file mode 100644 index 0000000000..4703a30e93 --- /dev/null +++ b/base/src/org/compiere/util/ExecuteResult.java @@ -0,0 +1,57 @@ +package org.compiere.util; + +import java.io.Serializable; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +public class ExecuteResult implements Serializable { + private int m_updateCount = 0; + private ArrayList m_resultSets = new ArrayList(); + private int resultSetPointer = 0; + private boolean firstResult = false; + + public int getUpdateCount() { + if (resultSetPointer >= m_resultSets.size()) { + int updateCount = m_updateCount; + m_updateCount = -1; + return updateCount; + } + return -1; + } + + public void setUpdateCount(int updateCount) { + m_updateCount = updateCount; + } + + public void addResultSet(ResultSet rs) { + m_resultSets.add(rs); + } + + public boolean getMoreResults() { + if (resultSetPointer >= m_resultSets.size()) + return false; + + //implicitly close the current resultset + try { + m_resultSets.get(resultSetPointer).close(); + } catch (SQLException e) {} + resultSetPointer ++; + return (resultSetPointer < m_resultSets.size()); + } + + public ResultSet getResultSet() { + if (resultSetPointer >= m_resultSets.size()) + return null; + + return m_resultSets.get(resultSetPointer); + } + + public boolean isFirstResult() { + return firstResult; + } + + public void setFirstResult(boolean firstResult) { + this.firstResult = firstResult; + } +} diff --git a/base/src/org/compiere/util/OutputParameter.java b/base/src/org/compiere/util/OutputParameter.java new file mode 100644 index 0000000000..ec1a663bd0 --- /dev/null +++ b/base/src/org/compiere/util/OutputParameter.java @@ -0,0 +1,37 @@ +package org.compiere.util; + +import java.io.Serializable; + +public class OutputParameter implements Serializable { + public OutputParameter(int sqlType, int scale, String typeName) { + this.sqlType = sqlType; + this.scale = scale; + this.typeName = typeName; + } + + private int sqlType = -1; + private int scale = -1; + private String typeName = null; + + private Serializable value = null; + + public Serializable getValue() { + return value; + } + + public void setValue(Serializable value) { + this.value = value; + } + + public int getSqlType() { + return sqlType; + } + + public int getScale() { + return scale; + } + + public String getTypeName() { + return typeName; + } +}