javax.persistence.SqlResultSetMapping Java Examples
The following examples show how to use
javax.persistence.SqlResultSetMapping.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JPAOverriddenAnnotationReader.java From lams with GNU General Public License v2.0 | 6 votes |
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; } }
Example #2
Source File: JPAOverriddenAnnotationReader.java From lams with GNU General Public License v2.0 | 5 votes |
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 ); } } }
Example #3
Source File: QueryBinder.java From lams with GNU General Public License v2.0 | 5 votes |
public static void bindSqlResultSetMappings( SqlResultSetMappings ann, MetadataBuildingContext context, boolean isDefault) { if ( ann == null ) { return; } for (SqlResultSetMapping rs : ann.value()) { //no need to handle inSecondPass context.getMetadataCollector().addSecondPass( new ResultsetMappingSecondPass( rs, context, true ) ); } }
Example #4
Source File: QueryBinder.java From lams with GNU General Public License v2.0 | 5 votes |
public static void bindSqlResultSetMapping( SqlResultSetMapping ann, MetadataBuildingContext context, boolean isDefault) { //no need to handle inSecondPass context.getMetadataCollector().addSecondPass( new ResultsetMappingSecondPass( ann, context, isDefault ) ); }
Example #5
Source File: JPAOverriddenAnnotationReader.java From lams with GNU General Public License v2.0 | 4 votes |
public static List<SqlResultSetMapping> buildSqlResultsetMappings( Element element, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) { final List<SqlResultSetMapping> builtResultSetMappings = new ArrayList<>(); 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<>(); } // process the <entity-result/> entityResultAnnotations.add( buildEntityResult( resultElement, defaults, classLoaderAccess ) ); } else if ( "column-result".equals( resultElement.getName() ) ) { if ( columnResultAnnotations == null ) { columnResultAnnotations = new ArrayList<>(); } columnResultAnnotations.add( buildColumnResult( resultElement, defaults, classLoaderAccess ) ); } else if ( "constructor-result".equals( resultElement.getName() ) ) { if ( constructorResultAnnotations == null ) { constructorResultAnnotations = new ArrayList<>(); } 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( AnnotationFactory.create( resultSetMappingAnnotation ) ); } return builtResultSetMappings; }
Example #6
Source File: ResultsetMappingSecondPass.java From lams with GNU General Public License v2.0 | 4 votes |
public ResultsetMappingSecondPass(SqlResultSetMapping ann, MetadataBuildingContext context, boolean isDefault) { this.ann = ann; this.context = context; this.isDefault = isDefault; }