HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (fix test failures)

This commit is contained in:
Steve Ebersole 2016-05-02 16:56:30 -05:00
parent 68bde01676
commit b67b5866ac
6 changed files with 33 additions and 17 deletions

View File

@ -25,7 +25,6 @@ import org.junit.Test;
import org.jboss.logging.Logger;
import static org.hibernate.userguide.util.TransactionUtil.doInJPA;
import static org.junit.Assert.assertTrue;
/**
@ -56,7 +55,7 @@ public class ManualFlushTest extends BaseEntityManagerFunctionalTestCase {
entityManager.persist(person);
Session session = entityManager.unwrap( Session.class);
session.setFlushMode( FlushMode.MANUAL);
session.setHibernateFlushMode( FlushMode.MANUAL );
assertTrue(((Number) entityManager
.createQuery("select count(id) from Person")

View File

@ -419,6 +419,7 @@ public class ProcedureCallImpl<R>
);
try {
LOG.debugf( "Preparing procedure call : %s", call );
final CallableStatement statement = (CallableStatement) getSession()
.getJdbcCoordinator()
.getStatementPreparer()
@ -596,7 +597,7 @@ public class ProcedureCallImpl<R>
getProducer().checkOpen( true );
try {
registerParameter( (ParameterRegistrationImplementor) registerParameter( position, type, mode ) );
registerParameter( position, type, mode );
}
catch (HibernateException he) {
throw getExceptionConverter().convert( he );

View File

@ -123,7 +123,7 @@ public interface QueryProducer {
*
* @see javax.persistence.EntityManager#createNativeQuery(String,Class)
*/
NativeQuery createNativeQuery(String sqlString, Class resultClass);
<R> NativeQuery<R> createNativeQuery(String sqlString, Class<R> resultClass);
/**
* Create a NativeQuery instance for the given native (SQL) query using

View File

@ -115,6 +115,9 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
this.producer = producer;
this.parameterMetadata = parameterMetadata;
this.queryParameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, producer.getFactory() );
// this.flushMode = producer.getHibernateFlushMode();
// this.cacheMode = producer.getCacheMode();
}
@Override

View File

@ -224,10 +224,24 @@ public class NativeQueryImpl<T> extends AbstractProducedQuery<T> implements Nati
// apps, so we only do the flush if a transaction is in progress.
//
// NOTE : this was added for JPA initially. Perhaps we want to only do this from JPA usage?
if ( getProducer().isTransactionInProgress() ) {
if ( shouldFlush() ) {
getProducer().flush();
}
}
private boolean shouldFlush() {
if ( getProducer().isTransactionInProgress() ) {
FlushMode effectiveFlushMode = getHibernateFlushMode();
if ( effectiveFlushMode == null ) {
effectiveFlushMode = getProducer().getHibernateFlushMode();
}
if ( effectiveFlushMode != FlushMode.MANUAL ) {
return true;
}
}
return false;
}
protected int doExecuteUpdate() {

View File

@ -14,7 +14,6 @@ import java.sql.SQLException;
import org.hibernate.ConnectionAcquisitionMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException;
import org.hibernate.ResourceClosedException;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.engine.jdbc.spi.JdbcServices;
@ -58,8 +57,11 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple
this.observer = jdbcSessionContext.getObserver();
this.resourceRegistry = resourceRegistry;
this.connectionHandlingMode = jdbcSessionContext.getPhysicalConnectionHandlingMode();
validateConnectionHandlingMode( connectionHandlingMode, jdbcConnectionAccess );
this.connectionHandlingMode = determineConnectionHandlingMode(
jdbcSessionContext.getPhysicalConnectionHandlingMode(),
jdbcConnectionAccess
);
this.sqlExceptionHelper = jdbcSessionContext.getServiceRegistry()
.getService( JdbcServices.class )
@ -70,18 +72,15 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple
}
}
private void validateConnectionHandlingMode(
private PhysicalConnectionHandlingMode determineConnectionHandlingMode(
PhysicalConnectionHandlingMode connectionHandlingMode,
JdbcConnectionAccess jdbcConnectionAccess) {
if ( connectionHandlingMode.getReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT ) {
// make sure the Connection access supports reacquisition...
// NOTE we used to just swap it here with a more correct release-mode, but
// really this ought to be validated at a higher level...
if ( !jdbcConnectionAccess.supportsAggressiveRelease() ) {
throw new HibernateException(
"Connection provider reports to not support aggressive release, but ATER_STATEMENT releasing was requested" );
}
if ( connectionHandlingMode.getReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT
&& !jdbcConnectionAccess.supportsAggressiveRelease() ) {
return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION;
}
return connectionHandlingMode;
}
private LogicalConnectionManagedImpl(