use of com.servoy.j2db.util.visitor.IVisitor in project servoy-client by Servoy.
the class JSDatabaseManager method validateQueryArguments.
private boolean validateQueryArguments(ISQLQuery select) {
if (select != null) {
if (select instanceof QuerySelect && ((QuerySelect) select).getColumns() == null) {
application.reportJSError("Custom query: " + select + " not executed because no columns are specified to be selected", null);
return false;
}
final List<Placeholder> placeHolders = new ArrayList<Placeholder>();
AbstractBaseQuery.acceptVisitor(select, new IVisitor() {
public Object visit(Object o) {
if (o instanceof Placeholder) {
placeHolders.add((Placeholder) o);
}
return o;
}
});
for (Placeholder placeholder : placeHolders) {
if (!placeholder.isSet()) {
application.reportJSError(// $NON-NLS-1$
"Custom query: " + select + " not executed because not all arguments have been set: " + placeholder.getKey(), // $NON-NLS-1$
null);
return false;
}
Object value = placeholder.getValue();
if (value instanceof DbIdentValue && ((DbIdentValue) value).getPkValue() == null) {
application.reportJSError(// $NON-NLS-1$
"Custom query: " + select + " not executed because the arguments have a database ident value that is null, from a not yet saved record", // $NON-NLS-1$
null);
return false;
}
if (value instanceof java.util.Date && !(value instanceof Timestamp) && !(value instanceof Time)) {
placeholder.setValue(new Timestamp(((java.util.Date) value).getTime()));
}
}
}
return true;
}
Aggregations