Handle NPE when no datarow is provided in queryData request

This commit is contained in:
Elaine Tan 2013-04-04 16:26:44 +08:00
parent 454495f198
commit e14cfc212a
1 changed files with 23 additions and 17 deletions

View File

@ -1384,14 +1384,17 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
String sqlquery = "SELECT * FROM " + tableName; String sqlquery = "SELECT * FROM " + tableName;
sqlquery = role.addAccessSQL(sqlquery, tableName, true, true); sqlquery = role.addAccessSQL(sqlquery, tableName, true, true);
for (DataField field : modelCRUD.getDataRow().getFieldArray()) { if (modelCRUD.getDataRow() != null)
if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) { {
sqlquery += " AND " + field.getColumn() + "=?"; for (DataField field : modelCRUD.getDataRow().getFieldArray()) {
} else { if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
throw new IdempiereServiceFault("Web service type " sqlquery += " AND " + field.getColumn() + "=?";
+ m_webservicetype.getValue() + ": input column " } else {
+ field.getColumn() + " not allowed", new QName("queryData")); throw new IdempiereServiceFault("Web service type "
} + m_webservicetype.getValue() + ": input column "
+ field.getColumn() + " not allowed", new QName("queryData"));
}
}
} }
if (modelCRUD.getFilter() != null && modelCRUD.getFilter().length() > 0) if (modelCRUD.getFilter() != null && modelCRUD.getFilter().length() > 0)
@ -1406,15 +1409,18 @@ public class ModelADServiceImpl extends AbstractService implements ModelADServic
{ {
pstmtquery = DB.prepareStatement (sqlquery, null); pstmtquery = DB.prepareStatement (sqlquery, null);
int p = 1; int p = 1;
for (DataField field : modelCRUD.getDataRow().getFieldArray()) { if (modelCRUD.getDataRow() != null)
int idx = poinfo.getColumnIndex(field.getColumn()); {
Class<?> c = poinfo.getColumnClass(idx); for (DataField field : modelCRUD.getDataRow().getFieldArray()) {
if (c == Integer.class) int idx = poinfo.getColumnIndex(field.getColumn());
pstmtquery.setInt(p++, Integer.valueOf(field.getVal())); Class<?> c = poinfo.getColumnClass(idx);
else if (c == Timestamp.class) if (c == Integer.class)
pstmtquery.setTimestamp(p++, Timestamp.valueOf(field.getVal())); pstmtquery.setInt(p++, Integer.valueOf(field.getVal()));
else if (c == Boolean.class || c == String.class) else if (c == Timestamp.class)
pstmtquery.setString(p++, field.getVal()); pstmtquery.setTimestamp(p++, Timestamp.valueOf(field.getVal()));
else if (c == Boolean.class || c == String.class)
pstmtquery.setString(p++, field.getVal());
}
} }
rsquery = pstmtquery.executeQuery (); rsquery = pstmtquery.executeQuery ();
// Angelo Dabala' (genied) must create just one DataSet, moved outside of the while loop // Angelo Dabala' (genied) must create just one DataSet, moved outside of the while loop