📄 cstatement.java
字号:
return p_stmt.getMoreResults(current);
throw new java.lang.UnsupportedOperationException ("Method getMoreResults() not yet implemented.");
}
/**
* Method getGeneratedKeys
* @return ResultSet
* @throws SQLException
* @see java.sql.Statement#getGeneratedKeys()
*/
public ResultSet getGeneratedKeys () throws SQLException
{
if (p_stmt != null)
return p_stmt.getGeneratedKeys();
throw new java.lang.UnsupportedOperationException ("Method getGeneratedKeys() not yet implemented.");
}
/**
* Method getResultSetHoldability
* @return int
* @throws SQLException
* @see java.sql.Statement#getResultSetHoldability()
*/
public int getResultSetHoldability () throws SQLException
{
if (p_stmt != null)
return p_stmt.getResultSetHoldability();
throw new java.lang.UnsupportedOperationException ("Method getResultSetHoldability() not yet implemented.");
}
/**
* Method setEscapeProcessing
* @param enable boolean
* @throws SQLException
* @see java.sql.Statement#setEscapeProcessing(boolean)
*/
public void setEscapeProcessing (boolean enable) throws SQLException
{
if (p_stmt != null)
p_stmt.setEscapeProcessing(enable);
else
throw new java.lang.UnsupportedOperationException ("Method setEscapeProcessing() not yet implemented.");
}
/**
* Method getQueryTimeout
* @return int
* @throws SQLException
* @see java.sql.Statement#getQueryTimeout()
*/
public int getQueryTimeout () throws SQLException
{
if (p_stmt != null)
return p_stmt.getQueryTimeout();
throw new java.lang.UnsupportedOperationException ("Method getQueryTimeout() not yet implemented.");
}
/**
* Method setQueryTimeout
* @param seconds int
* @throws SQLException
* @see java.sql.Statement#setQueryTimeout(int)
*/
public void setQueryTimeout (int seconds) throws SQLException
{
if (p_stmt != null)
p_stmt.setQueryTimeout (seconds);
else
throw new java.lang.UnsupportedOperationException ("Method setQueryTimeout() not yet implemented.");
}
/**
* Method cancel
* @throws SQLException
* @see java.sql.Statement#cancel()
*/
public void cancel () throws SQLException
{
if (p_stmt != null)
p_stmt.cancel();
else
throw new java.lang.UnsupportedOperationException ("Method cancel() not yet implemented.");
}
/**
* Method getWarnings
* @return SQLWarning
* @throws SQLException
* @see java.sql.Statement#getWarnings()
*/
public SQLWarning getWarnings () throws SQLException
{
if (p_stmt != null)
return p_stmt.getWarnings();
throw new java.lang.UnsupportedOperationException ("Method getWarnings() not yet implemented.");
}
/**
* Method clearWarnings
* @throws SQLException
* @see java.sql.Statement#clearWarnings()
*/
public void clearWarnings () throws SQLException
{
if (p_stmt != null)
p_stmt.clearWarnings();
else
throw new java.lang.UnsupportedOperationException ("Method clearWarnings() not yet implemented.");
}
/**
* Method setCursorName
* @param name String
* @throws SQLException
* @see java.sql.Statement#setCursorName(String)
*/
public void setCursorName (String name) throws SQLException
{
if (p_stmt != null)
p_stmt.setCursorName(name);
else
throw new java.lang.UnsupportedOperationException ("Method setCursorName() not yet implemented.");
}
/**
* Method getResultSet
* @return ResultSet
* @throws SQLException
* @see java.sql.Statement#getResultSet()
*/
public ResultSet getResultSet () throws SQLException
{
if (p_stmt != null)
return p_stmt.getResultSet();
throw new java.lang.UnsupportedOperationException ("Method getResultSet() not yet implemented.");
}
/**
* Method getUpdateCount
* @return int
* @throws SQLException
* @see java.sql.Statement#getUpdateCount()
*/
public int getUpdateCount () throws SQLException
{
if (p_stmt != null)
return p_stmt.getUpdateCount();
throw new java.lang.UnsupportedOperationException ("Method getUpdateCount() not yet implemented.");
}
/**
* Method getMoreResults
* @return boolean
* @throws SQLException
* @see java.sql.Statement#getMoreResults()
*/
public boolean getMoreResults () throws SQLException
{
if (p_stmt != null)
return p_stmt.getMoreResults();
throw new java.lang.UnsupportedOperationException ("Method getMoreResults() not yet implemented.");
}
/**
* Method setFetchDirection
* @param direction int
* @throws SQLException
* @see java.sql.Statement#setFetchDirection(int)
*/
public void setFetchDirection (int direction) throws SQLException
{
if (p_stmt != null)
p_stmt.setFetchDirection(direction);
else
throw new java.lang.UnsupportedOperationException ("Method setFetchDirection() not yet implemented.");
}
/**
* Method getFetchDirection
* @return int
* @throws SQLException
* @see java.sql.Statement#getFetchDirection()
*/
public int getFetchDirection () throws SQLException
{
if (p_stmt != null)
return p_stmt.getFetchDirection();
throw new java.lang.UnsupportedOperationException ("Method getFetchDirection() not yet implemented.");
}
/**
* Method setFetchSize
* @param rows int
* @throws SQLException
* @see java.sql.Statement#setFetchSize(int)
*/
public void setFetchSize (int rows) throws SQLException
{
if (p_stmt != null)
p_stmt.setFetchSize(rows);
else
throw new java.lang.UnsupportedOperationException ("Method setFetchSize() not yet implemented.");
}
/**
* Method getFetchSize
* @return int
* @throws SQLException
* @see java.sql.Statement#getFetchSize()
*/
public int getFetchSize () throws SQLException
{
if (p_stmt != null)
return p_stmt.getFetchSize();
throw new java.lang.UnsupportedOperationException ("Method getFetchSize() not yet implemented.");
}
/**
* Method getResultSetConcurrency
* @return int
* @throws SQLException
* @see java.sql.Statement#getResultSetConcurrency()
*/
public int getResultSetConcurrency () throws SQLException
{
if (p_stmt != null)
return p_stmt.getResultSetConcurrency();
throw new java.lang.UnsupportedOperationException ("Method getResultSetConcurrency() not yet implemented.");
}
/**
* Method getResultSetType
* @return int
* @throws SQLException
* @see java.sql.Statement#getResultSetType()
*/
public int getResultSetType () throws SQLException
{
if (p_stmt != null)
return p_stmt.getResultSetType();
throw new java.lang.UnsupportedOperationException ("Method getResultSetType() not yet implemented.");
}
/**
* Close
* @throws SQLException
* @see java.sql.Statement#close()
*/
public void close () throws SQLException
{
if (p_stmt != null)
p_stmt.close();
} // close
/*************************************************************************
* Execute Update.
* @return row count
*/
public int remote_executeUpdate()
{
log.finest("");
try
{
CompiereDatabase db = CConnection.get().getDatabase();
if (db == null)
throw new NullPointerException("Remote - No Database");
//
Statement pstmt = local_getStatement (false, null); // shared connection
int result = pstmt.executeUpdate(p_vo.getSql());
pstmt.close();
//
return result;
}
catch (Exception ex)
{
log.log(Level.SEVERE, p_vo.toString(), ex);
throw new RuntimeException (ex);
}
} // 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
* @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);
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);
try
{
if (stmt != null)
stmt.close();
stmt = null;
}
catch (SQLException ex1)
{
}
}
return stmt;
} // local_getStatement
/**
* Get Local Connection
* @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
/*************************************************************************
* Get Result as RowSet for Remote.
* Get shared connection for RMI!
* If RowSet is transfred via RMI, closing the RowSet does not close the connection
* @return result as RowSet
*/
public RowSet remote_getRowSet()
{
log.finest("remote");
/**
try
{
CompiereDatabase db = CConnection.get().getDatabase();
if (db == null)
{
log.log(Level.SEVERE, "No Database");
throw new NullPointerException("Remote - No Database");
}
//
Statement stmt = local_getStatement (false, null); // shared connection
ResultSet rs = stmt.executeQuery(p_vo.getSql());
RowSet rowSet = db.getRowSet (rs);
rs.close();
stmt.close();
//
if (rowSet != null)
return rowSet;
else
log.log(Level.SEVERE, "No RowSet");
throw new NullPointerException("Remore - No RowSet");
}
catch (Exception ex)
{
log.log(Level.SEVERE, p_vo.toString(), ex);
throw new RuntimeException (ex);
}
// return null;
**/
// Shared Connection
Connection conn = local_getConnection (null);
PreparedStatement pstmt = null;
RowSet rowSet = null;
try
{
pstmt = conn.prepareStatement(p_vo.getSql(),
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
// 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
throw new java.lang.UnsupportedOperationException ("Unknown Parameter Class=" + o.getClass());
}
//
ResultSet rs = pstmt.executeQuery();
rowSet = CCachedRowSet.getRowSet(rs);
pstmt.close();
pstmt = null;
}
catch (Exception ex)
{
log.log(Level.SEVERE, p_vo.toString(), ex);
throw new RuntimeException (ex);
}
// Close Cursor
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, "close pstmt", e);
}
return rowSet;
} // remote_getRowSet
} // CStatement
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -