use of javax.persistence.SqlResultSetMapping in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method addSqlResultsetMappingIfNeeded.
private void addSqlResultsetMappingIfNeeded(SqlResultSetMapping annotation, List<SqlResultSetMapping> resultsets) {
if (annotation != null) {
String resultsetName = annotation.name();
boolean present = false;
for (SqlResultSetMapping current : resultsets) {
if (current.name().equals(resultsetName)) {
present = true;
break;
}
}
if (!present) {
resultsets.add(annotation);
}
}
}
use of javax.persistence.SqlResultSetMapping 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;
}
use of javax.persistence.SqlResultSetMapping in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildSqlResultsetMappings.
public static List<SqlResultSetMapping> buildSqlResultsetMappings(Element element, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
final List<SqlResultSetMapping> builtResultSetMappings = new ArrayList<SqlResultSetMapping>();
if (element == null) {
return builtResultSetMappings;
}
// iterate over each <sql-result-set-mapping/> element
for (Object resultSetMappingElementObject : element.elements("sql-result-set-mapping")) {
final Element resultSetMappingElement = (Element) resultSetMappingElementObject;
final AnnotationDescriptor resultSetMappingAnnotation = new AnnotationDescriptor(SqlResultSetMapping.class);
copyStringAttribute(resultSetMappingAnnotation, resultSetMappingElement, "name", true);
// iterate over the <sql-result-set-mapping/> sub-elements, which should include:
// * <entity-result/>
// * <column-result/>
// * <constructor-result/>
List<EntityResult> entityResultAnnotations = null;
List<ColumnResult> columnResultAnnotations = null;
List<ConstructorResult> constructorResultAnnotations = null;
for (Object resultElementObject : resultSetMappingElement.elements()) {
final Element resultElement = (Element) resultElementObject;
if ("entity-result".equals(resultElement.getName())) {
if (entityResultAnnotations == null) {
entityResultAnnotations = new ArrayList<EntityResult>();
}
// process the <entity-result/>
entityResultAnnotations.add(buildEntityResult(resultElement, defaults, classLoaderAccess));
} else if ("column-result".equals(resultElement.getName())) {
if (columnResultAnnotations == null) {
columnResultAnnotations = new ArrayList<ColumnResult>();
}
columnResultAnnotations.add(buildColumnResult(resultElement, defaults, classLoaderAccess));
} else if ("constructor-result".equals(resultElement.getName())) {
if (constructorResultAnnotations == null) {
constructorResultAnnotations = new ArrayList<ConstructorResult>();
}
constructorResultAnnotations.add(buildConstructorResult(resultElement, defaults, classLoaderAccess));
} else {
// most likely the <result-class/> this code used to handle. I have left the code here,
// but commented it out for now. I'll just log a warning for now.
LOG.debug("Encountered unrecognized sql-result-set-mapping sub-element : " + resultElement.getName());
// String clazzName = subelement.attributeValue( "result-class" );
// if ( StringHelper.isNotEmpty( clazzName ) ) {
// Class clazz;
// try {
// clazz = ReflectHelper.classForName(
// XMLContext.buildSafeClassName( clazzName, defaults ),
// JPAOverriddenAnnotationReader.class
// );
// }
// catch ( ClassNotFoundException e ) {
// throw new AnnotationException( "Unable to find entity-class: " + clazzName, e );
// }
// ann.setValue( "resultClass", clazz );
// }
}
}
if (entityResultAnnotations != null && !entityResultAnnotations.isEmpty()) {
resultSetMappingAnnotation.setValue("entities", entityResultAnnotations.toArray(new EntityResult[entityResultAnnotations.size()]));
}
if (columnResultAnnotations != null && !columnResultAnnotations.isEmpty()) {
resultSetMappingAnnotation.setValue("columns", columnResultAnnotations.toArray(new ColumnResult[columnResultAnnotations.size()]));
}
if (constructorResultAnnotations != null && !constructorResultAnnotations.isEmpty()) {
resultSetMappingAnnotation.setValue("classes", constructorResultAnnotations.toArray(new ConstructorResult[constructorResultAnnotations.size()]));
}
// this was part of the old code too, but could never figure out what it is supposed to do...
// copyStringAttribute( ann, subelement, "result-set-mapping", false );
builtResultSetMappings.add((SqlResultSetMapping) AnnotationFactory.create(resultSetMappingAnnotation));
}
return builtResultSetMappings;
}
use of javax.persistence.SqlResultSetMapping in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getSqlResultSetMappings.
private SqlResultSetMappings getSqlResultSetMappings(Element tree, XMLContext.Default defaults) {
List<SqlResultSetMapping> results = buildSqlResultsetMappings(tree, defaults, classLoaderAccess);
if (defaults.canUseJavaAnnotations()) {
SqlResultSetMapping annotation = getPhysicalAnnotation(SqlResultSetMapping.class);
addSqlResultsetMappingIfNeeded(annotation, results);
SqlResultSetMappings annotations = getPhysicalAnnotation(SqlResultSetMappings.class);
if (annotations != null) {
for (SqlResultSetMapping current : annotations.value()) {
addSqlResultsetMappingIfNeeded(current, results);
}
}
}
if (results.size() > 0) {
AnnotationDescriptor ad = new AnnotationDescriptor(SqlResultSetMappings.class);
ad.setValue("value", results.toArray(new SqlResultSetMapping[results.size()]));
return AnnotationFactory.create(ad);
} else {
return null;
}
}
Aggregations