HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (continued fixing of hibernate-core test failures)
This commit is contained in:
parent
16c78f0438
commit
a7a039e291
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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 <a href="mailto:gavin@hibernate.org">Gavin King</a>
|
||||
* @author Emmanuel Bernard
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class QueryImpl<X> extends AbstractQueryImpl<X>
|
||||
implements TypedQuery<X>, 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<String, Class> 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<String, Class> 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<String>) 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<T> implements NullTypeBindableParameterRegistration<T> {
|
||||
private final QueryImpl jpaQuery;
|
||||
private final org.hibernate.Query nativeQuery;
|
||||
|
||||
private final String name;
|
||||
private final Integer position;
|
||||
private final Class<T> javaType;
|
||||
|
||||
private ParameterBind<T> bind;
|
||||
|
||||
protected ParameterRegistrationImpl(
|
||||
QueryImpl jpaQuery,
|
||||
org.hibernate.Query nativeQuery,
|
||||
String name,
|
||||
Class<T> 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<T> 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<T> 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<T>( 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<T>( value, specifiedTemporalType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterBind<T> 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<T>( null, null );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specialized handling for JPA "positional parameters".
|
||||
*
|
||||
* @param <T> The parameter type type.
|
||||
*/
|
||||
public static class JpaPositionalParameterRegistrationImpl<T> extends ParameterRegistrationImpl<T> {
|
||||
final Integer position;
|
||||
|
||||
protected JpaPositionalParameterRegistrationImpl(
|
||||
QueryImpl jpaQuery,
|
||||
org.hibernate.Query nativeQuery,
|
||||
Integer position,
|
||||
Class<T> 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<X> 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<X> 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<X> uniqueResult = new HashSet<X>( 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> T unwrap(Class<T> 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<X> list() {
|
||||
if ( getEntityGraphQueryHint() != null ) {
|
||||
// Safe to assume QueryImpl at this point.
|
||||
unwrap( org.hibernate.query.internal.QueryImpl.class ).applyEntityGraphQueryHint( getEntityGraphQueryHint() );
|
||||
}
|
||||
return query.list();
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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 <a href="mailto:gavin@hibernate.org">Gavin King</a>
|
||||
* @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<String> 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<String, Object> 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<String,Object> 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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.
|
||||
* <p/>
|
||||
* Not intended as base for {@link javax.persistence.StoredProcedureQuery}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractQueryImpl<X> extends BaseQueryImpl implements TypedQuery<X> {
|
||||
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<X> setMaxResults(int maxResults) {
|
||||
return (AbstractQueryImpl<X>) super.setMaxResults( maxResults );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractQueryImpl<X> setFirstResult(int firstResult) {
|
||||
return (AbstractQueryImpl<X>) super.setFirstResult( firstResult );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"deprecation"})
|
||||
public AbstractQueryImpl<X> setHint(String hintName, Object value) {
|
||||
super.setHint( hintName, value );
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings( {"UnusedDeclaration"})
|
||||
public Set<String> getSupportedHints() {
|
||||
return QueryHints.getDefinedHints();
|
||||
}
|
||||
|
||||
private javax.persistence.LockModeType jpaLockMode = javax.persistence.LockModeType.NONE;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public TypedQuery<X> 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 <T> AbstractQueryImpl<X> setParameter(Parameter<T> param, T value) {
|
||||
return (AbstractQueryImpl<X>) super.setParameter( param, value );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractQueryImpl<X> setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) {
|
||||
return (AbstractQueryImpl<X>) super.setParameter( param, value, temporalType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractQueryImpl<X> setParameter(Parameter<Date> param, Date value, TemporalType temporalType) {
|
||||
return (AbstractQueryImpl<X>) super.setParameter( param, value, temporalType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractQueryImpl<X> setParameter(String name, Object value) {
|
||||
return (AbstractQueryImpl<X>) super.setParameter( name, value );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractQueryImpl<X> setParameter(String name, Calendar value, TemporalType temporalType) {
|
||||
return (AbstractQueryImpl<X>) super.setParameter( name, value, temporalType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractQueryImpl<X> setParameter(String name, Date value, TemporalType temporalType) {
|
||||
return (AbstractQueryImpl<X>) super.setParameter( name, value, temporalType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractQueryImpl<X> setParameter(int position, Object value) {
|
||||
return (AbstractQueryImpl<X>) super.setParameter( position, value );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractQueryImpl<X> setParameter(int position, Calendar value, TemporalType temporalType) {
|
||||
return (AbstractQueryImpl<X>) super.setParameter( position, value, temporalType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractQueryImpl<X> setParameter(int position, Date value, TemporalType temporalType) {
|
||||
return (AbstractQueryImpl<X>) super.setParameter( position, value, temporalType );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractQueryImpl<X> setFlushMode(FlushModeType jpaFlushMode) {
|
||||
return (AbstractQueryImpl<X>) super.setFlushMode( jpaFlushMode );
|
||||
}
|
||||
|
||||
protected void checkTransaction() {
|
||||
if ( jpaLockMode != null && jpaLockMode != LockModeType.NONE ) {
|
||||
if ( !getEntityManager().isTransactionInProgress() ) {
|
||||
throw new TransactionRequiredException( "no transaction is in progress" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -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<EntityManager> isolatedEms = new ArrayList<EntityManager>();
|
||||
|
@ -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();
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <emmanuel@hibernate.org>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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.<MappedSuperclass>emptySet(),
|
||||
sfi,
|
||||
true
|
||||
);
|
||||
MetamodelImpl metamodel = new MetamodelImpl( sfi );
|
||||
metamodel.initialize( (MetadataImplementor) metadata, JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED );
|
||||
sfi.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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() );
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue