javax.persistence.NamedEntityGraph Java Examples

The following examples show how to use javax.persistence.NamedEntityGraph. 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
public static List<NamedEntityGraph> buildNamedEntityGraph(
		Element element,
		XMLContext.Default defaults,
		ClassLoaderAccess classLoaderAccess) {
	if ( element == null ) {
		return new ArrayList<>();
	}
	List<NamedEntityGraph> namedEntityGraphList = new ArrayList<>();
	List<Element> namedEntityGraphElements = element.elements( "named-entity-graph" );
	for ( Element subElement : namedEntityGraphElements ) {
		AnnotationDescriptor ann = new AnnotationDescriptor( NamedEntityGraph.class );
		copyStringAttribute( ann, subElement, "name", false );
		copyBooleanAttribute( ann, subElement, "include-all-attributes" );
		bindNamedAttributeNodes( subElement, ann );

		List<Element> subgraphNodes = subElement.elements( "subgraph" );
		List<Element> subclassSubgraphNodes = subElement.elements( "subclass-subgraph" );
		if(!subclassSubgraphNodes.isEmpty()) {
			subgraphNodes.addAll( subclassSubgraphNodes );
		}
		bindNamedSubgraph( defaults, ann, subgraphNodes, classLoaderAccess );
		namedEntityGraphList.add( AnnotationFactory.create( ann ) );
	}
	//TODO
	return namedEntityGraphList;
}
 
Example #2
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private NamedEntityGraphs getNamedEntityGraphs(Element tree, XMLContext.Default defaults) {
	List<NamedEntityGraph> queries = buildNamedEntityGraph( tree, defaults, classLoaderAccess );
	if ( defaults.canUseJavaAnnotations() ) {
		NamedEntityGraph annotation = getPhysicalAnnotation( NamedEntityGraph.class );
		addNamedEntityGraphIfNeeded( annotation, queries );
		NamedEntityGraphs annotations = getPhysicalAnnotation( NamedEntityGraphs.class );
		if ( annotations != null ) {
			for ( NamedEntityGraph current : annotations.value() ) {
				addNamedEntityGraphIfNeeded( current, queries );
			}
		}
	}
	if ( queries.size() > 0 ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( NamedEntityGraphs.class );
		ad.setValue( "value", queries.toArray( new NamedEntityGraph[queries.size()] ) );
		return AnnotationFactory.create( ad );
	}
	else {
		return null;
	}
}
 
Example #3
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void addNamedEntityGraphIfNeeded(NamedEntityGraph annotation, List<NamedEntityGraph> queries) {
	if ( annotation != null ) {
		String queryName = annotation.name();
		boolean present = false;
		for ( NamedEntityGraph current : queries ) {
			if ( current.name().equals( queryName ) ) {
				present = true;
				break;
			}
		}
		if ( !present ) {
			queries.add( annotation );
		}
	}

}
 
Example #4
Source File: NamedEntityGraphDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public NamedEntityGraphDefinition(NamedEntityGraph annotation, String jpaEntityName, String entityName) {
	this.annotation = annotation;
	this.jpaEntityName = jpaEntityName;
	this.entityName = entityName;
	this.name = StringHelper.isNotEmpty( annotation.name() )
			? annotation.name()
			: jpaEntityName;
	if ( name == null ) {
		throw new IllegalArgumentException( "Named entity graph name cannot be null" );
	}
}
 
Example #5
Source File: EntityBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processNamedEntityGraphs() {
	processNamedEntityGraph( annotatedClass.getAnnotation( NamedEntityGraph.class ) );
	final NamedEntityGraphs graphs = annotatedClass.getAnnotation( NamedEntityGraphs.class );
	if ( graphs != null ) {
		for ( NamedEntityGraph graph : graphs.value() ) {
			processNamedEntityGraph( graph );
		}
	}
}
 
Example #6
Source File: EntityBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processNamedEntityGraph(NamedEntityGraph annotation) {
	if ( annotation == null ) {
		return;
	}
	context.getMetadataCollector().addNamedEntityGraph(
			new NamedEntityGraphDefinition( annotation, name, persistentClass.getEntityName() )
	);
}
 
Example #7
Source File: MetamodelImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void applyNamedEntityGraphs(java.util.Collection<NamedEntityGraphDefinition> namedEntityGraphs) {
	for ( NamedEntityGraphDefinition definition : namedEntityGraphs ) {
		log.debugf(
				"Applying named entity graph [name=%s, entity-name=%s, jpa-entity-name=%s",
				definition.getRegisteredName(),
				definition.getEntityName(),
				definition.getJpaEntityName()
		);
		final EntityType entityType = entity( definition.getEntityName() );
		if ( entityType == null ) {
			throw new IllegalArgumentException(
					"Attempted to register named entity graph [" + definition.getRegisteredName()
							+ "] for unknown entity ["+ definition.getEntityName() + "]"

			);
		}
		final EntityGraphImpl entityGraph = new EntityGraphImpl(
				definition.getRegisteredName(),
				entityType,
				this.getSessionFactory()
		);

		final NamedEntityGraph namedEntityGraph = definition.getAnnotation();

		if ( namedEntityGraph.includeAllAttributes() ) {
			for ( Object attributeObject : entityType.getAttributes() ) {
				entityGraph.addAttributeNodes( (Attribute) attributeObject );
			}
		}

		if ( namedEntityGraph.attributeNodes() != null ) {
			applyNamedAttributeNodes( namedEntityGraph.attributeNodes(), namedEntityGraph, entityGraph );
		}

		entityGraphMap.put( definition.getRegisteredName(), entityGraph );
	}
}
 
Example #8
Source File: MetamodelImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void applyNamedSubgraphs(NamedEntityGraph namedEntityGraph, String subgraphName, SubgraphImpl subgraph) {
	for ( NamedSubgraph namedSubgraph : namedEntityGraph.subgraphs() ) {
		if ( subgraphName.equals( namedSubgraph.name() ) ) {
			applyNamedAttributeNodes(
					namedSubgraph.attributeNodes(),
					namedEntityGraph,
					subgraph
			);
		}
	}
}
 
Example #9
Source File: NamedEntityGraphDefinition.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public NamedEntityGraph getAnnotation() {
	return annotation;
}