Lookup RevisionTypeType rather than re-create CustomType instances
This commit is contained in:
parent
fd73a1af85
commit
5dfbaf58ef
|
@ -22,7 +22,7 @@ import org.hibernate.envers.internal.tools.query.Parameters;
|
||||||
import org.hibernate.envers.internal.tools.query.QueryBuilder;
|
import org.hibernate.envers.internal.tools.query.QueryBuilder;
|
||||||
import org.hibernate.envers.strategy.AuditStrategy;
|
import org.hibernate.envers.strategy.AuditStrategy;
|
||||||
import org.hibernate.query.Query;
|
import org.hibernate.query.Query;
|
||||||
import org.hibernate.type.CustomType;
|
import org.hibernate.type.BasicType;
|
||||||
|
|
||||||
import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.DEL_REVISION_TYPE_PARAMETER;
|
import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.DEL_REVISION_TYPE_PARAMETER;
|
||||||
import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REVISION_PARAMETER;
|
import static org.hibernate.envers.internal.entities.mapper.relation.query.QueryConstants.REVISION_PARAMETER;
|
||||||
|
@ -66,12 +66,13 @@ public abstract class AbstractRelationQueryGenerator implements RelationQueryGen
|
||||||
public Query getQuery(SharedSessionContractImplementor session, Object primaryKey, Number revision, boolean removed) {
|
public Query getQuery(SharedSessionContractImplementor session, Object primaryKey, Number revision, boolean removed) {
|
||||||
final String queryString = getQueryString( session.getFactory(), removed );
|
final String queryString = getQueryString( session.getFactory(), removed );
|
||||||
|
|
||||||
|
final BasicType<?> revisionType = session.getFactory()
|
||||||
|
.getTypeConfiguration()
|
||||||
|
.getBasicTypeRegistry()
|
||||||
|
.getRegisteredType( RevisionTypeType.class );
|
||||||
|
|
||||||
final Query query = session.createQuery( queryString );
|
final Query query = session.createQuery( queryString );
|
||||||
query.setParameter(
|
query.setParameter( DEL_REVISION_TYPE_PARAMETER, RevisionType.DEL, revisionType );
|
||||||
DEL_REVISION_TYPE_PARAMETER,
|
|
||||||
RevisionType.DEL,
|
|
||||||
new CustomType( new RevisionTypeType(), session.getFactory().getTypeConfiguration() )
|
|
||||||
);
|
|
||||||
query.setParameter( REVISION_PARAMETER, revision );
|
query.setParameter( REVISION_PARAMETER, revision );
|
||||||
|
|
||||||
final IdMapper prefixIdMapper = referencingIdData.getPrefixedMapper();
|
final IdMapper prefixIdMapper = referencingIdData.getPrefixedMapper();
|
||||||
|
|
|
@ -8,13 +8,11 @@ package org.hibernate.envers.internal.tools.query;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.criteria.JoinType;
|
import javax.persistence.criteria.JoinType;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.NotYetImplementedFor6Exception;
|
import org.hibernate.NotYetImplementedFor6Exception;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
@ -25,8 +23,7 @@ import org.hibernate.envers.internal.tools.StringTools;
|
||||||
import org.hibernate.envers.internal.tools.Triple;
|
import org.hibernate.envers.internal.tools.Triple;
|
||||||
import org.hibernate.envers.tools.Pair;
|
import org.hibernate.envers.tools.Pair;
|
||||||
import org.hibernate.query.Query;
|
import org.hibernate.query.Query;
|
||||||
import org.hibernate.sql.Template;
|
import org.hibernate.type.BasicType;
|
||||||
import org.hibernate.type.CustomType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class for incrementally building a HQL query.
|
* A class for incrementally building a HQL query.
|
||||||
|
@ -68,6 +65,8 @@ public class QueryBuilder {
|
||||||
|
|
||||||
private final SessionFactoryImplementor sessionFactory;
|
private final SessionFactoryImplementor sessionFactory;
|
||||||
|
|
||||||
|
private final BasicType<?> revisionType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param entityName Main entity which should be selected.
|
* @param entityName Main entity which should be selected.
|
||||||
* @param alias Alias of the entity
|
* @param alias Alias of the entity
|
||||||
|
@ -89,6 +88,10 @@ public class QueryBuilder {
|
||||||
this.paramCounter = paramCounter;
|
this.paramCounter = paramCounter;
|
||||||
this.sessionFactory = sessionFactory;
|
this.sessionFactory = sessionFactory;
|
||||||
|
|
||||||
|
this.revisionType = sessionFactory.getTypeConfiguration()
|
||||||
|
.getBasicTypeRegistry()
|
||||||
|
.getRegisteredType( RevisionTypeType.class );
|
||||||
|
|
||||||
final Parameters rootParameters = new Parameters( alias, "and", paramCounter );
|
final Parameters rootParameters = new Parameters( alias, "and", paramCounter );
|
||||||
parameters.add( rootParameters );
|
parameters.add( rootParameters );
|
||||||
|
|
||||||
|
@ -105,6 +108,7 @@ public class QueryBuilder {
|
||||||
this.entityName = other.entityName;
|
this.entityName = other.entityName;
|
||||||
this.alias = other.alias;
|
this.alias = other.alias;
|
||||||
this.sessionFactory = other.sessionFactory;
|
this.sessionFactory = other.sessionFactory;
|
||||||
|
this.revisionType = other.revisionType;
|
||||||
this.aliasCounter = other.aliasCounter.deepCopy();
|
this.aliasCounter = other.aliasCounter.deepCopy();
|
||||||
this.paramCounter = other.paramCounter.deepCopy();
|
this.paramCounter = other.paramCounter.deepCopy();
|
||||||
for (final Parameters params : other.parameters) {
|
for (final Parameters params : other.parameters) {
|
||||||
|
@ -318,11 +322,7 @@ public class QueryBuilder {
|
||||||
for ( Map.Entry<String, Object> paramValue : queryParamValues.entrySet() ) {
|
for ( Map.Entry<String, Object> paramValue : queryParamValues.entrySet() ) {
|
||||||
if ( paramValue.getValue() instanceof RevisionType ) {
|
if ( paramValue.getValue() instanceof RevisionType ) {
|
||||||
// this is needed when the ClassicQueryTranslatorFactory is used
|
// this is needed when the ClassicQueryTranslatorFactory is used
|
||||||
query.setParameter(
|
query.setParameter( paramValue.getKey(), paramValue.getValue(), revisionType );
|
||||||
paramValue.getKey(),
|
|
||||||
paramValue.getValue(),
|
|
||||||
new CustomType( new RevisionTypeType(), sessionFactory.getTypeConfiguration() )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
query.setParameter( paramValue.getKey(), paramValue.getValue() );
|
query.setParameter( paramValue.getKey(), paramValue.getValue() );
|
||||||
|
|
Loading…
Reference in New Issue