类javax.persistence.ConstructorResult源码实例Demo

下面列出了怎么用javax.persistence.ConstructorResult的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: JPAOverriddenAnnotationReader.java
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 );
}
 
源代码2 项目: lams   文件: JPAOverriddenAnnotationReader.java
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;
	}
 
 类所在包
 同包方法