Heng Sin Low 2009-05-20 04:34:18 +00:00
parent ba1efcca46
commit 0876a73879
1 changed files with 204 additions and 106 deletions

View File

@ -58,15 +58,15 @@ import org.compiere.process.SequenceCheck;
/** /**
* General Database Interface * General Database Interface
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: DB.java,v 1.8 2006/10/09 00:22:29 jjanke Exp $ * @version $Id: DB.java,v 1.8 2006/10/09 00:22:29 jjanke Exp $
* --- * ---
* Modifications: removed static references to database connection and instead always * Modifications: removed static references to database connection and instead always
* get a new connection from database pool manager which manages all connections * get a new connection from database pool manager which manages all connections
* set rw/ro properties for the connection accordingly. * set rw/ro properties for the connection accordingly.
* @author Ashley Ramdass (Posterita) * @author Ashley Ramdass (Posterita)
* *
* @author Teo Sarca, SC ARHIPAC SERVICE SRL * @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>BF [ 1647864 ] WAN: delete record error * <li>BF [ 1647864 ] WAN: delete record error
* <li>FR [ 1884435 ] Add more DB.getSQLValue helper methods * <li>FR [ 1884435 ] Add more DB.getSQLValue helper methods
@ -86,13 +86,13 @@ public final class DB
private static CConnection s_cc = null; private static CConnection s_cc = null;
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger (DB.class); private static CLogger log = CLogger.getCLogger (DB.class);
private static Object s_ccLock = new Object(); private static Object s_ccLock = new Object();
/** SQL Statement Separator "; " */ /** SQL Statement Separator "; " */
public static final String SQLSTATEMENT_SEPARATOR = "; "; public static final String SQLSTATEMENT_SEPARATOR = "; ";
/************************************************************************** /**************************************************************************
* Check need for post Upgrade * Check need for post Upgrade
* @param ctx context * @param ctx context
@ -101,10 +101,10 @@ public final class DB
public static boolean afterMigration (Properties ctx) public static boolean afterMigration (Properties ctx)
{ {
// UPDATE AD_System SET IsJustMigrated='Y' // UPDATE AD_System SET IsJustMigrated='Y'
MSystem system = MSystem.get(ctx); MSystem system = MSystem.get(ctx);
if (!system.isJustMigrated()) if (!system.isJustMigrated())
return false; return false;
// Role update // Role update
log.info("Role"); log.info("Role");
String sql = "SELECT * FROM AD_Role"; String sql = "SELECT * FROM AD_Role";
@ -118,7 +118,7 @@ public final class DB
{ {
MRole role = new MRole (ctx, rs, null); MRole role = new MRole (ctx, rs, null);
role.updateAccessRecords(); role.updateAccessRecords();
} }
} }
catch (Exception e) catch (Exception e)
{ {
@ -130,7 +130,7 @@ public final class DB
close(pstmt); close(pstmt);
rs= null; rs= null;
pstmt = null; pstmt = null;
} }
// Release Specif stuff & Print Format // Release Specif stuff & Print Format
try try
{ {
@ -145,11 +145,11 @@ public final class DB
// Language check // Language check
log.info("Language"); log.info("Language");
MLanguage.maintain(ctx); MLanguage.maintain(ctx);
// Sequence check // Sequence check
log.info("Sequence"); log.info("Sequence");
SequenceCheck.validate(ctx); SequenceCheck.validate(ctx);
// Costing Setup // Costing Setup
log.info("Costing"); log.info("Costing");
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(ctx, 0); MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(ctx, 0);
@ -158,12 +158,12 @@ public final class DB
ass[i].checkCosting(); ass[i].checkCosting();
ass[i].save(); ass[i].save();
} }
// Reset Flag // Reset Flag
system.setIsJustMigrated(false); system.setIsJustMigrated(false);
return system.save(); return system.save();
} // afterMigration } // afterMigration
/** /**
* Update Mail Settings for System Client and System User * Update Mail Settings for System Client and System User
*/ */
@ -177,7 +177,7 @@ public final class DB
File envFile = new File(envName); File envFile = new File(envName);
if (!envFile.exists()) if (!envFile.exists())
return; return;
Properties env = new Properties(); Properties env = new Properties();
try try
{ {
@ -192,7 +192,7 @@ public final class DB
String updated = env.getProperty("ADEMPIERE_MAIL_UPDATED"); String updated = env.getProperty("ADEMPIERE_MAIL_UPDATED");
if (updated != null && updated.equals("Y")) if (updated != null && updated.equals("Y"))
return; return;
// See org.compiere.install.ConfigurationData // See org.compiere.install.ConfigurationData
String server = env.getProperty("ADEMPIERE_MAIL_SERVER"); String server = env.getProperty("ADEMPIERE_MAIL_SERVER");
if (server == null || server.length() == 0) if (server == null || server.length() == 0)
@ -237,7 +237,7 @@ public final class DB
} }
} // updateMail } // updateMail
/************************************************************************** /**************************************************************************
* Set connection * Set connection
* @param cc connection * @param cc connection
@ -249,16 +249,16 @@ public final class DB
if (s_cc != null && s_cc.equals(cc)) if (s_cc != null && s_cc.equals(cc))
return; return;
DB.closeTarget(); DB.closeTarget();
// //
synchronized(s_ccLock) synchronized(s_ccLock)
{ {
s_cc = cc; s_cc = cc;
} }
s_cc.setDataSource(); s_cc.setDataSource();
log.config(s_cc + " - DS=" + s_cc.isDataSource()); log.config(s_cc + " - DS=" + s_cc.isDataSource());
// Trace.printStack(); // Trace.printStack();
} // setDBTarget } // setDBTarget
@ -270,28 +270,28 @@ public final class DB
public static boolean connect() { public static boolean connect() {
//direct connection //direct connection
boolean success =false; boolean success =false;
try try
{ {
Connection connRW = getConnectionRW(); Connection connRW = getConnectionRW();
if (connRW != null) if (connRW != null)
{ {
s_cc.readInfo(connRW); s_cc.readInfo(connRW);
connRW.close(); connRW.close();
} }
Connection connRO = getConnectionRO(); Connection connRO = getConnectionRO();
if (connRO != null) if (connRO != null)
{ {
connRO.close(); connRO.close();
} }
Connection connID = getConnectionID(); Connection connID = getConnectionID();
if (connID != null) if (connID != null)
{ {
connID.close(); connID.close();
} }
success = ((connRW != null) && (connRO != null) && (connID != null)); success = ((connRW != null) && (connRO != null) && (connID != null));
} }
catch (Exception e) catch (Exception e)
{ {
//logging here could cause infinite loop //logging here could cause infinite loop
@ -302,7 +302,7 @@ public final class DB
} }
return success; return success;
} }
/** /**
* @return true, if connected to database * @return true, if connected to database
*/ */
@ -310,7 +310,7 @@ public final class DB
{ {
return isConnected(true); return isConnected(true);
} }
/** /**
* Is there a connection to the database ? * Is there a connection to the database ?
* @param createNew If true, try to connect it not already connected * @param createNew If true, try to connect it not already connected
@ -320,7 +320,7 @@ public final class DB
{ {
//bug [1637432] //bug [1637432]
if (s_cc == null) return false; if (s_cc == null) return false;
//direct connection //direct connection
boolean success = false; boolean success = false;
CLogErrorBuffer eb = CLogErrorBuffer.get(false); CLogErrorBuffer eb = CLogErrorBuffer.get(false);
@ -353,7 +353,7 @@ public final class DB
{ {
return getConnectionRW(true); return getConnectionRW(true);
} }
/** /**
* Return (pooled) r/w AutoCommit, Serializable connection. * Return (pooled) r/w AutoCommit, Serializable connection.
* For Transaction control use Trx.getConnection() * For Transaction control use Trx.getConnection()
@ -401,7 +401,7 @@ public final class DB
try try
{ {
log.finest(s_cc.getConnectionURL() log.finest(s_cc.getConnectionURL()
+ ", UserID=" + s_cc.getDbUid() + ", UserID=" + s_cc.getDbUid()
+ ", AutoCommit=" + conn.getAutoCommit() + " (" + autoCommit + ")" + ", AutoCommit=" + conn.getAutoCommit() + " (" + autoCommit + ")"
+ ", TrxIso=" + conn.getTransactionIsolation() + "( " + trxLevel + ")"); + ", TrxIso=" + conn.getTransactionIsolation() + "( " + trxLevel + ")");
} }
@ -410,7 +410,7 @@ public final class DB
} }
**/ **/
} }
//hengsin: failed to set autocommit can lead to severe lock up of the system //hengsin: failed to set autocommit can lead to severe lock up of the system
try { try {
if (conn != null && conn.getAutoCommit() != autoCommit) if (conn != null && conn.getAutoCommit() != autoCommit)
@ -418,7 +418,7 @@ public final class DB
throw new IllegalStateException("Failed to set the requested auto commit mode on connection. [autoCommit=" + autoCommit +"]"); throw new IllegalStateException("Failed to set the requested auto commit mode on connection. [autoCommit=" + autoCommit +"]");
} }
} catch (SQLException e) {} } catch (SQLException e) {}
return conn; return conn;
} // createConnection } // createConnection
@ -453,7 +453,7 @@ public final class DB
{ {
throw new IllegalStateException("DB.getConnectionRO - @NoDBConnection@"); throw new IllegalStateException("DB.getConnectionRO - @NoDBConnection@");
} }
//hengsin: failed to set autocommit can lead to severe lock up of the system //hengsin: failed to set autocommit can lead to severe lock up of the system
try { try {
if (conn.getAutoCommit() != autoCommit) if (conn.getAutoCommit() != autoCommit)
@ -477,7 +477,7 @@ public final class DB
log.severe("No Database Connection"); log.severe("No Database Connection");
return null; return null;
} // getDatabase } // getDatabase
/** /**
* Get Database Driver. * Get Database Driver.
* Access to database specific functionality. * Access to database specific functionality.
@ -514,7 +514,7 @@ public final class DB
return false; return false;
} // isPostgreSQL } // isPostgreSQL
//begin vpj-cd e-evolution 02/07/2005 PostgreSQL //begin vpj-cd e-evolution 02/07/2005 PostgreSQL
/** /**
* Get Database Info * Get Database Info
* @return info * @return info
@ -526,7 +526,7 @@ public final class DB
return "No Database"; return "No Database";
} // getDatabaseInfo } // getDatabaseInfo
/************************************************************************** /**************************************************************************
* Check database Version with Code version * Check database Version with Code version
* @param ctx context * @param ctx context
@ -582,7 +582,7 @@ public final class DB
return false; return false;
} // isDatabaseOK } // isDatabaseOK
/************************************************************************** /**************************************************************************
* Check Build Version of Database against running client * Check Build Version of Database against running client
* @param ctx context * @param ctx context
@ -623,10 +623,10 @@ public final class DB
// Identical DB version // Identical DB version
if (buildClient.equals(buildDatabase)) if (buildClient.equals(buildDatabase))
return true; return true;
String AD_Message = "BuildVersionError"; String AD_Message = "BuildVersionError";
String title = org.compiere.Adempiere.getName() + " " + Msg.getMsg(ctx, AD_Message, true); String title = org.compiere.Adempiere.getName() + " " + Msg.getMsg(ctx, AD_Message, true);
// The program assumes build version {0}, but database has build Version {1}. // The program assumes build version {0}, but database has build Version {1}.
String msg = Msg.getMsg(ctx, AD_Message); // complete message String msg = Msg.getMsg(ctx, AD_Message); // complete message
msg = MessageFormat.format(msg, new Object[] {buildClient, buildDatabase}); msg = MessageFormat.format(msg, new Object[] {buildClient, buildDatabase});
if (! failOnBuild) { if (! failOnBuild) {
@ -665,11 +665,11 @@ public final class DB
* @param SQL sql * @param SQL sql
* @return Callable Statement * @return Callable Statement
*/ */
public static CallableStatement prepareCall(String sql) public static CallableStatement prepareCall(String sql)
{ {
return prepareCall(sql, ResultSet.CONCUR_UPDATABLE, null); return prepareCall(sql, ResultSet.CONCUR_UPDATABLE, null);
} }
/************************************************************************** /**************************************************************************
* Prepare Call * Prepare Call
* @param SQL sql * @param SQL sql
@ -685,7 +685,7 @@ public final class DB
trxName); trxName);
} // prepareCall } // prepareCall
/************************************************************************** /**************************************************************************
* Prepare Statement * Prepare Statement
* @param sql * @param sql
@ -715,7 +715,7 @@ public final class DB
concurrency = ResultSet.CONCUR_UPDATABLE; concurrency = ResultSet.CONCUR_UPDATABLE;
return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, concurrency, trxName); return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, concurrency, trxName);
} // prepareStatement } // prepareStatement
/** /**
* Prepare Statement. * Prepare Statement.
* @param sql sql statement * @param sql sql statement
@ -724,7 +724,7 @@ public final class DB
* @return Prepared Statement r/o or r/w depending on concur * @return Prepared Statement r/o or r/w depending on concur
* @deprecated * @deprecated
*/ */
public static CPreparedStatement prepareStatement (String sql, public static CPreparedStatement prepareStatement (String sql,
int resultSetType, int resultSetConcurrency) int resultSetType, int resultSetConcurrency)
{ {
return prepareStatement(sql, resultSetType, resultSetConcurrency, null); return prepareStatement(sql, resultSetType, resultSetConcurrency, null);
@ -738,7 +738,7 @@ public final class DB
* @param trxName transaction name * @param trxName transaction name
* @return Prepared Statement r/o or r/w depending on concur * @return Prepared Statement r/o or r/w depending on concur
*/ */
public static CPreparedStatement prepareStatement(String sql, public static CPreparedStatement prepareStatement(String sql,
int resultSetType, int resultSetConcurrency, String trxName) int resultSetType, int resultSetConcurrency, String trxName)
{ {
if (sql == null || sql.length() == 0) if (sql == null || sql.length() == 0)
@ -767,7 +767,7 @@ public final class DB
{ {
return ProxyFactory.newCStatement(resultSetType, resultSetConcurrency, trxName); return ProxyFactory.newCStatement(resultSetType, resultSetConcurrency, trxName);
} // createStatement } // createStatement
/** /**
* Set parameters for given statement * Set parameters for given statement
* @param stmt statements * @param stmt statements
@ -785,7 +785,7 @@ public final class DB
setParameter(stmt, i+1, params[i]); setParameter(stmt, i+1, params[i]);
} }
} }
/** /**
* Set parameters for given statement * Set parameters for given statement
* @param stmt statements * @param stmt statements
@ -803,11 +803,11 @@ public final class DB
setParameter(stmt, i+1, params.get(i)); setParameter(stmt, i+1, params.get(i));
} }
} }
/** /**
* Set PreparedStatement's parameter. * Set PreparedStatement's parameter.
* Similar with calling <code>pstmt.setObject(index, param)</code> * Similar with calling <code>pstmt.setObject(index, param)</code>
* @param pstmt * @param pstmt
* @param index * @param index
* @param param * @param param
@ -853,7 +853,20 @@ public final class DB
*/ */
public static int executeUpdate (String sql, String trxName) public static int executeUpdate (String sql, String trxName)
{ {
return executeUpdate(sql, null, false, trxName); return executeUpdate(sql, trxName, 0);
} // executeUpdate
/**
* Execute Update.
* saves "DBExecuteError" in Log
* @param sql sql
* @param trxName optional transaction name
* @param timeOut optional timeout parameter
* @return number of rows updated or -1 if error
*/
public static int executeUpdate (String sql, String trxName, int timeOut)
{
return executeUpdate(sql, null, false, trxName, timeOut);
} // executeUpdate } // executeUpdate
/** /**
@ -879,9 +892,23 @@ public final class DB
*/ */
public static int executeUpdate (String sql, boolean ignoreError, String trxName) public static int executeUpdate (String sql, boolean ignoreError, String trxName)
{ {
return executeUpdate (sql, null, ignoreError, trxName); return executeUpdate (sql, ignoreError, trxName, 0);
} // executeUpdate } // executeUpdate
/**
* Execute Update.
* saves "DBExecuteError" in Log
* @param sql sql
* @param ignoreError if true, no execution error is reported
* @param trxName transaction
* @param timeOut optional timeOut parameter
* @return number of rows updated or -1 if error
*/
public static int executeUpdate (String sql, boolean ignoreError, String trxName, int timeOut)
{
return executeUpdate (sql, null, ignoreError, trxName, timeOut);
}
/** /**
* Execute Update. * Execute Update.
* saves "DBExecuteError" in Log * saves "DBExecuteError" in Log
@ -892,7 +919,21 @@ public final class DB
*/ */
public static int executeUpdate (String sql, int param, String trxName) public static int executeUpdate (String sql, int param, String trxName)
{ {
return executeUpdate (sql, new Object[]{new Integer(param)}, false, trxName); return executeUpdate (sql, param, trxName, 0);
} // executeUpdate
/**
* Execute Update.
* saves "DBExecuteError" in Log
* @param sql sql
* @param param int param
* @param trxName transaction
* @param timeOut optional timeOut parameter
* @return number of rows updated or -1 if error
*/
public static int executeUpdate (String sql, int param, String trxName, int timeOut)
{
return executeUpdate (sql, new Object[]{new Integer(param)}, false, trxName, timeOut);
} // executeUpdate } // executeUpdate
/** /**
@ -906,7 +947,22 @@ public final class DB
*/ */
public static int executeUpdate (String sql, int param, boolean ignoreError, String trxName) public static int executeUpdate (String sql, int param, boolean ignoreError, String trxName)
{ {
return executeUpdate (sql, new Object[]{new Integer(param)}, ignoreError, trxName); return executeUpdate (sql, param, ignoreError, trxName, 0);
} // executeUpdate
/**
* Execute Update.
* saves "DBExecuteError" in Log
* @param sql sql
* @param param int parameter
* @param ignoreError if true, no execution error is reported
* @param trxName transaction
* @param timeOut optional timeOut parameter
* @return number of rows updated or -1 if error
*/
public static int executeUpdate (String sql, int param, boolean ignoreError, String trxName, int timeOut)
{
return executeUpdate (sql, new Object[]{new Integer(param)}, ignoreError, trxName, timeOut);
} // executeUpdate } // executeUpdate
/** /**
@ -919,17 +975,34 @@ public final class DB
* @return number of rows updated or -1 if error * @return number of rows updated or -1 if error
*/ */
public static int executeUpdate (String sql, Object[] params, boolean ignoreError, String trxName) public static int executeUpdate (String sql, Object[] params, boolean ignoreError, String trxName)
{
return executeUpdate(sql, params, ignoreError, trxName, 0);
}
/**
* Execute Update.
* saves "DBExecuteError" in Log
* @param sql sql
* @param params array of parameters
* @param ignoreError if true, no execution error is reported
* @param trxName optional transaction name
* @param timeOut optional timeOut parameter
* @return number of rows updated or -1 if error
*/
public static int executeUpdate (String sql, Object[] params, boolean ignoreError, String trxName, int timeOut)
{ {
if (sql == null || sql.length() == 0) if (sql == null || sql.length() == 0)
throw new IllegalArgumentException("Required parameter missing - " + sql); throw new IllegalArgumentException("Required parameter missing - " + sql);
// //
int no = -1; int no = -1;
CPreparedStatement cs = ProxyFactory.newCPreparedStatement(ResultSet.TYPE_FORWARD_ONLY, CPreparedStatement cs = ProxyFactory.newCPreparedStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE, sql, trxName); // converted in call ResultSet.CONCUR_UPDATABLE, sql, trxName); // converted in call
try try
{ {
setParameters(cs, params); setParameters(cs, params);
if (timeOut > 0)
cs.setQueryTimeout(timeOut);
no = cs.executeUpdate(); no = cs.executeUpdate();
// No Transaction - Commit // No Transaction - Commit
if (trxName == null) if (trxName == null)
@ -966,7 +1039,7 @@ public final class DB
} }
return no; return no;
} // executeUpdate } // executeUpdate
/** /**
* Execute Update and throw exception. * Execute Update and throw exception.
* @param sql * @param sql
@ -976,17 +1049,33 @@ public final class DB
* @throws SQLException * @throws SQLException
*/ */
public static int executeUpdateEx (String sql, Object[] params, String trxName) throws DBException public static int executeUpdateEx (String sql, Object[] params, String trxName) throws DBException
{
return executeUpdateEx(sql, params, trxName, 0);
}
/**
* Execute Update and throw exception.
* @param sql
* @param params statement parameters
* @param trxName transaction
* @param timeOut optional timeOut parameter
* @return number of rows updated
* @throws SQLException
*/
public static int executeUpdateEx (String sql, Object[] params, String trxName, int timeOut) throws DBException
{ {
if (sql == null || sql.length() == 0) if (sql == null || sql.length() == 0)
throw new IllegalArgumentException("Required parameter missing - " + sql); throw new IllegalArgumentException("Required parameter missing - " + sql);
// //
int no = -1; int no = -1;
CPreparedStatement cs = ProxyFactory.newCPreparedStatement(ResultSet.TYPE_FORWARD_ONLY, CPreparedStatement cs = ProxyFactory.newCPreparedStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE, sql, trxName); // converted in call ResultSet.CONCUR_UPDATABLE, sql, trxName); // converted in call
try try
{ {
setParameters(cs, params); setParameters(cs, params);
if (timeOut > 0)
cs.setQueryTimeout(timeOut);
no = cs.executeUpdate(); no = cs.executeUpdate();
// No Transaction - Commit // No Transaction - Commit
if (trxName == null) if (trxName == null)
@ -1028,7 +1117,7 @@ public final class DB
log.fine(statements[i]); log.fine(statements[i]);
no += executeUpdate(statements[i], null, ignoreError, trxName); no += executeUpdate(statements[i], null, ignoreError, trxName);
} }
return no; return no;
} // executeUpdareMultiple } // executeUpdareMultiple
@ -1038,7 +1127,16 @@ public final class DB
*/ */
public static int executeUpdateEx (String sql, String trxName) throws DBException public static int executeUpdateEx (String sql, String trxName) throws DBException
{ {
return executeUpdateEx(sql, null, trxName); return executeUpdateEx(sql, trxName, 0);
} // executeUpdateEx
/**
* Execute Update and throw exception.
* @see {@link #executeUpdateEx(String, Object[], String)}
*/
public static int executeUpdateEx (String sql, String trxName, int timeOut) throws DBException
{
return executeUpdateEx(sql, null, trxName, timeOut);
} // executeUpdateEx } // executeUpdateEx
/** /**
@ -1056,13 +1154,13 @@ public final class DB
{ {
return true; return true;
} }
try try
{ {
Trx trx = Trx.get(trxName, false); Trx trx = Trx.get(trxName, false);
if (trx != null) if (trx != null)
return trx.commit(true); return trx.commit(true);
if (throwException) if (throwException)
{ {
throw new IllegalStateException("Could not load transation with identifier: " + trxName); throw new IllegalStateException("Could not load transation with identifier: " + trxName);
@ -1078,7 +1176,7 @@ public final class DB
if (throwException) if (throwException)
throw e; throw e;
return false; return false;
} }
} // commit } // commit
/** /**
@ -1115,7 +1213,7 @@ public final class DB
/** /**
* Get Row Set. * Get Row Set.
* When a Rowset is closed, it also closes the underlying connection. * When a Rowset is closed, it also closes the underlying connection.
* If the created RowSet is transfered by RMI, closing it makes no difference * If the created RowSet is transfered by RMI, closing it makes no difference
* @param sql sql * @param sql sql
* @param local local RowSet (own connection) * @param local local RowSet (own connection)
* @return row set or null * @return row set or null
@ -1164,7 +1262,7 @@ public final class DB
} }
return retValue; return retValue;
} }
/** /**
* Get String Value from sql * Get String Value from sql
* @param trxName trx * @param trxName trx
@ -1198,7 +1296,7 @@ public final class DB
} }
return retValue; return retValue;
} }
/** /**
* Get int Value from sql * Get int Value from sql
* @param trxName trx * @param trxName trx
@ -1210,7 +1308,7 @@ public final class DB
{ {
return getSQLValue(trxName, sql, params.toArray(new Object[params.size()])); return getSQLValue(trxName, sql, params.toArray(new Object[params.size()]));
} }
/** /**
* Get String Value from sql * Get String Value from sql
* @param trxName trx * @param trxName trx
@ -1258,7 +1356,7 @@ public final class DB
{ {
return getSQLValueStringEx(trxName, sql, params.toArray(new Object[params.size()])); return getSQLValueStringEx(trxName, sql, params.toArray(new Object[params.size()]));
} }
/** /**
* Get String Value from sql * Get String Value from sql
* @param trxName trx * @param trxName trx
@ -1327,7 +1425,7 @@ public final class DB
} }
return retValue; return retValue;
} }
/** /**
* Get BigDecimal Value from sql * Get BigDecimal Value from sql
* @param trxName trx * @param trxName trx
@ -1341,7 +1439,7 @@ public final class DB
return getSQLValueBDEx(trxName, sql, params.toArray(new Object[params.size()])); return getSQLValueBDEx(trxName, sql, params.toArray(new Object[params.size()]));
} }
/** /**
* Get BigDecimal Value from sql * Get BigDecimal Value from sql
* @param trxName trx * @param trxName trx
@ -1409,7 +1507,7 @@ public final class DB
} }
return retValue; return retValue;
} }
/** /**
* Get BigDecimal Value from sql * Get BigDecimal Value from sql
* @param trxName trx * @param trxName trx
@ -1456,11 +1554,11 @@ public final class DB
params.toArray(arr); params.toArray(arr);
return getSQLValueTS(trxName, sql, arr); return getSQLValueTS(trxName, sql, arr);
} }
/** /**
* Get Array of Key Name Pairs * Get Array of Key Name Pairs
* @param sql select with id / name as first / second column * @param sql select with id / name as first / second column
* @param optional if true (-1,"") is added * @param optional if true (-1,"") is added
* @return array of {@link KeyNamePair} * @return array of {@link KeyNamePair}
* @see #getKeyNamePairs(String, boolean, Object...) * @see #getKeyNamePairs(String, boolean, Object...)
*/ */
@ -1468,7 +1566,7 @@ public final class DB
{ {
return getKeyNamePairs(sql, optional, (Object[])null); return getKeyNamePairs(sql, optional, (Object[])null);
} }
/** /**
* Get Array of Key Name Pairs * Get Array of Key Name Pairs
* @param sql select with id / name as first / second column * @param sql select with id / name as first / second column
@ -1481,7 +1579,7 @@ public final class DB
{ {
return getKeyNamePairs(sql, optional, params.toArray(new Object[params.size()])); return getKeyNamePairs(sql, optional, params.toArray(new Object[params.size()]));
} }
/** /**
* Get Array of Key Name Pairs * Get Array of Key Name Pairs
* @param sql select with id / name as first / second column * @param sql select with id / name as first / second column
@ -1522,7 +1620,7 @@ public final class DB
// s_log.fine("getKeyNamePairs #" + retValue.length); // s_log.fine("getKeyNamePairs #" + retValue.length);
return retValue; return retValue;
} // getKeyNamePairs } // getKeyNamePairs
/** /**
* Is Sales Order Trx. * Is Sales Order Trx.
* Assumes Sales Order. Queries IsSOTrx of table with where clause * Assumes Sales Order. Queries IsSOTrx of table with where clause
@ -1599,8 +1697,8 @@ public final class DB
} }
return isSOTrx; return isSOTrx;
} // isSOTrx } // isSOTrx
/************************************************************************** /**************************************************************************
* Get next number for Key column = 0 is Error. * Get next number for Key column = 0 is Error.
* * @param ctx client * * @param ctx client
@ -1625,17 +1723,17 @@ public final class DB
* @return next no * @return next no
*/ */
public static int getNextID (int AD_Client_ID, String TableName, String trxName) public static int getNextID (int AD_Client_ID, String TableName, String trxName)
{ {
boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue("SYSTEM_NATIVE_SEQUENCE",false); boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue("SYSTEM_NATIVE_SEQUENCE",false);
boolean adempiereSys = Ini.isPropertyBool(Ini.P_ADEMPIERESYS); boolean adempiereSys = Ini.isPropertyBool(Ini.P_ADEMPIERESYS);
if(SYSTEM_NATIVE_SEQUENCE && !adempiereSys) if(SYSTEM_NATIVE_SEQUENCE && !adempiereSys)
{ {
int m_sequence_id = CConnection.get().getDatabase().getNextID(TableName+"_SEQ"); int m_sequence_id = CConnection.get().getDatabase().getNextID(TableName+"_SEQ");
return m_sequence_id; return m_sequence_id;
} }
return MSequence.getNextID (AD_Client_ID, TableName, trxName); return MSequence.getNextID (AD_Client_ID, TableName, trxName);
} // getNextID } // getNextID
/** /**
@ -1654,18 +1752,18 @@ public final class DB
* 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 asking for a definitive or temporary sequence * @param definite asking for a definitive or temporary sequence
* @return document no or null * @return document no or null
*/ */
public static String getDocumentNo(int C_DocType_ID, String trxName, boolean definite) { public static String getDocumentNo(int C_DocType_ID, String trxName, boolean definite) {
return getDocumentNo(C_DocType_ID, trxName, definite, null); return getDocumentNo(C_DocType_ID, trxName, definite, null);
} }
/** /**
* 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 asking for a definitive or temporary sequence * @param definite asking for a definitive or temporary sequence
* @param PO * @param PO
* @return document no or null * @return document no or null
*/ */
@ -1685,7 +1783,7 @@ public final class DB
{ {
return getDocumentNo(AD_Client_ID, TableName, trxName, null); return getDocumentNo(AD_Client_ID, TableName, trxName, null);
} }
/** /**
* Get Document No from table * Get Document No from table
* @param AD_Client_ID client * @param AD_Client_ID client
@ -1714,7 +1812,7 @@ public final class DB
* @param trxName optional Transaction Name * @param trxName optional Transaction Name
* @return DocumentNo or null, if no doc number defined * @return DocumentNo or null, if no doc number defined
*/ */
public static String getDocumentNo (Properties ctx, int WindowNo, public static String getDocumentNo (Properties ctx, int WindowNo,
String TableName, boolean onlyDocType, String trxName) String TableName, boolean onlyDocType, String trxName)
{ {
if (ctx == null || TableName == null || TableName.length() == 0) if (ctx == null || TableName == null || TableName.length() == 0)
@ -1741,7 +1839,7 @@ public final class DB
/** /**
* Is this a remote client connection. * Is this a remote client connection.
* *
* Deprecated, always return false. * Deprecated, always return false.
* @return true if client and RMI or Objects on Server * @return true if client and RMI or Objects on Server
* @deprecated * @deprecated
@ -1750,10 +1848,10 @@ public final class DB
{ {
return false; return false;
} // isRemoteObjects } // isRemoteObjects
/** /**
* Is this a remote client connection * Is this a remote client connection
* *
* Deprecated, always return false. * Deprecated, always return false.
* @return true if client and RMI or Process on Server * @return true if client and RMI or Process on Server
* @deprecated * @deprecated
@ -1762,8 +1860,8 @@ public final class DB
{ {
return false; return false;
} // isRemoteProcess } // isRemoteProcess
/************************************************************************** /**************************************************************************
* Print SQL Warnings. * Print SQL Warnings.
* <br> * <br>
@ -1903,7 +2001,7 @@ public final class DB
; ;
} }
} }
/** /**
* convenient method to close statement * convenient method to close statement
* @param st * @param st
@ -1915,7 +2013,7 @@ public final class DB
; ;
} }
} }
/** /**
* convenient method to close result set and statement * convenient method to close result set and statement
* @param rs result set * @param rs result set
@ -1927,7 +2025,7 @@ public final class DB
close(rs); close(rs);
close(st); close(st);
} }
/** /**
* convenient method to close a {@link POResultSet} * convenient method to close a {@link POResultSet}
* @param rs result set * @param rs result set
@ -1937,7 +2035,7 @@ public final class DB
if (rs != null) if (rs != null)
rs.close(); rs.close();
} }
/** /**
* Try to get the SQLException from Exception * Try to get the SQLException from Exception
* @param e Exception * @param e Exception
@ -1954,10 +2052,10 @@ public final class DB
} }
return e; return e;
} }
/** Quote */ /** Quote */
private static final char QUOTE = '\''; private static final char QUOTE = '\'';
/** /**
* Run Post Migration manually * Run Post Migration manually
* @param args ignored * @param args ignored
@ -1969,8 +2067,8 @@ public final class DB
system.setIsJustMigrated(true); system.setIsJustMigrated(true);
afterMigration(Env.getCtx()); afterMigration(Env.getCtx());
} // main } // main
// Following methods are kept for BeanShell compatibility. // Following methods are kept for BeanShell compatibility.
// See BF [ 2030233 ] Remove duplicate code from DB class // See BF [ 2030233 ] Remove duplicate code from DB class
// TODO: remove this when BeanShell will support varargs methods // TODO: remove this when BeanShell will support varargs methods
@ -1980,7 +2078,7 @@ public final class DB
} }
public static int getSQLValue (String trxName, String sql, int int_param1) public static int getSQLValue (String trxName, String sql, int int_param1)
{ {
return getSQLValue(trxName, sql, new Object[]{int_param1}); return getSQLValue(trxName, sql, new Object[]{int_param1});
} }
public static int getSQLValue (String trxName, String sql, int int_param1, int int_param2) public static int getSQLValue (String trxName, String sql, int int_param1, int int_param2)
{ {
@ -2002,7 +2100,7 @@ public final class DB
{ {
return getSQLValueBD(trxName, sql, new Object[]{int_param1}); return getSQLValueBD(trxName, sql, new Object[]{int_param1});
} }
/** /**
* Get Array of ValueNamePair items. * Get Array of ValueNamePair items.
* <pre> Example: * <pre> Example:
@ -2045,7 +2143,7 @@ public final class DB
} }
return list.toArray(new ValueNamePair[list.size()]); return list.toArray(new ValueNamePair[list.size()]);
} }
/** /**
* Get Array of KeyNamePair items. * Get Array of KeyNamePair items.
* <pre> Example: * <pre> Example: