[ 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:
parent
42d32cc8f1
commit
f2444456f0
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
{
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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<Object> m_parameters = new ArrayList<Object>();
|
||||
/** Transaction Name **/
|
||||
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
|
||||
|
@ -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<Object>();
|
||||
m_namedParameters = new HashMap<String, Object>();
|
||||
} // clearParameters
|
||||
|
||||
/**
|
||||
* Get Parameters
|
||||
* @return arraylist
|
||||
*/
|
||||
public ArrayList getParameters()
|
||||
public ArrayList<Object> getParameters()
|
||||
{
|
||||
return m_parameters;
|
||||
} // getParameters
|
||||
|
||||
/***
|
||||
* get named parameters for callable statement
|
||||
* @return map
|
||||
*/
|
||||
public Map<String, Object> 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<String, OutputParameter> getNamedOutput()
|
||||
{
|
||||
return m_namedOutput;
|
||||
}
|
||||
|
||||
/*
|
||||
public boolean hasOutputParameters() {
|
||||
return m_ordinalOutput.size() > 0 || m_namedOutput.size() > 0;
|
||||
}*/
|
||||
} // CStatementVO
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue