6 - SQM based on JPA type system

This commit is contained in:
Andrea Boriero 2019-07-22 10:38:30 +01:00
parent 697aeb2f82
commit b196374da9
5 changed files with 41 additions and 66 deletions

View File

@ -80,7 +80,7 @@ public class EntityInstantiator {
.getFactory()
.getEntityPersister( entityName )
.getEntityTuplizer()
.instantiate( null, versionsReader.getSession() );
.instantiate( null, versionsReader.getSessionImplementor() );
// Putting the newly created entity instance into the first level cache, in case a one-to-one bidirectional
// relation is present (which is eagerly loaded).

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.envers.internal.reader;
import org.hibernate.Session;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.envers.AuditReader;
@ -17,7 +18,7 @@ import org.hibernate.envers.AuditReader;
public interface AuditReaderImplementor extends AuditReader {
SessionImplementor getSessionImplementor();
SessionImplementor getSession();
Session getSession();
FirstLevelCache getFirstLevelCache();
}

View File

@ -12,15 +12,12 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.persistence.criteria.JoinType;
import org.hibernate.HibernateException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.Session;
import org.hibernate.SharedSessionContract;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.internal.entities.RevisionTypeType;
import org.hibernate.envers.internal.tools.MutableInteger;
@ -29,12 +26,6 @@ import org.hibernate.envers.internal.tools.Triple;
import org.hibernate.envers.tools.Pair;
import org.hibernate.query.Query;
import org.hibernate.sql.Template;
import org.hibernate.sql.ordering.antlr.ColumnMapper;
import org.hibernate.sql.ordering.antlr.ColumnReference;
import org.hibernate.sql.ordering.antlr.FormulaReference;
import org.hibernate.sql.ordering.antlr.OrderByAliasResolver;
import org.hibernate.sql.ordering.antlr.OrderByTranslation;
import org.hibernate.sql.ordering.antlr.SqlValueReference;
import org.hibernate.type.CustomType;
/**
@ -252,43 +243,46 @@ public class QueryBuilder {
StringTools.append( sb, getOrderList().iterator(), ", " );
}
else if ( !orderFragments.isEmpty() ) {
sb.append( " order by " );
// todo (6.0) : How to backport HHH-12992 to use Template#translateOrderBy from master?
throw new NotYetImplementedFor6Exception( getClass() );
final Iterator<Pair<String, String>> fragmentIterator = orderFragments.iterator();
while( fragmentIterator.hasNext() ) {
final Pair<String, String> fragment = fragmentIterator.next();
final OrderByTranslation orderByFragmentTranslation = Template.translateOrderBy(
fragment.getSecond(),
new ColumnMapper() {
@Override
public SqlValueReference[] map(String reference) throws HibernateException {
return new SqlValueReference[ 0 ];
}
},
sessionFactory,
sessionFactory.getJdbcServices().getDialect(),
sessionFactory.getSqlFunctionRegistry()
);
sb.append( orderByFragmentTranslation.injectAliases( new QueryOrderByAliasResolver( fragment.getFirst() ) ) );
if ( fragmentIterator.hasNext() ) {
sb.append( ", " );
}
}
// sb.append( " order by " );
//
// final Iterator<Pair<String, String>> fragmentIterator = orderFragments.iterator();
// while( fragmentIterator.hasNext() ) {
// final Pair<String, String> fragment = fragmentIterator.next();
// final OrderByTranslation orderByFragmentTranslation = Template.translateOrderBy(
// fragment.getSecond(),
// new ColumnMapper() {
// @Override
// public SqlValueReference[] map(String reference) throws HibernateException {
// return new SqlValueReference[ 0 ];
// }
// },
// sessionFactory,
// sessionFactory.getJdbcServices().getDialect(),
// sessionFactory.getSqlFunctionRegistry()
// );
//
// sb.append( orderByFragmentTranslation.injectAliases( new QueryOrderByAliasResolver( fragment.getFirst() ) ) );
// if ( fragmentIterator.hasNext() ) {
// sb.append( ", " );
// }
// }
}
}
private class QueryOrderByAliasResolver implements OrderByAliasResolver {
private String alias;
public QueryOrderByAliasResolver(String alias) {
this.alias = alias;
}
@Override
public String resolveTableAlias(String columnReference) {
return alias;
}
}
// private class QueryOrderByAliasResolver implements OrderByAliasResolver {
// private String alias;
// public QueryOrderByAliasResolver(String alias) {
// this.alias = alias;
// }
//
// @Override
// public String resolveTableAlias(String columnReference) {
// return alias;
// }
// }
private List<String> getSelectAliasList() {
final List<String> aliasList = new ArrayList<>();

View File

@ -69,16 +69,6 @@ public class AuditProperty<T> implements AuditProjection {
return new SimpleAuditExpression( alias, propertyNameGetter, value, " like " );
}
/**
* Apply a "like" constraint
*
* @deprecated since 5.2, use {@link #like(String, MatchMode)}.
*/
@Deprecated
public AuditCriterion like(String value, org.hibernate.criterion.MatchMode matchMode) {
return new SimpleAuditExpression( alias, propertyNameGetter, matchMode.toMatchString( value ), " like" );
}
/**
* Apply a "like" constraint
*/
@ -93,16 +83,6 @@ public class AuditProperty<T> implements AuditProjection {
return new IlikeAuditExpression( alias, propertyNameGetter, value.toString() );
}
/**
* Apply an "ilike" constraint
*
* @deprecated since 5.2, use {@link #ilike(String, MatchMode)}.
*/
@Deprecated
public AuditCriterion ilike(String value, org.hibernate.criterion.MatchMode matchMode) {
return new IlikeAuditExpression( alias, propertyNameGetter, matchMode.toMatchString( value ) );
}
/**
* Apply on "ilike" constraint
*/

View File

@ -303,7 +303,7 @@ public abstract class AbstractAuditQuery implements AuditQueryImplementor {
query.setComment( comment );
}
if ( flushMode != null ) {
query.setFlushMode( flushMode );
query.setHibernateFlushMode( flushMode );
}
if ( cacheMode != null ) {
query.setCacheMode( cacheMode );