6 - SQM based on JPA type system

This commit is contained in:
Andrea Boriero 2019-08-19 10:11:28 +01:00
parent 00d3abba13
commit 58acd33b54
9 changed files with 71 additions and 2 deletions

View File

@ -170,6 +170,7 @@ import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper;
import org.hibernate.type.VersionType;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* Basic functionality for persisting an entity via JDBC
@ -1893,6 +1894,11 @@ public abstract class AbstractEntityPersister
.toStatementString();
}
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return getEntityKeyDefinition().getExpressableJavaTypeDescriptor();
}
protected interface InclusionChecker {
boolean includeProperty(int propertyNumber);
}

View File

@ -17,7 +17,6 @@ import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.cache.spi.access.EntityDataAccess;
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
@ -44,7 +43,6 @@ import org.hibernate.sql.SelectFragment;
import org.hibernate.type.AssociationType;
import org.hibernate.type.DiscriminatorType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* The default implementation of the <tt>EntityPersister</tt> interface.

View File

@ -141,6 +141,11 @@ public final class CompositionSingularSubAttributesHelper {
final AssociationType aType = (AssociationType) type;
return new AssociationAttributeDefinition() {
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return source.getExpressableJavaTypeDescriptor();
}
@Override
public void visitJdbcTypes(
Consumer action,
@ -241,6 +246,11 @@ public final class CompositionSingularSubAttributesHelper {
}
else if ( type.isComponentType() ) {
return new CompositionDefinition() {
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return source.getExpressableJavaTypeDescriptor();
}
@Override
public String getName() {
return name;
@ -275,6 +285,11 @@ public final class CompositionSingularSubAttributesHelper {
}
else {
return new AttributeDefinition() {
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return source.getExpressableJavaTypeDescriptor();
}
@Override
public String getName() {
return name;

View File

@ -28,6 +28,11 @@ public final class EntityIdentifierDefinitionHelper {
public static EntityIdentifierDefinition buildSimpleEncapsulatedIdentifierDefinition(final AbstractEntityPersister entityPersister) {
return new EncapsulatedEntityIdentifierDefinition() {
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return entityPersister.getEntityKeyDefinition().getExpressableJavaTypeDescriptor();
}
private final AttributeDefinitionAdapter attr = new AttributeDefinitionAdapter( entityPersister);
@Override
@ -51,6 +56,11 @@ public final class EntityIdentifierDefinitionHelper {
final AbstractEntityPersister entityPersister) {
return new EncapsulatedEntityIdentifierDefinition() {
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return entityPersister.getExpressableJavaTypeDescriptor();
}
private final CompositionDefinitionAdapter compositionDefinition = new CompositionDefinitionAdapter( entityPersister );
@Override
@ -72,6 +82,11 @@ public final class EntityIdentifierDefinitionHelper {
public static EntityIdentifierDefinition buildNonEncapsulatedCompositeIdentifierDefinition(final AbstractEntityPersister entityPersister) {
return new NonEncapsulatedEntityIdentifierDefinition() {
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return entityPersister.getEntityKeyDefinition().getExpressableJavaTypeDescriptor();
}
private final CompositionDefinitionAdapter compositionDefinition = new CompositionDefinitionAdapter( entityPersister );
@Override
@ -159,6 +174,11 @@ public final class EntityIdentifierDefinitionHelper {
protected AbstractEntityPersister getEntityPersister() {
return entityPersister;
}
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return getEntityPersister().getEntityKeyDefinition().getExpressableJavaTypeDescriptor();
}
}
private static class CompositionDefinitionAdapter extends AttributeDefinitionAdapter implements CompositionDefinition {
@ -180,5 +200,10 @@ public final class EntityIdentifierDefinitionHelper {
public Iterable<AttributeDefinition> getAttributes() {
return CompositionSingularSubAttributesHelper.getIdentifierSubAttributes( getEntityPersister() );
}
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return getEntityPersister().getEntityKeyDefinition().getExpressableJavaTypeDescriptor();
}
}
}

View File

@ -11,6 +11,7 @@ import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.walking.spi.AttributeSource;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* @author Steve Ebersole
@ -112,4 +113,9 @@ public abstract class AbstractNonIdentifierAttribute extends AbstractAttribute i
public String toString() {
return "Attribute(name=" + getName() + ", type=" + getType().getName() + " [" + loggableMetadata() + "])";
}
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return source().getExpressableJavaTypeDescriptor();
}
}

View File

@ -12,6 +12,7 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.tuple.AbstractNonIdentifierAttribute;
import org.hibernate.tuple.BaselineAttributeInformation;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* Represents a version property within the Hibernate runtime-metamodel.

View File

@ -55,6 +55,7 @@ import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.Type;
import org.hibernate.type.VersionType;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.junit.Assert;
import org.junit.Test;
@ -658,6 +659,11 @@ public class PersisterClassProviderTest {
public boolean isAffectedByEnabledFetchProfiles(LoadQueryInfluencers influencers) {
return false;
}
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return null;
}
}
public static class GoofyException extends RuntimeException {

View File

@ -56,6 +56,7 @@ import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type;
import org.hibernate.type.VersionType;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* @author Emmanuel Bernard <emmanuel@hibernate.org>
@ -644,6 +645,11 @@ public class GoofyPersisterClassProvider implements PersisterClassResolver {
public boolean isAffectedByEnabledFetchProfiles(LoadQueryInfluencers influencers) {
return false;
}
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return null;
}
}
public static class NoopCollectionPersister implements CollectionPersister {

View File

@ -56,6 +56,7 @@ import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;
import org.hibernate.type.VersionType;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
public class CustomPersister implements EntityPersister {
@ -755,4 +756,9 @@ public class CustomPersister implements EntityPersister {
public boolean isAffectedByEnabledFilters(LoadQueryInfluencers loadQueryInfluencers) {
return false;
}
@Override
public JavaTypeDescriptor getExpressableJavaTypeDescriptor() {
return getEntityKeyDefinition().getExpressableJavaTypeDescriptor();
}
}