nameMapping.setGetMethodName("getName");
nameMapping.setSetMethodName("setName");
nameMapping.setXPath("@name");
descriptor.addMapping(nameMapping);
XMLCompositeObjectMapping expressionMapping = new XMLCompositeObjectMapping();
expressionMapping.setAttributeName("selectionCriteria");
expressionMapping.setGetMethodName("getSelectionCriteria");
expressionMapping.setSetMethodName("setSelectionCriteria");
expressionMapping.setAttributeAccessor(new AttributeAccessor() {
public Object getAttributeValueFromObject(Object object) {
return ((DatabaseQuery)object).getSelectionCriteria();
}
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;
Vector arguments = query.getArguments();
Vector types = query.getArgumentTypeNames();
Vector 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((String)types.get(index));
}
if (!values.isEmpty()) {
queryArgument.setValue(values.get(index));
}
queryArguments.add(queryArgument);
}
return queryArguments;
}
public void setAttributeValueInObject(Object object, Object value) {
DatabaseQuery query = (DatabaseQuery)object;
Vector queryArguments = (Vector)value;
Vector arguments = NonSynchronizedVector.newInstance(queryArguments.size());
Vector types = NonSynchronizedVector.newInstance(queryArguments.size());
Vector values = NonSynchronizedVector.newInstance(queryArguments.size());
for (int index = 0; index < queryArguments.size(); index++) {
QueryArgument queryArgument = (QueryArgument)queryArguments.get(index);
arguments.add(queryArgument.getKey());
if (queryArgument.getValue() != null) {
values.add(queryArgument.getValue());
}
if (queryArgument.getType() != null) {
types.add(queryArgument.getType());
}
}
query.setArguments(arguments);
if (!types.isEmpty()) {
query.setArgumentTypes(types);
}
if (!values.isEmpty()) {
query.setArgumentValues(values);
}
}
});
argumentsMapping.setAttributeName("argumentsMapping");
argumentsMapping.setXPath(getSecondaryNamespaceXPath() + "arguments/" + getSecondaryNamespaceXPath() + "argument");
argumentsMapping.setReferenceClass(QueryArgument.class);
descriptor.addMapping(argumentsMapping);
XMLDirectMapping shouldMaintainCacheMapping = new XMLDirectMapping();
shouldMaintainCacheMapping.setAttributeName("shouldMaintainCache");
shouldMaintainCacheMapping.setGetMethodName("shouldMaintainCache");
shouldMaintainCacheMapping.setSetMethodName("setShouldMaintainCache");
shouldMaintainCacheMapping.setXPath(getPrimaryNamespaceXPath() + "maintain-cache/text()");
shouldMaintainCacheMapping.setNullValue(Boolean.TRUE);
descriptor.addMapping(shouldMaintainCacheMapping);
XMLDirectMapping shouldBindAllParametersMapping = new XMLDirectMapping();
shouldBindAllParametersMapping.setAttributeName("shouldBindAllParameters");
shouldBindAllParametersMapping.setXPath(getPrimaryNamespaceXPath() + "bind-all-parameters/text()");
descriptor.addMapping(shouldBindAllParametersMapping);
XMLDirectMapping shouldCacheStatementMapping = new XMLDirectMapping();
shouldCacheStatementMapping.setAttributeName("shouldCacheStatement");
shouldCacheStatementMapping.setXPath(getPrimaryNamespaceXPath() + "cache-statement/text()");
descriptor.addMapping(shouldCacheStatementMapping);
XMLDirectMapping queryTimeoutMapping = new XMLDirectMapping();
queryTimeoutMapping.setAttributeName("queryTimeout");
queryTimeoutMapping.setGetMethodName("getQueryTimeout");
queryTimeoutMapping.setSetMethodName("setQueryTimeout");
queryTimeoutMapping.setXPath(getPrimaryNamespaceXPath() + "timeout/text()");
queryTimeoutMapping.setNullValue(new Integer(DescriptorQueryManager.DefaultTimeout));
descriptor.addMapping(queryTimeoutMapping);
// feaure 2297
XMLDirectMapping shouldPrepareMapping = new XMLDirectMapping();
shouldPrepareMapping.setAttributeName("shouldPrepare");
shouldPrepareMapping.setGetMethodName("shouldPrepare");
shouldPrepareMapping.setSetMethodName("setShouldPrepare");
shouldPrepareMapping.setXPath(getPrimaryNamespaceXPath() + "prepare/text()");
shouldPrepareMapping.setNullValue(Boolean.TRUE);
descriptor.addMapping(shouldPrepareMapping);
XMLCompositeObjectMapping callMapping = new XMLCompositeObjectMapping();
callMapping.setAttributeName("call");
callMapping.setGetMethodName("getDatasourceCall");
callMapping.setSetMethodName("setDatasourceCall");
callMapping.setReferenceClass(Call.class);
callMapping.setXPath(getPrimaryNamespaceXPath() + "call");
descriptor.addMapping(callMapping);
XMLCompositeObjectMapping redirectorMapping = new XMLCompositeObjectMapping();
redirectorMapping.setAttributeName("redirector");
redirectorMapping.setGetMethodName("getRedirector");
redirectorMapping.setSetMethodName("setRedirector");
redirectorMapping.setReferenceClass(MethodBaseQueryRedirector.class);
redirectorMapping.setXPath(getPrimaryNamespaceXPath() + "query-redirector");
descriptor.addMapping(redirectorMapping);
return descriptor;
}