[ 1891711 ] ServerBean.saveLob doesn't support transaction

- added trxName parameter.
[ 1627679 ] Complete CPreparedStatement Implementation for WAN Profile
- added execute() support
- added output parameter and named parameter support for CallableStatement
- some cleanup and refactoring
This commit is contained in:
Heng Sin Low 2008-02-12 05:24:02 +00:00
parent 42d32cc8f1
commit f2444456f0
10 changed files with 871 additions and 442 deletions

View File

@ -56,6 +56,12 @@ public interface Server
public int stmt_executeUpdate( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) public int stmt_executeUpdate( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token )
throws java.rmi.RemoteException; 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. * Get next number for Key column = 0 is Error.
* @param AD_Client_ID client * @param AD_Client_ID client
@ -78,9 +84,8 @@ public interface Server
* Get Document No based on Document Type * Get Document No based on Document Type
* @param C_DocType_ID document type * @param C_DocType_ID document type
* @param trxName optional Transaction Name * @param trxName optional Transaction Name
* @param definite is definite sequence
* @return document no or null */ * @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; throws java.rmi.RemoteException;
/** /**
@ -153,9 +158,10 @@ public interface Server
* @param sql table name * @param sql table name
* @param displayType display type (i.e. BLOB/CLOB) * @param displayType display type (i.e. BLOB/CLOB)
* @param value the data * @param value the data
* @param trxName
* @param token Security Token * @param token Security Token
* @return true if updated */ * @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; throws java.rmi.RemoteException;
/** /**

View File

@ -51,6 +51,10 @@ public interface ServerLocal
* @return row count */ * @return row count */
public int stmt_executeUpdate( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) ; 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. * Get next number for Key column = 0 is Error.
* @param AD_Client_ID client * @param AD_Client_ID client
@ -71,9 +75,8 @@ public interface ServerLocal
* Get Document No based on Document Type * Get Document No based on Document Type
* @param C_DocType_ID document type * @param C_DocType_ID document type
* @param trxName optional Transaction Name * @param trxName optional Transaction Name
* @param definite is definite sequence
* @return document no or null */ * @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 * Process Remote
@ -138,9 +141,10 @@ public interface ServerLocal
* @param sql table name * @param sql table name
* @param displayType display type (i.e. BLOB/CLOB) * @param displayType display type (i.e. BLOB/CLOB)
* @param value the data * @param value the data
* @param trxName
* @param token Security Token * @param token Security Token
* @return true if updated */ * @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 * Describes the instance and its content for debugging purpose

View File

