use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class InventoryUtil method getLineCosts.
private static BigDecimal getLineCosts(PO line, BigDecimal lineQty, boolean isSOTrx) {
ArrayList<Object> params = new ArrayList<Object>();
String sql = "SELECT" + " SUM(" + MCostDetail.COLUMNNAME_Amt + ")" + ",SUM(" + MCostDetail.COLUMNNAME_Qty + ")" + " FROM " + MCostDetail.Table_Name + " WHERE " + line.get_TableName() + "_ID=?";
params.add(line.get_ID());
if (line instanceof I_M_MovementLine) {
sql += " AND " + MCostDetail.COLUMNNAME_IsSOTrx + "=?";
params.add(isSOTrx);
}
PreparedStatement pstmt = null;
ResultSet rs = null;
BigDecimal costs = null;
BigDecimal qty = null;
try {
pstmt = DB.prepareStatement(sql, line.get_TrxName());
DB.setParameters(pstmt, params);
rs = pstmt.executeQuery();
if (rs.next()) {
costs = rs.getBigDecimal(1);
qty = rs.getBigDecimal(2);
}
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
if (costs == null)
costs = Env.ZERO;
if (qty == null)
qty = Env.ZERO;
// Convert Qty sign from Absolute to Relative (for comparation purposes)
if (isSOTrx)
qty = qty.negate();
// Check Line Qty (if specified)
if (lineQty != null && qty.compareTo(lineQty) != 0) {
throw new RuntimeException("CostDetail Qty Not Match - TargetQty=" + lineQty + ", ActualQty=" + qty + ", Costs=" + costs);
}
return costs;
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class DBTest method test_getSQLValueBDEx.
public void test_getSQLValueBDEx() throws Exception {
BigDecimal result = DB.getSQLValueBDEx(null, "SELECT 10 FROM DUAL");
assertEquals(BigDecimal.TEN, result);
//
result = DB.getSQLValueBD(null, "SELECT 10 FROM AD_SYSTEM WHERE 1=2");
assertNull("No value should be returned", result);
//
DBException ex = null;
try {
result = DB.getSQLValueBDEx(null, "SELECT 10 FROM INEXISTENT_TABLE");
} catch (DBException e) {
ex = e;
}
assertNotNull("No DBException Was Throwed", ex);
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class DBTest method test_getSQLValueStringEx.
public void test_getSQLValueStringEx() throws Exception {
String result = DB.getSQLValueStringEx(null, "SELECT 'string' FROM DUAL");
assertEquals("string", result);
//
result = DB.getSQLValueStringEx(null, "SELECT 10 FROM AD_SYSTEM WHERE 1=2");
assertNull("No value should be returned", result);
//
DBException ex = null;
try {
result = DB.getSQLValueStringEx(null, "SELECT 'string' FROM INEXISTENT_TABLE");
} catch (DBException e) {
ex = e;
}
assertNotNull("No DBException Was Throwed", ex);
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class DBTest method test_getSQLValueEx.
public void test_getSQLValueEx() throws Exception {
int result = DB.getSQLValueEx(null, "SELECT 10 FROM DUAL");
assertEquals(10, result);
//
result = DB.getSQLValue(null, "SELECT 10 FROM AD_SYSTEM WHERE 1=2");
assertEquals("No value should be returned", -1, result);
//
DBException ex = null;
try {
result = DB.getSQLValueEx(null, "SELECT 10 FROM INEXISTENT_TABLE");
} catch (DBException e) {
ex = e;
}
assertNotNull("No DBException Was Throwed", ex);
}
use of org.adempiere.exceptions.DBException in project adempiere by adempiere.
the class DBTest method test_getSQLValueTSEx.
public void test_getSQLValueTSEx() throws Exception {
final Timestamp target = TimeUtil.getDay(2008, 01, 01);
//
Timestamp result = DB.getSQLValueTSEx(null, "SELECT TO_DATE('2008-01-01','YYYY-MM-DD') FROM AD_SYSTEM");
assertEquals(target, result);
//
result = DB.getSQLValueTSEx(null, "SELECT TO_DATE('2008-01-01','YYYY-MM-DD') FROM AD_SYSTEM WHERE 1=2");
assertNull("No value should be returned", result);
//
DBException ex = null;
try {
result = DB.getSQLValueTSEx(null, "SELECT TO_DATE('2008-01-01','YYYY-MM-DD') FROM INEXISTENT_TABLE");
} catch (DBException e) {
ex = e;
}
assertNotNull("No DBException Was Throwed", ex);
}
Aggregations