use of javax.persistence.NamedStoredProcedureQuery in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getNamedStoredProcedureQueries.
private NamedStoredProcedureQueries getNamedStoredProcedureQueries(Element tree, XMLContext.Default defaults) {
List<NamedStoredProcedureQuery> queries = buildNamedStoreProcedureQueries(tree, defaults, classLoaderAccess);
if (defaults.canUseJavaAnnotations()) {
NamedStoredProcedureQuery annotation = getPhysicalAnnotation(NamedStoredProcedureQuery.class);
addNamedStoredProcedureQueryIfNeeded(annotation, queries);
NamedStoredProcedureQueries annotations = getPhysicalAnnotation(NamedStoredProcedureQueries.class);
if (annotations != null) {
for (NamedStoredProcedureQuery current : annotations.value()) {
addNamedStoredProcedureQueryIfNeeded(current, queries);
}
}
}
if (queries.size() > 0) {
AnnotationDescriptor ad = new AnnotationDescriptor(NamedStoredProcedureQueries.class);
ad.setValue("value", queries.toArray(new NamedStoredProcedureQuery[queries.size()]));
return AnnotationFactory.create(ad);
} else {
return null;
}
}
use of javax.persistence.NamedStoredProcedureQuery in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method addNamedStoredProcedureQueryIfNeeded.
private void addNamedStoredProcedureQueryIfNeeded(NamedStoredProcedureQuery annotation, List<NamedStoredProcedureQuery> queries) {
if (annotation != null) {
String queryName = annotation.name();
boolean present = false;
for (NamedStoredProcedureQuery current : queries) {
if (current.name().equals(queryName)) {
present = true;
break;
}
}
if (!present) {
queries.add(annotation);
}
}
}
use of javax.persistence.NamedStoredProcedureQuery in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildNamedStoreProcedureQueries.
public static List<NamedStoredProcedureQuery> buildNamedStoreProcedureQueries(Element element, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
if (element == null) {
return new ArrayList<NamedStoredProcedureQuery>();
}
List namedStoredProcedureElements = element.elements("named-stored-procedure-query");
List<NamedStoredProcedureQuery> namedStoredProcedureQueries = new ArrayList<NamedStoredProcedureQuery>();
for (Object obj : namedStoredProcedureElements) {
Element subElement = (Element) obj;
AnnotationDescriptor ann = new AnnotationDescriptor(NamedStoredProcedureQuery.class);
copyStringAttribute(ann, subElement, "name", true);
copyStringAttribute(ann, subElement, "procedure-name", true);
List<Element> elements = subElement.elements("parameter");
List<StoredProcedureParameter> storedProcedureParameters = new ArrayList<StoredProcedureParameter>();
for (Element parameterElement : elements) {
AnnotationDescriptor parameterDescriptor = new AnnotationDescriptor(StoredProcedureParameter.class);
copyStringAttribute(parameterDescriptor, parameterElement, "name", false);
String modeValue = parameterElement.attributeValue("mode");
if (modeValue == null) {
parameterDescriptor.setValue("mode", ParameterMode.IN);
} else {
parameterDescriptor.setValue("mode", ParameterMode.valueOf(modeValue.toUpperCase(Locale.ROOT)));
}
String clazzName = parameterElement.attributeValue("class");
Class clazz;
try {
clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
} catch (ClassLoadingException e) {
throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
}
parameterDescriptor.setValue("type", clazz);
storedProcedureParameters.add((StoredProcedureParameter) AnnotationFactory.create(parameterDescriptor));
}
ann.setValue("parameters", storedProcedureParameters.toArray(new StoredProcedureParameter[storedProcedureParameters.size()]));
elements = subElement.elements("result-class");
List<Class> returnClasses = new ArrayList<Class>();
for (Element classElement : elements) {
String clazzName = classElement.getTextTrim();
Class clazz;
try {
clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
} catch (ClassLoadingException e) {
throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
}
returnClasses.add(clazz);
}
ann.setValue("resultClasses", returnClasses.toArray(new Class[returnClasses.size()]));
elements = subElement.elements("result-set-mapping");
List<String> resultSetMappings = new ArrayList<String>();
for (Element resultSetMappingElement : elements) {
resultSetMappings.add(resultSetMappingElement.getTextTrim());
}
ann.setValue("resultSetMappings", resultSetMappings.toArray(new String[resultSetMappings.size()]));
elements = subElement.elements("hint");
buildQueryHints(elements, ann);
namedStoredProcedureQueries.add((NamedStoredProcedureQuery) AnnotationFactory.create(ann));
}
return namedStoredProcedureQueries;
}
use of javax.persistence.NamedStoredProcedureQuery in project hibernate-orm by hibernate.
the class JPAMetadataProvider method getDefaults.
@Override
public Map<Object, Object> getDefaults() {
if (defaults == null) {
defaults = new HashMap<Object, Object>();
XMLContext.Default xmlDefaults = xmlContext.getDefault(null);
defaults.put("schema", xmlDefaults.getSchema());
defaults.put("catalog", xmlDefaults.getCatalog());
defaults.put("delimited-identifier", xmlDefaults.getDelimitedIdentifier());
List<Class> entityListeners = new ArrayList<Class>();
for (String className : xmlContext.getDefaultEntityListeners()) {
try {
entityListeners.add(classLoaderAccess.classForName(className));
} catch (ClassLoadingException e) {
throw new IllegalStateException("Default entity listener class not found: " + className);
}
}
defaults.put(EntityListeners.class, entityListeners);
for (Element element : xmlContext.getAllDocuments()) {
@SuppressWarnings("unchecked") List<Element> elements = element.elements("sequence-generator");
List<SequenceGenerator> sequenceGenerators = (List<SequenceGenerator>) defaults.get(SequenceGenerator.class);
if (sequenceGenerators == null) {
sequenceGenerators = new ArrayList<SequenceGenerator>();
defaults.put(SequenceGenerator.class, sequenceGenerators);
}
for (Element subelement : elements) {
sequenceGenerators.add(JPAOverriddenAnnotationReader.buildSequenceGeneratorAnnotation(subelement));
}
elements = element.elements("table-generator");
List<TableGenerator> tableGenerators = (List<TableGenerator>) defaults.get(TableGenerator.class);
if (tableGenerators == null) {
tableGenerators = new ArrayList<TableGenerator>();
defaults.put(TableGenerator.class, tableGenerators);
}
for (Element subelement : elements) {
tableGenerators.add(JPAOverriddenAnnotationReader.buildTableGeneratorAnnotation(subelement, xmlDefaults));
}
List<NamedQuery> namedQueries = (List<NamedQuery>) defaults.get(NamedQuery.class);
if (namedQueries == null) {
namedQueries = new ArrayList<NamedQuery>();
defaults.put(NamedQuery.class, namedQueries);
}
List<NamedQuery> currentNamedQueries = JPAOverriddenAnnotationReader.buildNamedQueries(element, false, xmlDefaults, classLoaderAccess);
namedQueries.addAll(currentNamedQueries);
List<NamedNativeQuery> namedNativeQueries = (List<NamedNativeQuery>) defaults.get(NamedNativeQuery.class);
if (namedNativeQueries == null) {
namedNativeQueries = new ArrayList<NamedNativeQuery>();
defaults.put(NamedNativeQuery.class, namedNativeQueries);
}
List<NamedNativeQuery> currentNamedNativeQueries = JPAOverriddenAnnotationReader.buildNamedQueries(element, true, xmlDefaults, classLoaderAccess);
namedNativeQueries.addAll(currentNamedNativeQueries);
List<SqlResultSetMapping> sqlResultSetMappings = (List<SqlResultSetMapping>) defaults.get(SqlResultSetMapping.class);
if (sqlResultSetMappings == null) {
sqlResultSetMappings = new ArrayList<SqlResultSetMapping>();
defaults.put(SqlResultSetMapping.class, sqlResultSetMappings);
}
List<SqlResultSetMapping> currentSqlResultSetMappings = JPAOverriddenAnnotationReader.buildSqlResultsetMappings(element, xmlDefaults, classLoaderAccess);
sqlResultSetMappings.addAll(currentSqlResultSetMappings);
List<NamedStoredProcedureQuery> namedStoredProcedureQueries = (List<NamedStoredProcedureQuery>) defaults.get(NamedStoredProcedureQuery.class);
if (namedStoredProcedureQueries == null) {
namedStoredProcedureQueries = new ArrayList<NamedStoredProcedureQuery>();
defaults.put(NamedStoredProcedureQuery.class, namedStoredProcedureQueries);
}
List<NamedStoredProcedureQuery> currentNamedStoredProcedureQueries = JPAOverriddenAnnotationReader.buildNamedStoreProcedureQueries(element, xmlDefaults, classLoaderAccess);
namedStoredProcedureQueries.addAll(currentNamedStoredProcedureQueries);
}
}
return defaults;
}
Aggregations