@ -118,7 +118,7 @@ public class PO_LOB implements Serializable
{ {
if (server != null) if (server != null)
{ // See ServerBean { // 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()) if (CLogMgt.isLevelFinest())
log.fine("server.updateLOB => " + success); log.fine("server.updateLOB => " + success);
return success; return success;

File diff suppressed because it is too large Load Diff

View File

@ -243,7 +243,8 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
{ {
if (p_stmt != null) if (p_stmt != null)
return ((PreparedStatement)p_stmt).execute(); 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 + "]"; return "CPreparedStatement[" + p_vo + "]";
} // toString } // 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()); 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 try
{ {
pstmt = conn.prepareStatement(p_vo.getSql(), p_vo.getResultSetType(), p_vo.getResultSetConcurrency());
// Set Parameters // Set Parameters
ArrayList parameters = p_vo.getParameters(); ArrayList parameters = p_vo.getParameters();
PreparedStatement pstmt = (PreparedStatement)p_stmt;
for (int i = 0; i < parameters.size(); i++) for (int i = 0; i < parameters.size(); i++)
{ {
Object o = parameters.get(i); Object o = parameters.get(i);
@ -829,15 +812,25 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
pstmt.setBigDecimal(i+1, (BigDecimal)o); pstmt.setBigDecimal(i+1, (BigDecimal)o);
log.finest("#" + (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) else if (o instanceof java.util.Date)
{ {
pstmt.setTimestamp(i+1, new Timestamp(((java.util.Date)o).getTime())); pstmt.setTimestamp(i+1, new Timestamp(((java.util.Date)o).getTime()));
log.finest("#" + (i+1) + " - Date=" + o); 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())); pstmt.setDouble(i+1, (Double)o);
log.finest("#" + (i+1) + " - Date=" + 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 else
throw new java.lang.UnsupportedOperationException ("Unknown Parameter Class=" + o.getClass()); throw new java.lang.UnsupportedOperationException ("Unknown Parameter Class=" + o.getClass());
@ -845,174 +838,29 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
} }
catch (SQLException ex) catch (SQLException ex)
{ {
log.log(Level.SEVERE, "local", ex); log.log(Level.SEVERE, "fillParametersFromVO", 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;
}
return pstmt;
} // local_getPreparedStatement } // 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. * Get Result as RowSet for local system.
* Note that connection is closed when closing Oracle CachedRowSet! * Note that connection is closed when closing Oracle CachedRowSet!
* @return result as RowSet * @return result as RowSet
*/ **/
@Override
protected RowSet local_getRowSet() protected RowSet local_getRowSet()
{ {
log.finest("local"); log.finest("local_getRowSet");
RowSet rowSet = null; RowSet rowSet = null;
ResultSet rs = null;
PreparedStatement pstmt = (PreparedStatement)p_stmt; PreparedStatement pstmt = (PreparedStatement)p_stmt;
try try
{ {
// Set Parameters fillParametersFromVO();
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());
}
// //
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
rowSet = CCachedRowSet.getRowSet(rs); rowSet = CCachedRowSet.getRowSet(rs);
rs.close();
}
catch (Exception ex)
{
log.log(Level.SEVERE, p_vo.toString(), ex);
throw new RuntimeException (ex);
}
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) catch (Exception ex)
{ {
@ -1021,27 +869,11 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
} }
finally finally
{ {
if (pstmt != null) DB.close(rs);
{
try
{
Connection conn = pstmt.getConnection();
pstmt.close();
if (p_vo.getTrxName() == null && !conn.isClosed())
{
conn.close();
} }
} return rowSet;
catch (SQLException e) } // local_getRowSet
{
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) public void setAsciiStream(int parameterIndex, java.io.InputStream x, long length)
throws SQLException throws SQLException
@ -1049,6 +881,7 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
} }
//uncomment the following methods to compile using jdk 6
//vpj-cd add support java 6 //vpj-cd add support java 6
/* /*
public void setBinaryStream(int parameterIndex, java.io.InputStream x, 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 public void setSQLXML(int parameterIndex, java.sql.SQLXML xmlObject) throws SQLException
{ {

View File

@ -122,6 +122,8 @@ public class CStatement implements Statement
protected CStatementVO p_vo = null; protected CStatementVO p_vo = null;
/** Remote Errors */ /** Remote Errors */
protected int p_remoteErrors = 0; 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)); p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null) if (p_stmt != null)
return p_stmt.execute(p_vo.getSql()); 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)); p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null) if (p_stmt != null)
return p_stmt.execute(p_vo.getSql(), autoGeneratedKeys); 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)); p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null) if (p_stmt != null)
return p_stmt.execute(p_vo.getSql(), columnIndexes); 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)); p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null) if (p_stmt != null)
return p_stmt.execute(p_vo.getSql(), columnNames); 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.");
} }
@ -748,129 +752,40 @@ public class CStatement implements Statement
close = true; close = true;
} // close } // close
/************************************************************************* /**
* Execute Update. *
* @return row count * @return boolean
* @throws SQLException
*/ */
public int remote_executeUpdate() protected boolean remote_execute() throws SQLException {
{ // Client -> remote sever
log.finest(""); log.finest("server => " + p_vo + ", Remote=" + DB.isRemoteObjects());
Statement pstmt = null;
try try
{ {
AdempiereDatabase db = CConnection.get().getDatabase(); if (DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false))
if (db == null) {
throw new NullPointerException("Remote - No Database"); Server server = CConnection.get().getServer();
// if (server != null)
pstmt = local_getStatement (false, p_vo.getTrxName()); {
int result = pstmt.executeUpdate(p_vo.getSql()); executeResult = server.stmt_execute(p_vo, SecurityToken.getInstance());
// p_vo.clearParameters(); // re-use of result set
return result; return executeResult.isFirstResult();
}
log.log(Level.SEVERE, "AppsServer not found");
}
throw new IllegalStateException("Remote Connection - Application server not available");
} }
catch (Exception ex) catch (Exception ex)
{ {
log.log(Level.SEVERE, p_vo.toString(), ex); log.log(Level.SEVERE, "AppsServer error", ex);
throw new RuntimeException (ex); if (ex instanceof SQLException)
} throw (SQLException)ex;
finally else if (ex instanceof RuntimeException)
{ throw (RuntimeException)ex;
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 else
{ throw new RuntimeException(ex);
if (dedicatedConnection)
conn = DB.createConnection (false, Connection.TRANSACTION_READ_COMMITTED);
else
conn = local_getConnection (trxName);
}
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 * Execute Query
@ -926,22 +841,23 @@ public class CStatement implements Statement
*/ */
protected RowSet local_getRowSet() protected RowSet local_getRowSet()
{ {
log.finest("remote"); log.finest("local_getRowSet");
Statement pstmt = p_stmt;
RowSet rowSet = null; RowSet rowSet = null;
ResultSet rs = null;
try try
{ {
ResultSet rs = pstmt.executeQuery(p_vo.getSql()); rs = p_stmt.executeQuery(p_vo.getSql());
rowSet = CCachedRowSet.getRowSet(rs); rowSet = CCachedRowSet.getRowSet(rs);
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception ex) catch (Exception ex)
{ {
log.log(Level.SEVERE, p_vo.toString(), ex); log.log(Level.SEVERE, p_vo.toString(), ex);
throw new RuntimeException (ex); throw new RuntimeException (ex);
} }
finally
{
DB.close(rs);
}
return rowSet; return rowSet;
} // local_getRowSet } // local_getRowSet

View File

@ -18,6 +18,8 @@ package org.compiere.util;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/** /**
* Adempiere Statement Value Object * Adempiere Statement Value Object
@ -64,6 +66,10 @@ public class CStatementVO implements Serializable
/** Transaction Name **/ /** Transaction Name **/
private String m_trxName = null; private String m_trxName = null;
private Map<String, OutputParameter> m_namedOutput = new HashMap<String, OutputParameter>();
private Map<String, Object>m_namedParameters = new HashMap<String, Object>();
/** /**
* String representation * String representation
* @return info * @return info
@ -100,6 +106,18 @@ public class CStatementVO implements Serializable
} }
else else
m_parameters.set(zeroIndex, element); 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 } // setParametsr
/** /**
@ -108,17 +126,27 @@ public class CStatementVO implements Serializable
public void clearParameters() public void clearParameters()
{ {
m_parameters = new ArrayList<Object>(); m_parameters = new ArrayList<Object>();
m_namedParameters = new HashMap<String, Object>();
} // clearParameters } // clearParameters
/** /**
* Get Parameters * Get Parameters
* @return arraylist * @return arraylist
*/ */
public ArrayList getParameters() public ArrayList<Object> getParameters()
{ {
return m_parameters; return m_parameters;
} // getParameters } // getParameters
/***
* get named parameters for callable statement
* @return map
*/
public Map<String, Object> getNamedParameters()
{
return m_namedParameters;
}
/** /**
* Get Parameter Count * Get Parameter Count
* @return arraylist * @return arraylist
@ -211,4 +239,53 @@ public class CStatementVO implements Serializable
m_trxName = trxName; 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<String, OutputParameter> getNamedOutput()
{
return m_namedOutput;
}
/*
public boolean hasOutputParameters() {
return m_ordinalOutput.size() > 0 || m_namedOutput.size() > 0;
}*/
} // CStatementVO } // CStatementVO

View File

@ -0,0 +1,25 @@
package org.compiere.util;
import java.util.Map;
public class CallableResult extends ExecuteResult {
private Map<Integer, OutputParameter> m_ordinalOutput = null;
private Map<String, OutputParameter> m_namedOutput = null;
public Map<Integer, OutputParameter> getOrdinalOutput() {
return m_ordinalOutput;
}
public void setOrdinalOutput(Map<Integer, OutputParameter> ordinalOutput) {
m_ordinalOutput = ordinalOutput;
}
public Map<String, OutputParameter> getNamedOutput() {
return m_namedOutput;
}
public void setNamedOutput(Map<String, OutputParameter> namedOutput) {
m_namedOutput = namedOutput;
}
}

View File

@ -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<ResultSet> m_resultSets = new ArrayList<ResultSet>();
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;
}
}

View File

@ -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;
}
}