use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class DB method getValueNamePairs.
/**
* Get Array of ValueNamePair items.
* <pre> Example:
* String sql = "SELECT Name, Description FROM AD_Ref_List WHERE AD_Reference_ID=?";
* ValueNamePair[] list = DB.getValueNamePairs(sql, false, params);
* </pre>
* @param sql SELECT Value_Column, Name_Column FROM ...
* @param optional if {@link ValueNamePair#EMPTY} is added
* @param params query parameters
* @return array of {@link ValueNamePair} or empty array
* @throws DBException if there is any SQLException
*/
public static ValueNamePair[] getValueNamePairs(String sql, boolean optional, List<Object> params) {
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList<ValueNamePair> list = new ArrayList<ValueNamePair>();
if (optional) {
list.add(ValueNamePair.EMPTY);
}
try {
pstmt = DB.prepareStatement(sql, null);
setParameters(pstmt, params);
rs = pstmt.executeQuery();
while (rs.next()) {
list.add(new ValueNamePair(rs.getString(1), rs.getString(2)));
}
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
close(rs, pstmt);
rs = null;
pstmt = null;
}
return list.toArray(new ValueNamePair[list.size()]);
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class DB method getIDsEx.
public static int[] getIDsEx(String trxName, String sql, Object... params) throws DBException {
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList<Integer> list = new ArrayList<Integer>();
try {
pstmt = DB.prepareStatement(sql, trxName);
setParameters(pstmt, params);
rs = pstmt.executeQuery();
while (rs.next()) {
list.add(rs.getInt(1));
}
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
close(rs, pstmt);
rs = null;
pstmt = null;
}
// Convert to array
int[] retValue = new int[list.size()];
for (int i = 0; i < retValue.length; i++) {
retValue[i] = list.get(i);
}
return retValue;
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class DB method getSQLValueStringEx.
/**
* Get String Value from sql
* @param trxName trx
* @param sql sql
* @param params array of parameters
* @return first value or null
* @throws DBException if there is any SQLException
*/
public static String getSQLValueStringEx(String trxName, String sql, Object... params) {
String retValue = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = prepareStatement(sql, trxName);
setParameters(pstmt, params);
rs = pstmt.executeQuery();
if (rs.next())
retValue = rs.getString(1);
else
log.fine("No Value " + sql);
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
close(rs, pstmt);
rs = null;
pstmt = null;
}
return retValue;
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class MPPOrderBOMLine method loadStorage.
/**
* Load Storage Info
* @param reload
*/
private void loadStorage(boolean reload) {
if (!reload && m_qtyOnHand != null && m_qtyAvailable != null) {
return;
}
//
final String sql = "SELECT " + " bomQtyAvailable(" + COLUMNNAME_M_Product_ID + ", " + COLUMNNAME_M_Warehouse_ID + ", 0)" + ",bomQtyOnHand(" + COLUMNNAME_M_Product_ID + ", " + COLUMNNAME_M_Warehouse_ID + ", 0)" + " FROM " + Table_Name + " WHERE " + COLUMNNAME_PP_Order_BOMLine_ID + "=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
DB.setParameters(pstmt, new Object[] { get_ID() });
rs = pstmt.executeQuery();
if (rs.next()) {
m_qtyAvailable = rs.getBigDecimal(1);
m_qtyOnHand = rs.getBigDecimal(2);
}
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class InventoryTestException method assertStorage.
private void assertStorage(MMDocument doc, String trxName) {
MLocator locator = InventoryUtil.getCreateLocator(-1, doc.LocatorValue, doc.LocatorValue);
MProduct product = InventoryUtil.getCreateProduct(doc);
int M_ASI_ID = -1;
if (!Util.isEmpty(doc.ASI, true)) {
M_ASI_ID = doc.scenario.getM_ASI_ID(doc.ASI);
}
ArrayList<Object> params = new ArrayList<Object>();
String sql = "SELECT" + " COALESCE(SUM(QtyOnHand),0)" + ",COALESCE(SUM(QtyReserved),0)" + ",COALESCE(SUM(QtyOrdered),0)" + " FROM M_Storage" + " WHERE M_Locator_ID=? AND M_Product_ID=?";
params.add(locator.get_ID());
params.add(product.get_ID());
if (M_ASI_ID >= 0) {
sql += " AND " + MStorage.COLUMNNAME_M_AttributeSetInstance_ID + "=?";
params.add(M_ASI_ID);
}
PreparedStatement pstmt = null;
ResultSet rs = null;
BigDecimal qtyOnHand = Env.ZERO;
BigDecimal qtyOrdered = Env.ZERO;
BigDecimal qtyReserved = Env.ZERO;
try {
pstmt = DB.prepareStatement(sql, trxName);
DB.setParameters(pstmt, params);
rs = pstmt.executeQuery();
if (rs.next()) {
qtyOnHand = rs.getBigDecimal(1);
qtyReserved = rs.getBigDecimal(2);
qtyOrdered = rs.getBigDecimal(3);
}
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
//
//
assertEquals("QtyOnHand not match " + doc, doc.Qty, qtyOnHand);
assertEquals("QtyReserved not match " + doc, doc.QtyReserved, qtyReserved);
assertEquals("QtyOrdered not match " + doc, doc.QtyOrdered, qtyOrdered);
}
Aggregations