From a7a039e291a039b6a5b7c9d2e7bafb24e6b26276 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 27 Apr 2016 09:28:30 -0500 Subject: [PATCH] HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (continued fixing of hibernate-core test failures) --- .../org/hibernate/jpa/persistence_1_0.xsd | 0 .../org/hibernate/jpa/persistence_2_0.xsd | 0 .../org/hibernate/jpa/persistence_2_1.xsd | 0 .../org/hibernate/jpa/internal/QueryImpl.java | 612 ---------- .../jpa/spi/AbstractEntityManagerImpl.java | 242 ---- .../hibernate/jpa/spi/AbstractQueryImpl.java | 209 ---- .../org/hibernate/jpa/spi/BaseQueryImpl.java | 1002 ----------------- .../BaseEntityManagerFunctionalTestCase.java | 11 +- .../test/EntityManagerFactoryUnwrapTest.java | 12 +- .../jpa/test/criteria/basic/Date3Type.java | 12 +- .../PersisterClassProviderTest.java | 62 +- .../id/FunkyIdGenerator.java | 4 +- .../test/lock/LockTimeoutPropertyTest.java | 11 +- .../jpa/test/metadata/MetadataTest.java | 12 +- .../hibernate/jpa/test/ops/GetLoadTest.java | 6 +- .../org/hibernate/jpa/test/ops/MergeTest.java | 10 +- .../hibernate/jpa/test/ops/PersistTest.java | 10 +- .../packaging/PackagedEntityManagerTest.java | 4 +- .../jpa/test/query/AddNamedQueryTest.java | 2 +- .../test/query/TypedValueParametersTest.java | 8 +- .../transaction/SynchronizationTypeTest.java | 4 +- .../TransactionJoinHandlingChecker.java | 4 +- .../transaction/TransactionJoiningTest.java | 8 +- .../org/hibernate/jpa/test/xml/XmlTest.java | 10 +- 24 files changed, 83 insertions(+), 2172 deletions(-) rename {hibernate-entitymanager => hibernate-core}/src/main/resources/org/hibernate/jpa/persistence_1_0.xsd (100%) rename {hibernate-entitymanager => hibernate-core}/src/main/resources/org/hibernate/jpa/persistence_2_0.xsd (100%) rename {hibernate-entitymanager => hibernate-core}/src/main/resources/org/hibernate/jpa/persistence_2_1.xsd (100%) delete mode 100755 hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/QueryImpl.java delete mode 100755 hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractEntityManagerImpl.java delete mode 100755 hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractQueryImpl.java delete mode 100644 hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/BaseQueryImpl.java diff --git a/hibernate-entitymanager/src/main/resources/org/hibernate/jpa/persistence_1_0.xsd b/hibernate-core/src/main/resources/org/hibernate/jpa/persistence_1_0.xsd similarity index 100% rename from hibernate-entitymanager/src/main/resources/org/hibernate/jpa/persistence_1_0.xsd rename to hibernate-core/src/main/resources/org/hibernate/jpa/persistence_1_0.xsd diff --git a/hibernate-entitymanager/src/main/resources/org/hibernate/jpa/persistence_2_0.xsd b/hibernate-core/src/main/resources/org/hibernate/jpa/persistence_2_0.xsd similarity index 100% rename from hibernate-entitymanager/src/main/resources/org/hibernate/jpa/persistence_2_0.xsd rename to hibernate-core/src/main/resources/org/hibernate/jpa/persistence_2_0.xsd diff --git a/hibernate-entitymanager/src/main/resources/org/hibernate/jpa/persistence_2_1.xsd b/hibernate-core/src/main/resources/org/hibernate/jpa/persistence_2_1.xsd similarity index 100% rename from hibernate-entitymanager/src/main/resources/org/hibernate/jpa/persistence_2_1.xsd rename to hibernate-core/src/main/resources/org/hibernate/jpa/persistence_2_1.xsd diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/QueryImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/QueryImpl.java deleted file mode 100755 index 7b4253b08c..0000000000 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/QueryImpl.java +++ /dev/null @@ -1,612 +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 . - */ -package org.hibernate.jpa.internal; - -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.persistence.NoResultException; -import javax.persistence.NonUniqueResultException; -import javax.persistence.ParameterMode; -import javax.persistence.PersistenceException; -import javax.persistence.Query; -import javax.persistence.TemporalType; -import javax.persistence.TypedQuery; - -import org.hibernate.CacheMode; -import org.hibernate.FlushMode; -import org.hibernate.HibernateException; -import org.hibernate.LockMode; -import org.hibernate.TypeMismatchException; -import org.hibernate.engine.query.spi.NamedParameterDescriptor; -import org.hibernate.engine.query.spi.OrdinalParameterDescriptor; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.hql.internal.QueryExecutionRequestException; -import org.hibernate.internal.EntityManagerMessageLogger; -import org.hibernate.jpa.AvailableSettings; -import org.hibernate.jpa.HibernateQuery; -import org.hibernate.jpa.TypedParameterValue; -import org.hibernate.jpa.internal.util.ConfigurationHelper; -import org.hibernate.jpa.internal.util.LockModeTypeHelper; -import org.hibernate.jpa.spi.AbstractQueryImpl; -import org.hibernate.jpa.spi.HibernateEntityManagerImplementor; -import org.hibernate.jpa.spi.NullTypeBindableParameterRegistration; -import org.hibernate.jpa.spi.ParameterBind; -import org.hibernate.query.NativeQuery; -import org.hibernate.query.internal.ParameterMetadataImpl; -import org.hibernate.type.CompositeCustomType; -import org.hibernate.type.Type; - -import static javax.persistence.TemporalType.DATE; -import static javax.persistence.TemporalType.TIME; -import static javax.persistence.TemporalType.TIMESTAMP; -import static org.hibernate.internal.HEMLogging.messageLogger; - -/** - * Hibernate implementation of both the {@link Query} and {@link TypedQuery} contracts. - * - * @author Gavin King - * @author Emmanuel Bernard - * @author Steve Ebersole - */ -public class QueryImpl extends AbstractQueryImpl - implements TypedQuery, HibernateQuery { - public static final EntityManagerMessageLogger LOG = messageLogger( QueryImpl.class ); - - private org.hibernate.Query query; - - public QueryImpl(org.hibernate.Query query, HibernateEntityManagerImplementor em) { - this( query, em, Collections.emptyMap() ); - } - - public QueryImpl( - org.hibernate.Query query, - HibernateEntityManagerImplementor em, - Map namedParameterTypeRedefinitions) { - super( em ); - this.query = query; - extractParameterInfo( namedParameterTypeRedefinitions ); - } - - @Override - protected boolean isNativeSqlQuery() { - return NativeQuery.class.isInstance( query ); - } - - @Override - protected boolean isSelectQuery() { - if ( isNativeSqlQuery() ) { - throw new IllegalStateException( "Cannot tell if native SQL query is SELECT query" ); - } - - return getEntityManager().getFactory().getSessionFactory().getQueryPlanCache() - .getHQLQueryPlan( query.getQueryString(), false, Collections.emptyMap() ) - .isSelect(); - } - - @SuppressWarnings({"unchecked", "RedundantCast"}) - private void extractParameterInfo(Map namedParameterTypeRedefinition) { - if ( !org.hibernate.query.internal.AbstractProducedQuery.class.isInstance( query ) ) { - throw new IllegalStateException( "Unknown query type for parameter extraction" ); - } - - boolean hadJpaPositionalParameters = false; - - final ParameterMetadataImpl parameterMetadata = (ParameterMetadataImpl) query.getParameterMetadata(); - - // extract named params - for ( String name : (Set) parameterMetadata.getNamedParameterNames() ) { - final NamedParameterDescriptor descriptor = parameterMetadata.getNamedParameterDescriptor( name ); - Class javaType = namedParameterTypeRedefinition.get( name ); - if ( javaType != null && mightNeedRedefinition( javaType, descriptor.getExpectedType() ) ) { - descriptor.resetExpectedType( - sfi().getTypeResolver().heuristicType( javaType.getName() ) - ); - } - else if ( descriptor.getExpectedType() != null ) { - javaType = descriptor.getExpectedType().getReturnedClass(); - } - - if ( descriptor.isJpaStyle() ) { - hadJpaPositionalParameters = true; - final Integer position = Integer.valueOf( name ); - registerParameter( new JpaPositionalParameterRegistrationImpl( this, query, position, javaType ) ); - } - else { - registerParameter( new ParameterRegistrationImpl( this, query, name, javaType ) ); - } - } - - if ( hadJpaPositionalParameters ) { - if ( parameterMetadata.getOrdinalParameterCount() > 0 ) { - throw new IllegalArgumentException( - "Cannot mix JPA positional parameters and native Hibernate positional/ordinal parameters" - ); - } - } - - // extract Hibernate native positional parameters - for ( int i = 0, max = parameterMetadata.getOrdinalParameterCount(); i < max; i++ ) { - final OrdinalParameterDescriptor descriptor = parameterMetadata.getOrdinalParameterDescriptor( i + 1 ); - Class javaType = descriptor.getExpectedType() == null ? - null : - descriptor.getExpectedType().getReturnedClass(); - registerParameter( new ParameterRegistrationImpl( this, query, i + 1, javaType ) ); - } - } - - private SessionFactoryImplementor sfi() { - return (SessionFactoryImplementor) getEntityManager().getFactory().getSessionFactory(); - } - - private boolean mightNeedRedefinition(Class javaType, Type expectedType) { - // only redefine dates/times/timestamps that are not wrapped in a CompositeCustomType - if ( expectedType == null ) { - return java.util.Date.class.isAssignableFrom( javaType ); - } - else { - return java.util.Date.class.isAssignableFrom( javaType ) - && !CompositeCustomType.class.isAssignableFrom( expectedType.getClass() ); - } - } - - private static class ParameterRegistrationImpl implements NullTypeBindableParameterRegistration { - private final QueryImpl jpaQuery; - private final org.hibernate.Query nativeQuery; - - private final String name; - private final Integer position; - private final Class javaType; - - private ParameterBind bind; - - protected ParameterRegistrationImpl( - QueryImpl jpaQuery, - org.hibernate.Query nativeQuery, - String name, - Class javaType) { - this.jpaQuery = jpaQuery; - this.nativeQuery = nativeQuery; - this.name = name; - this.javaType = javaType; - this.position = null; - } - - protected ParameterRegistrationImpl( - QueryImpl jpaQuery, - org.hibernate.Query nativeQuery, - Integer position, - Class javaType) { - this.jpaQuery = jpaQuery; - this.nativeQuery = nativeQuery; - this.position = position; - this.javaType = javaType; - this.name = null; - } - - @Override - public boolean isJpaPositionalParameter() { - return false; - } - - @Override - public Query getQuery() { - return jpaQuery; - } - - @Override - public String getName() { - return name; - } - - @Override - public Integer getPosition() { - return position; - } - - @Override - public Class getParameterType() { - return javaType; - } - - @Override - public ParameterMode getMode() { - // implicitly - return ParameterMode.IN; - } - - @Override - public boolean isBindable() { - // again, implicitly - return true; - } - - @Override - @SuppressWarnings("unchecked") - public void bindValue(T value) { - validateBinding( getParameterType(), value, null ); - - if ( name != null ) { - if ( value instanceof TypedParameterValue ) { - final TypedParameterValue typedValueWrapper = (TypedParameterValue ) value; - nativeQuery.setParameter( name, typedValueWrapper.getValue(), typedValueWrapper.getType() ); - value = (T) typedValueWrapper.getValue(); - } - else if ( value instanceof Collection ) { - nativeQuery.setParameterList( name, (Collection) value ); - } - else { - nativeQuery.setParameter( name, value ); - } - } - else { - if ( value instanceof TypedParameterValue ) { - final TypedParameterValue typedValueWrapper = (TypedParameterValue ) value; - nativeQuery.setParameter( position, typedValueWrapper.getValue(), typedValueWrapper.getType() ); - value = (T) typedValueWrapper.getValue(); - } - else { - nativeQuery.setParameter( position - 1, value ); - } - } - - bind = new ParameterBindImpl( value, null ); - } - - @Override - public void bindValue(T value, TemporalType specifiedTemporalType) { - validateBinding( getParameterType(), value, specifiedTemporalType ); - - if ( value == null || Date.class.isInstance( value ) ) { - if ( name != null ) { - if ( specifiedTemporalType == DATE ) { - nativeQuery.setDate( name, (Date) value ); - } - else if ( specifiedTemporalType == TIME ) { - nativeQuery.setTime( name, (Date) value ); - } - else if ( specifiedTemporalType == TIMESTAMP ) { - nativeQuery.setTimestamp( name, (Date) value ); - } - } - else { - if ( specifiedTemporalType == DATE ) { - nativeQuery.setDate( position - 1, (Date) value ); - } - else if ( specifiedTemporalType == TIME ) { - nativeQuery.setTime( position - 1, (Date) value ); - } - else if ( specifiedTemporalType == TIMESTAMP ) { - nativeQuery.setTimestamp( position - 1, (Date) value ); - } - } - } - else if ( Calendar.class.isInstance( value ) ) { - if ( name != null ) { - if ( specifiedTemporalType == DATE ) { - nativeQuery.setCalendarDate( name, (Calendar) value ); - } - else if ( specifiedTemporalType == TIME ) { - throw new IllegalArgumentException( "not yet implemented" ); - } - else if ( specifiedTemporalType == TIMESTAMP ) { - nativeQuery.setCalendar( name, (Calendar) value ); - } - } - else { - if ( specifiedTemporalType == DATE ) { - nativeQuery.setCalendarDate( position - 1, (Calendar) value ); - } - else if ( specifiedTemporalType == TIME ) { - throw new IllegalArgumentException( "not yet implemented" ); - } - else if ( specifiedTemporalType == TIMESTAMP ) { - nativeQuery.setCalendar( position - 1, (Calendar) value ); - } - } - } - else { - throw new IllegalArgumentException( - "Unexpected type [" + value + "] passed with TemporalType; expecting Date or Calendar" - ); - } - - bind = new ParameterBindImpl( value, specifiedTemporalType ); - } - - @Override - public ParameterBind getBind() { - return bind; - } - - @Override - public void bindNullValue(Class nullParameterType) { - if ( nullParameterType == null ) { - throw new IllegalArgumentException( "nullParameterType must be non-null" ); - } - if ( getParameterType() != null ) { - throw new IllegalArgumentException( - String.format( - "Cannot bind null value as type [%s]; it is already mapped as type [%s]", - nullParameterType.getName(), - getParameterType().getName() - ) - ); - } - validateBinding( nullParameterType, null, null ); - - if ( !org.hibernate.query.internal.AbstractProducedQuery.class.isInstance( jpaQuery.getHibernateQuery() ) ) { - throw new IllegalStateException( - "Unknown query type for binding null value" + jpaQuery.getHibernateQuery() - .getClass() - .getName() - ); - } -// org.hibernate.query.internal.AbstractProducedQuery abstractQuery = -// (org.hibernate.query.internal.AbstractProducedQuery) jpaQuery.getHibernateQuery(); -// final Type explicitType = abstractQuery.guessType( nullParameterType ); - final Type explicitType = null; - if ( name != null ) { - nativeQuery.setParameter( name, null, explicitType ); - } - else { - nativeQuery.setParameter( position - 1, null, explicitType ); - } - bind = new ParameterBindImpl( null, null ); - } - } - - /** - * Specialized handling for JPA "positional parameters". - * - * @param The parameter type type. - */ - public static class JpaPositionalParameterRegistrationImpl extends ParameterRegistrationImpl { - final Integer position; - - protected JpaPositionalParameterRegistrationImpl( - QueryImpl jpaQuery, - org.hibernate.Query nativeQuery, - Integer position, - Class javaType) { - super( jpaQuery, nativeQuery, position.toString(), javaType ); - this.position = position; - } - - @Override - public String getName() { - return null; - } - - @Override - public Integer getPosition() { - return position; - } - - @Override - public boolean isJpaPositionalParameter() { - return true; - } - } - - public org.hibernate.Query getHibernateQuery() { - return query; - } - - @Override - protected int internalExecuteUpdate() { - return query.executeUpdate(); - } - - @Override - protected void applyMaxResults(int maxResults) { - query.setMaxResults( maxResults ); - } - - @Override - protected void applyFirstResult(int firstResult) { - query.setFirstResult( firstResult ); - } - - @Override - protected boolean applyTimeoutHint(int timeout) { - query.setTimeout( timeout ); - return true; - } - - @Override - protected boolean applyCommentHint(String comment) { - query.setComment( comment ); - return true; - } - - @Override - protected boolean applyFetchSizeHint(int fetchSize) { - query.setFetchSize( fetchSize ); - return true; - } - - @Override - protected boolean applyCacheableHint(boolean isCacheable) { - query.setCacheable( isCacheable ); - return true; - } - - @Override - protected boolean applyCacheRegionHint(String regionName) { - query.setCacheRegion( regionName ); - return true; - } - - @Override - protected boolean applyReadOnlyHint(boolean isReadOnly) { - query.setReadOnly( isReadOnly ); - return true; - } - - @Override - protected boolean applyCacheModeHint(CacheMode cacheMode) { - query.setCacheMode( cacheMode ); - return true; - } - - @Override - protected boolean applyFlushModeHint(FlushMode flushMode) { - query.setFlushMode( flushMode ); - return true; - } - - @Override - protected boolean canApplyAliasSpecificLockModeHints() { - return org.hibernate.query.spi.QueryImplementor.class.isInstance( query ) - || org.hibernate.query.spi.NativeQueryImplementor.class.isInstance( query ); - } - - @Override - protected void applyAliasSpecificLockModeHint(String alias, LockMode lockMode) { - query.getLockOptions().setAliasSpecificLockMode( alias, lockMode ); - } - - @Override - @SuppressWarnings({"unchecked", "RedundantCast"}) - public List getResultList() { - getEntityManager().checkOpen( true ); - checkTransaction(); - beforeQuery(); - try { - return list(); - } - catch (QueryExecutionRequestException he) { - throw new IllegalStateException( he ); - } - catch (TypeMismatchException e) { - throw new IllegalArgumentException( e ); - } - catch (HibernateException he) { - throw getEntityManager().convert( he ); - } - } - - /** - * For JPA native SQL queries, we may need to perform a flush beforeQuery executing the query. - */ - private void beforeQuery() { -// final org.hibernate.Query query = getHibernateQuery(); -// if ( !org.hibernate.query.internal.AbstractProducedQuery.class.isInstance( query ) ) { -// // this need only exists for native SQL queries, not JPQL or Criteria queries (both of which do -// // partial auto flushing already). -// return; -// } -// -// final SQLQuery sqlQuery = (SQLQuery) query; -// if ( sqlQuery.getSynchronizedQuerySpaces() != null && !sqlQuery.getSynchronizedQuerySpaces().isEmpty() ) { -// // The application defined query spaces on the Hibernate native SQLQuery which means the query will already -// // perform a partial flush according to the defined query spaces, no need to do a full flush. -// return; -// } -// -// // otherwise we need to flush. the query itself is not required to execute in a transaction; if there is -// // no transaction, the flush would throw a TransactionRequiredException which would potentially break existing -// // apps, so we only do the flush if a transaction is in progress. -// if ( getEntityManager().isTransactionInProgress() ) { -// getEntityManager().flush(); -// } - } - - @Override - @SuppressWarnings({"unchecked", "RedundantCast"}) - public X getSingleResult() { - getEntityManager().checkOpen( true ); - checkTransaction(); - beforeQuery(); - try { - final List result = list(); - - if ( result.size() == 0 ) { - NoResultException nre = new NoResultException( "No entity found for query" ); - getEntityManager().handlePersistenceException( nre ); - throw nre; - } - else if ( result.size() > 1 ) { - final Set uniqueResult = new HashSet( result ); - if ( uniqueResult.size() > 1 ) { - NonUniqueResultException nure = new NonUniqueResultException( - "result returns more than one elements" - ); - getEntityManager().handlePersistenceException( nure ); - throw nure; - } - else { - return uniqueResult.iterator().next(); - } - } - else { - return result.get( 0 ); - } - } - catch (QueryExecutionRequestException he) { - throw new IllegalStateException( he ); - } - catch (TypeMismatchException e) { - throw new IllegalArgumentException( e ); - } - catch (HibernateException he) { - throw getEntityManager().convert( he ); - } - } - - @Override - @SuppressWarnings({"unchecked"}) - public T unwrap(Class tClass) { - if ( org.hibernate.Query.class.isAssignableFrom( tClass ) ) { - return (T) query; - } - if ( QueryImpl.class.isAssignableFrom( tClass ) ) { - return (T) this; - } - if ( HibernateQuery.class.isAssignableFrom( tClass ) ) { - return (T) this; - } - - throw new PersistenceException( - String.format( - "Unsure how to unwrap %s impl [%s] as requested type [%s]", - Query.class.getSimpleName(), - this.getClass().getName(), - tClass.getName() - ) - ); - } - - @Override - protected void internalApplyLockMode(javax.persistence.LockModeType lockModeType) { - query.getLockOptions().setLockMode( LockModeTypeHelper.getLockMode( lockModeType ) ); - if ( getHints() != null && getHints().containsKey( AvailableSettings.LOCK_TIMEOUT ) ) { - applyLockTimeoutHint( ConfigurationHelper.getInteger( getHints().get( AvailableSettings.LOCK_TIMEOUT ) ) ); - } - } - - @Override - protected boolean applyLockTimeoutHint(int timeout) { - query.getLockOptions().setTimeOut( timeout ); - return true; - } - - private List list() { - if ( getEntityGraphQueryHint() != null ) { - // Safe to assume QueryImpl at this point. - unwrap( org.hibernate.query.internal.QueryImpl.class ).applyEntityGraphQueryHint( getEntityGraphQueryHint() ); - } - return query.list(); - } - -} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractEntityManagerImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractEntityManagerImpl.java deleted file mode 100755 index 116fe26ac6..0000000000 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractEntityManagerImpl.java +++ /dev/null @@ -1,242 +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 . - */ -package org.hibernate.jpa.spi; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.persistence.PersistenceContextType; -import javax.persistence.StoredProcedureQuery; -import javax.persistence.SynchronizationType; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.metamodel.Metamodel; -import javax.persistence.spi.PersistenceUnitTransactionType; - -import org.hibernate.HibernateException; -import org.hibernate.LockOptions; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.internal.AbstractSessionImpl; -import org.hibernate.internal.EntityManagerMessageLogger; -import org.hibernate.internal.SessionFactoryImpl; -import org.hibernate.jpa.AvailableSettings; -import org.hibernate.jpa.QueryHints; -import org.hibernate.procedure.ProcedureCallMemento; -import org.hibernate.procedure.UnknownSqlResultSetMappingException; -import org.hibernate.query.procedure.internal.StoredProcedureQueryImpl; -import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl; -import org.hibernate.resource.transaction.spi.TransactionStatus; - -import static org.hibernate.internal.HEMLogging.messageLogger; - -/** - * @author Gavin King - * @author Emmanuel Bernard - * @author Steve Ebersole - * @author Hardy Ferentschik - */ -@SuppressWarnings("unchecked") -public abstract class AbstractEntityManagerImpl - extends AbstractSessionImpl - implements HibernateEntityManagerImplementor, Serializable { - private static final long serialVersionUID = 78818181L; - - private static final EntityManagerMessageLogger LOG = messageLogger( AbstractEntityManagerImpl.class ); - - private static final List ENTITY_MANAGER_SPECIFIC_PROPERTIES = new ArrayList<>(); - - static { - ENTITY_MANAGER_SPECIFIC_PROPERTIES.add( AvailableSettings.LOCK_SCOPE ); - ENTITY_MANAGER_SPECIFIC_PROPERTIES.add( AvailableSettings.LOCK_TIMEOUT ); - ENTITY_MANAGER_SPECIFIC_PROPERTIES.add( AvailableSettings.FLUSH_MODE ); - ENTITY_MANAGER_SPECIFIC_PROPERTIES.add( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE ); - ENTITY_MANAGER_SPECIFIC_PROPERTIES.add( AvailableSettings.SHARED_CACHE_STORE_MODE ); - ENTITY_MANAGER_SPECIFIC_PROPERTIES.add( QueryHints.SPEC_HINT_TIMEOUT ); - } - - private SessionFactoryImpl entityManagerFactory; - private SynchronizationType synchronizationType; - private PersistenceUnitTransactionType transactionType; - private Map properties; - private LockOptions lockOptions; - - protected AbstractEntityManagerImpl( - SessionFactoryImpl entityManagerFactory, - PersistenceContextType type, // TODO: remove as no longer used - SynchronizationType synchronizationType, - PersistenceUnitTransactionType transactionType, - Map properties) { - super( entityManagerFactory, null ); // null -> "tenant identifier" - this.entityManagerFactory = entityManagerFactory; - this.synchronizationType = synchronizationType; - this.transactionType = transactionType; - - this.lockOptions = new LockOptions(); - this.properties = new HashMap<>(); - for ( String key : ENTITY_MANAGER_SPECIFIC_PROPERTIES ) { - if ( entityManagerFactory.getProperties().containsKey( key ) ) { - this.properties.put( key, entityManagerFactory.getProperties().get( key ) ); - } - if ( properties != null && properties.containsKey( key ) ) { - this.properties.put( key, properties.get( key ) ); - } - } - } - - @Override - public SessionFactoryImplementor getEntityManagerFactory() { - return entityManagerFactory; - } - - public PersistenceUnitTransactionType getTransactionType() { - return transactionType; - } - - @Override - public SynchronizationType getSynchronizationType() { - return synchronizationType; - } - - @Override - public CriteriaBuilder getCriteriaBuilder() { - return entityManagerFactory.getCriteriaBuilder(); - } - - @Override - public Metamodel getMetamodel() { - return entityManagerFactory.getMetamodel(); - } - - @Override - public StoredProcedureQuery createNamedStoredProcedureQuery(String name) { - checkOpen(); - try { - final ProcedureCallMemento memento = getFactory().getNamedQueryRepository().getNamedProcedureCallMemento( name ); - if ( memento == null ) { - throw new IllegalArgumentException( "No @NamedStoredProcedureQuery was found with that name : " + name ); - } - final StoredProcedureQueryImpl jpaImpl = new StoredProcedureQueryImpl( memento, this ); - // apply hints - if ( memento.getHintsMap() != null ) { - for ( Map.Entry hintEntry : memento.getHintsMap().entrySet() ) { - jpaImpl.setHint( hintEntry.getKey(), hintEntry.getValue() ); - } - } - return jpaImpl; - } - catch ( RuntimeException e ) { - throw convert( e ); - } - } - - - @Override - public RuntimeException convert(HibernateException e) { - return convert( e, null ); - } - - public RuntimeException convert(RuntimeException e) { - RuntimeException result = e; - if ( e instanceof HibernateException ) { - result = convert( (HibernateException) e ); - } - else { - markForRollbackOnly(); - } - return result; - } - - public RuntimeException convert(RuntimeException e, LockOptions lockOptions) { - RuntimeException result = e; - if ( e instanceof HibernateException ) { - result = convert( (HibernateException) e , lockOptions ); - } - else { - markForRollbackOnly(); - } - return result; - } - - @Override - public StoredProcedureQuery createStoredProcedureQuery(String procedureName) { - checkOpen(); - try { - return new StoredProcedureQueryImpl( - createStoredProcedureCall( procedureName ), - this - ); - } - catch ( RuntimeException e ) { - throw convert( e ); - } - } - - @Override - public StoredProcedureQuery createStoredProcedureQuery(String procedureName, Class... resultClasses) { - checkOpen(); - try { - return new StoredProcedureQueryImpl( - createStoredProcedureCall( procedureName, resultClasses ), - this - ); - } - catch ( RuntimeException e ) { - throw convert( e ); - } - } - - @Override - public StoredProcedureQuery createStoredProcedureQuery(String procedureName, String... resultSetMappings) { - checkOpen(); - try { - try { - return new StoredProcedureQueryImpl( - createStoredProcedureCall( procedureName, resultSetMappings ), - this - ); - } - catch (UnknownSqlResultSetMappingException unknownResultSetMapping) { - throw new IllegalArgumentException( unknownResultSetMapping.getMessage(), unknownResultSetMapping ); - } - } - catch ( RuntimeException e ) { - throw convert( e ); - } - } - - @Override - public boolean isConnected() { - checkTransactionSynchStatus(); - return !isClosed() && getJdbcCoordinator().getLogicalConnection().isOpen(); - } - - @Override - public boolean isTransactionInProgress() { - checkTransactionSynchStatus(); - return !isClosed() && getTransactionCoordinator().getTransactionDriverControl() - .getStatus() == TransactionStatus.ACTIVE && getTransactionCoordinator().isJoined(); - } - - private void checkTransactionSynchStatus() { - pulseTransactionCoordinator(); - delayedAfterCompletion(); - } - - private void pulseTransactionCoordinator() { - if ( !isClosed() ) { - getTransactionCoordinator().pulse(); - } - } - - private void delayedAfterCompletion() { - if ( getTransactionCoordinator() instanceof JtaTransactionCoordinatorImpl ) { - ( (JtaTransactionCoordinatorImpl) getTransactionCoordinator() ).getSynchronizationCallbackCoordinator() - .processAnyDelayedAfterCompletion(); - } - } -} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractQueryImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractQueryImpl.java deleted file mode 100755 index 1b9902b6fb..0000000000 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractQueryImpl.java +++ /dev/null @@ -1,209 +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 . - */ -package org.hibernate.jpa.spi; - -import java.util.Calendar; -import java.util.Date; -import java.util.Set; -import javax.persistence.FlushModeType; -import javax.persistence.LockModeType; -import javax.persistence.Parameter; -import javax.persistence.TemporalType; -import javax.persistence.TransactionRequiredException; -import javax.persistence.TypedQuery; - -import org.hibernate.HibernateException; -import org.hibernate.TypeMismatchException; -import org.hibernate.hql.internal.QueryExecutionRequestException; -import org.hibernate.jpa.QueryHints; - -/** - * Base class for implementing both {@link javax.persistence.Query} and {@link javax.persistence.TypedQuery}, including - * query references built from criteria queries. - *

- * Not intended as base for {@link javax.persistence.StoredProcedureQuery} - * - * @author Steve Ebersole - */ -public abstract class AbstractQueryImpl extends BaseQueryImpl implements TypedQuery { - public AbstractQueryImpl(HibernateEntityManagerImplementor entityManager) { - super( entityManager ); - } - - protected HibernateEntityManagerImplementor getEntityManager() { - return entityManager(); - } - - /** - * Actually execute the update; all pre-requisites have been checked. - * - * @return The number of "affected rows". - */ - protected abstract int internalExecuteUpdate(); - - @Override - @SuppressWarnings({ "ThrowableInstanceNeverThrown" }) - public int executeUpdate() { - checkOpen( true ); - try { - if ( ! entityManager().isTransactionInProgress() ) { - entityManager().throwPersistenceException( - new TransactionRequiredException( - "Executing an update/delete query" - ) - ); - return 0; - } - return internalExecuteUpdate(); - } - catch ( QueryExecutionRequestException he) { - throw new IllegalStateException(he); - } - catch( TypeMismatchException e ) { - throw new IllegalArgumentException(e); - } - catch ( HibernateException he) { - entityManager().throwPersistenceException( he ); - return 0; - } - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setMaxResults(int maxResults) { - return (AbstractQueryImpl) super.setMaxResults( maxResults ); - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setFirstResult(int firstResult) { - return (AbstractQueryImpl) super.setFirstResult( firstResult ); - } - - @Override - @SuppressWarnings( {"deprecation"}) - public AbstractQueryImpl setHint(String hintName, Object value) { - super.setHint( hintName, value ); - return this; - } - - @SuppressWarnings( {"UnusedDeclaration"}) - public Set getSupportedHints() { - return QueryHints.getDefinedHints(); - } - - private javax.persistence.LockModeType jpaLockMode = javax.persistence.LockModeType.NONE; - - @Override - @SuppressWarnings({ "unchecked" }) - public TypedQuery setLockMode(javax.persistence.LockModeType lockModeType) { - checkOpen( true ); - - if ( isNativeSqlQuery() ) { - throw new IllegalStateException( "Illegal attempt to set lock mode on a native SQL query" ); - } - - if ( ! LockModeType.NONE.equals(lockModeType)) { - if ( ! isSelectQuery() ) { - throw new IllegalStateException( "Illegal attempt to set lock mode on a non-SELECT query" ); - } - } - if ( ! canApplyAliasSpecificLockModeHints() ) { - throw new IllegalStateException( "Not a JPAQL/Criteria query" ); - } - - this.jpaLockMode = lockModeType; - internalApplyLockMode( lockModeType ); - return this; - } - - @Override - public javax.persistence.LockModeType getLockMode() { - checkOpen( false ); - - if ( isNativeSqlQuery() ) { - throw new IllegalStateException( "Illegal attempt to set lock mode on a native SQL query" ); - } - - if ( ! isSelectQuery() ) { - throw new IllegalStateException( "Illegal attempt to set lock mode on a non-SELECT query" ); - } - - return jpaLockMode; - } - - - // convariant return handling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setParameter(Parameter param, T value) { - return (AbstractQueryImpl) super.setParameter( param, value ); - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setParameter(Parameter param, Calendar value, TemporalType temporalType) { - return (AbstractQueryImpl) super.setParameter( param, value, temporalType ); - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setParameter(Parameter param, Date value, TemporalType temporalType) { - return (AbstractQueryImpl) super.setParameter( param, value, temporalType ); - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setParameter(String name, Object value) { - return (AbstractQueryImpl) super.setParameter( name, value ); - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setParameter(String name, Calendar value, TemporalType temporalType) { - return (AbstractQueryImpl) super.setParameter( name, value, temporalType ); - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setParameter(String name, Date value, TemporalType temporalType) { - return (AbstractQueryImpl) super.setParameter( name, value, temporalType ); - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setParameter(int position, Object value) { - return (AbstractQueryImpl) super.setParameter( position, value ); - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setParameter(int position, Calendar value, TemporalType temporalType) { - return (AbstractQueryImpl) super.setParameter( position, value, temporalType ); - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setParameter(int position, Date value, TemporalType temporalType) { - return (AbstractQueryImpl) super.setParameter( position, value, temporalType ); - } - - @Override - @SuppressWarnings("unchecked") - public AbstractQueryImpl setFlushMode(FlushModeType jpaFlushMode) { - return (AbstractQueryImpl) super.setFlushMode( jpaFlushMode ); - } - - protected void checkTransaction() { - if ( jpaLockMode != null && jpaLockMode != LockModeType.NONE ) { - if ( !getEntityManager().isTransactionInProgress() ) { - throw new TransactionRequiredException( "no transaction is in progress" ); - } - } - } -} diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/BaseQueryImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/BaseQueryImpl.java deleted file mode 100644 index 31e73c8a6e..0000000000 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/BaseQueryImpl.java +++ /dev/null @@ -1,1002 +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 . - */ -package org.hibernate.jpa.spi; - -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import javax.persistence.CacheRetrieveMode; -import javax.persistence.CacheStoreMode; -import javax.persistence.FlushModeType; -import javax.persistence.LockModeType; -import javax.persistence.Parameter; -import javax.persistence.Query; -import javax.persistence.TemporalType; - -import org.hibernate.CacheMode; -import org.hibernate.FlushMode; -import org.hibernate.HibernateException; -import org.hibernate.LockMode; -import org.hibernate.QueryParameterException; -import org.hibernate.engine.query.spi.EntityGraphQueryHint; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.internal.EntityManagerMessageLogger; -import org.hibernate.jpa.AvailableSettings; -import org.hibernate.jpa.QueryHints; -import org.hibernate.jpa.TypedParameterValue; -import org.hibernate.jpa.graph.internal.EntityGraphImpl; -import org.hibernate.jpa.internal.util.CacheModeHelper; -import org.hibernate.jpa.internal.util.ConfigurationHelper; -import org.hibernate.jpa.internal.util.LockModeTypeHelper; -import org.hibernate.jpa.internal.util.PessimisticNumberParser; -import org.hibernate.procedure.NoSuchParameterException; -import org.hibernate.procedure.ParameterStrategyException; - -import org.jboss.logging.Logger; - -import static org.hibernate.jpa.QueryHints.HINT_CACHEABLE; -import static org.hibernate.jpa.QueryHints.HINT_CACHE_MODE; -import static org.hibernate.jpa.QueryHints.HINT_CACHE_REGION; -import static org.hibernate.jpa.QueryHints.HINT_COMMENT; -import static org.hibernate.jpa.QueryHints.HINT_FETCHGRAPH; -import static org.hibernate.jpa.QueryHints.HINT_FETCH_SIZE; -import static org.hibernate.jpa.QueryHints.HINT_FLUSH_MODE; -import static org.hibernate.jpa.QueryHints.HINT_LOADGRAPH; -import static org.hibernate.jpa.QueryHints.HINT_NATIVE_LOCKMODE; -import static org.hibernate.jpa.QueryHints.HINT_READONLY; -import static org.hibernate.jpa.QueryHints.HINT_TIMEOUT; -import static org.hibernate.jpa.QueryHints.SPEC_HINT_TIMEOUT; - -/** - * Intended as the base class for all {@link javax.persistence.Query} implementations, including - * {@link javax.persistence.TypedQuery} and {@link javax.persistence.StoredProcedureQuery}. Care should be taken - * that all changes here fit with all those usages. - * - * @author Steve Ebersole - */ -public abstract class BaseQueryImpl implements Query { - private static final EntityManagerMessageLogger LOG = Logger.getMessageLogger( - EntityManagerMessageLogger.class, - AbstractQueryImpl.class.getName() - ); - - private final SharedSessionContractImplementor entityManager; - - private int firstResult; - private int maxResults = -1; - private Map hints; - - private EntityGraphQueryHint entityGraphQueryHint; - - public BaseQueryImpl(SharedSessionContractImplementor entityManager) { - this.entityManager = entityManager; - } - - protected SharedSessionContractImplementor entityManager() { - return entityManager; - } - - protected void checkOpen(boolean markForRollbackIfClosed) { - entityManager.checkOpen( markForRollbackIfClosed ); - } - - - // Limits (first and max results) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - /** - * Apply the given first-result value. - * - * @param firstResult The specified first-result value. - */ - protected abstract void applyFirstResult(int firstResult); - - @Override - public BaseQueryImpl setFirstResult(int firstResult) { - checkOpen( true ); - - if ( firstResult < 0 ) { - throw new IllegalArgumentException( - "Negative value (" + firstResult + ") passed to setFirstResult" - ); - } - this.firstResult = firstResult; - applyFirstResult( firstResult ); - return this; - } - - @Override - public int getFirstResult() { - checkOpen( false ); // technically should rollback - return firstResult; - } - - /** - * Apply the given max results value. - * - * @param maxResults The specified max results - */ - protected abstract void applyMaxResults(int maxResults); - - @Override - public BaseQueryImpl setMaxResults(int maxResult) { - checkOpen( true ); - if ( maxResult < 0 ) { - throw new IllegalArgumentException( - "Negative value (" + maxResult + ") passed to setMaxResults" - ); - } - this.maxResults = maxResult; - applyMaxResults( maxResult ); - return this; - } - - public int getSpecifiedMaxResults() { - return maxResults; - } - - @Override - public int getMaxResults() { - checkOpen( false ); // technically should rollback - return maxResults == -1 - ? Integer.MAX_VALUE // stupid spec... MAX_VALUE?? - : maxResults; - } - - - // Hints ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - @SuppressWarnings( {"UnusedDeclaration"}) - public Set getSupportedHints() { - return QueryHints.getDefinedHints(); - } - - @Override - public Map getHints() { - checkOpen( false ); // technically should rollback - return hints; - } - - /** - * Apply the query timeout hint. - * - * @param timeout The timeout (in seconds!) specified as a hint - * - * @return {@code true} if the hint was "applied" - */ - protected abstract boolean applyTimeoutHint(int timeout); - - /** - * Apply the lock timeout (in seconds!) hint - * - * @param timeout The timeout (in seconds!) specified as a hint - * - * @return {@code true} if the hint was "applied" - */ - protected abstract boolean applyLockTimeoutHint(int timeout); - - /** - * Apply the comment hint. - * - * @param comment The comment specified as a hint - * - * @return {@code true} if the hint was "applied" - */ - protected abstract boolean applyCommentHint(String comment); - - /** - * Apply the fetch size hint - * - * @param fetchSize The fetch size specified as a hint - * - * @return {@code true} if the hint was "applied" - */ - protected abstract boolean applyFetchSizeHint(int fetchSize); - - /** - * Apply the cacheable (true/false) hint. - * - * @param isCacheable The value specified as hint - * - * @return {@code true} if the hint was "applied" - */ - protected abstract boolean applyCacheableHint(boolean isCacheable); - - /** - * Apply the cache region hint - * - * @param regionName The name of the cache region specified as a hint - * - * @return {@code true} if the hint was "applied" - */ - protected abstract boolean applyCacheRegionHint(String regionName); - - /** - * Apply the read-only (true/false) hint. - * - * @param isReadOnly The value specified as hint - * - * @return {@code true} if the hint was "applied" - */ - protected abstract boolean applyReadOnlyHint(boolean isReadOnly); - - /** - * Apply the CacheMode hint. - * - * @param cacheMode The CacheMode value specified as a hint. - * - * @return {@code true} if the hint was "applied" - */ - protected abstract boolean applyCacheModeHint(CacheMode cacheMode); - - /** - * Apply the FlushMode hint. - * - * @param flushMode The FlushMode value specified as hint - * - * @return {@code true} if the hint was "applied" - */ - protected abstract boolean applyFlushModeHint(FlushMode flushMode); - - /** - * Can alias-specific lock modes be applied? - * - * @return {@code true} indicates they can be applied, {@code false} otherwise. - */ - protected abstract boolean canApplyAliasSpecificLockModeHints(); - - /** - * Apply the alias specific lock modes. Assumes {@link #canApplyAliasSpecificLockModeHints()} has already been - * called and returned {@code true}. - * - * @param alias The alias to apply the 'lockMode' to. - * @param lockMode The LockMode to apply. - */ - protected abstract void applyAliasSpecificLockModeHint(String alias, LockMode lockMode); - - @Override - @SuppressWarnings( {"deprecation"}) - public BaseQueryImpl setHint(String hintName, Object value) { - checkOpen( true ); - boolean applied = false; - try { - if ( HINT_TIMEOUT.equals( hintName ) ) { - applied = applyTimeoutHint( ConfigurationHelper.getInteger( value ) ); - } - else if ( SPEC_HINT_TIMEOUT.equals( hintName ) ) { - // convert milliseconds to seconds - int timeout = (int)Math.round(ConfigurationHelper.getInteger( value ).doubleValue() / 1000.0 ); - applied = applyTimeoutHint( timeout ); - } - else if ( AvailableSettings.LOCK_TIMEOUT.equals( hintName ) ) { - applied = applyLockTimeoutHint( ConfigurationHelper.getInteger( value ) ); - } - else if ( HINT_COMMENT.equals( hintName ) ) { - applied = applyCommentHint( (String) value ); - } - else if ( HINT_FETCH_SIZE.equals( hintName ) ) { - applied = applyFetchSizeHint( ConfigurationHelper.getInteger( value ) ); - } - else if ( HINT_CACHEABLE.equals( hintName ) ) { - applied = applyCacheableHint( ConfigurationHelper.getBoolean( value ) ); - } - else if ( HINT_CACHE_REGION.equals( hintName ) ) { - applied = applyCacheRegionHint( (String) value ); - } - else if ( HINT_READONLY.equals( hintName ) ) { - applied = applyReadOnlyHint( ConfigurationHelper.getBoolean( value ) ); - } - else if ( HINT_CACHE_MODE.equals( hintName ) ) { - applied = applyCacheModeHint( ConfigurationHelper.getCacheMode( value ) ); - } - else if ( HINT_FLUSH_MODE.equals( hintName ) ) { - applied = applyFlushModeHint( ConfigurationHelper.getFlushMode( value ) ); - } - else if ( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE.equals( hintName ) ) { - final CacheRetrieveMode retrieveMode = value != null ? CacheRetrieveMode.valueOf( value.toString() ) : null; - final CacheStoreMode storeMode = getHint( AvailableSettings.SHARED_CACHE_STORE_MODE, CacheStoreMode.class ); - applied = applyCacheModeHint( CacheModeHelper.interpretCacheMode( storeMode, retrieveMode ) ); - } - else if ( AvailableSettings.SHARED_CACHE_STORE_MODE.equals( hintName ) ) { - final CacheStoreMode storeMode = value != null ? CacheStoreMode.valueOf( value.toString() ) : null; - final CacheRetrieveMode retrieveMode = getHint( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE, CacheRetrieveMode.class ); - applied = applyCacheModeHint( CacheModeHelper.interpretCacheMode( storeMode, retrieveMode ) ); - } - else if ( QueryHints.HINT_NATIVE_LOCKMODE.equals( hintName ) ) { - if ( !isNativeSqlQuery() ) { - throw new IllegalStateException( - "Illegal attempt to set lock mode on non-native query via hint; use Query#setLockMode instead" - ); - } - if ( LockMode.class.isInstance( value ) ) { - internalApplyLockMode( LockModeTypeHelper.getLockModeType( (LockMode) value ) ); - } - else if ( LockModeType.class.isInstance( value ) ) { - internalApplyLockMode( (LockModeType) value ); - } - else { - throw new IllegalArgumentException( - String.format( - "Native lock-mode hint [%s] must specify %s or %s. Encountered type : %s", - HINT_NATIVE_LOCKMODE, - LockMode.class.getName(), - LockModeType.class.getName(), - value.getClass().getName() - ) - ); - } - applied = true; - } - else if ( hintName.startsWith( AvailableSettings.ALIAS_SPECIFIC_LOCK_MODE ) ) { - if ( canApplyAliasSpecificLockModeHints() ) { - // extract the alias - final String alias = hintName.substring( AvailableSettings.ALIAS_SPECIFIC_LOCK_MODE.length() + 1 ); - // determine the LockMode - try { - final LockMode lockMode = LockModeTypeHelper.interpretLockMode( value ); - applyAliasSpecificLockModeHint( alias, lockMode ); - } - catch ( Exception e ) { - LOG.unableToDetermineLockModeValue( hintName, value ); - applied = false; - } - } - else { - applied = false; - } - } - else if ( HINT_FETCHGRAPH.equals( hintName ) || HINT_LOADGRAPH.equals( hintName ) ) { - if (value instanceof EntityGraphImpl) { - entityGraphQueryHint = new EntityGraphQueryHint( (EntityGraphImpl) value ); - } - else { - LOG.warnf( "The %s hint was set, but the value was not an EntityGraph!", hintName ); - } - applied = true; - } - else { - LOG.ignoringUnrecognizedQueryHint( hintName ); - } - } - catch ( ClassCastException e ) { - throw new IllegalArgumentException( "Value for hint" ); - } - - if ( applied ) { - if ( hints == null ) { - hints = new HashMap(); - } - hints.put( hintName, value ); - } - else { - LOG.debugf( "Skipping unsupported query hint [%s]", hintName ); - } - - return this; - } - - private > T getHint(String key, Class hintClass) { - Object hint = hints != null ? hints.get( key ) : null; - - if ( hint == null ) { - hint = entityManager.getProperties().get( key ); - } - - return hint != null ? Enum.valueOf( hintClass, hint.toString() ) : null; - } - - /** - * Is the query represented here a native SQL query? - * - * @return {@code true} if it is a native SQL query; {@code false} otherwise - */ - protected abstract boolean isNativeSqlQuery(); - - /** - * Is the query represented here a SELECT query? - * - * @return {@code true} if the query is a SELECT; {@code false} otherwise. - */ - protected abstract boolean isSelectQuery(); - - protected abstract void internalApplyLockMode(javax.persistence.LockModeType lockModeType); - - // FlushMode ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - private FlushModeType jpaFlushMode; - - @Override - public BaseQueryImpl setFlushMode(FlushModeType jpaFlushMode) { - checkOpen( true ); - this.jpaFlushMode = jpaFlushMode; - // TODO : treat as hint? - if ( jpaFlushMode == FlushModeType.AUTO ) { - applyFlushModeHint( FlushMode.AUTO ); - } - else if ( jpaFlushMode == FlushModeType.COMMIT ) { - applyFlushModeHint( FlushMode.COMMIT ); - } - return this; - } - - @SuppressWarnings( {"UnusedDeclaration"}) - protected FlushModeType getSpecifiedFlushMode() { - return jpaFlushMode; - } - - @Override - public FlushModeType getFlushMode() { - checkOpen( false ); - return jpaFlushMode != null - ? jpaFlushMode - : entityManager.getFlushMode(); - } - - - // Parameters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - private Set> parameterRegistrations; - - protected ParameterRegistration findParameterRegistration(Parameter parameter) { - if ( ParameterRegistration.class.isInstance( parameter ) ) { - final ParameterRegistration reg = (ParameterRegistration) parameter; - // validate the parameter source - if ( reg.getQuery() != this ) { - throw new IllegalArgumentException( "Passed Parameter was from different Query" ); - } - return reg; - } - else { - if ( parameter.getName() != null ) { - return findParameterRegistration( parameter.getName() ); - } - else if ( parameter.getPosition() != null ) { - return findParameterRegistration( parameter.getPosition() ); - } - } - - throw new IllegalArgumentException( "Unable to resolve incoming parameter [" + parameter + "] to registration" ); - } - - @SuppressWarnings("unchecked") - protected ParameterRegistration findParameterRegistration(String parameterName) { - if ( parameterRegistrations != null ) { - for ( ParameterRegistration param : parameterRegistrations ) { - if ( parameterName.equals( param.getName() ) ) { - return (ParameterRegistration) param; - } - } - - // legacy allowance of the application to access the parameter using the position as a String - final Integer jpaPositionalParameter = PessimisticNumberParser.toNumberOrNull( parameterName ); - if ( jpaPositionalParameter != null ) { - for ( ParameterRegistration param : parameterRegistrations ) { - if ( param.isJpaPositionalParameter() && jpaPositionalParameter.equals( param.getPosition() ) ) { - LOG.deprecatedJpaPositionalParameterAccess( jpaPositionalParameter ); - return (ParameterRegistration) param; - } - } - } - } - throw new IllegalArgumentException( "Parameter with that name [" + parameterName + "] did not exist" ); - } - - @SuppressWarnings("unchecked") - protected ParameterRegistration findParameterRegistration(int parameterPosition) { - if ( parameterRegistrations != null ) { - for ( ParameterRegistration param : parameterRegistrations ) { - if ( param.getPosition() == null ) { - continue; - } - if ( parameterPosition == param.getPosition() ) { - return (ParameterRegistration) param; - } - } - } - throw new IllegalArgumentException( "Parameter with that position [" + parameterPosition + "] did not exist" ); - } - - protected static class ParameterBindImpl implements ParameterBind { - private final T value; - private final TemporalType specifiedTemporalType; - - public ParameterBindImpl(T value, TemporalType specifiedTemporalType) { - this.value = value; - this.specifiedTemporalType = specifiedTemporalType; - } - - public T getValue() { - return value; - } - - public TemporalType getSpecifiedTemporalType() { - return specifiedTemporalType; - } - } - - private Set> parameterRegistrations() { - if ( parameterRegistrations == null ) { - // todo : could se use an identity set here? - parameterRegistrations = new HashSet>(); - } - return parameterRegistrations; - } - - protected void registerParameter(ParameterRegistration parameter) { - if ( parameter == null ) { - throw new IllegalArgumentException( "parameter cannot be null" ); - } - - if ( parameterRegistrations().contains( parameter ) ) { - LOG.debug( "Parameter registered multiple times : " + parameter ); - return; - } - - parameterRegistrations().add( parameter ); - } - - @Override - public BaseQueryImpl setParameter(Parameter param, T value) { - checkOpen( true ); - - try { - final ParameterRegistration parameterRegistrationExisting = findParameterRegistration( param ); - if ( value == null - && param.getParameterType() != null - && parameterRegistrationExisting.getParameterType() == null && - NullTypeBindableParameterRegistration.class.isInstance( parameterRegistrationExisting ) ) { - // we have: - // 1) a null value to bind; - // 2) parameterRegistrationExisting has no information about the Java type for that null value; - // 3) parameter.getParameterType() supplies a non-null parameter type; - // NOTE: According to Javadoc for javax.persistenceParameter#getParameterType: - // "Applications that use this method for Java Persistence query language - // queries and native queries will not be portable." - // and 4) parameterRegistrationExisting allows for overriding the null parameter type when - // binding a null value; - ( (NullTypeBindableParameterRegistration) parameterRegistrationExisting ).bindNullValue( param.getParameterType() ); - } - else { - // NOTE: The Javadoc for javax.persistence.Query#setParameter(Parameter param, T value) - // does not say anything about throwing IllegalArgumentException if - // javax.persistenceParameter#getParameterType is not assignable to the type, so we simply log - // a message if this is the case. - if ( param.getParameterType() != null && - parameterRegistrationExisting.getParameterType() != null && - !parameterRegistrationExisting.getParameterType().isAssignableFrom( param.getParameterType() ) ) { - LOG.warnf( - "Parameter type [%s] is not assignment compatible with requested type [%s] for parameter %s", - parameterRegistrationExisting.getParameterType().getName(), - param.getParameterType().getName(), - parameterRegistrationExisting.getName() == null ? - "at position [" + param.getPosition() + "]" : - "named [" + parameterRegistrationExisting.getName() + "]" - ); - } - parameterRegistrationExisting.bindValue( value ); - } - } - catch (QueryParameterException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( e.getMessage(), e ); - } - catch (HibernateException he) { - throw entityManager.convert( he ); - } - - return this; - } - - @Override - public BaseQueryImpl setParameter(Parameter param, Calendar value, TemporalType temporalType) { - checkOpen( true ); - - try { - findParameterRegistration( param ).bindValue( value, temporalType ); - } - catch (QueryParameterException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( e.getMessage(), e ); - } - catch (HibernateException he) { - throw entityManager.convert( he ); - } - - return this; - } - - @Override - public BaseQueryImpl setParameter(Parameter param, Date value, TemporalType temporalType) { - checkOpen( true ); - - try { - findParameterRegistration( param ).bindValue( value, temporalType ); - } - catch (QueryParameterException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( e.getMessage(), e ); - } - catch (HibernateException he) { - throw entityManager.convert( he ); - } - - return this; - } - - @Override - @SuppressWarnings("unchecked") - public BaseQueryImpl setParameter(String name, Object value) { - checkOpen( true ); - - try { - findParameterRegistration( name ).bindValue( value ); - } - catch (QueryParameterException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( e.getMessage(), e ); - } - catch (HibernateException he) { - throw entityManager.convert( he ); - } - - return this; - } - - @Override - public BaseQueryImpl setParameter(String name, Calendar value, TemporalType temporalType) { - checkOpen( true ); - - try { - findParameterRegistration( name ).bindValue( value, temporalType ); - } - catch (QueryParameterException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( e.getMessage(), e ); - } - catch (HibernateException he) { - throw entityManager.convert( he ); - } - - return this; - } - - @Override - public BaseQueryImpl setParameter(String name, Date value, TemporalType temporalType) { - checkOpen( true ); - - try { - findParameterRegistration( name ).bindValue( value, temporalType ); - } - catch (QueryParameterException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( e.getMessage(), e ); - } - catch (HibernateException he) { - throw entityManager.convert( he ); - } - - return this; - } - - @Override - public BaseQueryImpl setParameter(int position, Object value) { - checkOpen( true ); - - try { - findParameterRegistration( position ).bindValue( value ); - } - catch (QueryParameterException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( e.getMessage(), e ); - } - catch (HibernateException he) { - throw entityManager.convert( he ); - } - - return this; - } - - @Override - public BaseQueryImpl setParameter(int position, Calendar value, TemporalType temporalType) { - checkOpen( true ); - - try { - findParameterRegistration( position ).bindValue( value, temporalType ); - } - catch (QueryParameterException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( e.getMessage(), e ); - } - catch (HibernateException he) { - throw entityManager.convert( he ); - } - - return this; - } - - @Override - public BaseQueryImpl setParameter(int position, Date value, TemporalType temporalType) { - checkOpen( true ); - - try { - findParameterRegistration( position ).bindValue( value, temporalType ); - } - catch (ParameterStrategyException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( "Invalid mix of named and positional parameters", e ); - } - catch (NoSuchParameterException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( e.getMessage(), e ); - } - catch (QueryParameterException e) { - entityManager().markForRollbackOnly(); - throw new IllegalArgumentException( e.getMessage(), e ); - } - catch (HibernateException he) { - throw entityManager.convert( he ); - } - - return this; - } - - @Override - @SuppressWarnings("unchecked") - public Set getParameters() { - checkOpen( false ); - return parameterRegistrations(); - } - - @Override - public Parameter getParameter(String name) { - checkOpen( false ); - return findParameterRegistration( name ); - } - - @Override - @SuppressWarnings("unchecked") - public Parameter getParameter(String name, Class type) { - checkOpen( false ); - Parameter param = findParameterRegistration( name ); - - if ( param.getParameterType() != null ) { - // we were able to determine the expected type during analysis, so validate it here - if ( ! param.getParameterType().isAssignableFrom( type ) ) { - throw new IllegalArgumentException( - String.format( - "Parameter type [%s] is not assignment compatible with requested type [%s] for parameter named [%s]", - param.getParameterType().getName(), - type.getName(), - name - ) - ); - } - } - return (Parameter) param; - } - - @Override - public Parameter getParameter(int position) { - checkOpen( false ); - return findParameterRegistration( position ); - } - - @Override - @SuppressWarnings("unchecked") - public Parameter getParameter(int position, Class type) { - checkOpen( false ); - - Parameter param = findParameterRegistration( position ); - - if ( param.getParameterType() != null ) { - // we were able to determine the expected type during analysis, so validate it here - if ( ! param.getParameterType().isAssignableFrom( type ) ) { - throw new IllegalArgumentException( - String.format( - "Parameter type [%s] is not assignment compatible with requested type [%s] for parameter at position [%s]", - param.getParameterType().getName(), - type.getName(), - position - ) - ); - } - } - return (Parameter) param; - } - - @Override - public boolean isBound(Parameter param) { - checkOpen( false ); - final ParameterRegistration registration = findParameterRegistration( param ); - return registration != null && registration.isBindable() && registration.getBind() != null; - } - - @Override - @SuppressWarnings("unchecked") - public T getParameterValue(Parameter param) { - checkOpen( false ); - - final ParameterRegistration registration = findParameterRegistration( param ); - if ( registration == null ) { - throw new IllegalArgumentException( "Passed parameter [" + param + "] is not a (registered) parameter of this query" ); - } - - if ( ! registration.isBindable() ) { - throw new IllegalStateException( "Passed parameter [" + param + "] is not bindable" ); - } - - final ParameterBind bind = registration.getBind(); - if ( bind == null ) { - throw new IllegalStateException( "Parameter [" + param + "] has not yet been bound" ); - } - - return bind.getValue(); - } - - @Override - public Object getParameterValue(String name) { - checkOpen( false ); - return getParameterValue( getParameter( name ) ); - } - - @Override - public Object getParameterValue(int position) { - checkOpen( false ); - return getParameterValue( getParameter( position ) ); - } - - protected EntityGraphQueryHint getEntityGraphQueryHint() { - return entityGraphQueryHint; - } - - - - - - - - - - - - - - - - - - protected static void validateBinding(Class parameterType, Object bind, TemporalType temporalType) { - if ( bind == null || parameterType == null ) { - // nothing we can check - return; - } - - if ( bind instanceof TypedParameterValue ) { - bind = ( (TypedParameterValue ) bind ).getValue(); - } - - if ( Collection.class.isInstance( bind ) && ! Collection.class.isAssignableFrom( parameterType ) ) { - // we have a collection passed in where we are expecting a non-collection. - // NOTE : this can happen in Hibernate's notion of "parameter list" binding - // NOTE2 : the case of a collection value and an expected collection (if that can even happen) - // will fall through to the main check. - validateCollectionValuedParameterBinding( parameterType, (Collection) bind, temporalType ); - } - else if ( bind.getClass().isArray() ) { - validateArrayValuedParameterBinding( parameterType, bind, temporalType ); - } - else { - if ( ! isValidBindValue( parameterType, bind, temporalType ) ) { - throw new IllegalArgumentException( - String.format( - "Parameter value [%s] did not match expected type [%s (%s)]", - bind, - parameterType.getName(), - extractName( temporalType ) - ) - ); - } - } - } - - private static String extractName(TemporalType temporalType) { - return temporalType == null ? "n/a" : temporalType.name(); - } - - private static void validateCollectionValuedParameterBinding( - Class parameterType, - Collection value, - TemporalType temporalType) { - // validate the elements... - for ( Object element : value ) { - if ( ! isValidBindValue( parameterType, element, temporalType ) ) { - throw new IllegalArgumentException( - String.format( - "Parameter value element [%s] did not match expected type [%s (%s)]", - element, - parameterType.getName(), - extractName( temporalType ) - ) - ); - } - } - } - - private static void validateArrayValuedParameterBinding( - Class parameterType, - Object value, - TemporalType temporalType) { - if ( ! parameterType.isArray() ) { - throw new IllegalArgumentException( - String.format( - "Encountered array-valued parameter binding, but was expecting [%s (%s)]", - parameterType.getName(), - extractName( temporalType ) - ) - ); - } - - if ( value.getClass().getComponentType().isPrimitive() ) { - // we have a primitive array. we validate that the actual array has the component type (type of elements) - // we expect based on the component type of the parameter specification - if ( ! parameterType.getComponentType().isAssignableFrom( value.getClass().getComponentType() ) ) { - throw new IllegalArgumentException( - String.format( - "Primitive array-valued parameter bind value type [%s] did not match expected type [%s (%s)]", - value.getClass().getComponentType().getName(), - parameterType.getName(), - extractName( temporalType ) - ) - ); - } - } - else { - // we have an object array. Here we loop over the array and physically check each element against - // the type we expect based on the component type of the parameter specification - final Object[] array = (Object[]) value; - for ( Object element : array ) { - if ( ! isValidBindValue( parameterType.getComponentType(), element, temporalType ) ) { - throw new IllegalArgumentException( - String.format( - "Array-valued parameter value element [%s] did not match expected type [%s (%s)]", - element, - parameterType.getName(), - extractName( temporalType ) - ) - ); - } - } - } - } - - - private static boolean isValidBindValue(Class expectedType, Object value, TemporalType temporalType) { - if ( expectedType.isInstance( value ) ) { - return true; - } - - if ( temporalType != null ) { - final boolean parameterDeclarationIsTemporal = Date.class.isAssignableFrom( expectedType ) - || Calendar.class.isAssignableFrom( expectedType ); - final boolean bindIsTemporal = Date.class.isInstance( value ) - || Calendar.class.isInstance( value ); - - if ( parameterDeclarationIsTemporal && bindIsTemporal ) { - return true; - } - } - - return false; - } - - - - -} diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/BaseEntityManagerFunctionalTestCase.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/BaseEntityManagerFunctionalTestCase.java index cd03365396..f664d00874 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/BaseEntityManagerFunctionalTestCase.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/BaseEntityManagerFunctionalTestCase.java @@ -23,9 +23,9 @@ import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.bytecode.enhance.spi.EnhancementContext; import org.hibernate.cfg.Environment; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.StringHelper; import org.hibernate.jpa.AvailableSettings; -import org.hibernate.jpa.HibernateEntityManagerFactory; import org.hibernate.jpa.HibernatePersistenceProvider; import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; @@ -51,7 +51,7 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa private static final Dialect dialect = Dialect.getDialect(); private StandardServiceRegistryImpl serviceRegistry; - private HibernateEntityManagerFactory entityManagerFactory; + private SessionFactoryImplementor entityManagerFactory; private EntityManager em; private ArrayList isolatedEms = new ArrayList(); @@ -60,7 +60,7 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa return dialect; } - protected HibernateEntityManagerFactory entityManagerFactory() { + protected SessionFactoryImplementor entityManagerFactory() { return entityManagerFactory; } @@ -76,10 +76,9 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa entityManagerFactory = Bootstrap.getEntityManagerFactoryBuilder( buildPersistenceUnitDescriptor(), buildSettings() - ).build().unwrap( HibernateEntityManagerFactory.class ); + ).build().unwrap( SessionFactoryImplementor.class ); - serviceRegistry = (StandardServiceRegistryImpl) entityManagerFactory.getSessionFactory() - .getServiceRegistry() + serviceRegistry = (StandardServiceRegistryImpl) entityManagerFactory.getServiceRegistry() .getParentServiceRegistry(); afterEntityManagerFactoryBuilt(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/EntityManagerFactoryUnwrapTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/EntityManagerFactoryUnwrapTest.java index b01cdf3edc..29ab0abc4c 100755 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/EntityManagerFactoryUnwrapTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/EntityManagerFactoryUnwrapTest.java @@ -9,6 +9,7 @@ package org.hibernate.jpa.test; +import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceException; @@ -88,19 +89,10 @@ public class EntityManagerFactoryUnwrapTest extends BaseEntityManagerFunctionalT ); } - @Test - public void testEntityManagerCanBeUnwrappedToEntityManagerFactoryImpl() { - EntityManagerFactoryImpl entityManager = entityManagerFactory.unwrap( EntityManagerFactoryImpl.class ); - assertNotNull( - "Unwrapping to EntityManagerFactoryImpl should be ok", - entityManager - ); - } - @Test public void testEntityManagerCannotBeUnwrappedToUnrelatedType() { try { - entityManagerFactory.unwrap( EntityManagerImpl.class ); + entityManagerFactory.unwrap( EntityManager.class ); fail( "It should not be possible to unwrap to unrelated type." ); } catch ( PersistenceException e ) { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/Date3Type.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/Date3Type.java index a3fcd79c0b..ed5c8dc993 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/Date3Type.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/Date3Type.java @@ -15,7 +15,7 @@ import java.util.Date; import java.util.GregorianCalendar; import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.Type; import org.hibernate.usertype.CompositeUserType; @@ -95,7 +95,7 @@ public class Date3Type implements CompositeUserType { } @Override - public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { + public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { Date date = new Date(); Calendar c = GregorianCalendar.getInstance(); c.setTime( date ); @@ -110,7 +110,7 @@ public class Date3Type implements CompositeUserType { } @Override - public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { + public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { Date date = new Date(); Calendar c = GregorianCalendar.getInstance(); c.setTime( date ); @@ -135,17 +135,17 @@ public class Date3Type implements CompositeUserType { } @Override - public Serializable disassemble(Object value, SessionImplementor session) throws HibernateException { + public Serializable disassemble(Object value, SharedSessionContractImplementor session) throws HibernateException { return (Serializable) deepCopy( value ); } @Override - public Object assemble(Serializable cached, SessionImplementor session, Object owner) throws HibernateException { + public Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner) throws HibernateException { return deepCopy( cached ); } @Override - public Object replace(Object original, Object target, SessionImplementor session, Object owner) throws HibernateException { + public Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner) throws HibernateException { return deepCopy( original ); // TODO: improve } } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/PersisterClassProviderTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/PersisterClassProviderTest.java index d24cf53f7c..4536ceb455 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/PersisterClassProviderTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/PersisterClassProviderTest.java @@ -29,7 +29,7 @@ import org.hibernate.engine.internal.MutableEntityEntryFactory; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.EntityEntryFactory; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.ValueInclusion; import org.hibernate.id.IdentifierGenerator; import org.hibernate.internal.FilterAliasGenerator; @@ -48,9 +48,9 @@ import org.hibernate.persister.spi.PersisterClassResolver; import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.persister.walking.spi.AttributeDefinition; import org.hibernate.persister.walking.spi.EntityIdentifierDefinition; +import org.hibernate.tuple.entity.BytecodeEnhancementMetadataNonPojoImpl; import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityTuplizer; -import org.hibernate.tuple.entity.BytecodeEnhancementMetadataNonPojoImpl; import org.hibernate.type.Type; import org.hibernate.type.VersionType; @@ -216,12 +216,12 @@ public class PersisterClassProviderTest { } @Override - public int[] findDirty(Object[] currentState, Object[] previousState, Object owner, SessionImplementor session) { + public int[] findDirty(Object[] currentState, Object[] previousState, Object owner, SharedSessionContractImplementor session) { return new int[0]; } @Override - public int[] findModified(Object[] old, Object[] current, Object object, SessionImplementor session) { + public int[] findModified(Object[] old, Object[] current, Object object, SharedSessionContractImplementor session) { return new int[0]; } @@ -266,13 +266,13 @@ public class PersisterClassProviderTest { } @Override - public Object[] getNaturalIdentifierSnapshot(Serializable id, SessionImplementor session) { + public Object[] getNaturalIdentifierSnapshot(Serializable id, SharedSessionContractImplementor session) { return new Object[0]; } @Override public Serializable loadEntityIdByNaturalId(Object[] naturalIdValues, LockOptions lockOptions, - SessionImplementor session) { + SharedSessionContractImplementor session) { return null; } @@ -297,43 +297,43 @@ public class PersisterClassProviderTest { } @Override - public Object load(Serializable id, Object optionalObject, LockMode lockMode, SessionImplementor session) { + public Object load(Serializable id, Object optionalObject, LockMode lockMode, SharedSessionContractImplementor session) { return null; } @Override - public Object load(Serializable id, Object optionalObject, LockOptions lockOptions, SessionImplementor session) { + public Object load(Serializable id, Object optionalObject, LockOptions lockOptions, SharedSessionContractImplementor session) { return null; } @Override - public List multiLoad(Serializable[] ids, SessionImplementor session, MultiLoadOptions loadOptions) { + public List multiLoad(Serializable[] ids, SharedSessionContractImplementor session, MultiLoadOptions loadOptions) { return Collections.emptyList(); } @Override - public void lock(Serializable id, Object version, Object object, LockMode lockMode, SessionImplementor session) { + public void lock(Serializable id, Object version, Object object, LockMode lockMode, SharedSessionContractImplementor session) { } @Override - public void lock(Serializable id, Object version, Object object, LockOptions lockOptions, SessionImplementor session) { + public void lock(Serializable id, Object version, Object object, LockOptions lockOptions, SharedSessionContractImplementor session) { } @Override - public void insert(Serializable id, Object[] fields, Object object, SessionImplementor session) { + public void insert(Serializable id, Object[] fields, Object object, SharedSessionContractImplementor session) { } @Override - public Serializable insert(Object[] fields, Object object, SessionImplementor session) { + public Serializable insert(Object[] fields, Object object, SharedSessionContractImplementor session) { return null; } @Override - public void delete(Serializable id, Object version, Object object, SessionImplementor session) { + public void delete(Serializable id, Object version, Object object, SharedSessionContractImplementor session) { } @Override - public void update(Serializable id, Object[] fields, int[] dirtyFields, boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object object, Object rowId, SessionImplementor session) { + public void update(Serializable id, Object[] fields, int[] dirtyFields, boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object object, Object rowId, SharedSessionContractImplementor session) { } @Override @@ -442,22 +442,22 @@ public class PersisterClassProviderTest { } @Override - public Object[] getDatabaseSnapshot(Serializable id, SessionImplementor session) throws HibernateException { + public Object[] getDatabaseSnapshot(Serializable id, SharedSessionContractImplementor session) throws HibernateException { return new Object[0]; } @Override - public Serializable getIdByUniqueKey(Serializable key, String uniquePropertyName, SessionImplementor session) { + public Serializable getIdByUniqueKey(Serializable key, String uniquePropertyName, SharedSessionContractImplementor session) { throw new UnsupportedOperationException( "Not supported" ); } @Override - public Object getCurrentVersion(Serializable id, SessionImplementor session) throws HibernateException { + public Object getCurrentVersion(Serializable id, SharedSessionContractImplementor session) throws HibernateException { return null; } @Override - public Object forceVersionIncrement(Serializable id, Object currentVersion, SessionImplementor session) { + public Object forceVersionIncrement(Serializable id, Object currentVersion, SharedSessionContractImplementor session) { return null; } @@ -482,34 +482,34 @@ public class PersisterClassProviderTest { } @Override - public void afterInitialize(Object entity, SessionImplementor session) { + public void afterInitialize(Object entity, SharedSessionContractImplementor session) { } @Override - public void afterReassociate(Object entity, SessionImplementor session) { + public void afterReassociate(Object entity, SharedSessionContractImplementor session) { } @Override - public Object createProxy(Serializable id, SessionImplementor session) throws HibernateException { + public Object createProxy(Serializable id, SharedSessionContractImplementor session) throws HibernateException { return null; } @Override - public Boolean isTransient(Object object, SessionImplementor session) throws HibernateException { + public Boolean isTransient(Object object, SharedSessionContractImplementor session) throws HibernateException { return null; } @Override - public Object[] getPropertyValuesToInsert(Object object, Map mergeMap, SessionImplementor session) { + public Object[] getPropertyValuesToInsert(Object object, Map mergeMap, SharedSessionContractImplementor session) { return new Object[0]; } @Override - public void processInsertGeneratedProperties(Serializable id, Object entity, Object[] state, SessionImplementor session) { + public void processInsertGeneratedProperties(Serializable id, Object entity, Object[] state, SharedSessionContractImplementor session) { } @Override - public void processUpdateGeneratedProperties(Serializable id, Object entity, Object[] state, SessionImplementor session) { + public void processUpdateGeneratedProperties(Serializable id, Object entity, Object[] state, SharedSessionContractImplementor session) { } @Override @@ -556,12 +556,12 @@ public class PersisterClassProviderTest { } @Override - public Serializable getIdentifier(Object entity, SessionImplementor session) { + public Serializable getIdentifier(Object entity, SharedSessionContractImplementor session) { return null; } @Override - public void setIdentifier(Object entity, Serializable id, SessionImplementor session) { + public void setIdentifier(Object entity, Serializable id, SharedSessionContractImplementor session) { } @Override @@ -570,7 +570,7 @@ public class PersisterClassProviderTest { } @Override - public Object instantiate(Serializable id, SessionImplementor session) { + public Object instantiate(Serializable id, SharedSessionContractImplementor session) { return null; } @@ -585,7 +585,7 @@ public class PersisterClassProviderTest { } @Override - public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, SessionImplementor session) { + public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, SharedSessionContractImplementor session) { } @Override @@ -609,7 +609,7 @@ public class PersisterClassProviderTest { } @Override - public CacheEntry buildCacheEntry(Object entity, Object[] state, Object version, SessionImplementor session) { + public CacheEntry buildCacheEntry(Object entity, Object[] state, Object version, SharedSessionContractImplementor session) { return null; } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/id/FunkyIdGenerator.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/id/FunkyIdGenerator.java index 1f97ddc51a..76f29737dd 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/id/FunkyIdGenerator.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ejb3configuration/id/FunkyIdGenerator.java @@ -9,14 +9,14 @@ package org.hibernate.jpa.test.ejb3configuration.id; import java.io.Serializable; import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.id.IdentifierGenerator; /** * @author Emmanuel Bernard */ public class FunkyIdGenerator implements IdentifierGenerator { - public Serializable generate(SessionImplementor session, Object object) throws HibernateException { + public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException { throw new FunkyException(); } } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/lock/LockTimeoutPropertyTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/lock/LockTimeoutPropertyTest.java index 118e206752..6da606bdd6 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/lock/LockTimeoutPropertyTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/lock/LockTimeoutPropertyTest.java @@ -40,7 +40,8 @@ public class LockTimeoutPropertyTest extends BaseEntityManagerFunctionalTestCase em.getTransaction().begin(); Query query = em.createNamedQuery( "getAll" ); query.setLockMode( LockModeType.PESSIMISTIC_READ ); - int timeout = ((org.hibernate.jpa.internal.QueryImpl)query).getHibernateQuery().getLockOptions().getTimeOut(); + + int timeout = query.unwrap( org.hibernate.query.Query.class ).getLockOptions().getTimeOut(); assertEquals( 3000, timeout ); } @@ -54,15 +55,15 @@ public class LockTimeoutPropertyTest extends BaseEntityManagerFunctionalTestCase assertTrue( b ); int timeout = Integer.valueOf( em.getProperties().get( AvailableSettings.LOCK_TIMEOUT ).toString() ); assertEquals( 2000, timeout); - org.hibernate.jpa.internal.QueryImpl q = (org.hibernate.jpa.internal.QueryImpl) em.createQuery( "select u from UnversionedLock u" ); - timeout = q.getHibernateQuery().getLockOptions().getTimeOut(); + org.hibernate.query.Query q = (org.hibernate.query.Query) em.createQuery( "select u from UnversionedLock u" ); + timeout = q.getLockOptions().getTimeOut(); assertEquals( 2000, timeout ); Query query = em.createQuery( "select u from UnversionedLock u" ); query.setLockMode(LockModeType.PESSIMISTIC_WRITE); query.setHint( AvailableSettings.LOCK_TIMEOUT, 3000 ); - q = (org.hibernate.jpa.internal.QueryImpl)query; - timeout = q.getHibernateQuery().getLockOptions().getTimeOut(); + q = (org.hibernate.query.Query) query; + timeout = q.getLockOptions().getTimeOut(); assertEquals( 3000, timeout ); em.getTransaction().rollback(); em.close(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java index 3e3468e6de..65ee9ac633 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java @@ -6,7 +6,6 @@ */ package org.hibernate.jpa.test.metadata; -import java.util.Collections; import java.util.Locale; import java.util.Set; import javax.persistence.EntityManagerFactory; @@ -26,9 +25,10 @@ import javax.persistence.metamodel.Type; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; -import org.hibernate.mapping.MappedSuperclass; +import org.hibernate.metamodel.internal.JpaMetaModelPopulationSetting; import org.hibernate.metamodel.internal.MetamodelImpl; import org.junit.Test; @@ -94,12 +94,8 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { .addAnnotatedClass( WithGenericCollection.class ) .buildMetadata(); SessionFactoryImplementor sfi = (SessionFactoryImplementor) metadata.buildSessionFactory(); - MetamodelImpl.buildMetamodel( - metadata.getEntityBindings().iterator(), - Collections.emptySet(), - sfi, - true - ); + MetamodelImpl metamodel = new MetamodelImpl( sfi ); + metamodel.initialize( (MetadataImplementor) metadata, JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED ); sfi.close(); } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/GetLoadTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/GetLoadTest.java index e04c709cc7..4a39a2e831 100755 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/GetLoadTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/GetLoadTest.java @@ -97,13 +97,11 @@ public class GetLoadTest extends BaseEntityManagerFunctionalTestCase { } private void clearCounts() { - ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory().getStatistics().clear(); + entityManagerFactory().getStatistics().clear(); } private void assertFetchCount(int count) { - int fetches = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory() - .getStatistics() - .getEntityFetchCount(); + int fetches = ( int ) entityManagerFactory().getStatistics().getEntityFetchCount(); assertEquals( count, fetches ); } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/MergeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/MergeTest.java index fe42bebe54..c3c7b0e718 100755 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/MergeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/MergeTest.java @@ -86,20 +86,16 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase { } private void clearCounts() { - ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory().getStatistics().clear(); + entityManagerFactory().getStatistics().clear(); } private void assertInsertCount(int count) { - int inserts = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory() - .getStatistics() - .getEntityInsertCount(); + int inserts = ( int ) entityManagerFactory().getStatistics().getEntityInsertCount(); Assert.assertEquals( count, inserts ); } private void assertUpdateCount(int count) { - int updates = ( int ) entityManagerFactory().getSessionFactory() - .getStatistics() - .getEntityUpdateCount(); + int updates = ( int ) entityManagerFactory().getStatistics().getEntityUpdateCount(); Assert.assertEquals( count, updates ); } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/PersistTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/PersistTest.java index 7800ea5742..46e9256628 100755 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/PersistTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/ops/PersistTest.java @@ -193,20 +193,16 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase { } private void clearCounts() { - ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory().getStatistics().clear(); + entityManagerFactory().getStatistics().clear(); } private void assertInsertCount(int count) { - int inserts = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory() - .getStatistics() - .getEntityInsertCount(); + int inserts = ( int ) entityManagerFactory().getStatistics().getEntityInsertCount(); assertEquals( count, inserts ); } private void assertUpdateCount(int count) { - int updates = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory() - .getStatistics() - .getEntityUpdateCount(); + int updates = ( int ) entityManagerFactory().getStatistics().getEntityUpdateCount(); assertEquals( count, updates ); } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java index b7c1f9269b..396c6cfad6 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/packaging/PackagedEntityManagerTest.java @@ -15,7 +15,7 @@ import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import javax.persistence.PersistenceException; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.spi.EventType; import org.hibernate.internal.util.ConfigHelper; @@ -309,7 +309,7 @@ public class PackagedEntityManagerTest extends PackagingTestCase { EntityManagerFactory emf = Persistence.createEntityManagerFactory( "manager1", new HashMap() ); EntityManager em = emf.createEntityManager(); - EventListenerRegistry listenerRegistry = em.unwrap( SessionImplementor.class ).getFactory() + EventListenerRegistry listenerRegistry = em.unwrap( SharedSessionContractImplementor.class ).getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ); assertEquals( diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/AddNamedQueryTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/AddNamedQueryTest.java index 0100d22967..d42911f82a 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/AddNamedQueryTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/AddNamedQueryTest.java @@ -157,7 +157,7 @@ public class AddNamedQueryTest extends BaseEntityManagerFunctionalTestCase { query = em.createNamedQuery( name ); hibernateQuery = ( (HibernateQuery) query ).getHibernateQuery(); // assert the state of the query config settings based on the initial named query - assertEquals( (Integer) 51, hibernateQuery.getFirstResult() ); + assertEquals( 51, hibernateQuery.getFirstResult() ); assertNull( hibernateQuery.getMaxResults() ); assertEquals( FlushMode.AUTO, hibernateQuery.getFlushMode() ); assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/TypedValueParametersTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/TypedValueParametersTest.java index 8d32cd8deb..65a1dc8679 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/TypedValueParametersTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/query/TypedValueParametersTest.java @@ -17,7 +17,6 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.Id; -import javax.persistence.Persistence; import javax.persistence.Query; import javax.persistence.Table; import javax.persistence.TypedQuery; @@ -25,8 +24,7 @@ import javax.persistence.TypedQuery; import org.hibernate.HibernateException; import org.hibernate.annotations.Type; import org.hibernate.annotations.TypeDef; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.engine.spi.TypedValue; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.jpa.TypedParameterValue; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.type.CustomType; @@ -140,7 +138,7 @@ public class TypedValueParametersTest extends BaseEntityManagerFunctionalTestCas private final int SQLTYPE = java.sql.Types.VARCHAR; @Override - public void nullSafeSet(PreparedStatement statement, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { + public void nullSafeSet(PreparedStatement statement, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value == null) { statement.setNull(index, SQLTYPE); } else { @@ -160,7 +158,7 @@ public class TypedValueParametersTest extends BaseEntityManagerFunctionalTestCas } @Override - public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { + public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { String string = rs.getString(names[0]); if (rs.wasNull()) { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/SynchronizationTypeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/SynchronizationTypeTest.java index 9818f47e99..5844cb5b55 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/SynchronizationTypeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/SynchronizationTypeTest.java @@ -14,7 +14,7 @@ import javax.persistence.TransactionRequiredException; import javax.persistence.criteria.CriteriaDelete; import javax.persistence.criteria.CriteriaUpdate; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; @@ -71,7 +71,7 @@ public class SynchronizationTypeTest extends BaseEntityManagerFunctionalTestCase assertTrue( "setup problem", JtaStatusHelper.isActive( TestingJtaPlatformImpl.INSTANCE.getTransactionManager() ) ); EntityManager entityManager = entityManagerFactory().createEntityManager( SynchronizationType.UNSYNCHRONIZED, null ); - SessionImplementor session = entityManager.unwrap( SessionImplementor.class ); + SharedSessionContractImplementor session = entityManager.unwrap( SharedSessionContractImplementor.class ); ExtraAssertions.assertTyping( JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator() ); JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoinHandlingChecker.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoinHandlingChecker.java index 7463c95037..ae08b74fff 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoinHandlingChecker.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoinHandlingChecker.java @@ -8,7 +8,7 @@ package org.hibernate.jpa.test.transaction; import javax.persistence.EntityManager; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl; @@ -25,7 +25,7 @@ import static org.junit.Assert.assertTrue; */ public class TransactionJoinHandlingChecker { static void validateExplicitJoiningHandling(EntityManager entityManager) throws Exception { - SessionImplementor session = entityManager.unwrap( SessionImplementor.class ); + SharedSessionContractImplementor session = entityManager.unwrap( SharedSessionContractImplementor.class ); ExtraAssertions.assertTyping( JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator() ); JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoiningTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoiningTest.java index af0ca91a53..b297194461 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoiningTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoiningTest.java @@ -15,7 +15,7 @@ import javax.persistence.TransactionRequiredException; import javax.transaction.Status; import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; import org.hibernate.internal.SessionImpl; import org.hibernate.jpa.AvailableSettings; @@ -78,7 +78,7 @@ public class TransactionJoiningTest extends BaseEntityManagerFunctionalTestCase TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); EntityManager entityManager = entityManagerFactory().createEntityManager(); - SessionImplementor session = entityManager.unwrap( SessionImplementor.class ); + SharedSessionContractImplementor session = entityManager.unwrap( SharedSessionContractImplementor.class ); ExtraAssertions.assertTyping( JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator() ); JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator(); @@ -104,7 +104,7 @@ public class TransactionJoiningTest extends BaseEntityManagerFunctionalTestCase TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); EntityManager entityManager = entityManagerFactory().createEntityManager(); - SessionImplementor session = entityManager.unwrap( SessionImplementor.class ); + SharedSessionContractImplementor session = entityManager.unwrap( SharedSessionContractImplementor.class ); ExtraAssertions.assertTyping( JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator() ); JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator(); @@ -130,7 +130,7 @@ public class TransactionJoiningTest extends BaseEntityManagerFunctionalTestCase TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); EntityManager entityManager = entityManagerFactory().createEntityManager(); - SessionImplementor session = entityManager.unwrap( SessionImplementor.class ); + SharedSessionContractImplementor session = entityManager.unwrap( SharedSessionContractImplementor.class ); ExtraAssertions.assertTyping( JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator() ); JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlTest.java index 72ce0269ce..b094704db9 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/xml/XmlTest.java @@ -10,14 +10,14 @@ import java.util.Map; import javax.persistence.EntityManager; import javax.persistence.SharedCacheMode; -import junit.framework.Assert; -import org.junit.Test; - -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.persister.entity.EntityPersister; +import org.junit.Test; +import junit.framework.Assert; + /** * @author Emmanuel Bernard */ @@ -31,7 +31,7 @@ public class XmlTest extends BaseEntityManagerFunctionalTestCase { @Test public void testXmlMappingWithCacheable() throws Exception{ EntityManager em = getOrCreateEntityManager(); - SessionImplementor session = em.unwrap( SessionImplementor.class ); + SharedSessionContractImplementor session = em.unwrap( SharedSessionContractImplementor.class ); EntityPersister entityPersister= session.getFactory().getEntityPersister( Lighter.class.getName() ); Assert.assertTrue(entityPersister.hasCache()); }