String name = attrs.getValue("name");
Log log = getLog();
if (log.isTraceEnabled())
log.trace(_loc.get("parse-native-query", name));
QueryMetaData meta = getRepository().getCachedQueryMetaData(null, name);
if (meta != null && log.isWarnEnabled())
log.warn(_loc.get("override-query", name, currentLocation()));
meta = getRepository().addQueryMetaData(null, name);
meta.setDefiningType(_cls);
meta.setQueryString(attrs.getValue("query"));
meta.setLanguage(QueryLanguages.LANG_SQL);
String val = attrs.getValue("result-class");
if (val != null) {
Class<?> type = classForName(val);
if (ImplHelper.isManagedType(getConfiguration(), type))
meta.setCandidateType(type);
else
meta.setResultType(type);
}
val = attrs.getValue("result-set-mapping");
if (val != null)
meta.setResultSetMappingName(val);
Object cur = currentElement();
Object scope = (cur instanceof ClassMetaData)
? ((ClassMetaData) cur).getDescribedType() : null;
meta.setSource(getSourceFile(), scope, SourceTracker.SRC_XML);
Locator locator = getLocation().getLocator();
if (locator != null) {
meta.setLineNumber(Numbers.valueOf(locator.getLineNumber()));
meta.setColNumber(Numbers.valueOf(locator.getColumnNumber()));
}
if (isMetaDataMode())
meta.setSourceMode(MODE_META);
else if (isMappingMode())
meta.setSourceMode(MODE_MAPPING);
else
meta.setSourceMode(MODE_QUERY);
pushElement(meta);
return true;
}