}
});
}
private void addResultMapNodelets() {
parser.addNodelet("/sqlMap/resultMap/end()", new Nodelet() {
public void process(Node node) throws Exception {
state.getConfig().getErrorContext().setMoreInfo(null);
state.getConfig().getErrorContext().setObjectId(null);
}
});
parser.addNodelet("/sqlMap/resultMap", new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps());
String id = state.applyNamespace(attributes.getProperty("id"));
String resultClassName = attributes.getProperty("class");
String extended = state.applyNamespace(attributes.getProperty("extends"));
String xmlName = attributes.getProperty("xmlName");
String groupBy = attributes.getProperty("groupBy");
resultClassName = state.getConfig().getTypeHandlerFactory().resolveAlias(resultClassName);
Class resultClass;
try {
state.getConfig().getErrorContext().setMoreInfo("Check the result class.");
resultClass = Resources.classForName(resultClassName);
} catch (Exception e) {
throw new RuntimeException("Error configuring Result. Could not set ResultClass. Cause: " + e, e);
}
ResultMapConfig resultConf = state.getConfig().newResultMapConfig(id, resultClass, groupBy, extended,
xmlName);
state.setResultConfig(resultConf);
}
});
parser.addNodelet("/sqlMap/resultMap/result", new Nodelet() {
public void process(Node node) throws Exception {
Properties childAttributes = NodeletUtils.parseAttributes(node, state.getGlobalProps());
String propertyName = childAttributes.getProperty("property");
String nullValue = childAttributes.getProperty("nullValue");
String jdbcType = childAttributes.getProperty("jdbcType");
String javaType = childAttributes.getProperty("javaType");
String columnName = childAttributes.getProperty("column");
String columnIndexProp = childAttributes.getProperty("columnIndex");
String statementName = childAttributes.getProperty("select");
String resultMapName = childAttributes.getProperty("resultMap");
String callback = childAttributes.getProperty("typeHandler");
String notNullColumn = childAttributes.getProperty("notNullColumn");
state.getConfig().getErrorContext().setMoreInfo("Check the result mapping property type or name.");
Class javaClass = null;
try {
javaType = state.getConfig().getTypeHandlerFactory().resolveAlias(javaType);
if (javaType != null && javaType.length() > 0) {
javaClass = Resources.classForName(javaType);
}
} catch (ClassNotFoundException e) {
throw new RuntimeException("Error setting java type on result discriminator mapping. Cause: " + e);
}
state.getConfig()
.getErrorContext()
.setMoreInfo(
"Check the result mapping typeHandler attribute '" + callback
+ "' (must be a TypeHandler or TypeHandlerCallback implementation).");
Object typeHandlerImpl = null;
try {
if (callback != null && callback.length() > 0) {
callback = state.getConfig().getTypeHandlerFactory().resolveAlias(callback);
typeHandlerImpl = Resources.instantiate(callback);
}
} catch (Exception e) {
throw new RuntimeException("Error occurred during custom type handler configuration. Cause: " + e,
e);
}
Integer columnIndex = null;
if (columnIndexProp != null) {
try {
columnIndex = new Integer(columnIndexProp);
} catch (Exception e) {
throw new RuntimeException("Error parsing column index. Cause: " + e, e);
}
}
state.getResultConfig().addResultMapping(propertyName, columnName, columnIndex, javaClass, jdbcType,
nullValue, notNullColumn, statementName, resultMapName, typeHandlerImpl);
}
});
parser.addNodelet("/sqlMap/resultMap/discriminator/subMap", new Nodelet() {
public void process(Node node) throws Exception {
Properties childAttributes = NodeletUtils.parseAttributes(node, state.getGlobalProps());
String value = childAttributes.getProperty("value");
String resultMap = childAttributes.getProperty("resultMap");
resultMap = state.applyNamespace(resultMap);
state.getResultConfig().addDiscriminatorSubMap(value, resultMap);
}
});
parser.addNodelet("/sqlMap/resultMap/discriminator", new Nodelet() {
public void process(Node node) throws Exception {
Properties childAttributes = NodeletUtils.parseAttributes(node, state.getGlobalProps());
String nullValue = childAttributes.getProperty("nullValue");
String jdbcType = childAttributes.getProperty("jdbcType");
String javaType = childAttributes.getProperty("javaType");