javax.persistence.ConstructorResult Java Examples

The following examples show how to use javax.persistence.ConstructorResult. 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 vote down vote up
private static ConstructorResult buildConstructorResult(
		Element constructorResultElement,
		XMLContext.Default defaults,
		ClassLoaderAccess classLoaderAccess) {
	AnnotationDescriptor constructorResultDescriptor = new AnnotationDescriptor( ConstructorResult.class );

	final Class entityClass = resolveClassReference( constructorResultElement.attributeValue( "target-class" ), defaults, classLoaderAccess );
	constructorResultDescriptor.setValue( "targetClass", entityClass );

	List<ColumnResult> columnResultAnnotations = new ArrayList<>();
	for ( Element columnResultElement : (List<Element>) constructorResultElement.elements( "column" ) ) {
		columnResultAnnotations.add( buildColumnResult( columnResultElement, defaults, classLoaderAccess ) );
	}
	constructorResultDescriptor.setValue(
			"columns",
			columnResultAnnotations.toArray( new ColumnResult[ columnResultAnnotations.size() ] )
	);

	return AnnotationFactory.create( constructorResultDescriptor );
}
 
Example #2
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
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;
	}