public void setAttributeValueInObject(Object object, Object value) {
if (!(object instanceof ObjectLevelReadQuery)) {
return;
}
ObjectLevelReadQuery query = (ObjectLevelReadQuery)object;
Expression expression = (Expression)value;
if (expression != null) {
expression = expression.rebuildOn(query.getExpressionBuilder());
}
query.setSelectionCriteria(expression);
}
});
expressionMapping.setReferenceClass(Expression.class);
expressionMapping.setXPath(getSecondaryNamespaceXPath() + "criteria");
descriptor.addMapping(expressionMapping);
XMLCompositeCollectionMapping argumentsMapping = new XMLCompositeCollectionMapping();
// Handle translation of argument lists to query-arguments.
argumentsMapping.setAttributeAccessor(new AttributeAccessor() {
public Object getAttributeValueFromObject(Object object) {
DatabaseQuery query = (DatabaseQuery)object;
List<String> arguments = query.getArguments();
List<String> types = query.getArgumentTypeNames();
List<Object> values = query.getArgumentValues();
Vector queryArguments = new Vector(arguments.size());
for (int index = 0; index < arguments.size(); index++) {
QueryArgument queryArgument = new QueryArgument();
queryArgument.setKey(arguments.get(index));
if (!types.isEmpty()) {
queryArgument.setTypeName(types.get(index));
}
if (!values.isEmpty()) {
queryArgument.setValue(values.get(index));
}
if (query.hasNullableArguments()
&& query.getNullableArguments().contains(new DatabaseField((String)queryArgument.getKey()))) {
queryArgument.setNullable(true);
}
queryArguments.add(queryArgument);
}
return queryArguments;
}
public void setAttributeValueInObject(Object object, Object value) {
DatabaseQuery query = (DatabaseQuery)object;
List queryArguments = (List)value;
List<String> arguments = new ArrayList<String>(queryArguments.size());
List<Class> types = new ArrayList<Class>(queryArguments.size());
List<Object> values = new ArrayList<Object>(queryArguments.size());
for (int index = 0; index < queryArguments.size(); index++) {
QueryArgument queryArgument = (QueryArgument)queryArguments.get(index);
arguments.add((String)queryArgument.getKey());
if (queryArgument.getValue() != null) {
values.add(queryArgument.getValue());
}
if (queryArgument.getType() != null) {
types.add(queryArgument.getType());
}
if (queryArgument.isNullable()) {
query.getNullableArguments().add(new DatabaseField((String)queryArgument.getKey()));
}
}
query.setArguments(arguments);
if (!types.isEmpty()) {
query.setArgumentTypes(types);
}
if (!values.isEmpty()) {
query.setArgumentValues(values);
}
}
});
argumentsMapping.setAttributeName("argumentsMapping");
argumentsMapping.setXPath(getSecondaryNamespaceXPath() + "arguments/" + getSecondaryNamespaceXPath() + "argument");