6 - SQM based on JPA type system
This commit is contained in:
parent
26ff169db2
commit
3958e37103
|
@ -8,7 +8,8 @@ package org.hibernate.graph;
|
|||
|
||||
import java.util.Map;
|
||||
import javax.persistence.Subgraph;
|
||||
import javax.persistence.metamodel.Attribute;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA entity-graph AttributeNode contract.
|
||||
|
@ -18,7 +19,7 @@ import javax.persistence.metamodel.Attribute;
|
|||
* @author Andrea Boriero
|
||||
*/
|
||||
public interface AttributeNode<J> extends GraphNode<J>, javax.persistence.AttributeNode<J> {
|
||||
Attribute<?, J> getAttributeDescriptor();
|
||||
PersistentAttribute<?, J> getAttributeDescriptor();
|
||||
|
||||
Map<Class<? extends J>, SubGraph<? extends J>> getSubGraphs();
|
||||
Map<Class<? extends J>, SubGraph<? extends J>> getKeySubGraphs();
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
package org.hibernate.graph;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.metamodel.Attribute;
|
||||
import javax.persistence.metamodel.ManagedType;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
|
||||
/**
|
||||
* A container for {@link AttributeNode}s.
|
||||
|
@ -24,7 +25,7 @@ public interface Graph<J> extends GraphNode<J> {
|
|||
/**
|
||||
* Graphs apply only to ManagedTypes. Returns the ManagedType being graphed here.
|
||||
*/
|
||||
ManagedType<J> getGraphedType();
|
||||
ManagedDomainType<J> getGraphedType();
|
||||
|
||||
/**
|
||||
* Create a named (if passed `name` != null) root Graph. The `mutable`
|
||||
|
@ -63,7 +64,7 @@ public interface Graph<J> extends GraphNode<J> {
|
|||
* Find an already existing AttributeNode by corresponding attribute
|
||||
* reference, within this container
|
||||
*/
|
||||
<AJ> AttributeNode<AJ> findAttributeNode(Attribute<? extends J, AJ> attribute);
|
||||
<AJ> AttributeNode<AJ> findAttributeNode(PersistentAttribute<? extends J, AJ> attribute);
|
||||
|
||||
/**
|
||||
* Get a list of all existing AttributeNodes within this container
|
||||
|
@ -80,7 +81,7 @@ public interface Graph<J> extends GraphNode<J> {
|
|||
* Add an AttributeNode (with no associated SubGraphNode) to this container
|
||||
* by Attribute reference
|
||||
*/
|
||||
<AJ> AttributeNode<AJ> addAttributeNode(Attribute<? extends J,AJ> attribute);
|
||||
<AJ> AttributeNode<AJ> addAttributeNode(PersistentAttribute<? extends J,AJ> attribute);
|
||||
|
||||
|
||||
|
||||
|
@ -103,9 +104,9 @@ public interface Graph<J> extends GraphNode<J> {
|
|||
*
|
||||
* @apiNote If no such AttributeNode exists yet, it is created.
|
||||
*/
|
||||
<AJ> SubGraph<AJ> addSubGraph(Attribute<? extends J, AJ> attribute) throws CannotContainSubGraphException;
|
||||
<AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? extends J, AJ> attribute) throws CannotContainSubGraphException;
|
||||
|
||||
<AJ> SubGraph<? extends AJ> addSubGraph(Attribute<? extends J, AJ> attribute, Class<? extends AJ> type) throws CannotContainSubGraphException;
|
||||
<AJ> SubGraph<? extends AJ> addSubGraph(PersistentAttribute<? extends J, AJ> attribute, Class<? extends AJ> type) throws CannotContainSubGraphException;
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -114,6 +115,6 @@ public interface Graph<J> extends GraphNode<J> {
|
|||
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName) throws CannotContainSubGraphException;
|
||||
<AJ> SubGraph<AJ> addKeySubGraph(String attributeName, Class<AJ> type) throws CannotContainSubGraphException;
|
||||
|
||||
<AJ> SubGraph<AJ> addKeySubGraph(Attribute<? extends J,AJ> attribute) throws CannotContainSubGraphException;
|
||||
<AJ> SubGraph<? extends AJ> addKeySubGraph(Attribute<? extends J,AJ> attribute, Class<? extends AJ> type) throws CannotContainSubGraphException;
|
||||
<AJ> SubGraph<AJ> addKeySubGraph(PersistentAttribute<? extends J,AJ> attribute) throws CannotContainSubGraphException;
|
||||
<AJ> SubGraph<? extends AJ> addKeySubGraph(PersistentAttribute<? extends J,AJ> attribute, Class<? extends AJ> type) throws CannotContainSubGraphException;
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ import org.hibernate.graph.spi.AttributeNodeImplementor;
|
|||
import org.hibernate.graph.spi.GraphImplementor;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
|
||||
/**
|
||||
* Base class for {@link RootGraph} and {@link SubGraph} implementations.
|
||||
|
@ -32,11 +32,12 @@ import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements GraphImplementor<J> {
|
||||
private final ManagedTypeDescriptor<J> managedType;
|
||||
private Map<PersistentAttributeDescriptor<?,?>, AttributeNodeImplementor<?>> attrNodeMap;
|
||||
private final ManagedDomainType<J> managedType;
|
||||
private Map<PersistentAttribute<?,?>, AttributeNodeImplementor<?>> attrNodeMap;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public AbstractGraph(
|
||||
ManagedTypeDescriptor<J> managedType,
|
||||
ManagedDomainType<J> managedType,
|
||||
boolean mutable,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super( mutable, sessionFactory );
|
||||
|
@ -62,14 +63,14 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
|||
}
|
||||
|
||||
@Override
|
||||
public ManagedTypeDescriptor<J> getGraphedType() {
|
||||
public ManagedDomainType<J> getGraphedType() {
|
||||
return managedType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public RootGraphImplementor<J> makeRootGraph(String name, boolean mutable) {
|
||||
if ( getGraphedType() instanceof EntityTypeDescriptor ) {
|
||||
if ( getGraphedType() instanceof EntityDomainType ) {
|
||||
return new RootGraphImpl( name, mutable, this );
|
||||
}
|
||||
|
||||
|
@ -88,7 +89,7 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
|||
for ( GraphImplementor<J> other : others ) {
|
||||
for ( AttributeNodeImplementor<?> attributeNode : other.getAttributeNodeImplementors() ) {
|
||||
final AttributeNodeImplementor localAttributeNode = findAttributeNode(
|
||||
(PersistentAttributeDescriptor) attributeNode.getAttributeDescriptor()
|
||||
(PersistentAttribute) attributeNode.getAttributeDescriptor()
|
||||
);
|
||||
if ( localAttributeNode != null ) {
|
||||
// keep the local one, but merge in the incoming one
|
||||
|
@ -139,17 +140,17 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(String attributeName) {
|
||||
final PersistentAttributeDescriptor<? super J, ?> attribute = managedType.findAttribute( attributeName );
|
||||
final PersistentAttribute<? super J, ?> attribute = managedType.findAttribute( attributeName );
|
||||
if ( attribute == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return findAttributeNode( (PersistentAttributeDescriptor) attribute );
|
||||
return findAttributeNode( (PersistentAttribute) attribute );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttributeDescriptor<? extends J, AJ> attribute) {
|
||||
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttribute<? extends J, AJ> attribute) {
|
||||
if ( attrNodeMap == null ) {
|
||||
return null;
|
||||
}
|
||||
|
@ -176,14 +177,14 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
|||
}
|
||||
|
||||
@Override
|
||||
public <AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttributeDescriptor<? extends J, AJ> attribute)
|
||||
public <AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttribute<? extends J, AJ> attribute)
|
||||
throws CannotContainSubGraphException {
|
||||
return findOrCreateAttributeNode( attribute );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttributeDescriptor<? extends J, AJ> attribute) {
|
||||
public <AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttribute<? extends J, AJ> attribute) {
|
||||
verifyMutability();
|
||||
|
||||
AttributeNodeImplementor attrNode = null;
|
||||
|
|
|
@ -17,9 +17,9 @@ import org.hibernate.graph.SubGraph;
|
|||
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
|
@ -31,7 +31,7 @@ import org.jboss.logging.Logger;
|
|||
public class AttributeNodeImpl<J>
|
||||
extends AbstractGraphNode<J>
|
||||
implements AttributeNodeImplementor<J> {
|
||||
private final PersistentAttributeDescriptor<?, J> attribute;
|
||||
private final PersistentAttribute<?, J> attribute;
|
||||
|
||||
private Map<Class<? extends J>, SubGraphImplementor<? extends J>> subGraphMap;
|
||||
private Map<Class<? extends J>, SubGraphImplementor<? extends J>> keySubGraphMap;
|
||||
|
@ -39,7 +39,7 @@ public class AttributeNodeImpl<J>
|
|||
@SuppressWarnings("WeakerAccess")
|
||||
public <X> AttributeNodeImpl(
|
||||
boolean mutable,
|
||||
PersistentAttributeDescriptor<X, J> attribute,
|
||||
PersistentAttribute<X, J> attribute,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
this( mutable, attribute, null, null, sessionFactory );
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class AttributeNodeImpl<J>
|
|||
*/
|
||||
private AttributeNodeImpl(
|
||||
boolean mutable,
|
||||
PersistentAttributeDescriptor<?, J> attribute,
|
||||
PersistentAttribute<?, J> attribute,
|
||||
Map<Class<? extends J>, SubGraphImplementor<? extends J>> subGraphMap,
|
||||
Map<Class<? extends J>, SubGraphImplementor<? extends J>> keySubGraphMap,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
|
@ -65,7 +65,7 @@ public class AttributeNodeImpl<J>
|
|||
}
|
||||
|
||||
@Override
|
||||
public PersistentAttributeDescriptor<?, J> getAttributeDescriptor() {
|
||||
public PersistentAttribute<?, J> getAttributeDescriptor() {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
|
@ -102,14 +102,14 @@ public class AttributeNodeImpl<J>
|
|||
}
|
||||
|
||||
@Override
|
||||
public <S extends J> SubGraphImplementor<S> makeSubGraph(ManagedTypeDescriptor<S> subtype) {
|
||||
public <S extends J> SubGraphImplementor<S> makeSubGraph(ManagedDomainType<S> subtype) {
|
||||
return internalMakeSubgraph( subtype );
|
||||
}
|
||||
|
||||
private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(ManagedTypeDescriptor<S> type) {
|
||||
private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(ManagedDomainType<S> type) {
|
||||
assert type != null;
|
||||
|
||||
log.debugf( "Making sub-graph : ( (%s) %s )", type.getName(), getAttributeName() );
|
||||
log.debugf( "Making sub-graph : ( (%s) %s )", type.getTypeName(), getAttributeName() );
|
||||
|
||||
final SubGraphImplementor<S> subGraph = type.makeSubGraph();
|
||||
internalAddSubGraph( type.getJavaType(), subGraph );
|
||||
|
@ -118,11 +118,11 @@ public class AttributeNodeImpl<J>
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends J> ManagedTypeDescriptor<T> valueGraphTypeAsManaged() {
|
||||
final SimpleTypeDescriptor<J> valueGraphType = (SimpleTypeDescriptor) getAttributeDescriptor().getValueGraphType();
|
||||
private <T extends J> ManagedDomainType<T> valueGraphTypeAsManaged() {
|
||||
final SimpleDomainType<J> valueGraphType = (SimpleDomainType) getAttributeDescriptor().getValueGraphType();
|
||||
|
||||
if ( valueGraphType instanceof ManagedTypeDescriptor ) {
|
||||
return (ManagedTypeDescriptor) valueGraphType;
|
||||
if ( valueGraphType instanceof ManagedDomainType ) {
|
||||
return (ManagedDomainType) valueGraphType;
|
||||
}
|
||||
|
||||
throw new CannotContainSubGraphException(
|
||||
|
@ -141,7 +141,7 @@ public class AttributeNodeImpl<J>
|
|||
private <S extends J> SubGraphImplementor<S> internalMakeSubgraph(Class<S> subType) {
|
||||
verifyMutability();
|
||||
|
||||
final ManagedTypeDescriptor<S> managedType = valueGraphTypeAsManaged();
|
||||
final ManagedDomainType<S> managedType = valueGraphTypeAsManaged();
|
||||
|
||||
if ( subType == null ) {
|
||||
subType = managedType.getJavaType();
|
||||
|
@ -183,13 +183,13 @@ public class AttributeNodeImpl<J>
|
|||
}
|
||||
|
||||
@Override
|
||||
public <S extends J> SubGraphImplementor<S> makeKeySubGraph(ManagedTypeDescriptor<S> subtype) {
|
||||
public <S extends J> SubGraphImplementor<S> makeKeySubGraph(ManagedDomainType<S> subtype) {
|
||||
return internalMakeKeySubgraph( subtype );
|
||||
}
|
||||
|
||||
private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(ManagedTypeDescriptor<S> type) {
|
||||
private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(ManagedDomainType<S> type) {
|
||||
|
||||
log.debugf( "Making key sub-graph : ( (%s) %s )", type.getName(), getAttributeName() );
|
||||
log.debugf( "Making key sub-graph : ( (%s) %s )", type.getTypeName(), getAttributeName() );
|
||||
|
||||
final SubGraphImplementor<S> subGraph = type.makeSubGraph();
|
||||
internalAddKeySubGraph( type.getJavaType(), subGraph );
|
||||
|
@ -201,9 +201,9 @@ public class AttributeNodeImpl<J>
|
|||
private <S extends J> SubGraphImplementor<S> internalMakeKeySubgraph(Class<S> type) {
|
||||
verifyMutability();
|
||||
|
||||
final ManagedTypeDescriptor<S> managedType = keyGraphTypeAsManaged();
|
||||
final ManagedDomainType<S> managedType = keyGraphTypeAsManaged();
|
||||
|
||||
final ManagedTypeDescriptor<S> subType;
|
||||
final ManagedDomainType<S> subType;
|
||||
|
||||
if ( type == null ) {
|
||||
subType = managedType;
|
||||
|
@ -232,18 +232,18 @@ public class AttributeNodeImpl<J>
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends J> ManagedTypeDescriptor<T> keyGraphTypeAsManaged() {
|
||||
final SimpleTypeDescriptor<J> keyGraphType = (SimpleTypeDescriptor) getAttributeDescriptor().getKeyGraphType();
|
||||
private <T extends J> ManagedDomainType<T> keyGraphTypeAsManaged() {
|
||||
final SimpleDomainType<J> keyGraphType = (SimpleDomainType) getAttributeDescriptor().getKeyGraphType();
|
||||
|
||||
if ( keyGraphType instanceof ManagedTypeDescriptor ) {
|
||||
return (ManagedTypeDescriptor) keyGraphType;
|
||||
if ( keyGraphType instanceof ManagedDomainType ) {
|
||||
return (ManagedDomainType) keyGraphType;
|
||||
}
|
||||
|
||||
throw new CannotContainSubGraphException(
|
||||
String.format(
|
||||
Locale.ROOT,
|
||||
"Attribute [%s#%s] (%s) cannot contain key sub-graphs - %s",
|
||||
getAttributeDescriptor().getDeclaringType().getName(),
|
||||
getAttributeDescriptor().getDeclaringType().getTypeName(),
|
||||
getAttributeName(),
|
||||
getAttributeDescriptor().getPersistentAttributeType().name(),
|
||||
keyGraphType
|
||||
|
|
|
@ -14,8 +14,8 @@ import org.hibernate.graph.SubGraph;
|
|||
import org.hibernate.graph.spi.GraphImplementor;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
|
||||
/**
|
||||
* The Hibernate implementation of the JPA EntityGraph contract.
|
||||
|
@ -27,14 +27,14 @@ public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>
|
|||
|
||||
public RootGraphImpl(
|
||||
String name,
|
||||
EntityTypeDescriptor<J> entityType,
|
||||
EntityDomainType<J> entityType,
|
||||
boolean mutable,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super( entityType, mutable, sessionFactory );
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public RootGraphImpl(String name, EntityTypeDescriptor<J> entityType, SessionFactoryImplementor sessionFactory) {
|
||||
public RootGraphImpl(String name, EntityDomainType<J> entityType, SessionFactoryImplementor sessionFactory) {
|
||||
this(
|
||||
name,
|
||||
entityType,
|
||||
|
@ -78,12 +78,12 @@ public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(EntityTypeDescriptor<? super J> entityType) {
|
||||
public boolean appliesTo(EntityDomainType<? super J> entityType) {
|
||||
if ( this.getGraphedType().equals( entityType ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
IdentifiableTypeDescriptor superType = entityType.getSupertype();
|
||||
IdentifiableDomainType superType = entityType.getSupertype();
|
||||
while ( superType != null ) {
|
||||
if ( superType.equals( entityType ) ) {
|
||||
return true;
|
||||
|
|
|
@ -11,15 +11,15 @@ import javax.persistence.metamodel.Attribute;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SubGraphImpl<J> extends AbstractGraph<J> implements SubGraphImplementor<J> {
|
||||
public SubGraphImpl(
|
||||
ManagedTypeDescriptor<J> managedType,
|
||||
ManagedDomainType<J> managedType,
|
||||
boolean mutable,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super( managedType, mutable, sessionFactory );
|
||||
|
@ -51,16 +51,16 @@ public class SubGraphImpl<J> extends AbstractGraph<J> implements SubGraphImpleme
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <AJ> AttributeNodeImplementor<AJ> addAttributeNode(Attribute<? extends J, AJ> attribute) {
|
||||
return addAttributeNode( (PersistentAttributeDescriptor) attribute );
|
||||
return addAttributeNode( (PersistentAttribute) attribute );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(ManagedTypeDescriptor<? super J> managedType) {
|
||||
public boolean appliesTo(ManagedDomainType<? super J> managedType) {
|
||||
if ( this.getGraphedType().equals( managedType ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ManagedTypeDescriptor superType = managedType.getSuperType();
|
||||
ManagedDomainType superType = managedType.getSuperType();
|
||||
while ( superType != null ) {
|
||||
if ( superType.equals( managedType ) ) {
|
||||
return true;
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
package org.hibernate.graph.internal.parse;
|
||||
|
||||
import org.hibernate.graph.CannotContainSubGraphException;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -34,14 +34,14 @@ public enum PathQualifierType {
|
|||
)
|
||||
);
|
||||
|
||||
private static ManagedTypeDescriptor resolveSubTypeManagedType(
|
||||
SimpleTypeDescriptor<?> graphType,
|
||||
private static ManagedDomainType resolveSubTypeManagedType(
|
||||
SimpleDomainType<?> graphType,
|
||||
String subTypeName) {
|
||||
if ( !( graphType instanceof ManagedTypeDescriptor ) ) {
|
||||
if ( !( graphType instanceof ManagedDomainType ) ) {
|
||||
throw new CannotContainSubGraphException( "The given type [" + graphType + "] is not a ManagedType" );
|
||||
}
|
||||
|
||||
ManagedTypeDescriptor managedType = (ManagedTypeDescriptor) graphType;
|
||||
ManagedDomainType managedType = (ManagedDomainType) graphType;
|
||||
|
||||
if ( subTypeName != null ) {
|
||||
managedType = managedType.findSubType( subTypeName );
|
||||
|
|
|
@ -12,8 +12,7 @@ import javax.persistence.Subgraph;
|
|||
|
||||
import org.hibernate.graph.AttributeNode;
|
||||
import org.hibernate.graph.SubGraph;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
|
||||
/**
|
||||
* Integration version of the AttributeNode contract
|
||||
|
@ -22,9 +21,6 @@ import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface AttributeNodeImplementor<J> extends AttributeNode<J>, GraphNodeImplementor<J> {
|
||||
@Override
|
||||
PersistentAttributeDescriptor<?, J> getAttributeDescriptor();
|
||||
|
||||
Map<Class<? extends J>, SubGraphImplementor<? extends J>> getSubGraphMap();
|
||||
Map<Class<? extends J>, SubGraphImplementor<? extends J>> getKeySubGraphMap();
|
||||
|
||||
|
@ -75,9 +71,9 @@ public interface AttributeNodeImplementor<J> extends AttributeNode<J>, GraphNode
|
|||
@Override
|
||||
<S extends J> SubGraphImplementor<S> makeKeySubGraph(Class<S> subtype);
|
||||
|
||||
<S extends J> SubGraphImplementor<S> makeSubGraph(ManagedTypeDescriptor<S> subtype);
|
||||
<S extends J> SubGraphImplementor<S> makeSubGraph(ManagedDomainType<S> subtype);
|
||||
|
||||
<S extends J> SubGraphImplementor<S> makeKeySubGraph(ManagedTypeDescriptor<S> subtype);
|
||||
<S extends J> SubGraphImplementor<S> makeKeySubGraph(ManagedDomainType<S> subtype);
|
||||
|
||||
void merge(AttributeNodeImplementor<?> attributeNode);
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
*/
|
||||
package org.hibernate.graph.spi;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.MapPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
import org.hibernate.metamodel.model.domain.MapPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
||||
|
||||
/**
|
||||
* Helper containing utilities useful for graph handling
|
||||
|
@ -19,25 +19,25 @@ import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
|||
*/
|
||||
public class GraphHelper {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <J> SimpleTypeDescriptor<J> resolveKeyTypeDescriptor(SingularPersistentAttribute attribute) {
|
||||
public static <J> SimpleDomainType<J> resolveKeyTypeDescriptor(SingularPersistentAttribute attribute) {
|
||||
// only valid for entity-valued attributes where the entity has a
|
||||
// composite id
|
||||
final SimpleTypeDescriptor attributeType = attribute.getType();
|
||||
if ( attributeType instanceof IdentifiableTypeDescriptor ) {
|
||||
return ( (IdentifiableTypeDescriptor) attributeType ).getIdType();
|
||||
final SimpleDomainType attributeType = attribute.getType();
|
||||
if ( attributeType instanceof IdentifiableDomainType ) {
|
||||
return ( (IdentifiableDomainType) attributeType ).getIdType();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <J> SimpleTypeDescriptor<J> resolveKeyTypeDescriptor(PluralPersistentAttribute attribute) {
|
||||
@SuppressWarnings({"unchecked", "ConstantConditions"})
|
||||
public static <J> SimpleDomainType<J> resolveKeyTypeDescriptor(PluralPersistentAttribute attribute) {
|
||||
if ( attribute instanceof SingularPersistentAttribute ) {
|
||||
// only valid for entity-valued attributes where the entity has a
|
||||
// composite id
|
||||
final SimpleTypeDescriptor attributeType = ( (SingularPersistentAttribute) attribute ).getType();
|
||||
if ( attributeType instanceof IdentifiableTypeDescriptor ) {
|
||||
return ( (IdentifiableTypeDescriptor) attributeType ).getIdType();
|
||||
final SimpleDomainType attributeType = ( (SingularPersistentAttribute) attribute ).getType();
|
||||
if ( attributeType instanceof IdentifiableDomainType ) {
|
||||
return ( (IdentifiableDomainType) attributeType ).getIdType();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -8,16 +8,14 @@ package org.hibernate.graph.spi;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import javax.persistence.metamodel.Attribute;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.graph.AttributeNode;
|
||||
import org.hibernate.graph.CannotBecomeEntityGraphException;
|
||||
import org.hibernate.graph.CannotContainSubGraphException;
|
||||
import org.hibernate.graph.Graph;
|
||||
import org.hibernate.graph.SubGraph;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
|
||||
/**
|
||||
* Integration version of the Graph contract
|
||||
|
@ -27,7 +25,7 @@ import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
|||
* @author Andrea Boriero
|
||||
*/
|
||||
public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
||||
boolean appliesTo(ManagedTypeDescriptor<? super J> managedType);
|
||||
boolean appliesTo(ManagedDomainType<? super J> managedType);
|
||||
|
||||
boolean appliesTo(Class<? super J> javaType);
|
||||
|
||||
|
@ -40,9 +38,6 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
|||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Co-variant returns
|
||||
|
||||
@Override
|
||||
ManagedTypeDescriptor<J> getGraphedType();
|
||||
|
||||
@Override
|
||||
RootGraphImplementor<J> makeRootGraph(String name, boolean mutable) throws CannotBecomeEntityGraphException;
|
||||
|
||||
|
@ -73,32 +68,22 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
|||
@Override
|
||||
<AJ> AttributeNodeImplementor<AJ> findAttributeNode(String attributeName);
|
||||
|
||||
<AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttributeDescriptor<? extends J, AJ> attribute);
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> AttributeNodeImplementor<AJ> findAttributeNode(Attribute<? extends J, AJ> attribute) {
|
||||
return (AttributeNodeImplementor) findAttributeNode( (PersistentAttributeDescriptor) attribute );
|
||||
}
|
||||
<AJ> AttributeNodeImplementor<AJ> findAttributeNode(PersistentAttribute<? extends J, AJ> attribute);
|
||||
|
||||
@Override
|
||||
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(String attributeName) throws CannotContainSubGraphException;
|
||||
|
||||
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttributeDescriptor<? extends J, AJ> attribute) throws CannotContainSubGraphException;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> AttributeNodeImplementor<AJ> addAttributeNode(Attribute<? extends J, AJ> attribute)
|
||||
throws CannotContainSubGraphException {
|
||||
return addAttributeNode( (PersistentAttributeDescriptor) attribute );
|
||||
}
|
||||
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttribute<? extends J, AJ> attribute)
|
||||
throws CannotContainSubGraphException;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(String name) {
|
||||
return findOrCreateAttributeNode( (PersistentAttributeDescriptor) getGraphedType().getAttribute( name ) );
|
||||
return findOrCreateAttributeNode( (PersistentAttribute) getGraphedType().getAttribute( name ) );
|
||||
}
|
||||
|
||||
<AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttributeDescriptor<? extends J, AJ> attribute);
|
||||
<AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttribute<? extends J, AJ> attribute);
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -111,35 +96,24 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> SubGraphImplementor<AJ> addSubGraph(String attributeName, Class<AJ> subType) throws CannotContainSubGraphException {
|
||||
default <AJ> SubGraphImplementor<AJ> addSubGraph(String attributeName, Class<AJ> subType)
|
||||
throws CannotContainSubGraphException {
|
||||
return findOrCreateAttributeNode( attributeName ).makeSubGraph( subType );
|
||||
}
|
||||
|
||||
default <AJ> SubGraphImplementor<AJ> addSubGraph(PersistentAttributeDescriptor<? extends J, AJ> attribute)
|
||||
@Override
|
||||
default <AJ> SubGraphImplementor<AJ> addSubGraph(PersistentAttribute<? extends J, AJ> attribute)
|
||||
throws CannotContainSubGraphException {
|
||||
return findOrCreateAttributeNode( attribute ).makeSubGraph();
|
||||
}
|
||||
|
||||
default <AJ> SubGraphImplementor<AJ> addSubGraph(PersistentAttributeDescriptor<? extends J, AJ> attribute, Class<AJ> subType)
|
||||
throws CannotContainSubGraphException {
|
||||
@Override
|
||||
default <AJ> SubGraphImplementor<? extends AJ> addSubGraph(
|
||||
PersistentAttribute<? extends J, AJ> attribute,
|
||||
Class<? extends AJ> subType) throws CannotContainSubGraphException {
|
||||
return findOrCreateAttributeNode( attribute ).makeSubGraph( subType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> SubGraphImplementor<AJ> addSubGraph(Attribute<? extends J, AJ> attribute)
|
||||
throws CannotContainSubGraphException {
|
||||
return addSubGraph( (PersistentAttributeDescriptor) attribute );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> SubGraph<? extends AJ> addSubGraph(Attribute<? extends J, AJ> attribute, Class<? extends AJ> type)
|
||||
throws CannotContainSubGraphException {
|
||||
return addSubGraph( (PersistentAttributeDescriptor) attribute, type );
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// key sub graph nodes
|
||||
|
@ -151,35 +125,19 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> SubGraphImplementor<AJ> addKeySubGraph(String attributeName, Class<AJ> subtype) {
|
||||
return findOrCreateAttributeNode( attributeName ).makeKeySubGraph( subtype );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> SubGraphImplementor<AJ> addKeySubGraph(PersistentAttributeDescriptor<? extends J, AJ> attribute) {
|
||||
@Override
|
||||
default <AJ> SubGraphImplementor<AJ> addKeySubGraph(PersistentAttribute<? extends J, AJ> attribute) {
|
||||
return findOrCreateAttributeNode( attribute ).makeKeySubGraph();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> SubGraphImplementor<AJ> addKeySubGraph(Attribute<? extends J, AJ> attribute) {
|
||||
return addKeySubGraph( (PersistentAttributeDescriptor) attribute );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> SubGraphImplementor<? extends AJ> addKeySubGraph(
|
||||
PersistentAttributeDescriptor<? extends J, AJ> attribute,
|
||||
PersistentAttribute<? extends J, AJ> attribute,
|
||||
Class<? extends AJ> subType) throws CannotContainSubGraphException {
|
||||
return findOrCreateAttributeNode( attribute ).makeKeySubGraph( subType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
default <AJ> SubGraphImplementor<? extends AJ> addKeySubGraph(
|
||||
Attribute<? extends J, AJ> attribute,
|
||||
Class<? extends AJ> subType) throws CannotContainSubGraphException {
|
||||
return addKeySubGraph( (PersistentAttributeDescriptor) attribute, subType );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
package org.hibernate.graph.spi;
|
||||
|
||||
import org.hibernate.graph.RootGraph;
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
|
||||
/**
|
||||
* Integration version of the RootGraph contract
|
||||
|
@ -16,13 +16,13 @@ import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface RootGraphImplementor<J> extends RootGraph<J>, GraphImplementor<J> {
|
||||
boolean appliesTo(EntityTypeDescriptor<? super J> entityType);
|
||||
boolean appliesTo(EntityDomainType<? super J> entityType);
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
default boolean appliesTo(ManagedTypeDescriptor<? super J> managedType) {
|
||||
assert managedType instanceof EntityTypeDescriptor;
|
||||
return appliesTo( (EntityTypeDescriptor) managedType );
|
||||
default boolean appliesTo(ManagedDomainType<? super J> managedType) {
|
||||
assert managedType instanceof EntityDomainType;
|
||||
return appliesTo( (EntityDomainType) managedType );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,12 +6,10 @@
|
|||
*/
|
||||
package org.hibernate.graph.spi;
|
||||
|
||||
import javax.persistence.metamodel.Attribute;
|
||||
|
||||
import org.hibernate.graph.CannotBecomeEntityGraphException;
|
||||
import org.hibernate.graph.CannotContainSubGraphException;
|
||||
import org.hibernate.graph.SubGraph;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
|
||||
/**
|
||||
* Integration version of the SubGraph contract
|
||||
|
@ -38,11 +36,10 @@ public interface SubGraphImplementor<J> extends SubGraph<J>, GraphImplementor<J>
|
|||
<AJ> SubGraphImplementor<AJ> addKeySubGraph(String attributeName);
|
||||
|
||||
@Override
|
||||
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(Attribute<? extends J, AJ> attribute);
|
||||
<AJ> AttributeNodeImplementor<AJ> addAttributeNode(PersistentAttribute<? extends J, AJ> attribute);
|
||||
|
||||
@Override
|
||||
default <AJ> SubGraphImplementor<? extends AJ> addKeySubGraph(
|
||||
PersistentAttributeDescriptor<? extends J, AJ> attribute, Class<? extends AJ> subType)
|
||||
default <AJ> SubGraphImplementor<? extends AJ> addKeySubGraph(PersistentAttribute<? extends J, AJ> attribute, Class<? extends AJ> subType)
|
||||
throws CannotContainSubGraphException {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel;
|
||||
|
||||
import javax.persistence.metamodel.PluralAttribute;
|
||||
|
||||
/**
|
||||
* Classifications of the plurality.
|
||||
*/
|
||||
public enum CollectionClassification {
|
||||
SET( PluralAttribute.CollectionType.SET ),
|
||||
LIST( PluralAttribute.CollectionType.LIST ),
|
||||
MAP( PluralAttribute.CollectionType.MAP ),
|
||||
BAG( PluralAttribute.CollectionType.COLLECTION ),
|
||||
SORTED_SET( PluralAttribute.CollectionType.SET ),
|
||||
ORDERED_SET( PluralAttribute.CollectionType.SET ),
|
||||
SORTED_MAP( PluralAttribute.CollectionType.MAP ),
|
||||
ORDERED_MAP( PluralAttribute.CollectionType.MAP ),
|
||||
IDBAG( PluralAttribute.CollectionType.COLLECTION ),
|
||||
ARRAY( PluralAttribute.CollectionType.COLLECTION );
|
||||
|
||||
private final PluralAttribute.CollectionType jpaClassification;
|
||||
|
||||
CollectionClassification(PluralAttribute.CollectionType jpaClassification) {
|
||||
this.jpaClassification = jpaClassification;
|
||||
}
|
||||
|
||||
public PluralAttribute.CollectionType toJpaClassification() {
|
||||
return jpaClassification;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Enumeration of the built-in ways that Hibernate can represent the
|
||||
* application's domain model.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum RepresentationMode {
|
||||
POJO( "pojo" ),
|
||||
MAP( "map", "dynamic-map" );
|
||||
|
||||
private final String externalName;
|
||||
private final String alternativeExternalName;
|
||||
|
||||
RepresentationMode(String externalName) {
|
||||
this ( externalName, null );
|
||||
}
|
||||
|
||||
RepresentationMode(String externalName, String alternativeExternalName) {
|
||||
this.externalName = externalName;
|
||||
this.alternativeExternalName = alternativeExternalName;
|
||||
}
|
||||
|
||||
public String getExternalName() {
|
||||
return externalName;
|
||||
}
|
||||
|
||||
public static RepresentationMode fromExternalName(String externalName) {
|
||||
if ( externalName == null ) {
|
||||
return POJO;
|
||||
}
|
||||
|
||||
if ( MAP.externalName.equalsIgnoreCase( externalName )
|
||||
|| MAP.alternativeExternalName.equalsIgnoreCase( externalName ) ) {
|
||||
return MAP;
|
||||
}
|
||||
|
||||
if ( POJO.externalName.equalsIgnoreCase( externalName ) ) {
|
||||
return POJO;
|
||||
}
|
||||
|
||||
return valueOf( externalName.toUpperCase( Locale.ROOT ) );
|
||||
}
|
||||
}
|
|
@ -29,25 +29,28 @@ import org.hibernate.mapping.OneToMany;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.Value;
|
||||
import org.hibernate.metamodel.model.domain.internal.AbstractIdentifiableType;
|
||||
import org.hibernate.metamodel.model.AttributeClassification;
|
||||
import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.internal.BasicTypeImpl;
|
||||
import org.hibernate.metamodel.model.domain.internal.EmbeddableTypeImpl;
|
||||
import org.hibernate.metamodel.model.domain.internal.MapMember;
|
||||
import org.hibernate.metamodel.model.domain.internal.MappedSuperclassTypeImpl;
|
||||
import org.hibernate.metamodel.model.domain.internal.PluralAttributeBuilder;
|
||||
import org.hibernate.metamodel.model.domain.internal.SingularAttributeImpl;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.EmbeddedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
||||
import org.hibernate.property.access.internal.PropertyAccessMapImpl;
|
||||
import org.hibernate.property.access.spi.Getter;
|
||||
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||
import org.hibernate.type.ComponentType;
|
||||
import org.hibernate.type.EmbeddedComponentType;
|
||||
import org.hibernate.type.EntityType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* A factory for building {@link Attribute} instances. Exposes 3 main services for building<ol>
|
||||
|
@ -79,13 +82,13 @@ public class AttributeFactory {
|
|||
* @return The built attribute descriptor or null if the attribute is not part of the JPA 2 model (eg backrefs)
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public <X, Y> PersistentAttributeDescriptor<X, Y> buildAttribute(ManagedTypeDescriptor<X> ownerType, Property property) {
|
||||
public <X, Y> PersistentAttribute<X, Y> buildAttribute(ManagedDomainType<X> ownerType, Property property) {
|
||||
if ( property.isSynthetic() ) {
|
||||
// hide synthetic/virtual properties (fabricated by Hibernate) from the JPA metamodel.
|
||||
LOG.tracef( "Skipping synthetic property %s(%s)", ownerType.getName(), property.getName() );
|
||||
LOG.tracef( "Skipping synthetic property %s(%s)", ownerType.getTypeName(), property.getName() );
|
||||
return null;
|
||||
}
|
||||
LOG.trace( "Building attribute [" + ownerType.getName() + "." + property.getName() + "]" );
|
||||
LOG.trace( "Building attribute [" + ownerType.getTypeName() + "." + property.getName() + "]" );
|
||||
final AttributeContext<X> attributeContext = wrap( ownerType, property );
|
||||
final AttributeMetadata<X, Y> attributeMetadata = determineAttributeMetadata( attributeContext, normalMemberResolver );
|
||||
if ( attributeMetadata == null ) {
|
||||
|
@ -95,11 +98,11 @@ public class AttributeFactory {
|
|||
return buildPluralAttribute( (PluralAttributeMetadata) attributeMetadata );
|
||||
}
|
||||
final SingularAttributeMetadata<X, Y> singularAttributeMetadata = (SingularAttributeMetadata<X, Y>) attributeMetadata;
|
||||
final SimpleTypeDescriptor<Y> metaModelType = determineSimpleType( singularAttributeMetadata.getValueContext() );
|
||||
final SimpleDomainType<Y> metaModelType = determineSimpleType( singularAttributeMetadata.getValueContext() );
|
||||
return new SingularAttributeImpl(
|
||||
ownerType,
|
||||
attributeMetadata.getName(),
|
||||
attributeMetadata.getJpaAttributeNature(),
|
||||
attributeMetadata.getAttributeClassification(),
|
||||
metaModelType,
|
||||
attributeMetadata.getMember(),
|
||||
false,
|
||||
|
@ -108,9 +111,9 @@ public class AttributeFactory {
|
|||
);
|
||||
}
|
||||
|
||||
private <X> AttributeContext<X> wrap(final ManagedTypeDescriptor<X> ownerType, final Property property) {
|
||||
private <X> AttributeContext<X> wrap(final ManagedDomainType<X> ownerType, final Property property) {
|
||||
return new AttributeContext<X>() {
|
||||
public ManagedTypeDescriptor<X> getOwnerType() {
|
||||
public ManagedDomainType<X> getOwnerType() {
|
||||
return ownerType;
|
||||
}
|
||||
|
||||
|
@ -132,9 +135,9 @@ public class AttributeFactory {
|
|||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public <X, Y> SingularPersistentAttribute<X, Y> buildIdAttribute(
|
||||
IdentifiableTypeDescriptor<X> ownerType,
|
||||
IdentifiableDomainType<X> ownerType,
|
||||
Property property) {
|
||||
LOG.trace( "Building identifier attribute [" + ownerType.getName() + "." + property.getName() + "]" );
|
||||
LOG.trace( "Building identifier attribute [" + ownerType.getTypeName() + "." + property.getName() + "]" );
|
||||
|
||||
final SingularAttributeMetadata<X, Y> attributeMetadata = (SingularAttributeMetadata) determineAttributeMetadata(
|
||||
wrap( ownerType, property ),
|
||||
|
@ -146,7 +149,7 @@ public class AttributeFactory {
|
|||
property.getName(),
|
||||
determineSimpleType( attributeMetadata.getValueContext() ),
|
||||
attributeMetadata.getMember(),
|
||||
attributeMetadata.getJpaAttributeNature()
|
||||
attributeMetadata.getAttributeClassification()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -162,7 +165,7 @@ public class AttributeFactory {
|
|||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(
|
||||
IdentifiableTypeDescriptor<X> ownerType,
|
||||
IdentifiableDomainType<X> ownerType,
|
||||
Property property) {
|
||||
LOG.trace( "Building version attribute [ownerType.getTypeName()" + "." + "property.getName()]" );
|
||||
|
||||
|
@ -174,18 +177,24 @@ public class AttributeFactory {
|
|||
return new SingularAttributeImpl.Version(
|
||||
ownerType,
|
||||
property.getName(),
|
||||
attributeMetadata.getJpaAttributeNature(),
|
||||
attributeMetadata.getAttributeClassification(),
|
||||
determineSimpleType( attributeMetadata.getValueContext() ),
|
||||
attributeMetadata.getMember()
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <X, Y, E, K> PersistentAttributeDescriptor<X, Y> buildPluralAttribute(PluralAttributeMetadata<X, Y, E> attributeMetadata) {
|
||||
private <X, Y, E, K> PluralPersistentAttribute<X,Y,E> buildPluralAttribute(PluralAttributeMetadata<X, Y, E> attributeMetadata) {
|
||||
final JavaTypeDescriptor<Y> javaTypeDescriptor = context.getSessionFactory()
|
||||
.getMetamodel()
|
||||
.getTypeConfiguration()
|
||||
.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( attributeMetadata.getJavaType() );
|
||||
|
||||
final PluralAttributeBuilder info = new PluralAttributeBuilder(
|
||||
attributeMetadata.getOwnerType(),
|
||||
determineSimpleType( attributeMetadata.getElementValueContext() ),
|
||||
attributeMetadata.getJavaType(),
|
||||
javaTypeDescriptor,
|
||||
java.util.Map.class.isAssignableFrom( attributeMetadata.getJavaType() )
|
||||
? determineSimpleType( attributeMetadata.getMapKeyValueContext() )
|
||||
: null
|
||||
|
@ -194,18 +203,20 @@ public class AttributeFactory {
|
|||
return info
|
||||
.member( attributeMetadata.getMember() )
|
||||
.property( attributeMetadata.getPropertyMapping() )
|
||||
.persistentAttributeType( attributeMetadata.getJpaAttributeNature() )
|
||||
.persistentAttributeClassification( attributeMetadata.getAttributeClassification() )
|
||||
.build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <Y> SimpleTypeDescriptor<Y> determineSimpleType(ValueContext typeContext) {
|
||||
private <Y> SimpleDomainType<Y> determineSimpleType(ValueContext typeContext) {
|
||||
final JavaTypeDescriptor<Y> javaTypeDescriptor = context.getSessionFactory()
|
||||
.getMetamodel()
|
||||
.getTypeConfiguration()
|
||||
.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( typeContext.getJpaBindableType() );
|
||||
switch ( typeContext.getValueClassification() ) {
|
||||
case BASIC: {
|
||||
return new BasicTypeImpl<Y>(
|
||||
typeContext.getJpaBindableType(),
|
||||
Type.PersistenceType.BASIC
|
||||
);
|
||||
return new BasicTypeImpl<>( javaTypeDescriptor );
|
||||
}
|
||||
case ENTITY: {
|
||||
final org.hibernate.type.EntityType type = (EntityType) typeContext.getHibernateValue().getType();
|
||||
|
@ -222,19 +233,19 @@ public class AttributeFactory {
|
|||
javaType = component.getComponentClass();
|
||||
}
|
||||
|
||||
final EmbeddedTypeDescriptor<Y> embeddableType = new EmbeddableTypeImpl<Y>(
|
||||
final EmbeddableTypeImpl<Y> embeddableType = new EmbeddableTypeImpl<Y>(
|
||||
javaType,
|
||||
typeContext.getAttributeMetadata().getOwnerType(),
|
||||
(ComponentType) typeContext.getHibernateValue().getType(),
|
||||
context.getSessionFactory()
|
||||
);
|
||||
context.registerEmbeddedableType( embeddableType );
|
||||
context.registerEmbeddableType( embeddableType );
|
||||
|
||||
final ManagedTypeDescriptor.InFlightAccess<Y> inFlightAccess = embeddableType.getInFlightAccess();
|
||||
final EmbeddableTypeImpl.InFlightAccess<Y> inFlightAccess = embeddableType.getInFlightAccess();
|
||||
final Iterator<Property> subProperties = component.getPropertyIterator();
|
||||
while ( subProperties.hasNext() ) {
|
||||
final Property property = subProperties.next();
|
||||
final PersistentAttributeDescriptor<Y, Object> attribute = buildAttribute( embeddableType, property );
|
||||
final PersistentAttribute<Y, Object> attribute = buildAttribute( embeddableType, property );
|
||||
if ( attribute != null ) {
|
||||
inFlightAccess.addAttribute( attribute );
|
||||
}
|
||||
|
@ -294,10 +305,7 @@ public class AttributeFactory {
|
|||
}
|
||||
|
||||
/**
|
||||
* Basic contract for describing an attribute. The "description" is partially in terms
|
||||
* of JPA ({@link #getJpaAttributeNature} and {@link #getOwnerType}), partially in
|
||||
* terms of Hibernate ({@link #getPropertyMapping}) and partially just in terms of the java
|
||||
* model itself ({@link #getName}, {@link #getMember} and {@link #getJavaType}).
|
||||
* Basic contract for describing an attribute.
|
||||
*
|
||||
* @param <X> The attribute owner type
|
||||
* @param <Y> The attribute type.
|
||||
|
@ -325,18 +333,16 @@ public class AttributeFactory {
|
|||
Class<Y> getJavaType();
|
||||
|
||||
/**
|
||||
* Get the JPA attribute type classification for this attribute.
|
||||
*
|
||||
* @return The JPA attribute type classification
|
||||
* Get the classification for this attribute
|
||||
*/
|
||||
Attribute.PersistentAttributeType getJpaAttributeNature();
|
||||
AttributeClassification getAttributeClassification();
|
||||
|
||||
/**
|
||||
* Retrieve the attribute owner's metamodel information
|
||||
*
|
||||
* @return The metamodel information for the attribute owner
|
||||
*/
|
||||
ManagedTypeDescriptor<X> getOwnerType();
|
||||
ManagedDomainType<X> getOwnerType();
|
||||
|
||||
/**
|
||||
* Retrieve the Hibernate property mapping related to this attribute.
|
||||
|
@ -411,7 +417,7 @@ public class AttributeFactory {
|
|||
*
|
||||
* @return The owner.
|
||||
*/
|
||||
ManagedTypeDescriptor<X> getOwnerType();
|
||||
ManagedDomainType<X> getOwnerType();
|
||||
|
||||
/**
|
||||
* Retrieve the Hibernate property mapping.
|
||||
|
@ -471,7 +477,7 @@ public class AttributeFactory {
|
|||
attributeContext.getPropertyMapping(),
|
||||
attributeContext.getOwnerType(),
|
||||
member,
|
||||
determineSingularAssociationAttributeType( member )
|
||||
determineSingularAssociationClassification( member )
|
||||
);
|
||||
}
|
||||
// collection
|
||||
|
@ -482,8 +488,8 @@ public class AttributeFactory {
|
|||
|
||||
// First, determine the type of the elements and use that to help determine the
|
||||
// collection type)
|
||||
final Attribute.PersistentAttributeType elementPersistentAttributeType;
|
||||
final Attribute.PersistentAttributeType persistentAttributeType;
|
||||
final AttributeClassification elementClassification;
|
||||
final AttributeClassification attributeClassification;
|
||||
if ( elementType.isAnyType() ) {
|
||||
if ( context.isIgnoreUnsupported() ) {
|
||||
return null;
|
||||
|
@ -494,21 +500,21 @@ public class AttributeFactory {
|
|||
}
|
||||
final boolean isManyToMany = isManyToMany( member );
|
||||
if ( elementValue instanceof Component ) {
|
||||
elementPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED;
|
||||
persistentAttributeType = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
|
||||
elementClassification = AttributeClassification.EMBEDDED;
|
||||
attributeClassification = AttributeClassification.ELEMENT_COLLECTION;
|
||||
}
|
||||
else if ( elementType.isAssociationType() ) {
|
||||
elementPersistentAttributeType = isManyToMany ?
|
||||
Attribute.PersistentAttributeType.MANY_TO_MANY :
|
||||
Attribute.PersistentAttributeType.ONE_TO_MANY;
|
||||
persistentAttributeType = elementPersistentAttributeType;
|
||||
elementClassification = isManyToMany ?
|
||||
AttributeClassification.MANY_TO_MANY :
|
||||
AttributeClassification.ONE_TO_MANY;
|
||||
attributeClassification = elementClassification;
|
||||
}
|
||||
else {
|
||||
elementPersistentAttributeType = Attribute.PersistentAttributeType.BASIC;
|
||||
persistentAttributeType = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
|
||||
elementClassification = AttributeClassification.BASIC;
|
||||
attributeClassification = AttributeClassification.ELEMENT_COLLECTION;
|
||||
}
|
||||
|
||||
final Attribute.PersistentAttributeType keyPersistentAttributeType;
|
||||
final AttributeClassification indexClassification;
|
||||
|
||||
// Finally, we determine the type of the map key (if needed)
|
||||
if ( value instanceof Map ) {
|
||||
|
@ -524,25 +530,25 @@ public class AttributeFactory {
|
|||
}
|
||||
}
|
||||
if ( keyValue instanceof Component ) {
|
||||
keyPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED;
|
||||
indexClassification = AttributeClassification.EMBEDDED;
|
||||
}
|
||||
else if ( keyType.isAssociationType() ) {
|
||||
keyPersistentAttributeType = Attribute.PersistentAttributeType.MANY_TO_ONE;
|
||||
indexClassification = AttributeClassification.MANY_TO_ONE;
|
||||
}
|
||||
else {
|
||||
keyPersistentAttributeType = Attribute.PersistentAttributeType.BASIC;
|
||||
indexClassification = AttributeClassification.BASIC;
|
||||
}
|
||||
}
|
||||
else {
|
||||
keyPersistentAttributeType = null;
|
||||
indexClassification = null;
|
||||
}
|
||||
return new PluralAttributeMetadataImpl(
|
||||
attributeContext.getPropertyMapping(),
|
||||
attributeContext.getOwnerType(),
|
||||
member,
|
||||
persistentAttributeType,
|
||||
elementPersistentAttributeType,
|
||||
keyPersistentAttributeType
|
||||
attributeClassification,
|
||||
elementClassification,
|
||||
indexClassification
|
||||
);
|
||||
}
|
||||
else if ( value instanceof OneToMany ) {
|
||||
|
@ -567,58 +573,58 @@ public class AttributeFactory {
|
|||
}
|
||||
else if ( attributeContext.getPropertyMapping().isComposite() ) {
|
||||
// component
|
||||
return new SingularAttributeMetadataImpl<X, Y>(
|
||||
return new SingularAttributeMetadataImpl<>(
|
||||
attributeContext.getPropertyMapping(),
|
||||
attributeContext.getOwnerType(),
|
||||
member,
|
||||
Attribute.PersistentAttributeType.EMBEDDED
|
||||
AttributeClassification.EMBEDDED
|
||||
);
|
||||
}
|
||||
else {
|
||||
// basic type
|
||||
return new SingularAttributeMetadataImpl<X, Y>(
|
||||
return new SingularAttributeMetadataImpl<>(
|
||||
attributeContext.getPropertyMapping(),
|
||||
attributeContext.getOwnerType(),
|
||||
member,
|
||||
Attribute.PersistentAttributeType.BASIC
|
||||
AttributeClassification.BASIC
|
||||
);
|
||||
}
|
||||
throw new UnsupportedOperationException( "oops, we are missing something: " + attributeContext.getPropertyMapping() );
|
||||
}
|
||||
|
||||
public static Attribute.PersistentAttributeType determineSingularAssociationAttributeType(Member member) {
|
||||
if ( Field.class.isInstance( member ) ) {
|
||||
public static AttributeClassification determineSingularAssociationClassification(Member member) {
|
||||
if ( member instanceof Field ) {
|
||||
return ( (Field) member ).getAnnotation( OneToOne.class ) != null
|
||||
? Attribute.PersistentAttributeType.ONE_TO_ONE
|
||||
: Attribute.PersistentAttributeType.MANY_TO_ONE;
|
||||
? AttributeClassification.ONE_TO_ONE
|
||||
: AttributeClassification.MANY_TO_ONE;
|
||||
}
|
||||
else if ( MapMember.class.isInstance( member ) ) {
|
||||
return Attribute.PersistentAttributeType.MANY_TO_ONE; // curious to see how this works for non-annotated methods
|
||||
else if ( member instanceof MapMember ) {
|
||||
return AttributeClassification.MANY_TO_ONE; // curious to see how this works for non-annotated methods
|
||||
}
|
||||
else {
|
||||
return ( (Method) member ).getAnnotation( OneToOne.class ) != null
|
||||
? Attribute.PersistentAttributeType.ONE_TO_ONE
|
||||
: Attribute.PersistentAttributeType.MANY_TO_ONE;
|
||||
? AttributeClassification.ONE_TO_ONE
|
||||
: AttributeClassification.MANY_TO_ONE;
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class BaseAttributeMetadata<X, Y> implements AttributeMetadata<X, Y> {
|
||||
private final Property propertyMapping;
|
||||
private final ManagedTypeDescriptor<X> ownerType;
|
||||
private final ManagedDomainType<X> ownerType;
|
||||
private final Member member;
|
||||
private final Class<Y> javaType;
|
||||
private final Attribute.PersistentAttributeType persistentAttributeType;
|
||||
private final AttributeClassification attributeClassification;
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
protected BaseAttributeMetadata(
|
||||
Property propertyMapping,
|
||||
ManagedTypeDescriptor<X> ownerType,
|
||||
ManagedDomainType<X> ownerType,
|
||||
Member member,
|
||||
Attribute.PersistentAttributeType persistentAttributeType) {
|
||||
AttributeClassification attributeClassification) {
|
||||
this.propertyMapping = propertyMapping;
|
||||
this.ownerType = ownerType;
|
||||
this.member = member;
|
||||
this.persistentAttributeType = persistentAttributeType;
|
||||
this.attributeClassification = attributeClassification;
|
||||
|
||||
final Class declaredType;
|
||||
|
||||
|
@ -661,11 +667,12 @@ public class AttributeFactory {
|
|||
return javaType;
|
||||
}
|
||||
|
||||
public Attribute.PersistentAttributeType getJpaAttributeNature() {
|
||||
return persistentAttributeType;
|
||||
@Override
|
||||
public AttributeClassification getAttributeClassification() {
|
||||
return attributeClassification;
|
||||
}
|
||||
|
||||
public ManagedTypeDescriptor<X> getOwnerType() {
|
||||
public ManagedDomainType<X> getOwnerType() {
|
||||
return ownerType;
|
||||
}
|
||||
|
||||
|
@ -721,10 +728,10 @@ public class AttributeFactory {
|
|||
|
||||
private SingularAttributeMetadataImpl(
|
||||
Property propertyMapping,
|
||||
ManagedTypeDescriptor<X> ownerType,
|
||||
ManagedDomainType<X> ownerType,
|
||||
Member member,
|
||||
Attribute.PersistentAttributeType persistentAttributeType) {
|
||||
super( propertyMapping, ownerType, member, persistentAttributeType );
|
||||
AttributeClassification attributeClassification) {
|
||||
super( propertyMapping, ownerType, member, attributeClassification );
|
||||
valueContext = new ValueContext() {
|
||||
public Value getHibernateValue() {
|
||||
return getPropertyMapping().getValue();
|
||||
|
@ -735,7 +742,7 @@ public class AttributeFactory {
|
|||
}
|
||||
|
||||
public ValueClassification getValueClassification() {
|
||||
switch ( getJpaAttributeNature() ) {
|
||||
switch ( attributeClassification ) {
|
||||
case EMBEDDED: {
|
||||
return ValueClassification.EMBEDDABLE;
|
||||
}
|
||||
|
@ -763,8 +770,8 @@ public class AttributeFactory {
|
|||
extends BaseAttributeMetadata<X, Y>
|
||||
implements PluralAttributeMetadata<X, Y, E> {
|
||||
private final PluralAttribute.CollectionType attributeCollectionType;
|
||||
private final Attribute.PersistentAttributeType elementPersistentAttributeType;
|
||||
private final Attribute.PersistentAttributeType keyPersistentAttributeType;
|
||||
private final AttributeClassification elementClassification;
|
||||
private final AttributeClassification keyClassification;
|
||||
private final Class elementJavaType;
|
||||
private final Class keyJavaType;
|
||||
private final ValueContext elementValueContext;
|
||||
|
@ -772,18 +779,18 @@ public class AttributeFactory {
|
|||
|
||||
private PluralAttributeMetadataImpl(
|
||||
Property propertyMapping,
|
||||
ManagedTypeDescriptor<X> ownerType,
|
||||
ManagedDomainType<X> ownerType,
|
||||
Member member,
|
||||
Attribute.PersistentAttributeType persistentAttributeType,
|
||||
Attribute.PersistentAttributeType elementPersistentAttributeType,
|
||||
Attribute.PersistentAttributeType keyPersistentAttributeType) {
|
||||
super( propertyMapping, ownerType, member, persistentAttributeType );
|
||||
AttributeClassification attributeClassification,
|
||||
AttributeClassification elementClassification,
|
||||
AttributeClassification keyClassification) {
|
||||
super( propertyMapping, ownerType, member, attributeClassification );
|
||||
this.attributeCollectionType = determineCollectionType( getJavaType() );
|
||||
this.elementPersistentAttributeType = elementPersistentAttributeType;
|
||||
this.keyPersistentAttributeType = keyPersistentAttributeType;
|
||||
this.elementClassification = elementClassification;
|
||||
this.keyClassification = keyClassification;
|
||||
|
||||
ParameterizedType signatureType = getSignatureType( member );
|
||||
if ( keyPersistentAttributeType == null ) {
|
||||
if ( this.keyClassification == null ) {
|
||||
elementJavaType = signatureType != null ?
|
||||
getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) :
|
||||
Object.class; //FIXME and honor targetEntity?
|
||||
|
@ -808,7 +815,7 @@ public class AttributeFactory {
|
|||
}
|
||||
|
||||
public ValueClassification getValueClassification() {
|
||||
switch ( PluralAttributeMetadataImpl.this.elementPersistentAttributeType ) {
|
||||
switch ( PluralAttributeMetadataImpl.this.elementClassification ) {
|
||||
case EMBEDDED: {
|
||||
return ValueClassification.EMBEDDABLE;
|
||||
}
|
||||
|
@ -827,7 +834,7 @@ public class AttributeFactory {
|
|||
};
|
||||
|
||||
// interpret the key, if one
|
||||
if ( keyPersistentAttributeType != null ) {
|
||||
if ( this.keyClassification != null ) {
|
||||
this.keyValueContext = new ValueContext() {
|
||||
public Value getHibernateValue() {
|
||||
return ( (Map) getPropertyMapping().getValue() ).getIndex();
|
||||
|
@ -838,7 +845,7 @@ public class AttributeFactory {
|
|||
}
|
||||
|
||||
public ValueClassification getValueClassification() {
|
||||
switch ( PluralAttributeMetadataImpl.this.keyPersistentAttributeType ) {
|
||||
switch ( PluralAttributeMetadataImpl.this.keyClassification ) {
|
||||
case EMBEDDED: {
|
||||
return ValueClassification.EMBEDDABLE;
|
||||
}
|
||||
|
@ -948,45 +955,39 @@ public class AttributeFactory {
|
|||
return false;
|
||||
}
|
||||
|
||||
private final MemberResolver embeddedMemberResolver = new MemberResolver() {
|
||||
@Override
|
||||
public Member resolveMember(AttributeContext attributeContext) {
|
||||
final EmbeddedTypeDescriptor embeddableType = (EmbeddedTypeDescriptor<?>) attributeContext.getOwnerType();
|
||||
final String attributeName = attributeContext.getPropertyMapping().getName();
|
||||
private final MemberResolver embeddedMemberResolver = attributeContext -> {
|
||||
final EmbeddableDomainType embeddableType = (EmbeddableDomainType<?>) attributeContext.getOwnerType();
|
||||
final String attributeName = attributeContext.getPropertyMapping().getName();
|
||||
|
||||
final Getter getter = embeddableType.getHibernateType()
|
||||
.getComponentTuplizer()
|
||||
.getGetter( embeddableType.getHibernateType().getPropertyIndex( attributeName ) );
|
||||
return PropertyAccessMapImpl.GetterImpl.class.isInstance( getter )
|
||||
? new MapMember( attributeName, attributeContext.getPropertyMapping().getType().getReturnedClass() )
|
||||
: getter.getMember();
|
||||
}
|
||||
final Getter getter = embeddableType.getHibernateType()
|
||||
.getComponentTuplizer()
|
||||
.getGetter( embeddableType.getHibernateType().getPropertyIndex( attributeName ) );
|
||||
return PropertyAccessMapImpl.GetterImpl.class.isInstance( getter )
|
||||
? new MapMember( attributeName, attributeContext.getPropertyMapping().getType().getReturnedClass() )
|
||||
: getter.getMember();
|
||||
};
|
||||
|
||||
|
||||
private final MemberResolver virtualIdentifierMemberResolver = new MemberResolver() {
|
||||
@Override
|
||||
public Member resolveMember(AttributeContext attributeContext) {
|
||||
final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType();
|
||||
final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType );
|
||||
if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) {
|
||||
throw new IllegalArgumentException( "expecting IdClass mapping" );
|
||||
}
|
||||
org.hibernate.type.Type type = entityMetamodel.getIdentifierProperty().getType();
|
||||
if ( !EmbeddedComponentType.class.isInstance( type ) ) {
|
||||
throw new IllegalArgumentException( "expecting IdClass mapping" );
|
||||
}
|
||||
|
||||
final EmbeddedComponentType componentType = (EmbeddedComponentType) type;
|
||||
final String attributeName = attributeContext.getPropertyMapping().getName();
|
||||
|
||||
final Getter getter = componentType.getComponentTuplizer()
|
||||
.getGetter( componentType.getPropertyIndex( attributeName ) );
|
||||
|
||||
return PropertyAccessMapImpl.GetterImpl.class.isInstance( getter )
|
||||
? new MapMember( attributeName, attributeContext.getPropertyMapping().getType().getReturnedClass() )
|
||||
: getter.getMember();
|
||||
private final MemberResolver virtualIdentifierMemberResolver = attributeContext -> {
|
||||
final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType();
|
||||
final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType );
|
||||
if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) {
|
||||
throw new IllegalArgumentException( "expecting IdClass mapping" );
|
||||
}
|
||||
org.hibernate.type.Type type = entityMetamodel.getIdentifierProperty().getType();
|
||||
if ( !EmbeddedComponentType.class.isInstance( type ) ) {
|
||||
throw new IllegalArgumentException( "expecting IdClass mapping" );
|
||||
}
|
||||
|
||||
final EmbeddedComponentType componentType = (EmbeddedComponentType) type;
|
||||
final String attributeName = attributeContext.getPropertyMapping().getName();
|
||||
|
||||
final Getter getter = componentType.getComponentTuplizer()
|
||||
.getGetter( componentType.getPropertyIndex( attributeName ) );
|
||||
|
||||
return PropertyAccessMapImpl.GetterImpl.class.isInstance( getter )
|
||||
? new MapMember( attributeName, attributeContext.getPropertyMapping().getType().getReturnedClass() )
|
||||
: getter.getMember();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -995,7 +996,7 @@ public class AttributeFactory {
|
|||
private final MemberResolver normalMemberResolver = new MemberResolver() {
|
||||
@Override
|
||||
public Member resolveMember(AttributeContext attributeContext) {
|
||||
final ManagedTypeDescriptor ownerType = attributeContext.getOwnerType();
|
||||
final ManagedDomainType ownerType = attributeContext.getOwnerType();
|
||||
final Property property = attributeContext.getPropertyMapping();
|
||||
final Type.PersistenceType persistenceType = ownerType.getPersistenceType();
|
||||
if ( Type.PersistenceType.EMBEDDABLE == persistenceType ) {
|
||||
|
|
|
@ -32,16 +32,17 @@ import org.hibernate.mapping.KeyValue;
|
|||
import org.hibernate.mapping.MappedSuperclass;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.metamodel.model.domain.internal.AbstractIdentifiableType;
|
||||
import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.internal.AttributeContainer;
|
||||
import org.hibernate.metamodel.model.domain.internal.EntityTypeImpl;
|
||||
import org.hibernate.metamodel.model.domain.internal.MappedSuperclassTypeImpl;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.EmbeddedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.MappedSuperclassTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
||||
|
||||
/**
|
||||
* Defines a context for storing information during the building of the {@link MetamodelImpl}.
|
||||
|
@ -51,7 +52,7 @@ import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
|||
* <p/>
|
||||
* At the end of the day, clients are interested in the {@link #getEntityTypeMap} and {@link #getEmbeddableTypeSet}
|
||||
* results, which represent all the registered {@linkplain #registerEntityType entities} and
|
||||
* {@linkplain #registerEmbeddedableType embeddables} respectively.
|
||||
* {@linkplain #registerEmbeddableType embeddables} respectively.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Emmanuel Bernard
|
||||
|
@ -64,14 +65,14 @@ class MetadataContext {
|
|||
private final boolean ignoreUnsupported;
|
||||
private final AttributeFactory attributeFactory = new AttributeFactory( this );
|
||||
|
||||
private Map<Class<?>, EntityTypeDescriptor<?>> entityTypes = new HashMap<>();
|
||||
private Map<String, EntityTypeDescriptor<?>> entityTypesByEntityName = new HashMap<>();
|
||||
private Map<PersistentClass, EntityTypeDescriptor<?>> entityTypesByPersistentClass = new HashMap<>();
|
||||
private Map<Class<?>, EntityDomainType<?>> entityTypes = new HashMap<>();
|
||||
private Map<String, EntityDomainType<?>> entityTypesByEntityName = new HashMap<>();
|
||||
private Map<PersistentClass, EntityDomainType<?>> entityTypesByPersistentClass = new HashMap<>();
|
||||
|
||||
private Set<EmbeddedTypeDescriptor<?>> embeddables = new HashSet<>();
|
||||
private Set<EmbeddableDomainType<?>> embeddables = new HashSet<>();
|
||||
|
||||
private Map<MappedSuperclass, MappedSuperclassTypeDescriptor<?>> mappedSuperclassByMappedSuperclassMapping = new HashMap<>();
|
||||
private Map<MappedSuperclassTypeDescriptor<?>, PersistentClass> mappedSuperClassTypeToPersistentClass = new HashMap<>();
|
||||
private Map<MappedSuperclass, MappedSuperclassDomainType<?>> mappedSuperclassByMappedSuperclassMapping = new HashMap<>();
|
||||
private Map<MappedSuperclassDomainType<?>, PersistentClass> mappedSuperClassTypeToPersistentClass = new HashMap<>();
|
||||
|
||||
//this list contains MappedSuperclass and EntityTypes ordered by superclass first
|
||||
private List<Object> orderedMappings = new ArrayList<>();
|
||||
|
@ -103,11 +104,11 @@ class MetadataContext {
|
|||
*
|
||||
* @return The {@linkplain Class java type} to {@link EntityTypeImpl} map.
|
||||
*/
|
||||
public Map<Class<?>, EntityTypeDescriptor<?>> getEntityTypeMap() {
|
||||
public Map<Class<?>, EntityDomainType<?>> getEntityTypeMap() {
|
||||
return Collections.unmodifiableMap( entityTypes );
|
||||
}
|
||||
|
||||
public Set<EmbeddedTypeDescriptor<?>> getEmbeddableTypeSet() {
|
||||
public Set<EmbeddableDomainType<?>> getEmbeddableTypeSet() {
|
||||
return Collections.unmodifiableSet( embeddables );
|
||||
}
|
||||
|
||||
|
@ -117,7 +118,7 @@ class MetadataContext {
|
|||
mappedSuperclassByMappedSuperclassMapping.size()
|
||||
);
|
||||
|
||||
for ( MappedSuperclassTypeDescriptor mappedSuperclassType : mappedSuperclassByMappedSuperclassMapping.values() ) {
|
||||
for ( MappedSuperclassDomainType mappedSuperclassType : mappedSuperclassByMappedSuperclassMapping.values() ) {
|
||||
mappedSuperClassTypeMap.put(
|
||||
mappedSuperclassType.getJavaType(),
|
||||
mappedSuperclassType
|
||||
|
@ -141,15 +142,15 @@ class MetadataContext {
|
|||
orderedMappings.add( persistentClass );
|
||||
}
|
||||
|
||||
/*package*/ void registerEmbeddedableType(EmbeddedTypeDescriptor<?> embeddableType) {
|
||||
if ( !( ignoreUnsupported && embeddableType.getParent().getJavaType() == null ) ) {
|
||||
/*package*/ void registerEmbeddableType(EmbeddableDomainType<?> embeddableType) {
|
||||
if ( !( ignoreUnsupported && Map.class.isAssignableFrom( embeddableType.getJavaTypeDescriptor().getJavaType() ) ) ) {
|
||||
embeddables.add( embeddableType );
|
||||
}
|
||||
}
|
||||
|
||||
/*package*/ void registerMappedSuperclassType(
|
||||
MappedSuperclass mappedSuperclass,
|
||||
MappedSuperclassTypeDescriptor<?> mappedSuperclassType) {
|
||||
MappedSuperclassDomainType<?> mappedSuperclassType) {
|
||||
mappedSuperclassByMappedSuperclassMapping.put( mappedSuperclass, mappedSuperclassType );
|
||||
orderedMappings.add( mappedSuperclass );
|
||||
mappedSuperClassTypeToPersistentClass.put( mappedSuperclassType, getEntityWorkedOn() );
|
||||
|
@ -165,7 +166,7 @@ class MetadataContext {
|
|||
*
|
||||
* @return Tne corresponding JPA {@link org.hibernate.type.EntityType}, or null if not yet processed.
|
||||
*/
|
||||
public EntityTypeDescriptor<?> locateEntityType(PersistentClass persistentClass) {
|
||||
public EntityDomainType<?> locateEntityType(PersistentClass persistentClass) {
|
||||
return entityTypesByPersistentClass.get( persistentClass );
|
||||
}
|
||||
|
||||
|
@ -177,7 +178,7 @@ class MetadataContext {
|
|||
*
|
||||
* @return The corresponding JPA {@link org.hibernate.type.EntityType}, or null.
|
||||
*/
|
||||
public EntityTypeDescriptor<?> locateEntityType(Class<?> javaType) {
|
||||
public EntityDomainType<?> locateEntityType(Class<?> javaType) {
|
||||
return entityTypes.get( javaType );
|
||||
}
|
||||
|
||||
|
@ -190,11 +191,11 @@ class MetadataContext {
|
|||
* @return The corresponding JPA {@link org.hibernate.type.EntityType}, or null.
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public <E> EntityTypeDescriptor<E> locateEntityType(String entityName) {
|
||||
return (EntityTypeDescriptor) entityTypesByEntityName.get( entityName );
|
||||
public <E> EntityDomainType<E> locateEntityType(String entityName) {
|
||||
return (EntityDomainType) entityTypesByEntityName.get( entityName );
|
||||
}
|
||||
|
||||
public Map<String, EntityTypeDescriptor<?>> getEntityTypesByEntityName() {
|
||||
public Map<String, EntityDomainType<?>> getEntityTypesByEntityName() {
|
||||
return Collections.unmodifiableMap( entityTypesByEntityName );
|
||||
}
|
||||
|
||||
|
@ -216,7 +217,7 @@ class MetadataContext {
|
|||
LOG.trace( "Starting entity [" + safeMapping.getEntityName() + ']' );
|
||||
}
|
||||
try {
|
||||
final EntityTypeDescriptor<?> jpaMapping = entityTypesByPersistentClass.get( safeMapping );
|
||||
final EntityDomainType<?> jpaMapping = entityTypesByPersistentClass.get( safeMapping );
|
||||
|
||||
applyIdMetadata( safeMapping, jpaMapping );
|
||||
applyVersionAttribute( safeMapping, jpaMapping );
|
||||
|
@ -234,13 +235,13 @@ class MetadataContext {
|
|||
// skip the version property, it was already handled previously.
|
||||
continue;
|
||||
}
|
||||
final PersistentAttributeDescriptor attribute = attributeFactory.buildAttribute( jpaMapping, property );
|
||||
final PersistentAttribute attribute = attributeFactory.buildAttribute( jpaMapping, property );
|
||||
if ( attribute != null ) {
|
||||
jpaMapping.getInFlightAccess().addAttribute( attribute );
|
||||
( ( AttributeContainer) jpaMapping ).getInFlightAccess().addAttribute( attribute );
|
||||
}
|
||||
}
|
||||
|
||||
jpaMapping.getInFlightAccess().finishUp();
|
||||
( ( AttributeContainer) jpaMapping ).getInFlightAccess().finishUp();
|
||||
|
||||
if ( staticMetamodelScanEnabled ) {
|
||||
populateStaticMetamodel( jpaMapping );
|
||||
|
@ -259,7 +260,7 @@ class MetadataContext {
|
|||
LOG.trace( "Starting mapped superclass [" + safeMapping.getMappedClass().getName() + ']' );
|
||||
}
|
||||
try {
|
||||
final MappedSuperclassTypeDescriptor<?> jpaType = mappedSuperclassByMappedSuperclassMapping.get( safeMapping );
|
||||
final MappedSuperclassDomainType<?> jpaType = mappedSuperclassByMappedSuperclassMapping.get( safeMapping );
|
||||
|
||||
applyIdMetadata( safeMapping, jpaType );
|
||||
applyVersionAttribute( safeMapping, jpaType );
|
||||
|
@ -271,12 +272,12 @@ class MetadataContext {
|
|||
// skip the version property, it was already handled previously.
|
||||
continue;
|
||||
}
|
||||
final PersistentAttributeDescriptor attribute = attributeFactory.buildAttribute( jpaType, property );
|
||||
final PersistentAttribute attribute = attributeFactory.buildAttribute( jpaType, property );
|
||||
if ( attribute != null ) {
|
||||
jpaType.getInFlightAccess().addAttribute( attribute );
|
||||
( ( AttributeContainer) jpaType ).getInFlightAccess().addAttribute( attribute );
|
||||
}
|
||||
}
|
||||
jpaType.getInFlightAccess().finishUp();
|
||||
( ( AttributeContainer) jpaType ).getInFlightAccess().finishUp();
|
||||
|
||||
if ( staticMetamodelScanEnabled ) {
|
||||
populateStaticMetamodel( jpaType );
|
||||
|
@ -294,7 +295,7 @@ class MetadataContext {
|
|||
}
|
||||
|
||||
if ( staticMetamodelScanEnabled ) {
|
||||
for ( EmbeddedTypeDescriptor embeddable : embeddables ) {
|
||||
for ( EmbeddableDomainType embeddable : embeddables ) {
|
||||
populateStaticMetamodel( embeddable );
|
||||
}
|
||||
}
|
||||
|
@ -302,20 +303,20 @@ class MetadataContext {
|
|||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <X> void applyIdMetadata(PersistentClass persistentClass, IdentifiableTypeDescriptor<?> identifiableType) {
|
||||
private <X> void applyIdMetadata(PersistentClass persistentClass, IdentifiableDomainType<?> identifiableType) {
|
||||
if ( persistentClass.hasIdentifierProperty() ) {
|
||||
final Property declaredIdentifierProperty = persistentClass.getDeclaredIdentifierProperty();
|
||||
if ( declaredIdentifierProperty != null ) {
|
||||
identifiableType.getInFlightAccess().applyIdAttribute(
|
||||
(SingularPersistentAttribute) attributeFactory.buildIdAttribute( identifiableType, declaredIdentifierProperty )
|
||||
( ( AttributeContainer) identifiableType ).getInFlightAccess().applyIdAttribute(
|
||||
attributeFactory.buildIdAttribute( identifiableType, declaredIdentifierProperty )
|
||||
);
|
||||
}
|
||||
}
|
||||
else if ( persistentClass.hasIdentifierMapper() ) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<Property> propertyIterator = persistentClass.getIdentifierMapper().getPropertyIterator();
|
||||
identifiableType.getInFlightAccess().applyIdClassAttributes(
|
||||
(Set) buildIdClassAttributes( identifiableType, propertyIterator )
|
||||
( ( AttributeContainer) identifiableType ).getInFlightAccess().applyIdClassAttributes(
|
||||
buildIdClassAttributes( identifiableType, propertyIterator )
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -327,8 +328,8 @@ class MetadataContext {
|
|||
}
|
||||
else {
|
||||
//FIXME take care of declared vs non declared property
|
||||
identifiableType.getInFlightAccess().applyIdAttribute(
|
||||
(SingularPersistentAttribute) attributeFactory.buildIdAttribute(
|
||||
( ( AttributeContainer) identifiableType ).getInFlightAccess().applyIdAttribute(
|
||||
attributeFactory.buildIdAttribute(
|
||||
identifiableType,
|
||||
(Property) component.getPropertyIterator().next()
|
||||
)
|
||||
|
@ -338,11 +339,12 @@ class MetadataContext {
|
|||
}
|
||||
}
|
||||
|
||||
private <X> void applyIdMetadata(MappedSuperclass mappingType, MappedSuperclassTypeDescriptor<X> jpaMappingType) {
|
||||
private <X> void applyIdMetadata(MappedSuperclass mappingType, MappedSuperclassDomainType<X> jpaMappingType) {
|
||||
if ( mappingType.hasIdentifierProperty() ) {
|
||||
final Property declaredIdentifierProperty = mappingType.getDeclaredIdentifierProperty();
|
||||
if ( declaredIdentifierProperty != null ) {
|
||||
jpaMappingType.getInFlightAccess().applyIdAttribute(
|
||||
//noinspection unchecked
|
||||
( ( AttributeContainer) jpaMappingType ).getInFlightAccess().applyIdAttribute(
|
||||
attributeFactory.buildIdAttribute( jpaMappingType, declaredIdentifierProperty )
|
||||
);
|
||||
}
|
||||
|
@ -355,30 +357,33 @@ class MetadataContext {
|
|||
jpaMappingType,
|
||||
propertyIterator
|
||||
);
|
||||
jpaMappingType.getInFlightAccess().applyIdClassAttributes( attributes );
|
||||
//noinspection unchecked
|
||||
( ( AttributeContainer) jpaMappingType ).getInFlightAccess().applyIdClassAttributes( attributes );
|
||||
}
|
||||
}
|
||||
|
||||
private <X> void applyVersionAttribute(PersistentClass persistentClass, EntityTypeDescriptor<X> jpaEntityType) {
|
||||
private <X> void applyVersionAttribute(PersistentClass persistentClass, EntityDomainType<X> jpaEntityType) {
|
||||
final Property declaredVersion = persistentClass.getDeclaredVersion();
|
||||
if ( declaredVersion != null ) {
|
||||
jpaEntityType.getInFlightAccess().applyVersionAttribute(
|
||||
//noinspection unchecked
|
||||
( ( AttributeContainer) jpaEntityType ).getInFlightAccess().applyVersionAttribute(
|
||||
attributeFactory.buildVersionAttribute( jpaEntityType, declaredVersion )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private <X> void applyVersionAttribute(MappedSuperclass mappingType, MappedSuperclassTypeDescriptor<X> jpaMappingType) {
|
||||
private <X> void applyVersionAttribute(MappedSuperclass mappingType, MappedSuperclassDomainType<X> jpaMappingType) {
|
||||
final Property declaredVersion = mappingType.getDeclaredVersion();
|
||||
if ( declaredVersion != null ) {
|
||||
jpaMappingType.getInFlightAccess().applyVersionAttribute(
|
||||
//noinspection unchecked
|
||||
( ( AttributeContainer) jpaMappingType ).getInFlightAccess().applyVersionAttribute(
|
||||
attributeFactory.buildVersionAttribute( jpaMappingType, declaredVersion )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private <X> Set<SingularPersistentAttribute<? super X, ?>> buildIdClassAttributes(
|
||||
IdentifiableTypeDescriptor<X> ownerType,
|
||||
IdentifiableDomainType<X> ownerType,
|
||||
Iterator<Property> propertyIterator) {
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.trace( "Building old-school composite identifier [" + ownerType.getJavaType().getName() + ']' );
|
||||
|
@ -390,7 +395,7 @@ class MetadataContext {
|
|||
return attributes;
|
||||
}
|
||||
|
||||
private <X> void populateStaticMetamodel(ManagedTypeDescriptor<X> managedType) {
|
||||
private <X> void populateStaticMetamodel(ManagedDomainType<X> managedType) {
|
||||
final Class<X> managedTypeClass = managedType.getJavaType();
|
||||
if ( managedTypeClass == null ) {
|
||||
// should indicate MAP entity mode, skip...
|
||||
|
@ -408,7 +413,7 @@ class MetadataContext {
|
|||
|
||||
// todo : this does not account for @MappeSuperclass, mainly because this is not being tracked in our
|
||||
// internal metamodel as populated from the annotations properly
|
||||
ManagedTypeDescriptor<? super X> superType = managedType.getSuperType();
|
||||
ManagedDomainType<? super X> superType = managedType.getSuperType();
|
||||
if ( superType != null ) {
|
||||
populateStaticMetamodel( superType );
|
||||
}
|
||||
|
@ -416,7 +421,7 @@ class MetadataContext {
|
|||
|
||||
private final Set<Class> processedMetamodelClasses = new HashSet<Class>();
|
||||
|
||||
private <X> void registerAttributes(Class metamodelClass, ManagedTypeDescriptor<X> managedType) {
|
||||
private <X> void registerAttributes(Class metamodelClass, ManagedDomainType<X> managedType) {
|
||||
if ( !processedMetamodelClasses.add( metamodelClass ) ) {
|
||||
return;
|
||||
}
|
||||
|
@ -426,7 +431,7 @@ class MetadataContext {
|
|||
registerAttribute( metamodelClass, attribute );
|
||||
}
|
||||
|
||||
if ( IdentifiableType.class.isInstance( managedType ) ) {
|
||||
if ( managedType instanceof IdentifiableType ) {
|
||||
final AbstractIdentifiableType<X> entityType = (AbstractIdentifiableType<X>) managedType;
|
||||
|
||||
// handle version
|
||||
|
@ -504,7 +509,7 @@ class MetadataContext {
|
|||
}
|
||||
}
|
||||
|
||||
public MappedSuperclassTypeDescriptor<?> locateMappedSuperclassType(MappedSuperclass mappedSuperclass) {
|
||||
public MappedSuperclassDomainType<?> locateMappedSuperclassType(MappedSuperclass mappedSuperclass) {
|
||||
return mappedSuperclassByMappedSuperclassMapping.get( mappedSuperclass );
|
||||
}
|
||||
|
||||
|
|
|
@ -60,11 +60,11 @@ import org.hibernate.mapping.RootClass;
|
|||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.metamodel.model.domain.internal.EntityTypeImpl;
|
||||
import org.hibernate.metamodel.model.domain.internal.MappedSuperclassTypeImpl;
|
||||
import org.hibernate.metamodel.model.domain.spi.EmbeddedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.MappedSuperclassTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType;
|
||||
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
@ -74,6 +74,7 @@ import org.hibernate.persister.spi.PersisterFactory;
|
|||
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||
import org.hibernate.type.AssociationType;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
|
@ -98,8 +99,8 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
private final Map<String,Set<String>> collectionRolesByEntityParticipant = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<EntityNameResolver,Object> entityNameResolvers = new ConcurrentHashMap<>();
|
||||
|
||||
private final Map<Class<?>, EntityTypeDescriptor<?>> jpaEntityTypeMap = new ConcurrentHashMap<>();
|
||||
private final Map<String, EntityTypeDescriptor<?>> jpaEntityTypesByEntityName = new ConcurrentHashMap<>();
|
||||
private final Map<Class<?>, EntityDomainType<?>> jpaEntityTypeMap = new ConcurrentHashMap<>();
|
||||
private final Map<String, EntityDomainType<?>> jpaEntityTypesByEntityName = new ConcurrentHashMap<>();
|
||||
|
||||
private final Map<Class<?>, MappedSuperclassType<?>> jpaMappedSuperclassTypeMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
@ -123,7 +124,7 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
/**
|
||||
* There can be multiple instances of an Embeddable type, each one being relative to its parent entity.
|
||||
*/
|
||||
private final Set<EmbeddedTypeDescriptor<?>> jpaEmbeddableTypes = new CopyOnWriteArraySet<>();
|
||||
private final Set<EmbeddableDomainType<?>> jpaEmbeddableTypes = new CopyOnWriteArraySet<>();
|
||||
|
||||
/**
|
||||
* That's not strictly correct in the JPA standard since for a given Java type we could have
|
||||
|
@ -133,7 +134,7 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
* A better approach would be if the parent class and attribute name would be included as well
|
||||
* when trying to locate the embeddable type.
|
||||
*/
|
||||
private final Map<Class<?>, EmbeddedTypeDescriptor<?>> jpaEmbeddableTypeMap = new ConcurrentHashMap<>();
|
||||
private final Map<Class<?>, EmbeddableDomainType<?>> jpaEmbeddableTypeMap = new ConcurrentHashMap<>();
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
private final transient Map<String,RootGraphImplementor> entityGraphMap = new ConcurrentHashMap<>();
|
||||
|
@ -275,7 +276,7 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
|
||||
this.jpaEntityTypeMap.putAll( context.getEntityTypeMap() );
|
||||
this.jpaEmbeddableTypes.addAll( context.getEmbeddableTypeSet() );
|
||||
for ( EmbeddedTypeDescriptor<?> embeddable: jpaEmbeddableTypes ) {
|
||||
for ( EmbeddableDomainType<?> embeddable: jpaEmbeddableTypes ) {
|
||||
this.jpaEmbeddableTypeMap.put( embeddable.getJavaType(), embeddable );
|
||||
}
|
||||
this.jpaMappedSuperclassTypeMap.putAll( context.getMappedSuperclassTypeMap() );
|
||||
|
@ -340,7 +341,7 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
definition.getEntityName(),
|
||||
definition.getJpaEntityName()
|
||||
);
|
||||
final EntityTypeDescriptor entityType = entity( definition.getEntityName() );
|
||||
final EntityDomainType entityType = entity( definition.getEntityName() );
|
||||
if ( entityType == null ) {
|
||||
throw new IllegalArgumentException(
|
||||
"Attempted to register named entity graph [" + definition.getRegisteredName()
|
||||
|
@ -443,8 +444,8 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
private static EntityTypeDescriptor<?> locateOrBuildEntityType(PersistentClass persistentClass, MetadataContext context) {
|
||||
EntityTypeDescriptor<?> entityType = context.locateEntityType( persistentClass );
|
||||
private static EntityDomainType<?> locateOrBuildEntityType(PersistentClass persistentClass, MetadataContext context) {
|
||||
EntityDomainType<?> entityType = context.locateEntityType( persistentClass );
|
||||
if ( entityType == null ) {
|
||||
entityType = buildEntityType( persistentClass, context );
|
||||
}
|
||||
|
@ -457,7 +458,7 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
final Class javaType = persistentClass.getMappedClass();
|
||||
context.pushEntityWorkedOn( persistentClass );
|
||||
final MappedSuperclass superMappedSuperclass = persistentClass.getSuperMappedSuperclass();
|
||||
IdentifiableTypeDescriptor<?> superType = superMappedSuperclass == null
|
||||
IdentifiableDomainType<?> superType = superMappedSuperclass == null
|
||||
? null
|
||||
: locateOrBuildMappedSuperclassType( superMappedSuperclass, context );
|
||||
//no mappedSuperclass, check for a super entity
|
||||
|
@ -467,8 +468,14 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
? null
|
||||
: locateOrBuildEntityType( superPersistentClass, context );
|
||||
}
|
||||
|
||||
final JavaTypeDescriptor javaTypeDescriptor = context.getSessionFactory()
|
||||
.getMetamodel()
|
||||
.getTypeConfiguration()
|
||||
.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( javaType );
|
||||
EntityTypeImpl entityType = new EntityTypeImpl(
|
||||
javaType,
|
||||
javaTypeDescriptor,
|
||||
superType,
|
||||
persistentClass,
|
||||
context.getSessionFactory()
|
||||
|
@ -479,9 +486,9 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
return entityType;
|
||||
}
|
||||
|
||||
private static MappedSuperclassTypeDescriptor<?> locateOrBuildMappedSuperclassType(
|
||||
private static MappedSuperclassDomainType<?> locateOrBuildMappedSuperclassType(
|
||||
MappedSuperclass mappedSuperclass, MetadataContext context) {
|
||||
MappedSuperclassTypeDescriptor<?> mappedSuperclassType = context.locateMappedSuperclassType( mappedSuperclass );
|
||||
MappedSuperclassDomainType<?> mappedSuperclassType = context.locateMappedSuperclassType( mappedSuperclass );
|
||||
if ( mappedSuperclassType == null ) {
|
||||
mappedSuperclassType = buildMappedSuperclassType( mappedSuperclass, context );
|
||||
}
|
||||
|
@ -494,7 +501,7 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
MappedSuperclass mappedSuperclass,
|
||||
MetadataContext context) {
|
||||
final MappedSuperclass superMappedSuperclass = mappedSuperclass.getSuperMappedSuperclass();
|
||||
IdentifiableTypeDescriptor<?> superType = superMappedSuperclass == null
|
||||
IdentifiableDomainType<?> superType = superMappedSuperclass == null
|
||||
? null
|
||||
: locateOrBuildMappedSuperclassType( superMappedSuperclass, context );
|
||||
//no mappedSuperclass, check for a super entity
|
||||
|
@ -504,9 +511,13 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
? null
|
||||
: locateOrBuildEntityType( superPersistentClass, context );
|
||||
}
|
||||
final Class javaType = mappedSuperclass.getMappedClass();
|
||||
final JavaTypeDescriptor javaTypeDescriptor = context.getSessionFactory()
|
||||
.getMetamodel()
|
||||
.getTypeConfiguration()
|
||||
.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( mappedSuperclass.getMappedClass() );
|
||||
MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(
|
||||
javaType,
|
||||
javaTypeDescriptor,
|
||||
mappedSuperclass,
|
||||
superType,
|
||||
context.getSessionFactory()
|
||||
|
@ -560,17 +571,17 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public <X> EntityTypeDescriptor<X> entity(Class<X> cls) {
|
||||
public <X> EntityDomainType<X> entity(Class<X> cls) {
|
||||
final EntityType<?> entityType = jpaEntityTypeMap.get( cls );
|
||||
if ( entityType == null ) {
|
||||
throw new IllegalArgumentException( "Not an entity: " + cls );
|
||||
}
|
||||
return (EntityTypeDescriptor<X>) entityType;
|
||||
return (EntityDomainType<X>) entityType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public <X> ManagedTypeDescriptor<X> managedType(Class<X> cls) {
|
||||
public <X> ManagedDomainType<X> managedType(Class<X> cls) {
|
||||
ManagedType<?> type = jpaEntityTypeMap.get( cls );
|
||||
if ( type == null ) {
|
||||
type = jpaMappedSuperclassTypeMap.get( cls );
|
||||
|
@ -581,17 +592,17 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
if ( type == null ) {
|
||||
throw new IllegalArgumentException( "Not a managed type: " + cls );
|
||||
}
|
||||
return (ManagedTypeDescriptor<X>) type;
|
||||
return (ManagedDomainType<X>) type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public <X> EmbeddedTypeDescriptor<X> embeddable(Class<X> cls) {
|
||||
final EmbeddedTypeDescriptor<?> embeddableType = jpaEmbeddableTypeMap.get( cls );
|
||||
public <X> EmbeddableDomainType<X> embeddable(Class<X> cls) {
|
||||
final EmbeddableDomainType<?> embeddableType = jpaEmbeddableTypeMap.get( cls );
|
||||
if ( embeddableType == null ) {
|
||||
throw new IllegalArgumentException( "Not an embeddable: " + cls );
|
||||
}
|
||||
return (EmbeddedTypeDescriptor<X>) embeddableType;
|
||||
return (EmbeddableDomainType<X>) embeddableType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -618,8 +629,8 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <X> EntityTypeDescriptor<X> entity(String entityName) {
|
||||
return (EntityTypeDescriptor) jpaEntityTypesByEntityName.get( entityName );
|
||||
public <X> EntityDomainType<X> entity(String entityName) {
|
||||
return (EntityDomainType) jpaEntityTypesByEntityName.get( entityName );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -774,7 +785,7 @@ public class MetamodelImpl implements MetamodelImplementor, Serializable {
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<RootGraphImplementor<? super T>> findEntityGraphsByJavaType(Class<T> entityClass) {
|
||||
final EntityTypeDescriptor<T> entityType = entity( entityClass );
|
||||
final EntityDomainType<T> entityType = entity( entityClass );
|
||||
if ( entityType == null ) {
|
||||
throw new IllegalArgumentException( "Given class is not an entity : " + entityClass.getName() );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractDomainType<J> implements DomainType<J> {
|
||||
private final SessionFactoryImplementor sessionFactory;
|
||||
|
||||
private final JavaTypeDescriptor<J> javaTypeDescriptor;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public AbstractDomainType(
|
||||
JavaTypeDescriptor<J> javaTypeDescriptor,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
this.javaTypeDescriptor = javaTypeDescriptor;
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
protected SessionFactoryImplementor sessionFactory() {
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaTypeDescriptor<J> getJavaTypeDescriptor() {
|
||||
return javaTypeDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<J> getJavaType() {
|
||||
return getJavaTypeDescriptor().getJavaType();
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.internal;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
|
@ -14,11 +14,9 @@ import javax.persistence.metamodel.IdentifiableType;
|
|||
import javax.persistence.metamodel.SingularAttribute;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
||||
import org.hibernate.metamodel.RepresentationMode;
|
||||
import org.hibernate.metamodel.model.domain.internal.AttributeContainer;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* Defines commonality for the JPA {@link IdentifiableType} types. JPA defines
|
||||
|
@ -33,25 +31,25 @@ import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
|||
*/
|
||||
public abstract class AbstractIdentifiableType<J>
|
||||
extends AbstractManagedType<J>
|
||||
implements IdentifiableTypeDescriptor<J>, Serializable {
|
||||
implements IdentifiableDomainType<J>, Serializable {
|
||||
|
||||
private final boolean hasIdentifierProperty;
|
||||
private final boolean hasIdClass;
|
||||
private SingularPersistentAttribute<J, ?> id;
|
||||
private SingularPersistentAttribute<J,?> id;
|
||||
private Set<SingularPersistentAttribute<? super J,?>> idClassAttributes;
|
||||
|
||||
private final boolean isVersioned;
|
||||
private SingularPersistentAttribute<J, ?> versionAttribute;
|
||||
|
||||
public AbstractIdentifiableType(
|
||||
Class<J> javaType,
|
||||
String typeName,
|
||||
IdentifiableTypeDescriptor<? super J> superType,
|
||||
JavaTypeDescriptor<J> javaTypeDescriptor,
|
||||
IdentifiableDomainType<? super J> superType,
|
||||
boolean hasIdClass,
|
||||
boolean hasIdentifierProperty,
|
||||
boolean versioned,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super( javaType, typeName, superType, sessionFactory );
|
||||
super( typeName, javaTypeDescriptor, superType, sessionFactory );
|
||||
this.hasIdClass = hasIdClass;
|
||||
this.hasIdentifierProperty = hasIdentifierProperty;
|
||||
this.isVersioned = versioned;
|
||||
|
@ -59,13 +57,14 @@ public abstract class AbstractIdentifiableType<J>
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected IdentifiableTypeDescriptor.InFlightAccess createInFlightAccess() {
|
||||
protected InFlightAccessImpl createInFlightAccess() {
|
||||
return new InFlightAccessImpl( super.createInFlightAccess() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifiableTypeDescriptor.InFlightAccess<J> getInFlightAccess() {
|
||||
return (IdentifiableTypeDescriptor.InFlightAccess<J>) super.getInFlightAccess();
|
||||
@SuppressWarnings("unchecked")
|
||||
public InFlightAccessImpl getInFlightAccess() {
|
||||
return (InFlightAccessImpl) super.getInFlightAccess();
|
||||
}
|
||||
|
||||
public boolean hasIdClass() {
|
||||
|
@ -79,16 +78,21 @@ public abstract class AbstractIdentifiableType<J>
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public IdentifiableTypeDescriptor<? super J> getSuperType() {
|
||||
public IdentifiableDomainType<? super J> getSuperType() {
|
||||
// overridden simply to perform the cast
|
||||
return (IdentifiableTypeDescriptor) super.getSuperType();
|
||||
return (IdentifiableDomainType) super.getSuperType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifiableDomainType<? super J> getSupertype() {
|
||||
return getSuperType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public <Y> SingularPersistentAttribute<? super J, Y> getId(Class<Y> javaType) {
|
||||
ensureNoIdClass();
|
||||
SingularPersistentAttribute id = locateIdAttribute();
|
||||
SingularPersistentAttribute id = findIdAttribute();
|
||||
if ( id != null ) {
|
||||
checkType( id, javaType );
|
||||
}
|
||||
|
@ -105,14 +109,14 @@ public abstract class AbstractIdentifiableType<J>
|
|||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SingularPersistentAttribute locateIdAttribute() {
|
||||
@SuppressWarnings({"unchecked", "RedundantIfStatement"})
|
||||
public SingularPersistentAttribute findIdAttribute() {
|
||||
if ( id != null ) {
|
||||
return id;
|
||||
}
|
||||
else {
|
||||
if ( getSuperType() != null ) {
|
||||
SingularPersistentAttribute id = getSuperType().locateIdAttribute();
|
||||
SingularPersistentAttribute id = getSuperType().findIdAttribute();
|
||||
if ( id != null ) {
|
||||
return id;
|
||||
}
|
||||
|
@ -149,17 +153,16 @@ public abstract class AbstractIdentifiableType<J>
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SimpleTypeDescriptor<?> getIdType() {
|
||||
final SingularPersistentAttribute id = locateIdAttribute();
|
||||
public SimpleDomainType<?> getIdType() {
|
||||
final SingularPersistentAttribute id = findIdAttribute();
|
||||
if ( id != null ) {
|
||||
return id.getType();
|
||||
return (SimpleDomainType<?>) id.getType();
|
||||
}
|
||||
|
||||
Set<SingularPersistentAttribute<? super J, ?>> idClassAttributes = getIdClassAttributesSafely();
|
||||
if ( idClassAttributes != null ) {
|
||||
if ( idClassAttributes.size() == 1 ) {
|
||||
return idClassAttributes.iterator().next().getType();
|
||||
return (SimpleDomainType<?>) idClassAttributes.iterator().next().getType();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +180,7 @@ public abstract class AbstractIdentifiableType<J>
|
|||
return null;
|
||||
}
|
||||
final Set<SingularPersistentAttribute<? super J,?>> attributes = new HashSet<>();
|
||||
collectIdClassAttributes( attributes );
|
||||
visitIdClassAttributes( attributes::add );
|
||||
|
||||
if ( attributes.isEmpty() ) {
|
||||
return null;
|
||||
|
@ -194,7 +197,7 @@ public abstract class AbstractIdentifiableType<J>
|
|||
}
|
||||
|
||||
final Set<SingularPersistentAttribute<? super J,?>> attributes = new HashSet<>();
|
||||
collectIdClassAttributes( attributes );
|
||||
visitIdClassAttributes( attributes::add );
|
||||
|
||||
if ( attributes.isEmpty() ) {
|
||||
throw new IllegalArgumentException( "Unable to locate IdClass attributes [" + getJavaType() + "]" );
|
||||
|
@ -203,17 +206,6 @@ public abstract class AbstractIdentifiableType<J>
|
|||
return (Set) attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void collectIdClassAttributes(Set<SingularPersistentAttribute<? super J,?>> attributes) {
|
||||
if ( idClassAttributes != null ) {
|
||||
attributes.addAll( idClassAttributes );
|
||||
}
|
||||
else if ( getSuperType() != null ) {
|
||||
getSuperType().collectIdClassAttributes( (Set) attributes );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void visitIdClassAttributes(Consumer<SingularPersistentAttribute<? super J, ?>> attributeConsumer) {
|
||||
|
@ -241,7 +233,7 @@ public abstract class AbstractIdentifiableType<J>
|
|||
return null;
|
||||
}
|
||||
|
||||
SingularPersistentAttribute version = locateVersionAttribute();
|
||||
SingularPersistentAttribute version = findVersionAttribute();
|
||||
if ( version != null ) {
|
||||
checkType( version, javaType );
|
||||
}
|
||||
|
@ -249,14 +241,14 @@ public abstract class AbstractIdentifiableType<J>
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public SingularPersistentAttribute locateVersionAttribute() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public SingularPersistentAttribute findVersionAttribute() {
|
||||
if ( versionAttribute != null ) {
|
||||
return versionAttribute;
|
||||
}
|
||||
|
||||
if ( getSuperType() != null ) {
|
||||
return getSuperType().locateVersionAttribute();
|
||||
return getSuperType().findVersionAttribute();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -289,23 +281,24 @@ public abstract class AbstractIdentifiableType<J>
|
|||
return versionAttribute;
|
||||
}
|
||||
|
||||
private class InFlightAccessImpl implements IdentifiableTypeDescriptor.InFlightAccess<J> {
|
||||
private class InFlightAccessImpl extends AbstractManagedType.InFlightAccessImpl {
|
||||
private final AbstractManagedType.InFlightAccess managedTypeAccess;
|
||||
|
||||
private InFlightAccessImpl(ManagedTypeDescriptor.InFlightAccess managedTypeAccess) {
|
||||
private InFlightAccessImpl(AttributeContainer.InFlightAccess managedTypeAccess) {
|
||||
this.managedTypeAccess = managedTypeAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void applyIdAttribute(SingularPersistentAttribute<J, ?> idAttribute) {
|
||||
public void applyIdAttribute(SingularPersistentAttribute idAttribute) {
|
||||
AbstractIdentifiableType.this.id = idAttribute;
|
||||
managedTypeAccess.addAttribute( idAttribute );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyIdClassAttributes(Set<SingularPersistentAttribute<? super J,?>> idClassAttributes) {
|
||||
for ( SingularAttribute<? super J,?> idClassAttribute : idClassAttributes ) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void applyIdClassAttributes(Set idClassAttributes) {
|
||||
for ( SingularAttribute idClassAttribute : ( (Set<SingularPersistentAttribute>) idClassAttributes ) ) {
|
||||
if ( AbstractIdentifiableType.this == idClassAttribute.getDeclaringType() ) {
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
SingularPersistentAttribute<J,?> declaredAttribute = (SingularPersistentAttribute) idClassAttribute;
|
||||
|
@ -317,14 +310,14 @@ public abstract class AbstractIdentifiableType<J>
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void applyVersionAttribute(SingularPersistentAttribute<J, ?> versionAttribute) {
|
||||
public void applyVersionAttribute(SingularPersistentAttribute versionAttribute) {
|
||||
AbstractIdentifiableType.this.versionAttribute = versionAttribute;
|
||||
managedTypeAccess.addAttribute( versionAttribute );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addAttribute(PersistentAttributeDescriptor attribute) {
|
||||
public void addAttribute(PersistentAttribute attribute) {
|
||||
managedTypeAccess.addAttribute( attribute );
|
||||
}
|
||||
|
|
@ -4,15 +4,15 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.internal;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.persistence.metamodel.Attribute;
|
||||
import javax.persistence.metamodel.Bindable;
|
||||
import javax.persistence.metamodel.CollectionAttribute;
|
||||
import javax.persistence.metamodel.ListAttribute;
|
||||
import javax.persistence.metamodel.ManagedType;
|
||||
|
@ -21,48 +21,41 @@ import javax.persistence.metamodel.PluralAttribute;
|
|||
import javax.persistence.metamodel.SetAttribute;
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
|
||||
import org.hibernate.annotations.common.AssertionFailure;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.graph.internal.SubGraphImpl;
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.metamodel.model.domain.DomainType;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.BagPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.DomainModelHelper;
|
||||
import org.hibernate.metamodel.model.domain.spi.ListPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.MapPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.SetPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
||||
import org.hibernate.metamodel.RepresentationMode;
|
||||
import org.hibernate.metamodel.model.domain.internal.AttributeContainer;
|
||||
import org.hibernate.metamodel.model.domain.internal.DomainModelHelper;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* Defines commonality for the JPA {@link ManagedType} hierarchy of interfaces.
|
||||
* Commonality for Hibernate's implementations of the JPA {@link ManagedType}
|
||||
* contract.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractManagedType<J>
|
||||
extends AbstractType<J>
|
||||
implements ManagedTypeDescriptor<J>, Serializable {
|
||||
extends AbstractDomainType<J>
|
||||
implements ManagedDomainType<J>, AttributeContainer<J>, Serializable {
|
||||
private final String hibernateTypeName;
|
||||
private final ManagedDomainType<? super J> superType;
|
||||
private final RepresentationMode representationMode;
|
||||
|
||||
private final SessionFactoryImplementor sessionFactory;
|
||||
|
||||
private final ManagedTypeDescriptor<? super J> superType;
|
||||
|
||||
private final Map<String, PersistentAttributeDescriptor<J, ?>> declaredAttributes = new HashMap<>();
|
||||
private final Map<String, SingularPersistentAttribute<J, ?>> declaredSingularAttributes = new HashMap<>();
|
||||
private final Map<String, PluralPersistentAttribute<J, ?, ?>> declaredPluralAttributes = new HashMap<>();
|
||||
|
||||
private transient InFlightAccess<J> inFlightAccess;
|
||||
|
||||
protected AbstractManagedType(
|
||||
Class<J> javaType,
|
||||
String typeName,
|
||||
ManagedTypeDescriptor<? super J> superType,
|
||||
String hibernateTypeName,
|
||||
JavaTypeDescriptor<J> javaTypeDescriptor,
|
||||
ManagedDomainType<? super J> superType,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super( javaType, typeName );
|
||||
super( javaTypeDescriptor, sessionFactory );
|
||||
this.hibernateTypeName = hibernateTypeName;
|
||||
this.superType = superType;
|
||||
this.sessionFactory = sessionFactory;
|
||||
|
||||
// todo (6.0) : need to handle RepresentationMode#MAP as well
|
||||
this.representationMode = RepresentationMode.POJO;
|
||||
|
||||
this.inFlightAccess = createInFlightAccess();
|
||||
}
|
||||
|
@ -72,82 +65,96 @@ public abstract class AbstractManagedType<J>
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getTypeName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainType<J> getType() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManagedTypeDescriptor<? super J> getSuperType() {
|
||||
public ManagedDomainType<? super J> getSuperType() {
|
||||
return superType;
|
||||
}
|
||||
|
||||
protected SessionFactoryImplementor sessionFactory() {
|
||||
return sessionFactory;
|
||||
@Override
|
||||
public RepresentationMode getRepresentationMode() {
|
||||
return representationMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InFlightAccess<J> getInFlightAccess() {
|
||||
if ( inFlightAccess == null ) {
|
||||
throw new IllegalStateException( "Type has been locked" );
|
||||
}
|
||||
|
||||
return inFlightAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<Attribute<? super J, ?>> getAttributes() {
|
||||
HashSet attributes = new HashSet<Attribute<J, ?>>( declaredAttributes.values() );
|
||||
final HashSet attributes = new HashSet<>( getDeclaredAttributes() );
|
||||
|
||||
if ( getSuperType() != null ) {
|
||||
attributes.addAll( getSuperType().getAttributes() );
|
||||
}
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<Attribute<J, ?>> getDeclaredAttributes() {
|
||||
return new HashSet<>( declaredAttributes.values() );
|
||||
if ( declaredSingularAttributes.isEmpty() && declaredPluralAttributes.isEmpty() ) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
final HashSet attributes = new HashSet<>( declaredSingularAttributes.values() );
|
||||
attributes.addAll( declaredPluralAttributes.values() );
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public PersistentAttributeDescriptor<? super J, ?> getAttribute(String name) {
|
||||
PersistentAttributeDescriptor<? super J, ?> attribute = declaredAttributes.get( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getAttribute( name );
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public PersistentAttribute<? super J,?> getAttribute(String name) {
|
||||
final PersistentAttribute attribute = findAttribute( name );
|
||||
checkNotNull( "Attribute ", attribute, name );
|
||||
return attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistentAttributeDescriptor<J, ?> findDeclaredAttribute(String name) {
|
||||
return declaredAttributes.get( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistentAttributeDescriptor<? super J, ?> findAttribute(String name) {
|
||||
PersistentAttributeDescriptor<? super J, ?> attribute = findDeclaredAttribute( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().findAttribute( name );
|
||||
@SuppressWarnings("unchecked")
|
||||
public PersistentAttribute<? super J,?> findAttribute(String name) {
|
||||
// first look at declared attributes
|
||||
PersistentAttribute attribute = findDeclaredAttribute( name );
|
||||
if ( attribute != null ) {
|
||||
return attribute;
|
||||
}
|
||||
return attribute;
|
||||
|
||||
if ( getSuperType() != null ) {
|
||||
attribute = getSuperType().findAttribute( name );
|
||||
//noinspection RedundantIfStatement
|
||||
if ( attribute != null ) {
|
||||
return attribute;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistentAttributeDescriptor<J, ?> getDeclaredAttribute(String name) {
|
||||
PersistentAttributeDescriptor<J, ?> attr = declaredAttributes.get( name );
|
||||
@SuppressWarnings("unchecked")
|
||||
public PersistentAttribute<J,?> findDeclaredAttribute(String name) {
|
||||
// try singular attribute
|
||||
PersistentAttribute attribute = declaredSingularAttributes.get( name );
|
||||
if ( attribute != null ) {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
// next plural
|
||||
attribute = declaredPluralAttributes.get( name );
|
||||
//noinspection RedundantIfStatement
|
||||
if ( attribute != null ) {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public PersistentAttribute<J,?> getDeclaredAttribute(String name) {
|
||||
PersistentAttribute attr = findDeclaredAttribute( name );
|
||||
checkNotNull( "Attribute ", attr, name );
|
||||
return attr;
|
||||
}
|
||||
|
||||
private void checkNotNull(String attributeType, Attribute<?,?> attribute, String name) {
|
||||
|
||||
if ( attribute == null ) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
|
@ -160,10 +167,19 @@ public abstract class AbstractManagedType<J>
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return hibernateTypeName;
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Singular attributes
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public Set<SingularAttribute<? super J, ?>> getSingularAttributes() {
|
||||
HashSet attributes = new HashSet<SingularAttribute<J, ?>>( declaredSingularAttributes.values() );
|
||||
HashSet attributes = new HashSet<>( declaredSingularAttributes.values() );
|
||||
if ( getSuperType() != null ) {
|
||||
attributes.addAll( getSuperType().getSingularAttributes() );
|
||||
}
|
||||
|
@ -172,48 +188,57 @@ public abstract class AbstractManagedType<J>
|
|||
|
||||
@Override
|
||||
public Set<SingularAttribute<J, ?>> getDeclaredSingularAttributes() {
|
||||
return new HashSet<SingularAttribute<J, ?>>( declaredSingularAttributes.values() );
|
||||
return new HashSet<>( declaredSingularAttributes.values() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public SingularAttribute<? super J, ?> getSingularAttribute(String name) {
|
||||
SingularAttribute<? super J, ?> attribute = declaredSingularAttributes.get( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getSingularAttribute( name );
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public SingularPersistentAttribute<? super J, ?> getSingularAttribute(String name) {
|
||||
SingularPersistentAttribute attribute = findSingularAttribute( name );
|
||||
checkNotNull( "SingularAttribute ", attribute, name );
|
||||
return attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingularAttribute<J, ?> getDeclaredSingularAttribute(String name) {
|
||||
final SingularAttribute<J, ?> attr = declaredSingularAttributes.get( name );
|
||||
checkNotNull( "SingularAttribute ", attr, name );
|
||||
return attr;
|
||||
@SuppressWarnings("unchecked")
|
||||
public SingularPersistentAttribute<? super J, ?> findSingularAttribute(String name) {
|
||||
SingularPersistentAttribute attribute = findDeclaredSingularAttribute( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().findSingularAttribute( name );
|
||||
}
|
||||
return attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public <Y> SingularPersistentAttribute<? super J, Y> getSingularAttribute(String name, Class<Y> type) {
|
||||
SingularAttribute<? super J, ?> attribute = declaredSingularAttributes.get( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getSingularAttribute( name );
|
||||
}
|
||||
checkTypeForSingleAttribute( "SingularAttribute ", attribute, name, type );
|
||||
SingularAttribute attribute = findSingularAttribute( name );
|
||||
checkTypeForSingleAttribute( attribute, name, type );
|
||||
return (SingularPersistentAttribute) attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( "unchecked")
|
||||
@SuppressWarnings("unchecked")
|
||||
public SingularAttribute<J, ?> getDeclaredSingularAttribute(String name) {
|
||||
final SingularAttribute attr = findDeclaredSingularAttribute( name );
|
||||
checkNotNull( "SingularAttribute ", attr, name );
|
||||
return attr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingularPersistentAttribute<? super J, ?> findDeclaredSingularAttribute(String name) {
|
||||
return declaredSingularAttributes.get( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <Y> SingularPersistentAttribute<J, Y> getDeclaredSingularAttribute(String name, Class<Y> javaType) {
|
||||
final SingularAttribute<J, ?> attr = declaredSingularAttributes.get( name );
|
||||
checkTypeForSingleAttribute( "SingularAttribute ", attr, name, javaType );
|
||||
final SingularAttribute attr = findDeclaredSingularAttribute( name );
|
||||
checkTypeForSingleAttribute( attr, name, javaType );
|
||||
return (SingularPersistentAttribute) attr;
|
||||
}
|
||||
|
||||
private <Y> void checkTypeForSingleAttribute(
|
||||
String attributeType,
|
||||
SingularAttribute<?,?> attribute,
|
||||
String name,
|
||||
Class<Y> javaType) {
|
||||
|
@ -222,14 +247,14 @@ public abstract class AbstractManagedType<J>
|
|||
return;
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
attributeType + " named " + name
|
||||
+ ( javaType != null ? " and of type " + javaType.getName() : "" )
|
||||
+ " is not present"
|
||||
"SingularAttribute named " + name
|
||||
+ ( javaType != null ? " and of type " + javaType.getName() : "" )
|
||||
+ " is not present"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "SimplifiableIfStatement" })
|
||||
@SuppressWarnings({"SimplifiableIfStatement", "WeakerAccess"})
|
||||
protected <Y> boolean isPrimitiveVariant(SingularAttribute<?,?> attribute, Class<Y> javaType) {
|
||||
if ( attribute == null ) {
|
||||
return false;
|
||||
|
@ -261,41 +286,88 @@ public abstract class AbstractManagedType<J>
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Plural attributes
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set<PluralAttribute<? super J, ?, ?>> getPluralAttributes() {
|
||||
HashSet attributes = new HashSet<PluralAttribute<? super J, ?, ?>>( declaredPluralAttributes.values() );
|
||||
final Set attributes = getDeclaredPluralAttributes();
|
||||
|
||||
if ( getSuperType() != null ) {
|
||||
attributes.addAll( getSuperType().getPluralAttributes() );
|
||||
}
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PluralAttribute<J, ?, ?>> getDeclaredPluralAttributes() {
|
||||
return new HashSet<PluralAttribute<J,?,?>>( declaredPluralAttributes.values() );
|
||||
return new HashSet<>( declaredPluralAttributes.values() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public CollectionAttribute<? super J, ?> getCollection(String name) {
|
||||
PluralPersistentAttribute attribute = getPluralAttribute( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getPluralAttribute( name );
|
||||
@SuppressWarnings({"unchecked", "RedundantIfStatement"})
|
||||
public PluralPersistentAttribute findPluralAttribute(String name) {
|
||||
PluralPersistentAttribute<? super J, ?, ?> attribute = findDeclaredPluralAttribute( name );
|
||||
if ( attribute != null ) {
|
||||
return attribute;
|
||||
}
|
||||
basicCollectionCheck( attribute, name );
|
||||
return ( CollectionAttribute<J, ?> ) attribute;
|
||||
|
||||
if ( getSuperType() != null ) {
|
||||
attribute = getSuperType().findDeclaredPluralAttribute( name );
|
||||
if ( attribute != null ) {
|
||||
return attribute;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluralPersistentAttribute<? super J, ?, ?> findDeclaredPluralAttribute(String name) {
|
||||
return declaredPluralAttributes.get( name );
|
||||
}
|
||||
|
||||
private <E> void checkTypeForPluralAttributes(
|
||||
String attributeType,
|
||||
PluralAttribute<?,?,?> attribute,
|
||||
String name,
|
||||
Class<E> elementType,
|
||||
PluralAttribute.CollectionType collectionType) {
|
||||
if ( attribute == null
|
||||
|| ( elementType != null && !attribute.getBindableJavaType().equals( elementType ) )
|
||||
|| attribute.getCollectionType() != collectionType ) {
|
||||
throw new IllegalArgumentException(
|
||||
attributeType + " named " + name
|
||||
+ ( elementType != null ? " and of element type " + elementType : "" )
|
||||
+ " is not present"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Bags
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public PluralPersistentAttribute<? super J, ?, ?> getPluralAttribute(String name) {
|
||||
return declaredPluralAttributes.get( name );
|
||||
public BagPersistentAttribute<? super J, ?> getCollection(String name) {
|
||||
PluralPersistentAttribute attribute = findPluralAttribute( name );
|
||||
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().findPluralAttribute( name );
|
||||
}
|
||||
|
||||
basicCollectionCheck( attribute, name );
|
||||
|
||||
return (BagPersistentAttribute<J, ?>) attribute;
|
||||
}
|
||||
|
||||
private void basicCollectionCheck(PluralAttribute<? super J, ?, ?> attribute, String name) {
|
||||
checkNotNull( "CollectionAttribute", attribute, name );
|
||||
if ( ! CollectionAttribute.class.isAssignableFrom( attribute.getClass() ) ) {
|
||||
if ( ! BagPersistentAttribute.class.isAssignableFrom( attribute.getClass() ) ) {
|
||||
throw new IllegalArgumentException( name + " is not a CollectionAttribute: " + attribute.getClass() );
|
||||
}
|
||||
}
|
||||
|
@ -303,25 +375,46 @@ public abstract class AbstractManagedType<J>
|
|||
@Override
|
||||
@SuppressWarnings( "unchecked")
|
||||
public CollectionAttribute<J, ?> getDeclaredCollection(String name) {
|
||||
final PluralAttribute<J,?,?> attribute = declaredPluralAttributes.get( name );
|
||||
final PluralAttribute attribute = findDeclaredPluralAttribute( name );
|
||||
basicCollectionCheck( attribute, name );
|
||||
return ( CollectionAttribute<J, ?> ) attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public <E> BagPersistentAttribute<? super J, E> getCollection(String name, Class<E> elementType) {
|
||||
PluralAttribute<? super J, ?, ?> attribute = findPluralAttribute( name );
|
||||
checkCollectionElementType( attribute, name, elementType );
|
||||
return (BagPersistentAttribute) attribute;
|
||||
}
|
||||
|
||||
private <E> void checkCollectionElementType(PluralAttribute<?,?,?> attribute, String name, Class<E> elementType) {
|
||||
checkTypeForPluralAttributes( "CollectionAttribute", attribute, name, elementType, PluralAttribute.CollectionType.COLLECTION );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> CollectionAttribute<J, E> getDeclaredCollection(String name, Class<E> elementType) {
|
||||
final PluralAttribute attribute = findDeclaredPluralAttribute( name );
|
||||
checkCollectionElementType( attribute, name, elementType );
|
||||
return (CollectionAttribute) attribute;
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Set attributes
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public SetPersistentAttribute<? super J, ?> getSet(String name) {
|
||||
PluralAttribute<? super J, ?, ?> attribute = getPluralAttribute( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getPluralAttribute( name );
|
||||
}
|
||||
final PluralAttribute attribute = findPluralAttribute( name );
|
||||
basicSetCheck( attribute, name );
|
||||
return (SetPersistentAttribute) attribute;
|
||||
}
|
||||
|
||||
private void basicSetCheck(PluralAttribute<? super J, ?, ?> attribute, String name) {
|
||||
checkNotNull( "SetAttribute", attribute, name );
|
||||
if ( ! SetAttribute.class.isAssignableFrom( attribute.getClass() ) ) {
|
||||
if ( ! SetPersistentAttribute.class.isAssignableFrom( attribute.getClass() ) ) {
|
||||
throw new IllegalArgumentException( name + " is not a SetAttribute: " + attribute.getClass() );
|
||||
}
|
||||
}
|
||||
|
@ -329,25 +422,46 @@ public abstract class AbstractManagedType<J>
|
|||
@Override
|
||||
@SuppressWarnings( "unchecked")
|
||||
public SetPersistentAttribute<J, ?> getDeclaredSet(String name) {
|
||||
final PluralAttribute<J,?,?> attribute = declaredPluralAttributes.get( name );
|
||||
final PluralAttribute attribute = findDeclaredPluralAttribute( name );
|
||||
basicSetCheck( attribute, name );
|
||||
return (SetPersistentAttribute) attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public <E> SetAttribute<? super J, E> getSet(String name, Class<E> elementType) {
|
||||
PluralAttribute<? super J, ?, ?> attribute = findPluralAttribute( name );
|
||||
checkSetElementType( attribute, name, elementType );
|
||||
return ( SetAttribute<? super J, E> ) attribute;
|
||||
}
|
||||
|
||||
private <E> void checkSetElementType(PluralAttribute<? super J, ?, ?> attribute, String name, Class<E> elementType) {
|
||||
checkTypeForPluralAttributes( "SetAttribute", attribute, name, elementType, PluralAttribute.CollectionType.SET );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> SetAttribute<J, E> getDeclaredSet(String name, Class<E> elementType) {
|
||||
final PluralAttribute attribute = findDeclaredPluralAttribute( name );
|
||||
checkSetElementType( attribute, name, elementType );
|
||||
return ( SetAttribute<J, E> ) attribute;
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// List attributes
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public ListPersistentAttribute<? super J, ?> getList(String name) {
|
||||
PluralAttribute<? super J, ?, ?> attribute = getPluralAttribute( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getPluralAttribute( name );
|
||||
}
|
||||
PluralAttribute<? super J, ?, ?> attribute = findPluralAttribute( name );
|
||||
basicListCheck( attribute, name );
|
||||
return (ListPersistentAttribute) attribute;
|
||||
}
|
||||
|
||||
private void basicListCheck(PluralAttribute<? super J, ?, ?> attribute, String name) {
|
||||
checkNotNull( "ListAttribute", attribute, name );
|
||||
if ( ! ListAttribute.class.isAssignableFrom( attribute.getClass() ) ) {
|
||||
if ( ! ListPersistentAttribute.class.isAssignableFrom( attribute.getClass() ) ) {
|
||||
throw new IllegalArgumentException( name + " is not a ListAttribute: " + attribute.getClass() );
|
||||
}
|
||||
}
|
||||
|
@ -355,18 +469,39 @@ public abstract class AbstractManagedType<J>
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ListPersistentAttribute<J, ?> getDeclaredList(String name) {
|
||||
final PluralAttribute<J,?,?> attribute = declaredPluralAttributes.get( name );
|
||||
final PluralAttribute attribute = findDeclaredPluralAttribute( name );
|
||||
basicListCheck( attribute, name );
|
||||
return (ListPersistentAttribute) attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public <E> ListAttribute<? super J, E> getList(String name, Class<E> elementType) {
|
||||
PluralAttribute<? super J, ?, ?> attribute = findPluralAttribute( name );
|
||||
checkListElementType( attribute, name, elementType );
|
||||
return ( ListAttribute<? super J, E> ) attribute;
|
||||
}
|
||||
|
||||
private <E> void checkListElementType(PluralAttribute<? super J, ?, ?> attribute, String name, Class<E> elementType) {
|
||||
checkTypeForPluralAttributes( "ListAttribute", attribute, name, elementType, PluralAttribute.CollectionType.LIST );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> ListAttribute<J, E> getDeclaredList(String name, Class<E> elementType) {
|
||||
final PluralAttribute attribute = findDeclaredPluralAttribute( name );
|
||||
checkListElementType( attribute, name, elementType );
|
||||
return ( ListAttribute<J, E> ) attribute;
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Map attributes
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public MapPersistentAttribute<? super J, ?, ?> getMap(String name) {
|
||||
PluralAttribute<? super J, ?, ?> attribute = getPluralAttribute( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getPluralAttribute( name );
|
||||
}
|
||||
PluralAttribute<? super J, ?, ?> attribute = findPluralAttribute( name );
|
||||
basicMapCheck( attribute, name );
|
||||
return (MapPersistentAttribute) attribute;
|
||||
}
|
||||
|
@ -381,104 +516,15 @@ public abstract class AbstractManagedType<J>
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public MapPersistentAttribute<J, ?, ?> getDeclaredMap(String name) {
|
||||
final PluralAttribute<J,?,?> attribute = declaredPluralAttributes.get( name );
|
||||
final PluralAttribute attribute = findDeclaredPluralAttribute( name );
|
||||
basicMapCheck( attribute, name );
|
||||
return (MapPersistentAttribute) attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public <E> BagPersistentAttribute<? super J, E> getCollection(String name, Class<E> elementType) {
|
||||
PluralAttribute<? super J, ?, ?> attribute = declaredPluralAttributes.get( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getPluralAttribute( name );
|
||||
}
|
||||
checkCollectionElementType( attribute, name, elementType );
|
||||
return (BagPersistentAttribute) attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> CollectionAttribute<J, E> getDeclaredCollection(String name, Class<E> elementType) {
|
||||
final PluralAttribute<J,?,?> attribute = declaredPluralAttributes.get( name );
|
||||
checkCollectionElementType( attribute, name, elementType );
|
||||
return (CollectionAttribute) attribute;
|
||||
}
|
||||
|
||||
private <E> void checkCollectionElementType(PluralAttribute<?,?,?> attribute, String name, Class<E> elementType) {
|
||||
checkTypeForPluralAttributes( "CollectionAttribute", attribute, name, elementType, PluralAttribute.CollectionType.COLLECTION );
|
||||
}
|
||||
|
||||
private <E> void checkTypeForPluralAttributes(
|
||||
String attributeType,
|
||||
PluralAttribute<?,?,?> attribute,
|
||||
String name,
|
||||
Class<E> elementType,
|
||||
PluralAttribute.CollectionType collectionType) {
|
||||
if ( attribute == null
|
||||
|| ( elementType != null && !attribute.getBindableJavaType().equals( elementType ) )
|
||||
|| attribute.getCollectionType() != collectionType ) {
|
||||
throw new IllegalArgumentException(
|
||||
attributeType + " named " + name
|
||||
+ ( elementType != null ? " and of element type " + elementType : "" )
|
||||
+ " is not present"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public <E> SetAttribute<? super J, E> getSet(String name, Class<E> elementType) {
|
||||
PluralAttribute<? super J, ?, ?> attribute = declaredPluralAttributes.get( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getPluralAttribute( name );
|
||||
}
|
||||
checkSetElementType( attribute, name, elementType );
|
||||
return ( SetAttribute<? super J, E> ) attribute;
|
||||
}
|
||||
|
||||
private <E> void checkSetElementType(PluralAttribute<? super J, ?, ?> attribute, String name, Class<E> elementType) {
|
||||
checkTypeForPluralAttributes( "SetAttribute", attribute, name, elementType, PluralAttribute.CollectionType.SET );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> SetAttribute<J, E> getDeclaredSet(String name, Class<E> elementType) {
|
||||
final PluralAttribute<J,?,?> attribute = declaredPluralAttributes.get( name );
|
||||
checkSetElementType( attribute, name, elementType );
|
||||
return ( SetAttribute<J, E> ) attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public <E> ListAttribute<? super J, E> getList(String name, Class<E> elementType) {
|
||||
PluralAttribute<? super J, ?, ?> attribute = declaredPluralAttributes.get( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getPluralAttribute( name );
|
||||
}
|
||||
checkListElementType( attribute, name, elementType );
|
||||
return ( ListAttribute<? super J, E> ) attribute;
|
||||
}
|
||||
|
||||
private <E> void checkListElementType(PluralAttribute<? super J, ?, ?> attribute, String name, Class<E> elementType) {
|
||||
checkTypeForPluralAttributes( "ListAttribute", attribute, name, elementType, PluralAttribute.CollectionType.LIST );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> ListAttribute<J, E> getDeclaredList(String name, Class<E> elementType) {
|
||||
final PluralAttribute<J,?,?> attribute = declaredPluralAttributes.get( name );
|
||||
checkListElementType( attribute, name, elementType );
|
||||
return ( ListAttribute<J, E> ) attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public <K, V> MapAttribute<? super J, K, V> getMap(String name, Class<K> keyType, Class<V> valueType) {
|
||||
PluralAttribute<? super J, ?, ?> attribute = getPluralAttribute( name );
|
||||
if ( attribute == null && getSuperType() != null ) {
|
||||
attribute = getSuperType().getPluralAttribute( name );
|
||||
}
|
||||
PluralAttribute<? super J, ?, ?> attribute = findPluralAttribute( name );
|
||||
checkMapValueType( attribute, name, valueType );
|
||||
final MapAttribute<? super J, K, V> mapAttribute = ( MapAttribute<? super J, K, V> ) attribute;
|
||||
checkMapKeyType( mapAttribute, name, keyType );
|
||||
|
@ -498,7 +544,7 @@ public abstract class AbstractManagedType<J>
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <K, V> MapAttribute<J, K, V> getDeclaredMap(String name, Class<K> keyType, Class<V> valueType) {
|
||||
final PluralAttribute<J,?,?> attribute = declaredPluralAttributes.get( name );
|
||||
final PluralAttribute attribute = findDeclaredPluralAttribute( name );
|
||||
checkMapValueType( attribute, name, valueType );
|
||||
final MapAttribute<J, K, V> mapAttribute = ( MapAttribute<J, K, V> ) attribute;
|
||||
checkMapKeyType( mapAttribute, name, keyType );
|
||||
|
@ -506,43 +552,51 @@ public abstract class AbstractManagedType<J>
|
|||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public SubGraphImplementor<J> makeSubGraph() {
|
||||
return new SubGraphImpl<>( this, true, sessionFactory );
|
||||
return new SubGraphImpl( this, true, sessionFactory() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends J> ManagedTypeDescriptor<S> findSubType(String subTypeName) {
|
||||
public <S extends J> ManagedDomainType<S> findSubType(String subTypeName) {
|
||||
return DomainModelHelper.resolveSubType( this, subTypeName, sessionFactory() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends J> ManagedTypeDescriptor<S> findSubType(Class<S> subType) {
|
||||
public <S extends J> ManagedDomainType<S> findSubType(Class<S> subType) {
|
||||
return DomainModelHelper.resolveSubType( this, subType, sessionFactory() );
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Creation
|
||||
|
||||
private transient InFlightAccess<J> inFlightAccess;
|
||||
|
||||
@Override
|
||||
public InFlightAccess<J> getInFlightAccess() {
|
||||
if ( inFlightAccess == null ) {
|
||||
throw new IllegalStateException( "Type has been locked" );
|
||||
}
|
||||
|
||||
return inFlightAccess;
|
||||
}
|
||||
|
||||
protected class InFlightAccessImpl implements InFlightAccess<J> {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addAttribute(PersistentAttributeDescriptor<J, ?> attribute) {
|
||||
// put it in the collective group of attributes
|
||||
declaredAttributes.put( attribute.getName(), attribute );
|
||||
|
||||
// additionally classify as singular or plural attribute
|
||||
final Bindable.BindableType bindableType = ( ( Bindable ) attribute ).getBindableType();
|
||||
switch ( bindableType ) {
|
||||
case SINGULAR_ATTRIBUTE : {
|
||||
declaredSingularAttributes.put( attribute.getName(), (SingularPersistentAttribute<J,?>) attribute );
|
||||
break;
|
||||
}
|
||||
case PLURAL_ATTRIBUTE : {
|
||||
declaredPluralAttributes.put(attribute.getName(), (PluralPersistentAttribute<J,?,?>) attribute );
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
throw new AssertionFailure( "unknown bindable type: " + bindableType );
|
||||
}
|
||||
public void addAttribute(PersistentAttribute<J,?> attribute) {
|
||||
if ( attribute instanceof SingularPersistentAttribute ) {
|
||||
declaredSingularAttributes.put( attribute.getName(), (SingularPersistentAttribute<J,?>) attribute );
|
||||
}
|
||||
else if ( attribute instanceof PluralPersistentAttribute ) {
|
||||
declaredPluralAttributes.put(attribute.getName(), (PluralPersistentAttribute<J,?,?>) attribute );
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
"Unable to classify attribute as singular or plural [" + attribute + "] for `" + this + '`'
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
|
@ -4,12 +4,12 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
/**
|
||||
* Specialization of DomainType for types that can be used as function returns
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface AllowableFunctionReturnType<T> extends SimpleTypeDescriptor<T> {
|
||||
public interface AllowableFunctionReturnType<T> extends SimpleDomainType<T> {
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
/**
|
||||
* Specialization of DomainType for types that can be used as a
|
|
@ -4,12 +4,12 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
/**
|
||||
* Specialization of DomainType for types that can be used as query parameter bind values
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface AllowableParameterType<J> extends SimpleTypeDescriptor<J> {
|
||||
public interface AllowableParameterType<J> extends SimpleDomainType<J> {
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import javax.persistence.TemporalType;
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import java.util.Collection;
|
||||
import javax.persistence.metamodel.CollectionAttribute;
|
||||
|
@ -14,14 +14,14 @@ import javax.persistence.metamodel.CollectionAttribute;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface BagPersistentAttribute<D,E> extends CollectionAttribute<D,E>,
|
||||
PluralPersistentAttribute<D, Collection<E>,E> {
|
||||
public interface BagPersistentAttribute<D,E>
|
||||
extends CollectionAttribute<D,E>, PluralPersistentAttribute<D,Collection<E>,E> {
|
||||
@Override
|
||||
SimpleTypeDescriptor<E> getValueGraphType();
|
||||
SimpleDomainType<E> getValueGraphType();
|
||||
|
||||
@Override
|
||||
SimpleTypeDescriptor<E> getElementType();
|
||||
SimpleDomainType<E> getElementType();
|
||||
|
||||
@Override
|
||||
ManagedTypeDescriptor<D> getDeclaringType();
|
||||
ManagedDomainType<D> getDeclaringType();
|
||||
}
|
|
@ -4,12 +4,15 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.DomainType;
|
||||
import org.hibernate.metamodel.CollectionClassification;
|
||||
|
||||
/**
|
||||
* DomainType for a plural attribute
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface DomainTypeDescriptor<J> extends DomainType<J> {
|
||||
public interface CollectionDomainType<C,E> extends DomainType<C> {
|
||||
CollectionClassification getCollectionClassification();
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import org.hibernate.query.sqm.SqmExpressable;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
|
@ -24,12 +25,24 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface DomainType<J> extends javax.persistence.metamodel.Type<J> {
|
||||
public interface DomainType<J> extends SqmExpressable<J> {
|
||||
/**
|
||||
* The name of the type - this is Hibernate notion of the type name including
|
||||
* non-pojo mappings, etc.
|
||||
* The name of the type.
|
||||
*
|
||||
* @apiNote This is the Hibernate notion of the type name. For most types
|
||||
* this will simply be the Java type (i.e. {@link Class}) name. However
|
||||
* using the String allows for Hibernate's dynamic model feature.
|
||||
*/
|
||||
String getTypeName();
|
||||
default String getTypeName() {
|
||||
// default impl to handle the general case returning the Java type name
|
||||
return getJavaTypeDescriptor().getJavaType().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* The descriptor for the Java type (i.e. {@link Class}) represented by this
|
||||
* DomainType.
|
||||
*
|
||||
* @see #getTypeName
|
||||
*/
|
||||
JavaTypeDescriptor<J> getJavaTypeDescriptor();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import javax.persistence.metamodel.EmbeddableType;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link EmbeddableType} contract.
|
||||
*
|
||||
* @apiNote Temporarily extends the deprecated EmbeddableType. See the {@link EmbeddableType}
|
||||
* Javadocs for more information
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface EmbeddableDomainType<J> extends ManagedDomainType<J>, EmbeddableType<J> {
|
||||
}
|
|
@ -6,16 +6,16 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import javax.persistence.metamodel.EmbeddableType;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link } contract.
|
||||
*
|
||||
* @apiNote Notice that this describes {@link javax.persistence.Embedded}, not
|
||||
* {@link javax.persistence.Embeddable} - like {@link CollectionDomainType}, it includes
|
||||
* mapping information per usage (attribute)
|
||||
* @deprecated (since 6.0) Use {@link EmbeddableDomainType} instead. Originally intended
|
||||
* to describe the actual usage of an embeddable (the embedded) because it was intended
|
||||
* to include the mapping (column, etc) information. However, that causes us to need
|
||||
* multiple embeddable instances per embeddable class.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface EmbeddedDomainType<J> extends SimpleDomainType<J>, EmbeddableType<J> {
|
||||
@Deprecated
|
||||
public interface EmbeddedDomainType<J> extends EmbeddableDomainType<J> {
|
||||
}
|
||||
|
|
|
@ -15,6 +15,6 @@ import org.hibernate.query.sqm.SqmPathSource;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface EntityDomainType<J> extends IdentifiableDomainType<J>, EntityType<J>, SqmPathSource<J,J> {
|
||||
public interface EntityDomainType<J> extends IdentifiableDomainType<J>, EntityType<J>, SqmPathSource<J> {
|
||||
String getHibernateEntityName();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,10 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import javax.persistence.metamodel.IdentifiableType;
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
|
||||
/**
|
||||
* Extension to the JPA {@link IdentifiableType} contract
|
||||
|
@ -14,4 +17,32 @@ import javax.persistence.metamodel.IdentifiableType;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface IdentifiableDomainType<J> extends ManagedDomainType<J>, IdentifiableType<J> {
|
||||
@Override
|
||||
<Y> SingularPersistentAttribute<? super J, Y> getId(Class<Y> type);
|
||||
|
||||
@Override
|
||||
<Y> SingularPersistentAttribute<J, Y> getDeclaredId(Class<Y> type);
|
||||
|
||||
@Override
|
||||
<Y> SingularPersistentAttribute<? super J, Y> getVersion(Class<Y> type);
|
||||
|
||||
@Override
|
||||
<Y> SingularPersistentAttribute<J, Y> getDeclaredVersion(Class<Y> type);
|
||||
|
||||
@Override
|
||||
Set<SingularAttribute<? super J, ?>> getIdClassAttributes();
|
||||
|
||||
@Override
|
||||
SimpleDomainType<?> getIdType();
|
||||
|
||||
@Override
|
||||
IdentifiableDomainType<? super J> getSupertype();
|
||||
|
||||
boolean hasIdClass();
|
||||
|
||||
SingularPersistentAttribute<J,?> findIdAttribute();
|
||||
|
||||
void visitIdClassAttributes(Consumer<SingularPersistentAttribute<? super J,?>> action);
|
||||
|
||||
SingularPersistentAttribute<? super J, ?> findVersionAttribute();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.metamodel.ListAttribute;
|
|
@ -8,8 +8,54 @@ package org.hibernate.metamodel.model.domain;
|
|||
|
||||
import javax.persistence.metamodel.ManagedType;
|
||||
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.metamodel.RepresentationMode;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link ManagedType} contract
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ManagedDomainType<J> extends SimpleDomainType<J>, ManagedType<J>, Navigable<J,J> {
|
||||
}
|
||||
public interface ManagedDomainType<J> extends SimpleDomainType<J>, ManagedType<J> {
|
||||
/**
|
||||
* Get the type name.
|
||||
*
|
||||
* For dynamic models ({@link RepresentationMode#MAP}), this returns the symbolic name
|
||||
* since the Java type is {@link java.util.Map}
|
||||
*
|
||||
* For typed models, this returns the name of the Java class
|
||||
*
|
||||
* @return The type name.
|
||||
*
|
||||
* @see #getRepresentationMode()
|
||||
*/
|
||||
String getTypeName();
|
||||
|
||||
/**
|
||||
* This type's super type descriptor. Note : we define this on the managed
|
||||
* type descriptor in anticipation of supporting embeddable inheritance
|
||||
*/
|
||||
ManagedDomainType<? super J> getSuperType();
|
||||
|
||||
RepresentationMode getRepresentationMode();
|
||||
|
||||
@Override
|
||||
PersistentAttribute<? super J,?> getAttribute(String name);
|
||||
|
||||
@Override
|
||||
PersistentAttribute<J,?> getDeclaredAttribute(String name);
|
||||
|
||||
PersistentAttribute<? super J,?> findAttribute(String name);
|
||||
SingularPersistentAttribute<? super J,?> findSingularAttribute(String name);
|
||||
PluralPersistentAttribute<? super J, ?,?> findPluralAttribute(String name);
|
||||
|
||||
PersistentAttribute<J,?> findDeclaredAttribute(String name);
|
||||
SingularPersistentAttribute<? super J, ?> findDeclaredSingularAttribute(String name);
|
||||
PluralPersistentAttribute<? super J, ?, ?> findDeclaredPluralAttribute(String name);
|
||||
|
||||
SubGraphImplementor<J> makeSubGraph();
|
||||
<S extends J> SubGraphImplementor<S> makeSubGraph(Class<S> subClassType);
|
||||
|
||||
<S extends J> ManagedDomainType<S> findSubType(String subTypeName);
|
||||
<S extends J> ManagedDomainType<S> findSubType(Class<S> subType);
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.persistence.metamodel.MapAttribute;
|
||||
|
@ -16,5 +16,5 @@ import javax.persistence.metamodel.MapAttribute;
|
|||
*/
|
||||
public interface MapPersistentAttribute<D,K,V> extends MapAttribute<D, K, V>, PluralPersistentAttribute<D,Map<K,V>,V> {
|
||||
@Override
|
||||
SimpleTypeDescriptor<K> getKeyType();
|
||||
SimpleDomainType<K> getKeyType();
|
||||
}
|
|
@ -16,12 +16,17 @@ import org.hibernate.query.sqm.SqmPathSource;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface PersistentAttribute<D,J,B> extends Attribute<D,J>, SqmPathSource<J,B> {
|
||||
public interface PersistentAttribute<D,J> extends Attribute<D,J>, SqmPathSource<J> {
|
||||
@Override
|
||||
ManagedDomainType<D> getDeclaringType();
|
||||
|
||||
/**
|
||||
* The classification of the attribute (is it a basic type, entity, etc)
|
||||
*/
|
||||
AttributeClassification getAttributeClassification();
|
||||
|
||||
DomainType<?> getType();
|
||||
|
||||
SimpleDomainType<?> getValueGraphType();
|
||||
SimpleDomainType<?> getKeyGraphType();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import javax.persistence.metamodel.PluralAttribute;
|
||||
|
||||
|
@ -16,13 +16,16 @@ import javax.persistence.metamodel.PluralAttribute;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface PluralPersistentAttribute<D,C,E> extends PluralAttribute<D,C,E>, PersistentAttributeDescriptor<D,C,E> {
|
||||
public interface PluralPersistentAttribute<D,C,E> extends PluralAttribute<D,C,E>, PersistentAttribute<D,C> {
|
||||
@Override
|
||||
ManagedTypeDescriptor<D> getDeclaringType();
|
||||
ManagedDomainType<D> getDeclaringType();
|
||||
|
||||
@Override
|
||||
SimpleTypeDescriptor<E> getElementType();
|
||||
CollectionDomainType<C,E> getType();
|
||||
|
||||
@Override
|
||||
SimpleTypeDescriptor<E> getValueGraphType();
|
||||
SimpleDomainType<E> getElementType();
|
||||
|
||||
@Override
|
||||
SimpleDomainType<E> getValueGraphType();
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import java.util.Set;
|
||||
import javax.persistence.metamodel.SetAttribute;
|
|
@ -11,5 +11,5 @@ package org.hibernate.metamodel.model.domain;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SimpleDomainType<J> extends DomainType<J> {
|
||||
public interface SimpleDomainType<J> extends DomainType<J>, javax.persistence.metamodel.Type<J> {
|
||||
}
|
||||
|
|
|
@ -4,31 +4,31 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain;
|
||||
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link SingularAttribute} descriptor
|
||||
*
|
||||
* todo (6.0) : Create an form of singular attribute (and plural) in the API package (org.hibernate.metamodel.model.domain)
|
||||
* and have this extend it
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SingularPersistentAttribute<D,J> extends SingularAttribute<D,J>, PersistentAttributeDescriptor<D,J,J> {
|
||||
public interface SingularPersistentAttribute<D,J> extends SingularAttribute<D,J>, PersistentAttribute<D,J> {
|
||||
@Override
|
||||
SimpleTypeDescriptor<J> getType();
|
||||
SimpleDomainType<J> getType();
|
||||
|
||||
@Override
|
||||
ManagedTypeDescriptor<D> getDeclaringType();
|
||||
ManagedDomainType<D> getDeclaringType();
|
||||
|
||||
@Override
|
||||
SimpleDomainType<J> getSqmNodeType();
|
||||
|
||||
/**
|
||||
* For a singular attribute, the value type is defined as the
|
||||
* attribute type
|
||||
*/
|
||||
@Override
|
||||
default SimpleTypeDescriptor<?> getValueGraphType() {
|
||||
default SimpleDomainType<?> getValueGraphType() {
|
||||
return getType();
|
||||
}
|
||||
|
|
@ -16,10 +16,9 @@ import javax.persistence.metamodel.Attribute;
|
|||
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.metamodel.model.AttributeClassification;
|
||||
import org.hibernate.metamodel.model.domain.DomainType;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.PersistentAttributeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
|
@ -31,24 +30,24 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractAttribute<D,J,B>
|
||||
implements PersistentAttributeDescriptor<D,J,B>, Serializable {
|
||||
private final ManagedTypeDescriptor<D> declaringType;
|
||||
implements PersistentAttribute<D,J>, Serializable {
|
||||
private final ManagedDomainType<D> declaringType;
|
||||
private final String name;
|
||||
private final JavaTypeDescriptor<J> attributeType;
|
||||
|
||||
private final AttributeClassification attributeClassification;
|
||||
|
||||
private final SimpleTypeDescriptor<B> valueType;
|
||||
private final SimpleDomainType<B> valueType;
|
||||
private transient Member member;
|
||||
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected AbstractAttribute(
|
||||
ManagedTypeDescriptor<D> declaringType,
|
||||
ManagedDomainType<D> declaringType,
|
||||
String name,
|
||||
JavaTypeDescriptor<J> attributeType,
|
||||
AttributeClassification attributeClassification,
|
||||
SimpleTypeDescriptor<B> valueType,
|
||||
SimpleDomainType<B> valueType,
|
||||
Member member) {
|
||||
this.declaringType = declaringType;
|
||||
this.name = name;
|
||||
|
@ -64,7 +63,7 @@ public abstract class AbstractAttribute<D,J,B>
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getNavigableName() {
|
||||
public String getPathName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
|
@ -74,7 +73,7 @@ public abstract class AbstractAttribute<D,J,B>
|
|||
}
|
||||
|
||||
@Override
|
||||
public DomainType<B> getSqmNodeType() {
|
||||
public SimpleDomainType<B> getSqmNodeType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
|
@ -84,7 +83,7 @@ public abstract class AbstractAttribute<D,J,B>
|
|||
}
|
||||
|
||||
@Override
|
||||
public ManagedTypeDescriptor<D> getDeclaringType() {
|
||||
public ManagedDomainType<D> getDeclaringType() {
|
||||
return declaringType;
|
||||
}
|
||||
|
||||
|
@ -104,13 +103,13 @@ public abstract class AbstractAttribute<D,J,B>
|
|||
}
|
||||
|
||||
@Override
|
||||
public SimpleTypeDescriptor<?> getValueGraphType() {
|
||||
public SimpleDomainType<?> getValueGraphType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return declaringType.getName() + '#' + name + '(' + attributeClassification + ')';
|
||||
return declaringType.getTypeName() + '#' + name + '(' + attributeClassification + ')';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,8 +9,11 @@ package org.hibernate.metamodel.model.domain.internal;
|
|||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
|
||||
import org.hibernate.metamodel.CollectionClassification;
|
||||
import org.hibernate.metamodel.model.domain.AbstractManagedType;
|
||||
import org.hibernate.metamodel.model.domain.CollectionDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
import org.hibernate.query.sqm.produce.spi.SqmCreationState;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath;
|
||||
|
@ -26,7 +29,17 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
|||
*/
|
||||
public abstract class AbstractPluralAttribute<D,C,E>
|
||||
extends AbstractAttribute<D,C,E>
|
||||
implements PluralPersistentAttribute<D,C,E>, Serializable {
|
||||
implements PluralPersistentAttribute<D,C,E>, CollectionDomainType<C,E>, Serializable {
|
||||
|
||||
public static <X,C,E,K> PluralAttributeBuilder<X,C,E,K> create(
|
||||
AbstractManagedType<X> ownerType,
|
||||
SimpleDomainType<E> attrType,
|
||||
JavaTypeDescriptor<C> collectionClass,
|
||||
SimpleDomainType<K> keyType) {
|
||||
return new PluralAttributeBuilder<>( ownerType, attrType, collectionClass, keyType );
|
||||
}
|
||||
|
||||
private final CollectionClassification classification;
|
||||
|
||||
protected AbstractPluralAttribute(PluralAttributeBuilder<D,C,E,?> builder) {
|
||||
super(
|
||||
|
@ -37,29 +50,45 @@ public abstract class AbstractPluralAttribute<D,C,E>
|
|||
builder.getValueType(),
|
||||
builder.getMember()
|
||||
);
|
||||
}
|
||||
|
||||
public static <X,C,E,K> PluralAttributeBuilder<X,C,E,K> create(
|
||||
AbstractManagedType<X> ownerType,
|
||||
SimpleTypeDescriptor<E> attrType,
|
||||
JavaTypeDescriptor<C> collectionClass,
|
||||
SimpleTypeDescriptor<K> keyType) {
|
||||
return new PluralAttributeBuilder<>( ownerType, attrType, collectionClass, keyType );
|
||||
this.classification = builder.getCollectionClassification();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleTypeDescriptor<E> getElementType() {
|
||||
public CollectionClassification getCollectionClassification() {
|
||||
return classification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionType getCollectionType() {
|
||||
return getCollectionClassification().toJpaClassification();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionDomainType<C, E> getType() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
// todo (6.0) : this should return the "role"
|
||||
// - for now just return the name of the collection type
|
||||
return getCollectionType().name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleDomainType<E> getElementType() {
|
||||
return getValueGraphType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SimpleTypeDescriptor<E> getValueGraphType() {
|
||||
return (SimpleTypeDescriptor<E>) super.getValueGraphType();
|
||||
public SimpleDomainType<E> getValueGraphType() {
|
||||
return (SimpleDomainType<E>) super.getValueGraphType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleTypeDescriptor<?> getKeyGraphType() {
|
||||
public SimpleDomainType<?> getKeyGraphType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -84,16 +113,13 @@ public abstract class AbstractPluralAttribute<D,C,E>
|
|||
return getElementType().getJavaType();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<C> getJavaType() {
|
||||
return getJavaTypeDescriptor().getJavaType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmPath createSqmPath(
|
||||
SqmPath<?> lhs,
|
||||
SqmCreationState creationState) {
|
||||
public SqmPath<C> createSqmPath(SqmPath<?> lhs, SqmCreationState creationState) {
|
||||
return new SqmPluralValuedSimplePath( );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.io.Serializable;
|
|||
import javax.persistence.metamodel.Type;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.DomainTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* Defines commonality for the JPA {@link Type} hierarchy of interfaces.
|
||||
|
@ -18,36 +19,44 @@ import org.hibernate.metamodel.model.domain.spi.DomainTypeDescriptor;
|
|||
* @author Brad Koehn
|
||||
*/
|
||||
public abstract class AbstractType<X> implements DomainTypeDescriptor<X>, Serializable {
|
||||
private final Class<X> javaType;
|
||||
private final JavaTypeDescriptor<X> javaTypeDescriptor;
|
||||
private final String typeName;
|
||||
|
||||
/**
|
||||
* Instantiates the type based on the given Java type.
|
||||
*
|
||||
* @param javaType The Java type of the JPA model type.
|
||||
*/
|
||||
protected AbstractType(Class<X> javaType) {
|
||||
this( javaType, javaType != null ? javaType.getName() : null );
|
||||
protected AbstractType(JavaTypeDescriptor<X> javaTypeDescriptor) {
|
||||
this(
|
||||
javaTypeDescriptor,
|
||||
javaTypeDescriptor.getJavaType() != null
|
||||
? javaTypeDescriptor.getJavaType().getName()
|
||||
: null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates the type based on the given Java type.
|
||||
*/
|
||||
protected AbstractType(Class<X> javaType, String typeName) {
|
||||
this.javaType = javaType;
|
||||
protected AbstractType(JavaTypeDescriptor<X> javaTypeDescriptor, String typeName) {
|
||||
this.javaTypeDescriptor = javaTypeDescriptor;
|
||||
this.typeName = typeName == null ? "unknown" : typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaTypeDescriptor<X> getJavaTypeDescriptor() {
|
||||
return javaTypeDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p/>
|
||||
* IMPL NOTE : The Hibernate version may return {@code null} here in the case of either dynamic models or
|
||||
* entity classes mapped multiple times using entity-name. In these cases, the {@link #getTypeName()} value
|
||||
* should be used.
|
||||
*
|
||||
* @implNote The Hibernate impl may return {@code null} here in the case of either
|
||||
* dynamic models or entity classes mapped multiple times using entity-name. In
|
||||
* these cases, the {@link #getTypeName()} value should be used.
|
||||
*/
|
||||
@Override
|
||||
public Class<X> getJavaType() {
|
||||
return javaType;
|
||||
return javaTypeDescriptor.getJavaType();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.internal;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface AttributeContainer<J> {
|
||||
InFlightAccess<J> getInFlightAccess();
|
||||
|
||||
/**
|
||||
* Used during creation of the type
|
||||
*/
|
||||
interface InFlightAccess<J> {
|
||||
void addAttribute(PersistentAttribute<J,?,?> attribute);
|
||||
|
||||
default void applyIdAttribute(SingularPersistentAttribute<J, ?> idAttribute) {
|
||||
throw new UnsupportedOperationException(
|
||||
"AttributeContainer [" + getClass().getName() + "] does not support identifiers"
|
||||
);
|
||||
}
|
||||
|
||||
default void applyIdClassAttributes(Set<SingularPersistentAttribute<? super J, ?>> idClassAttributes) {
|
||||
throw new UnsupportedOperationException(
|
||||
"AttributeContainer [" + getClass().getName() + "] does not support identifiers"
|
||||
);
|
||||
}
|
||||
|
||||
default void applyVersionAttribute(SingularPersistentAttribute<J, ?> versionAttribute) {
|
||||
throw new UnsupportedOperationException(
|
||||
"AttributeContainer [" + getClass().getName() + "] does not support versions"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when configuration of the type is complete
|
||||
*/
|
||||
void finishUp();
|
||||
}
|
||||
}
|
|
@ -8,13 +8,19 @@ package org.hibernate.metamodel.model.domain.internal;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.BagPersistentAttribute;
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.metamodel.model.domain.BagPersistentAttribute;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
import org.hibernate.query.sqm.produce.path.spi.SemanticPathPart;
|
||||
import org.hibernate.query.sqm.produce.spi.SqmCreationState;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
class BagAttributeImpl<X, E> extends AbstractPluralAttribute<X, Collection<E>, E>
|
||||
class BagAttributeImpl<X, E>
|
||||
extends AbstractPluralAttribute<X, Collection<E>, E>
|
||||
implements BagPersistentAttribute<X, E> {
|
||||
|
||||
BagAttributeImpl(PluralAttributeBuilder<X, Collection<E>, E, ?> xceBuilder) {
|
||||
super( xceBuilder );
|
||||
}
|
||||
|
@ -23,4 +29,18 @@ class BagAttributeImpl<X, E> extends AbstractPluralAttribute<X, Collection<E>, E
|
|||
public CollectionType getCollectionType() {
|
||||
return CollectionType.COLLECTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmPathSource<?> findSubPathSource(String name) {
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SemanticPathPart resolvePathPart(
|
||||
String name,
|
||||
String currentContextKey,
|
||||
boolean isTerminal,
|
||||
SqmCreationState creationState) {
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,42 +8,29 @@ package org.hibernate.metamodel.model.domain.internal;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.DomainType;
|
||||
import org.hibernate.metamodel.model.domain.spi.BasicTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.BasicDomainType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class BasicTypeImpl<J> implements BasicTypeDescriptor<J>, Serializable {
|
||||
private final Class<J> clazz;
|
||||
private PersistenceType persistenceType;
|
||||
public class BasicTypeImpl<J> implements BasicDomainType<J>, Serializable {
|
||||
private final JavaTypeDescriptor<J> javaTypeDescriptor;
|
||||
|
||||
public BasicTypeImpl(JavaTypeDescriptor<J> javaTypeDescriptor) {
|
||||
this.javaTypeDescriptor = javaTypeDescriptor;
|
||||
}
|
||||
|
||||
public PersistenceType getPersistenceType() {
|
||||
return persistenceType;
|
||||
}
|
||||
|
||||
public Class<J> getJavaType() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public BasicTypeImpl(Class<J> clazz, PersistenceType persistenceType) {
|
||||
this.clazz = clazz;
|
||||
this.persistenceType = persistenceType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return clazz.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainType<J> getType() {
|
||||
return this;
|
||||
return PersistenceType.BASIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaTypeDescriptor<J> getJavaTypeDescriptor() {
|
||||
return getType().getJavaTypeDescriptor();
|
||||
return javaTypeDescriptor;
|
||||
}
|
||||
|
||||
public Class<J> getJavaType() {
|
||||
return getJavaTypeDescriptor().getJavaType();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,13 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
package org.hibernate.metamodel.model.domain.internal;
|
||||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
|
@ -17,31 +20,23 @@ import org.hibernate.persister.entity.EntityPersister;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DomainModelHelper {
|
||||
public static EntityPersister resolveEntityPersister(
|
||||
EntityTypeDescriptor<?> entityType,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
// Our EntityTypeImpl#getType impl returns the Hibernate entity-name
|
||||
// which is exactly what we want
|
||||
final String hibernateEntityName = entityType.getName();
|
||||
return sessionFactory.getMetamodel().entityPersister( hibernateEntityName );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, S extends T> ManagedTypeDescriptor<S> resolveSubType(
|
||||
ManagedTypeDescriptor<T> baseType,
|
||||
public static <T, S extends T> ManagedDomainType<S> resolveSubType(
|
||||
ManagedDomainType<T> baseType,
|
||||
String subTypeName,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
final MetamodelImplementor metamodel = sessionFactory.getMetamodel();
|
||||
|
||||
if ( baseType instanceof EmbeddedTypeDescriptor<?> ) {
|
||||
if ( baseType instanceof EmbeddableDomainType<?> ) {
|
||||
// todo : at least validate the string is a valid sub-type of the embeddable class?
|
||||
return (ManagedTypeDescriptor) baseType;
|
||||
return (ManagedDomainType) baseType;
|
||||
}
|
||||
|
||||
final String importedClassName = metamodel.getImportedClassName( subTypeName );
|
||||
if ( importedClassName != null ) {
|
||||
// first, try to find it by name directly..
|
||||
ManagedTypeDescriptor<S> subManagedType = metamodel.entity( importedClassName );
|
||||
ManagedDomainType<S> subManagedType = metamodel.entity( importedClassName );
|
||||
if ( subManagedType != null ) {
|
||||
return subManagedType;
|
||||
}
|
||||
|
@ -58,15 +53,30 @@ public class DomainModelHelper {
|
|||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException( "Unknown sub-type name (" + baseType.getName() + ") : " + subTypeName );
|
||||
throw new IllegalArgumentException( "Unknown sub-type name (" + baseType.getTypeName() + ") : " + subTypeName );
|
||||
}
|
||||
|
||||
public static <S> ManagedTypeDescriptor<S> resolveSubType(
|
||||
ManagedTypeDescriptor<? super S> baseType,
|
||||
public static <S> ManagedDomainType<S> resolveSubType(
|
||||
ManagedDomainType<? super S> baseType,
|
||||
Class<S> subTypeClass,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
// todo : validate the hierarchy-ness...
|
||||
final MetamodelImplementor metamodel = sessionFactory.getMetamodel();
|
||||
return metamodel.managedType( subTypeClass );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve a JPA EntityType descriptor to it's corresponding EntityPersister
|
||||
* in the Hibernate mapping type system
|
||||
*/
|
||||
public static EntityPersister resolveEntityPersister(
|
||||
EntityDomainType<?> entityType,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
// Our EntityTypeImpl#getType impl returns the Hibernate entity-name
|
||||
// which is exactly what we want
|
||||
final String hibernateEntityName = entityType.getName();
|
||||
return sessionFactory.getMetamodel().entityPersister( hibernateEntityName );
|
||||
}
|
||||
|
||||
}
|
|
@ -7,13 +7,16 @@
|
|||
package org.hibernate.metamodel.model.domain.internal;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.graph.internal.SubGraphImpl;
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.metamodel.model.domain.spi.EmbeddedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.AbstractManagedType;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.type.ComponentType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* Standard Hibernate implementation of JPA's {@link javax.persistence.metamodel.EmbeddableType}
|
||||
|
@ -24,17 +27,33 @@ import org.hibernate.type.ComponentType;
|
|||
*/
|
||||
public class EmbeddableTypeImpl<J>
|
||||
extends AbstractManagedType<J>
|
||||
implements EmbeddedTypeDescriptor<J>, Serializable {
|
||||
implements EmbeddableDomainType<J>, Serializable {
|
||||
|
||||
private final ManagedTypeDescriptor<?> parent;
|
||||
private final ManagedDomainType<?> parent;
|
||||
private final ComponentType hibernateType;
|
||||
|
||||
public EmbeddableTypeImpl(
|
||||
Class<J> javaType,
|
||||
ManagedTypeDescriptor<?> parent,
|
||||
JavaTypeDescriptor<J> javaTypeDescriptor,
|
||||
ManagedDomainType<?> parent,
|
||||
ComponentType hibernateType,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super( javaType, null, null, sessionFactory );
|
||||
super( javaTypeDescriptor.getJavaType().getName(), javaTypeDescriptor, null, sessionFactory );
|
||||
this.parent = parent;
|
||||
this.hibernateType = hibernateType;
|
||||
}
|
||||
|
||||
public EmbeddableTypeImpl(
|
||||
String name,
|
||||
ManagedDomainType<?> parent,
|
||||
ComponentType hibernateType,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
//noinspection unchecked
|
||||
super(
|
||||
name,
|
||||
(JavaTypeDescriptor) sessionFactory.getMetamodel().getTypeConfiguration().getJavaTypeDescriptorRegistry().getDescriptor( Map.class ),
|
||||
null,
|
||||
sessionFactory
|
||||
);
|
||||
this.parent = parent;
|
||||
this.hibernateType = hibernateType;
|
||||
}
|
||||
|
@ -44,7 +63,7 @@ public class EmbeddableTypeImpl<J>
|
|||
return PersistenceType.EMBEDDABLE;
|
||||
}
|
||||
|
||||
public ManagedTypeDescriptor<?> getParent() {
|
||||
public ManagedDomainType<?> getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,15 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.graph.internal.SubGraphImpl;
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
|
||||
import org.hibernate.metamodel.model.domain.DomainType;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
import org.hibernate.query.sqm.produce.path.spi.SemanticPathPart;
|
||||
import org.hibernate.query.sqm.produce.spi.SqmCreationState;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* Defines the Hibernate implementation of the JPA {@link EntityType} contract.
|
||||
|
@ -24,18 +31,18 @@ import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
|
|||
*/
|
||||
public class EntityTypeImpl<J>
|
||||
extends AbstractIdentifiableType<J>
|
||||
implements EntityTypeDescriptor<J>, Serializable {
|
||||
implements EntityDomainType<J>, Serializable {
|
||||
private final String jpaEntityName;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public EntityTypeImpl(
|
||||
Class javaType,
|
||||
IdentifiableTypeDescriptor<? super J> superType,
|
||||
JavaTypeDescriptor<J> javaTypeDescriptor,
|
||||
IdentifiableDomainType<? super J> superType,
|
||||
PersistentClass persistentClass,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super(
|
||||
javaType,
|
||||
persistentClass.getEntityName(),
|
||||
javaTypeDescriptor,
|
||||
superType,
|
||||
persistentClass.getDeclaredIdentifierMapper() != null || ( superType != null && superType.hasIdClass() ),
|
||||
persistentClass.hasIdentifierProperty(),
|
||||
|
@ -55,6 +62,30 @@ public class EntityTypeImpl<J>
|
|||
return super.getTypeName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPathName() {
|
||||
return getHibernateEntityName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainType<?> getSqmNodeType() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmPathSource<?> findSubPathSource(String name) {
|
||||
return findAttribute( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SemanticPathPart resolvePathPart(
|
||||
String name,
|
||||
String currentContextKey,
|
||||
boolean isTerminal,
|
||||
SqmCreationState creationState) {
|
||||
return findAttribute( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindableType getBindableType() {
|
||||
return BindableType.ENTITY_TYPE;
|
||||
|
@ -65,13 +96,18 @@ public class EntityTypeImpl<J>
|
|||
return getJavaType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaTypeDescriptor<J> getJavaTypeDescriptor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistenceType getPersistenceType() {
|
||||
return PersistenceType.ENTITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifiableTypeDescriptor<? super J> getSuperType() {
|
||||
public IdentifiableDomainType<? super J> getSuperType() {
|
||||
return super.getSuperType();
|
||||
}
|
||||
|
||||
|
@ -100,4 +136,13 @@ public class EntityTypeImpl<J>
|
|||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmPath<J> createSqmPath(
|
||||
SqmPath<?> lhs,
|
||||
SqmCreationState creationState) {
|
||||
throw new UnsupportedOperationException(
|
||||
"EntityType cannot be used to create an SqmPath - that would be an SqmFrom which are created directly"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ package org.hibernate.metamodel.model.domain.internal;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.ListPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.ListPersistentAttribute;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
|
|
@ -8,15 +8,20 @@ package org.hibernate.metamodel.model.domain.internal;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.MapPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.metamodel.model.domain.MapPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
import org.hibernate.query.sqm.produce.path.spi.SemanticPathPart;
|
||||
import org.hibernate.query.sqm.produce.spi.SqmCreationState;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmExpression;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
class MapAttributeImpl<X, K, V> extends AbstractPluralAttribute<X, Map<K, V>, V>
|
||||
implements MapPersistentAttribute<X, K, V> {
|
||||
private final SimpleTypeDescriptor<K> keyType;
|
||||
class MapAttributeImpl<X, K, V> extends AbstractPluralAttribute<X, Map<K, V>, V> implements MapPersistentAttribute<X, K, V> {
|
||||
private final SimpleDomainType<K> keyType;
|
||||
|
||||
MapAttributeImpl(PluralAttributeBuilder<X, Map<K, V>, V, K> xceBuilder) {
|
||||
super( xceBuilder );
|
||||
|
@ -34,12 +39,35 @@ class MapAttributeImpl<X, K, V> extends AbstractPluralAttribute<X, Map<K, V>, V>
|
|||
}
|
||||
|
||||
@Override
|
||||
public SimpleTypeDescriptor<K> getKeyType() {
|
||||
public SimpleDomainType<K> getKeyType() {
|
||||
return keyType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleTypeDescriptor<K> getKeyGraphType() {
|
||||
public SimpleDomainType<K> getKeyGraphType() {
|
||||
return getKeyType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmPathSource<?> findSubPathSource(String name) {
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SemanticPathPart resolvePathPart(
|
||||
String name,
|
||||
String currentContextKey,
|
||||
boolean isTerminal,
|
||||
SqmCreationState creationState) {
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmPath resolveIndexedAccess(
|
||||
SqmExpression selector,
|
||||
String currentContextKey,
|
||||
boolean isTerminal,
|
||||
SqmCreationState creationState) {
|
||||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,22 +10,25 @@ import org.hibernate.cfg.NotYetImplementedException;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.mapping.MappedSuperclass;
|
||||
import org.hibernate.metamodel.model.domain.spi.IdentifiableTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.MappedSuperclassTypeDescriptor;
|
||||
import org.hibernate.metamodel.RepresentationMode;
|
||||
import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class MappedSuperclassTypeImpl<X> extends AbstractIdentifiableType<X> implements MappedSuperclassTypeDescriptor<X> {
|
||||
public class MappedSuperclassTypeImpl<X> extends AbstractIdentifiableType<X> implements MappedSuperclassDomainType<X> {
|
||||
public MappedSuperclassTypeImpl(
|
||||
Class<X> javaType,
|
||||
JavaTypeDescriptor<X> javaTypeDescriptor,
|
||||
MappedSuperclass mappedSuperclass,
|
||||
IdentifiableTypeDescriptor<? super X> superType,
|
||||
IdentifiableDomainType<? super X> superType,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super(
|
||||
javaType,
|
||||
javaType.getName(),
|
||||
javaTypeDescriptor.getJavaType().getName(),
|
||||
javaTypeDescriptor,
|
||||
superType,
|
||||
mappedSuperclass.getDeclaredIdentifierMapper() != null || ( superType != null && superType.hasIdClass() ),
|
||||
mappedSuperclass.hasIdentifierProperty(),
|
||||
|
|
|
@ -13,39 +13,40 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.metamodel.CollectionClassification;
|
||||
import org.hibernate.metamodel.model.AttributeClassification;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* A "parameter object" for creating a plural attribute
|
||||
*/
|
||||
public class PluralAttributeBuilder<D, C, E, K> {
|
||||
private final ManagedTypeDescriptor<D> declaringType;
|
||||
private final SimpleTypeDescriptor<E> valueType;
|
||||
private final ManagedDomainType<D> declaringType;
|
||||
private final SimpleDomainType<E> valueType;
|
||||
|
||||
private SimpleTypeDescriptor<K> keyType;
|
||||
|
||||
private JavaTypeDescriptor<C> collectionJavaTypeDescriptor;
|
||||
private SimpleDomainType<K> keyType;
|
||||
|
||||
private AttributeClassification attributeClassification;
|
||||
private CollectionClassification collectionClassification;
|
||||
private JavaTypeDescriptor<C> collectionJavaTypeDescriptor;
|
||||
|
||||
private Property property;
|
||||
private Member member;
|
||||
|
||||
public PluralAttributeBuilder(
|
||||
ManagedTypeDescriptor<D> ownerType,
|
||||
SimpleTypeDescriptor<E> elementType,
|
||||
ManagedDomainType<D> ownerType,
|
||||
SimpleDomainType<E> elementType,
|
||||
JavaTypeDescriptor<C> collectionJavaTypeDescriptor,
|
||||
SimpleTypeDescriptor<K> keyType) {
|
||||
SimpleDomainType<K> keyType) {
|
||||
this.declaringType = ownerType;
|
||||
this.valueType = elementType;
|
||||
this.collectionJavaTypeDescriptor = collectionJavaTypeDescriptor;
|
||||
this.keyType = keyType;
|
||||
}
|
||||
|
||||
public ManagedTypeDescriptor<D> getDeclaringType() {
|
||||
public ManagedDomainType<D> getDeclaringType() {
|
||||
return declaringType;
|
||||
}
|
||||
|
||||
|
@ -53,7 +54,11 @@ public class PluralAttributeBuilder<D, C, E, K> {
|
|||
return attributeClassification;
|
||||
}
|
||||
|
||||
public SimpleTypeDescriptor<K> getKeyType() {
|
||||
public CollectionClassification getCollectionClassification() {
|
||||
return collectionClassification;
|
||||
}
|
||||
|
||||
public SimpleDomainType<K> getKeyType() {
|
||||
return keyType;
|
||||
}
|
||||
|
||||
|
@ -61,7 +66,7 @@ public class PluralAttributeBuilder<D, C, E, K> {
|
|||
return collectionJavaTypeDescriptor;
|
||||
}
|
||||
|
||||
public SimpleTypeDescriptor<E> getValueType() {
|
||||
public SimpleDomainType<E> getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ package org.hibernate.metamodel.model.domain.internal;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.SetPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SetPersistentAttribute;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
|
|
@ -13,15 +13,18 @@ import java.util.function.Supplier;
|
|||
|
||||
import org.hibernate.graph.spi.GraphHelper;
|
||||
import org.hibernate.metamodel.model.AttributeClassification;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SimpleTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
import org.hibernate.query.sqm.produce.path.spi.SemanticPathPart;
|
||||
import org.hibernate.query.sqm.produce.spi.SqmCreationState;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmAnyValuedSimplePath;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmEmbeddedValuedSimplePath;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmExpression;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
|
@ -34,16 +37,16 @@ public class SingularAttributeImpl<D,J>
|
|||
private final boolean isVersion;
|
||||
private final boolean isOptional;
|
||||
|
||||
private final SimpleTypeDescriptor<J> attributeType;
|
||||
private final SimpleDomainType<J> attributeType;
|
||||
|
||||
// NOTE : delay access for timing reasons
|
||||
private final DelayedKeyTypeAccess graphKeyTypeAccess = new DelayedKeyTypeAccess();
|
||||
|
||||
public SingularAttributeImpl(
|
||||
ManagedTypeDescriptor<D> declaringType,
|
||||
ManagedDomainType<D> declaringType,
|
||||
String name,
|
||||
AttributeClassification attributeClassification,
|
||||
SimpleTypeDescriptor<J> attributeType,
|
||||
SimpleDomainType<J> attributeType,
|
||||
Member member,
|
||||
boolean isIdentifier,
|
||||
boolean isVersion,
|
||||
|
@ -57,25 +60,62 @@ public class SingularAttributeImpl<D,J>
|
|||
}
|
||||
|
||||
@Override
|
||||
public SimpleTypeDescriptor<J> getValueGraphType() {
|
||||
public SimpleDomainType<J> getValueGraphType() {
|
||||
return attributeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleTypeDescriptor<J> getKeyGraphType() {
|
||||
public SimpleDomainType<J> getKeyGraphType() {
|
||||
return graphKeyTypeAccess.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleDomainType<J> getSqmNodeType() {
|
||||
return super.getSqmNodeType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmPathSource<?> findSubPathSource(String name) {
|
||||
switch ( getAttributeClassification() ) {
|
||||
case EMBEDDED:
|
||||
case ONE_TO_ONE:
|
||||
case MANY_TO_ONE: {
|
||||
return ( (SqmPathSource) getSqmNodeType() ).findSubPathSource( name );
|
||||
}
|
||||
default: {
|
||||
throw new UnsupportedOperationException( "Attribute does not contain sub-paths" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SemanticPathPart resolvePathPart(
|
||||
String name,
|
||||
String currentContextKey,
|
||||
boolean isTerminal,
|
||||
SqmCreationState creationState) {
|
||||
return findSubPathSource( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmPath resolveIndexedAccess(
|
||||
SqmExpression selector,
|
||||
String currentContextKey,
|
||||
boolean isTerminal,
|
||||
SqmCreationState creationState) {
|
||||
throw new UnsupportedOperationException( "Singular attribute cannot be index-accessed" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subclass used to simplify instantiation of singular attributes representing an entity's
|
||||
* identifier.
|
||||
*/
|
||||
public static class Identifier<D, J> extends SingularAttributeImpl<D, J> {
|
||||
public static class Identifier<D,J> extends SingularAttributeImpl<D,J> {
|
||||
public Identifier(
|
||||
ManagedTypeDescriptor<D> declaringType,
|
||||
ManagedDomainType<D> declaringType,
|
||||
String name,
|
||||
SimpleTypeDescriptor<J> attributeType,
|
||||
SimpleDomainType<J> attributeType,
|
||||
Member member,
|
||||
AttributeClassification attributeClassification) {
|
||||
super( declaringType, name, attributeClassification, attributeType, member, true, false, false );
|
||||
|
@ -88,10 +128,10 @@ public class SingularAttributeImpl<D,J>
|
|||
*/
|
||||
public static class Version<X,Y> extends SingularAttributeImpl<X,Y> {
|
||||
public Version(
|
||||
ManagedTypeDescriptor<X> declaringType,
|
||||
ManagedDomainType<X> declaringType,
|
||||
String name,
|
||||
AttributeClassification attributeClassification,
|
||||
SimpleTypeDescriptor<Y> attributeType,
|
||||
SimpleDomainType<Y> attributeType,
|
||||
Member member) {
|
||||
super( declaringType, name, attributeClassification, attributeType, member, false, true, false );
|
||||
}
|
||||
|
@ -113,7 +153,7 @@ public class SingularAttributeImpl<D,J>
|
|||
}
|
||||
|
||||
@Override
|
||||
public SimpleTypeDescriptor<J> getType() {
|
||||
public SimpleDomainType<J> getType() {
|
||||
return attributeType;
|
||||
}
|
||||
|
||||
|
@ -161,7 +201,7 @@ public class SingularAttributeImpl<D,J>
|
|||
String.format(
|
||||
Locale.ROOT,
|
||||
"Cannot create SqmPath from singular attribute [%s#%s] - unknown classification : %s",
|
||||
getDeclaringType().getName(),
|
||||
getDeclaringType().getTypeName(),
|
||||
getName(),
|
||||
getAttributeClassification()
|
||||
)
|
||||
|
@ -170,12 +210,12 @@ public class SingularAttributeImpl<D,J>
|
|||
}
|
||||
}
|
||||
|
||||
private class DelayedKeyTypeAccess implements Supplier<SimpleTypeDescriptor<J>>, Serializable {
|
||||
private class DelayedKeyTypeAccess implements Supplier<SimpleDomainType<J>>, Serializable {
|
||||
private boolean resolved;
|
||||
private SimpleTypeDescriptor<J> type;
|
||||
private SimpleDomainType<J> type;
|
||||
|
||||
@Override
|
||||
public SimpleTypeDescriptor<J> get() {
|
||||
public SimpleDomainType<J> get() {
|
||||
if ( ! resolved ) {
|
||||
type = GraphHelper.resolveKeyTypeDescriptor( SingularAttributeImpl.this );
|
||||
resolved = true;
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
|
||||
import javax.persistence.metamodel.BasicType;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.BasicDomainType;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link BasicType} descriptor
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface BasicTypeDescriptor<J> extends BasicDomainType<J>, SimpleTypeDescriptor<J>, SqmPathSource<J,J> {
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
|
||||
import javax.persistence.metamodel.EmbeddableType;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.EmbeddedDomainType;
|
||||
import org.hibernate.type.ComponentType;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link EmbeddableType} descriptor
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface EmbeddedTypeDescriptor<J> extends EmbeddedDomainType<J>, ManagedTypeDescriptor<J> {
|
||||
ComponentType getHibernateType();
|
||||
|
||||
ManagedTypeDescriptor<?> getParent();
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
|
||||
import javax.persistence.metamodel.EntityType;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link EntityType} descriptor
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface EntityTypeDescriptor<J> extends EntityDomainType<J>, IdentifiableTypeDescriptor<J> {
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import javax.persistence.metamodel.IdentifiableType;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link IdentifiableType} descriptor
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface IdentifiableTypeDescriptor<J> extends IdentifiableDomainType<J>, ManagedTypeDescriptor<J> {
|
||||
boolean hasIdClass();
|
||||
|
||||
SingularPersistentAttribute<? super J,?> locateIdAttribute();
|
||||
|
||||
void collectIdClassAttributes(Set<SingularPersistentAttribute<? super J,?>> attributes);
|
||||
|
||||
void visitIdClassAttributes(Consumer<SingularPersistentAttribute<? super J,?>> attributeConsumer);
|
||||
|
||||
interface InFlightAccess<X> extends ManagedTypeDescriptor.InFlightAccess<X> {
|
||||
void applyIdAttribute(SingularPersistentAttribute<X, ?> idAttribute);
|
||||
void applyIdClassAttributes(Set<SingularPersistentAttribute<? super X, ?>> idClassAttributes);
|
||||
void applyVersionAttribute(SingularPersistentAttribute<X, ?> versionAttribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
InFlightAccess<J> getInFlightAccess();
|
||||
|
||||
@Override
|
||||
SimpleTypeDescriptor<?> getIdType();
|
||||
|
||||
@Override
|
||||
<Y> SingularPersistentAttribute<J, Y> getDeclaredId(Class<Y> type);
|
||||
|
||||
@Override
|
||||
<Y> SingularPersistentAttribute<? super J, Y> getId(Class<Y> type);
|
||||
|
||||
SingularPersistentAttribute<? super J,?> locateVersionAttribute();
|
||||
|
||||
@Override
|
||||
<Y> SingularPersistentAttribute<? super J, Y> getVersion(Class<Y> type);
|
||||
|
||||
@Override
|
||||
<Y> SingularPersistentAttribute<J, Y> getDeclaredVersion(Class<Y> type);
|
||||
|
||||
@Override
|
||||
IdentifiableTypeDescriptor<? super J> getSuperType();
|
||||
|
||||
@Override
|
||||
default IdentifiableTypeDescriptor<? super J> getSupertype() {
|
||||
return getSuperType();
|
||||
}
|
||||
}
|
|
@ -1,191 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
|
||||
import javax.persistence.metamodel.CollectionAttribute;
|
||||
import javax.persistence.metamodel.ListAttribute;
|
||||
import javax.persistence.metamodel.ManagedType;
|
||||
import javax.persistence.metamodel.MapAttribute;
|
||||
import javax.persistence.metamodel.SetAttribute;
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
|
||||
import org.hibernate.graph.Graph;
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link ManagedType} descriptor
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ManagedTypeDescriptor<J> extends SimpleTypeDescriptor<J>, ManagedDomainType<J>, NavigableDescriptor<J,J> {
|
||||
/**
|
||||
* Get this ManagedType's super type descriptor. ATM only supported for the
|
||||
* {@link IdentifiableTypeDescriptor} branch of the ManagedType tree
|
||||
*/
|
||||
ManagedTypeDescriptor<? super J> getSuperType();
|
||||
|
||||
/**
|
||||
* The Hibernate "type name" ("entity name" - for non-POJO representations)
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Make an empty sub-graph based on this type.
|
||||
*
|
||||
* @apiNote Note that this is *not* the same as the type's
|
||||
* {@linkplain #getDefaultGraph "default" graph}
|
||||
*/
|
||||
SubGraphImplementor<J> makeSubGraph();
|
||||
|
||||
/**
|
||||
* The default graph for this type. Generally this is used to
|
||||
* implement JPA's notion of a "load graph" for undefined sub-graphs.
|
||||
*
|
||||
* @apiNote The return is immutable ({@link Graph#isMutable()} == {@code false}) -
|
||||
* use a {@linkplain Graph#makeCopy mutable copy}
|
||||
*/
|
||||
default SubGraphImplementor<J> getDefaultGraph() {
|
||||
throw new UnsupportedOperationException( "Not yet implemented - " + getClass().getName() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a sub-graph based on one of this type's sub-types
|
||||
*/
|
||||
<S extends J> SubGraphImplementor<S> makeSubGraph(Class<S> subType);
|
||||
|
||||
<S extends J> ManagedTypeDescriptor<S> findSubType(String subTypeName);
|
||||
|
||||
<S extends J> ManagedTypeDescriptor<S> findSubType(Class<S> type);
|
||||
|
||||
/**
|
||||
* In-flight access to the managed type. Used to add attributes, etc.
|
||||
* Valid only during boot.
|
||||
*/
|
||||
InFlightAccess<J> getInFlightAccess();
|
||||
|
||||
/**
|
||||
* Used during creation of the managed type object to add its attributes
|
||||
*/
|
||||
interface InFlightAccess<J> {
|
||||
void addAttribute(PersistentAttributeDescriptor<J, ?> attribute);
|
||||
|
||||
/**
|
||||
* Called when configuration of the managed-type is complete
|
||||
*/
|
||||
void finishUp();
|
||||
}
|
||||
|
||||
PersistentAttributeDescriptor<J, ?> findDeclaredAttribute(String name);
|
||||
|
||||
PersistentAttributeDescriptor<? super J, ?> findAttribute(String name);
|
||||
|
||||
@Override
|
||||
PersistentAttributeDescriptor<J, ?> getDeclaredAttribute(String name);
|
||||
|
||||
@Override
|
||||
PersistentAttributeDescriptor<? super J, ?> getAttribute(String name);
|
||||
|
||||
@Override
|
||||
<Y> SingularPersistentAttribute<? super J, Y> getSingularAttribute(String name, Class<Y> type);
|
||||
|
||||
@Override
|
||||
<Y> SingularPersistentAttribute<J,Y> getDeclaredSingularAttribute(String name, Class<Y> type);
|
||||
|
||||
<C,E> PluralPersistentAttribute<J,C,E> getPluralAttribute(String name);
|
||||
|
||||
@Override
|
||||
<E> BagPersistentAttribute<? super J, E> getCollection(String name, Class<E> elementType);
|
||||
|
||||
@Override
|
||||
default <E> CollectionAttribute<J, E> getDeclaredCollection(
|
||||
String name, Class<E> elementType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default <E> SetAttribute<? super J, E> getSet(String name, Class<E> elementType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default <E> SetAttribute<J, E> getDeclaredSet(String name, Class<E> elementType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default <E> ListAttribute<? super J, E> getList(String name, Class<E> elementType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default <E> ListAttribute<J, E> getDeclaredList(String name, Class<E> elementType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default <K, V> MapAttribute<? super J, K, V> getMap(
|
||||
String name, Class<K> keyType, Class<V> valueType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default <K, V> MapAttribute<J, K, V> getDeclaredMap(
|
||||
String name, Class<K> keyType, Class<V> valueType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default SingularAttribute<? super J, ?> getSingularAttribute(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default SingularAttribute<J, ?> getDeclaredSingularAttribute(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default CollectionAttribute<? super J, ?> getCollection(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default CollectionAttribute<J, ?> getDeclaredCollection(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default SetPersistentAttribute<? super J, ?> getSet(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default SetPersistentAttribute<J, ?> getDeclaredSet(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default ListPersistentAttribute<? super J, ?> getList(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default ListPersistentAttribute<J, ?> getDeclaredList(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default MapPersistentAttribute<? super J, ?, ?> getMap(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default MapPersistentAttribute<J, ?, ?> getDeclaredMap(String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
|
||||
import javax.persistence.metamodel.MappedSuperclassType;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link MappedSuperclassType} descriptor
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface MappedSuperclassTypeDescriptor<J> extends MappedSuperclassDomainType<J>, IdentifiableTypeDescriptor<J> {
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
|
||||
import javax.persistence.metamodel.Attribute;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
|
||||
/**
|
||||
* Hibernate extension to the JPA {@link Attribute} descriptor
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface PersistentAttributeDescriptor<D,J,B> extends PersistentAttribute<D,J,B> {
|
||||
@Override
|
||||
ManagedTypeDescriptor<D> getDeclaringType();
|
||||
|
||||
SimpleTypeDescriptor<?> getValueGraphType();
|
||||
SimpleTypeDescriptor<?> getKeyGraphType();
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.metamodel.model.domain.spi;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SimpleTypeDescriptor<J> extends SimpleDomainType<J>, DomainTypeDescriptor<J> {
|
||||
}
|
|
@ -17,9 +17,9 @@ import org.hibernate.MappingException;
|
|||
import org.hibernate.Metamodel;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.metamodel.model.domain.spi.EmbeddedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ManagedTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
@ -165,19 +165,19 @@ public interface MetamodelImplementor extends Metamodel {
|
|||
|
||||
|
||||
@Override
|
||||
<X> EntityTypeDescriptor<X> entity(String entityName);
|
||||
<X> EntityDomainType<X> entity(String entityName);
|
||||
|
||||
@Override
|
||||
<X> EntityTypeDescriptor<X> entity(Class<X> cls);
|
||||
<X> EntityDomainType<X> entity(Class<X> cls);
|
||||
|
||||
@Override
|
||||
<X> ManagedTypeDescriptor<X> managedType(Class<X> cls);
|
||||
<X> ManagedDomainType<X> managedType(Class<X> cls);
|
||||
|
||||
@Override
|
||||
<X> EmbeddedTypeDescriptor<X> embeddable(Class<X> cls);
|
||||
<X> EmbeddableDomainType<X> embeddable(Class<X> cls);
|
||||
|
||||
@Override
|
||||
default EntityTypeDescriptor getEntityTypeByName(String entityName) {
|
||||
default EntityDomainType getEntityTypeByName(String entityName) {
|
||||
return entity( entityName );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.hibernate.metamodel.model.domain.DomainType;
|
|||
import org.hibernate.query.sqm.produce.path.spi.SemanticPathPart;
|
||||
import org.hibernate.query.sqm.produce.spi.SqmCreationState;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmExpression;
|
||||
|
||||
/**
|
||||
* Represents parts of the application's domain model that can be used
|
||||
|
@ -20,7 +21,7 @@ import org.hibernate.query.sqm.tree.domain.SqmPath;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface SqmPathSource<J,B> extends SqmExpressable<J>, SemanticPathPart {
|
||||
public interface SqmPathSource<J> extends SqmExpressable<J>, SemanticPathPart {
|
||||
/**
|
||||
* The name of this thing. Mainly used in logging and when creating a
|
||||
* {@link org.hibernate.query.NavigablePath}
|
||||
|
@ -30,12 +31,21 @@ public interface SqmPathSource<J,B> extends SqmExpressable<J>, SemanticPathPart
|
|||
/**
|
||||
* The type of SqmPaths this source creates
|
||||
*/
|
||||
DomainType<B> getSqmNodeType();
|
||||
DomainType<?> getSqmNodeType();
|
||||
|
||||
SqmPathSource<?,?> findSubPathSource(String name);
|
||||
SqmPathSource<?> findSubPathSource(String name);
|
||||
|
||||
/**
|
||||
* Create an SQM path for this source relative to the given left-hand side
|
||||
*/
|
||||
SqmPath<B> createSqmPath(SqmPath<?> lhs, SqmCreationState creationState);
|
||||
SqmPath<J> createSqmPath(SqmPath<?> lhs, SqmCreationState creationState);
|
||||
|
||||
@Override
|
||||
default SqmPath resolveIndexedAccess(
|
||||
SqmExpression selector,
|
||||
String currentContextKey,
|
||||
boolean isTerminal,
|
||||
SqmCreationState creationState) {
|
||||
throw new UnsupportedOperationException( "SqmPathSource [" + getClass().getName() + "] cannot be index accessed" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,10 @@ package org.hibernate.query.sqm.produce.function;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.AllowableFunctionReturnType;
|
||||
import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType;
|
||||
import org.hibernate.query.spi.QueryEngine;
|
||||
import org.hibernate.query.sqm.produce.function.internal.SelfRenderingSqmFunction;
|
||||
import org.hibernate.query.sqm.tree.SqmTypedNode;
|
||||
import org.hibernate.sql.Template;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
|
|
@ -11,7 +11,7 @@ import javax.persistence.criteria.Predicate;
|
|||
import javax.persistence.criteria.Root;
|
||||
import javax.persistence.metamodel.EntityType;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.query.criteria.JpaCriteriaDelete;
|
||||
import org.hibernate.query.criteria.JpaPredicate;
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
|
@ -67,7 +67,7 @@ public class SqmDeleteStatement<T>
|
|||
|
||||
@Override
|
||||
public Root<T> from(Class<T> entityClass) {
|
||||
final EntityTypeDescriptor<T> entity = nodeBuilder().getDomainModel().entity( entityClass );
|
||||
final EntityDomainType<T> entity = nodeBuilder().getDomainModel().entity( entityClass );
|
||||
SqmRoot<T> root = new SqmRoot<>( entity, null, nodeBuilder() );
|
||||
setTarget( root );
|
||||
return root;
|
||||
|
@ -75,7 +75,7 @@ public class SqmDeleteStatement<T>
|
|||
|
||||
@Override
|
||||
public Root<T> from(EntityType<T> entity) {
|
||||
SqmRoot<T> root = new SqmRoot<>( (EntityTypeDescriptor<T>) entity, null, nodeBuilder() );
|
||||
SqmRoot<T> root = new SqmRoot<>( (EntityDomainType<T>) entity, null, nodeBuilder() );
|
||||
setTarget( root );
|
||||
return root;
|
||||
}
|
||||
|
|
|
@ -24,13 +24,14 @@ import javax.persistence.metamodel.SetAttribute;
|
|||
import javax.persistence.metamodel.SingularAttribute;
|
||||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.metamodel.model.domain.spi.BagPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.BagPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.ListPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.MapPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.SetPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.ListPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.MapPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SetPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.query.criteria.JpaPath;
|
||||
import org.hibernate.query.criteria.JpaSubQuery;
|
||||
|
@ -61,7 +62,7 @@ public abstract class AbstractSqmFrom<O,T> extends AbstractSqmPath<T> implements
|
|||
|
||||
protected AbstractSqmFrom(
|
||||
NavigablePath navigablePath,
|
||||
SqmPathSource<?,T> referencedNavigable,
|
||||
SqmPathSource<T> referencedNavigable,
|
||||
SqmFrom lhs,
|
||||
String alias,
|
||||
NodeBuilder nodeBuilder) {
|
||||
|
@ -77,14 +78,14 @@ public abstract class AbstractSqmFrom<O,T> extends AbstractSqmPath<T> implements
|
|||
* Intended for use with {@link SqmRoot}
|
||||
*/
|
||||
protected AbstractSqmFrom(
|
||||
EntityTypeDescriptor<T> entityTypeDescriptor,
|
||||
EntityDomainType<T> entityType,
|
||||
String alias,
|
||||
NodeBuilder nodeBuilder) {
|
||||
super(
|
||||
alias == null
|
||||
? new NavigablePath( entityTypeDescriptor.getHibernateEntityName() )
|
||||
: new NavigablePath( entityTypeDescriptor.getHibernateEntityName() + '(' + alias + ')' ),
|
||||
entityTypeDescriptor,
|
||||
? new NavigablePath( entityType.getHibernateEntityName() )
|
||||
: new NavigablePath( entityType.getHibernateEntityName() + '(' + alias + ')' ),
|
||||
entityType,
|
||||
null,
|
||||
nodeBuilder
|
||||
);
|
||||
|
|
|
@ -16,10 +16,10 @@ import javax.persistence.metamodel.PluralAttribute;
|
|||
import javax.persistence.metamodel.SingularAttribute;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.DomainType;
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.spi.MapPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.SingularPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.MapPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
|
@ -38,7 +38,7 @@ public abstract class AbstractSqmPath<T> extends AbstractSqmExpression<T> implem
|
|||
@SuppressWarnings("WeakerAccess")
|
||||
protected AbstractSqmPath(
|
||||
NavigablePath navigablePath,
|
||||
SqmPathSource<?,T> referencedPathSource,
|
||||
SqmPathSource<?> referencedPathSource,
|
||||
SqmPath<?> lhs,
|
||||
NodeBuilder nodeBuilder) {
|
||||
super( referencedPathSource, nodeBuilder );
|
||||
|
@ -47,7 +47,7 @@ public abstract class AbstractSqmPath<T> extends AbstractSqmExpression<T> implem
|
|||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
protected AbstractSqmPath(SqmPathSource<?,T> referencedPathSource, SqmPath lhs, NodeBuilder nodeBuilder) {
|
||||
protected AbstractSqmPath(SqmPathSource<?> referencedPathSource, SqmPath lhs, NodeBuilder nodeBuilder) {
|
||||
this(
|
||||
lhs == null
|
||||
? new NavigablePath( referencedPathSource.getPathName() )
|
||||
|
@ -90,8 +90,8 @@ public abstract class AbstractSqmPath<T> extends AbstractSqmExpression<T> implem
|
|||
@SuppressWarnings("unchecked")
|
||||
public SqmExpression<Class<? extends T>> type() {
|
||||
if ( pathTypeExpression == null ) {
|
||||
final DomainType<T> sqmNodeType = getReferencedPathSource().getSqmNodeType();
|
||||
if ( sqmNodeType instanceof EntityTypeDescriptor ) {
|
||||
final DomainType sqmNodeType = getReferencedPathSource().getSqmNodeType();
|
||||
if ( sqmNodeType instanceof EntityDomainType ) {
|
||||
pathTypeExpression = new SqmBasicValuedSimplePath(
|
||||
getNavigablePath().append( "{type}" ),
|
||||
???,
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
*/
|
||||
package org.hibernate.query.sqm.tree.domain;
|
||||
|
||||
import org.hibernate.metamodel.model.mapping.spi.Navigable;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -18,19 +18,19 @@ public abstract class AbstractSqmSimplePath<T> extends AbstractSqmPath<T> implem
|
|||
|
||||
public AbstractSqmSimplePath(
|
||||
NavigablePath navigablePath,
|
||||
Navigable<T> referencedNavigable,
|
||||
SqmPathSource<T> referencedPathSource,
|
||||
SqmPath lhs,
|
||||
NodeBuilder nodeBuilder) {
|
||||
this( navigablePath, referencedNavigable, lhs, null, nodeBuilder );
|
||||
this( navigablePath, referencedPathSource, lhs, null, nodeBuilder );
|
||||
}
|
||||
|
||||
public AbstractSqmSimplePath(
|
||||
NavigablePath navigablePath,
|
||||
Navigable<T> referencedNavigable,
|
||||
SqmPathSource<T> referencedPathSource,
|
||||
SqmPath lhs,
|
||||
String explicitAlias,
|
||||
NodeBuilder nodeBuilder) {
|
||||
super( referencedNavigable, lhs, nodeBuilder );
|
||||
super( referencedPathSource, lhs, nodeBuilder );
|
||||
this.navigablePath = navigablePath;
|
||||
|
||||
setExplicitAlias( explicitAlias );
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.hibernate.query.criteria.JpaPath;
|
|||
import org.hibernate.query.criteria.PathException;
|
||||
import org.hibernate.query.sqm.ParsingException;
|
||||
import org.hibernate.query.sqm.SemanticException;
|
||||
import org.hibernate.query.sqm.SqmExpressable;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
import org.hibernate.query.sqm.produce.SqmCreationHelper;
|
||||
import org.hibernate.query.sqm.produce.path.spi.SemanticPathPart;
|
||||
|
@ -44,7 +45,7 @@ public interface SqmPath<T> extends SqmExpression<T>, SemanticPathPart, JpaPath<
|
|||
*
|
||||
* @see SqmPathSource#createSqmPath
|
||||
*/
|
||||
SqmPathSource<?, T> getReferencedPathSource();
|
||||
SqmPathSource<?> getReferencedPathSource();
|
||||
|
||||
/**
|
||||
* Retrieve the explicit alias, if one. May return null
|
||||
|
@ -63,7 +64,7 @@ public interface SqmPath<T> extends SqmExpression<T>, SemanticPathPart, JpaPath<
|
|||
DomainType<T> getNodeType();
|
||||
|
||||
@Override
|
||||
default void applyInferableType(DomainType<T> type) {
|
||||
default void applyInferableType(SqmExpressable<T> type) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
@ -133,7 +134,7 @@ public interface SqmPath<T> extends SqmExpression<T>, SemanticPathPart, JpaPath<
|
|||
* todo (6.0) : ideally we'd delay this until SQM -> SQL AST conversion : criteria-as-SQM
|
||||
*/
|
||||
default void prepareForSubNavigableReference(
|
||||
SqmPathSource<?,?> subNavigable,
|
||||
SqmPathSource<?> subNavigable,
|
||||
boolean isSubReferenceTerminal,
|
||||
SqmCreationState creationState) {
|
||||
SqmCreationHelper.resolveAsLhs( getLhs(), this, subNavigable, isSubReferenceTerminal, creationState );
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.query.sqm.tree.domain;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.PluralPersistentAttribute;
|
||||
import org.hibernate.metamodel.model.mapping.spi.CollectionElement;
|
||||
import org.hibernate.metamodel.model.mapping.spi.CollectionIndex;
|
||||
import org.hibernate.metamodel.model.mapping.EntityTypeDescriptor;
|
||||
|
@ -25,7 +26,7 @@ import org.hibernate.type.descriptor.java.internal.CollectionJavaDescriptor;
|
|||
public class SqmPluralValuedSimplePath<E> extends AbstractSqmSimplePath<E> {
|
||||
public SqmPluralValuedSimplePath(
|
||||
NavigablePath navigablePath,
|
||||
PluralValuedNavigable referencedNavigable,
|
||||
PluralPersistentAttribute referencedNavigable,
|
||||
SqmPath lhs,
|
||||
NodeBuilder nodeBuilder) {
|
||||
this( navigablePath, referencedNavigable, lhs, null, nodeBuilder );
|
||||
|
@ -33,7 +34,7 @@ public class SqmPluralValuedSimplePath<E> extends AbstractSqmSimplePath<E> {
|
|||
|
||||
public SqmPluralValuedSimplePath(
|
||||
NavigablePath navigablePath,
|
||||
PluralValuedNavigable referencedNavigable,
|
||||
PluralPersistentAttribute referencedNavigable,
|
||||
SqmPath lhs,
|
||||
String explicitAlias,
|
||||
NodeBuilder nodeBuilder) {
|
||||
|
|
|
@ -8,7 +8,7 @@ package org.hibernate.query.sqm.tree.domain;
|
|||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.query.criteria.PathException;
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
import org.hibernate.query.sqm.SqmJoinable;
|
||||
|
@ -31,7 +31,7 @@ public class SqmSingularJoin<O,T> extends AbstractSqmAttributeJoin<O,T> {
|
|||
|
||||
@Override
|
||||
public <S extends T> SqmTreatedSingularJoin<O,T,S> treatAs(Class<S> treatJavaType) throws PathException {
|
||||
final EntityTypeDescriptor<S> targetDescriptor = nodeBuilder().getDomainModel().entity( treatJavaType );
|
||||
final EntityDomainType<S> targetDescriptor = nodeBuilder().getDomainModel().entity( treatJavaType );
|
||||
return new SqmTreatedSingularJoin<>( this, targetDescriptor, null );
|
||||
}
|
||||
|
||||
|
|
|
@ -6,25 +6,25 @@
|
|||
*/
|
||||
package org.hibernate.query.sqm.tree.from;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.query.criteria.JpaRoot;
|
||||
import org.hibernate.query.criteria.PathException;
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
import org.hibernate.query.sqm.consume.spi.SemanticQueryWalker;
|
||||
import org.hibernate.query.sqm.tree.domain.AbstractSqmFrom;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmTreatedRoot;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SqmRoot<E> extends AbstractSqmFrom<E,E> implements JpaRoot<E> {
|
||||
public SqmRoot(
|
||||
EntityTypeDescriptor<E> entityTypeDescriptor,
|
||||
EntityDomainType<E> entityType,
|
||||
String alias,
|
||||
NodeBuilder nodeBuilder) {
|
||||
super( entityTypeDescriptor, alias, nodeBuilder );
|
||||
super( entityType, alias, nodeBuilder );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,16 +39,16 @@ public class SqmRoot<E> extends AbstractSqmFrom<E,E> implements JpaRoot<E> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SqmPathSource<?, E> getReferencedPathSource() {
|
||||
return (EntityTypeDescriptor<E>) super.getReferencedPathSource();
|
||||
public EntityDomainType<E> getReferencedPathSource() {
|
||||
return (EntityDomainType<E>) super.getReferencedPathSource();
|
||||
}
|
||||
|
||||
public String getEntityName() {
|
||||
return getReferencedPathSource().getEntityName();
|
||||
return getReferencedPathSource().getHibernateEntityName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityJavaDescriptor<E> getJavaTypeDescriptor() {
|
||||
public JavaTypeDescriptor<E> getJavaTypeDescriptor() {
|
||||
return getReferencedPathSource().getJavaTypeDescriptor();
|
||||
}
|
||||
|
||||
|
@ -69,18 +69,18 @@ public class SqmRoot<E> extends AbstractSqmFrom<E,E> implements JpaRoot<E> {
|
|||
// JPA
|
||||
|
||||
@Override
|
||||
public EntityTypeDescriptor<E> getManagedType() {
|
||||
public EntityDomainType<E> getManagedType() {
|
||||
return getReferencedPathSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityTypeDescriptor<E> getModel() {
|
||||
public EntityDomainType<E> getModel() {
|
||||
return getReferencedPathSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends E> SqmTreatedRoot<E, S> treatAs(Class<S> treatJavaType) throws PathException {
|
||||
final EntityTypeDescriptor<S> typeDescriptor = nodeBuilder().getDomainModel().entity( treatJavaType );
|
||||
final EntityDomainType<S> typeDescriptor = nodeBuilder().getDomainModel().entity( treatJavaType );
|
||||
return new SqmTreatedRoot<>( this, typeDescriptor, nodeBuilder() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,10 @@ public interface JavaTypeDescriptor<T> extends Serializable {
|
|||
* Retrieve the natural comparator for this type.
|
||||
*/
|
||||
default Comparator<T> getComparator() {
|
||||
return Comparable.class.isAssignableFrom( Comparable.class ) ? ComparableComparator.INSTANCE : null;
|
||||
//noinspection unchecked
|
||||
return Comparable.class.isAssignableFrom( getJavaType() )
|
||||
? ComparableComparator.INSTANCE
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.metamodel.model.domain.spi.EntityTypeDescriptor;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -177,7 +177,7 @@ public class EntityGraphUsingFetchGraphTest extends BaseEntityManagerFunctionalT
|
|||
em.getTransaction().begin();
|
||||
|
||||
final EntityGraph<CustomerOrder> entityGraph = em.createEntityGraph( CustomerOrder.class );
|
||||
EntityTypeDescriptor<CustomerOrder> customerOrderEntityType =
|
||||
EntityDomainType<CustomerOrder> customerOrderEntityType =
|
||||
entityManagerFactory().getMetamodel().entity( CustomerOrder.class );
|
||||
entityGraph.addAttributeNodes(
|
||||
(Attribute) customerOrderEntityType.getAttribute( "shippingAddress" ),
|
||||
|
@ -187,14 +187,14 @@ public class EntityGraphUsingFetchGraphTest extends BaseEntityManagerFunctionalT
|
|||
|
||||
final Subgraph<OrderPosition> orderProductsSubgraph =
|
||||
entityGraph.addSubgraph( (Attribute) customerOrderEntityType.getAttribute( "orderPosition" ) );
|
||||
EntityTypeDescriptor<OrderPosition> positionEntityType =
|
||||
EntityDomainType<OrderPosition> positionEntityType =
|
||||
entityManagerFactory().getMetamodel().entity( OrderPosition.class );
|
||||
orderProductsSubgraph.addAttributeNodes( (Attribute) positionEntityType.getAttribute( "amount" ) );
|
||||
orderProductsSubgraph.addAttributeNodes( (Attribute) positionEntityType.getAttribute( "product" ) );
|
||||
|
||||
final Subgraph<Product> productSubgraph =
|
||||
orderProductsSubgraph.addSubgraph( (Attribute) positionEntityType.getAttribute( "product" ) );
|
||||
EntityTypeDescriptor<Product> productEntityType = entityManagerFactory().getMetamodel().entity( Product.class );
|
||||
EntityDomainType<Product> productEntityType = entityManagerFactory().getMetamodel().entity( Product.class );
|
||||
productSubgraph.addAttributeNodes( (Attribute) productEntityType.getAttribute( "productName" ) );
|
||||
|
||||
TypedQuery<CustomerOrder> query = em.createQuery(
|
||||
|
|
Loading…
Reference in New Issue