HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (fix test failures)
This commit is contained in:
parent
c79ff0f7ee
commit
1ece6056d1
|
@ -17,7 +17,7 @@ public final class RowSelection {
|
||||||
private Integer timeout;
|
private Integer timeout;
|
||||||
private Integer fetchSize;
|
private Integer fetchSize;
|
||||||
|
|
||||||
public void setFirstRow(Integer firstRow) {
|
public void setFirstRow(int firstRow) {
|
||||||
this.firstRow = firstRow;
|
this.firstRow = firstRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ public final class RowSelection {
|
||||||
return firstRow;
|
return firstRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxRows(Integer maxRows) {
|
public void setMaxRows(int maxRows) {
|
||||||
this.maxRows = maxRows;
|
this.maxRows = maxRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public final class RowSelection {
|
||||||
return maxRows;
|
return maxRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeout(Integer timeout) {
|
public void setTimeout(int timeout) {
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +45,15 @@ public final class RowSelection {
|
||||||
return fetchSize;
|
return fetchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFetchSize(Integer fetchSize) {
|
public void setFetchSize(int fetchSize) {
|
||||||
this.fetchSize = fetchSize;
|
this.fetchSize = fetchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean definesLimits() {
|
public boolean definesLimits() {
|
||||||
return maxRows != null || (firstRow != null && firstRow <= 0);
|
return maxRows != null || (firstRow != null && firstRow <= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unsetMaxRows() {
|
||||||
|
maxRows = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -842,12 +842,24 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||||
.setCacheable( query.isCacheable() )
|
.setCacheable( query.isCacheable() )
|
||||||
.setCacheRegion( query.getCacheRegion() )
|
.setCacheRegion( query.getCacheRegion() )
|
||||||
.setCacheMode( query.getCacheMode() )
|
.setCacheMode( query.getCacheMode() )
|
||||||
.setTimeout( query.getTimeout() )
|
|
||||||
.setFetchSize( query.getFetchSize() )
|
|
||||||
.setFirstResult( query.getFirstResult() )
|
|
||||||
.setMaxResults( query.getMaxResults() )
|
|
||||||
.setReadOnly( query.isReadOnly() )
|
.setReadOnly( query.isReadOnly() )
|
||||||
.setFlushMode( query.getHibernateFlushMode() );
|
.setFlushMode( query.getHibernateFlushMode() );
|
||||||
|
|
||||||
|
if ( query.getQueryOptions().getFirstRow() != null ) {
|
||||||
|
builder.setFirstResult( query.getQueryOptions().getFirstRow() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( query.getQueryOptions().getMaxRows() != null ) {
|
||||||
|
builder.setMaxResults( query.getQueryOptions().getMaxRows() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( query.getQueryOptions().getTimeout() != null ) {
|
||||||
|
builder.setTimeout( query.getQueryOptions().getTimeout() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( query.getQueryOptions().getFetchSize() != null ) {
|
||||||
|
builder.setFetchSize( query.getQueryOptions().getFetchSize() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,7 +25,6 @@ import javax.sql.DataSource;
|
||||||
import javassist.CtClass;
|
import javassist.CtClass;
|
||||||
import javassist.CtField;
|
import javassist.CtField;
|
||||||
|
|
||||||
import org.hibernate.Interceptor;
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.SessionFactoryObserver;
|
import org.hibernate.SessionFactoryObserver;
|
||||||
import org.hibernate.boot.CacheRegionDefinition;
|
import org.hibernate.boot.CacheRegionDefinition;
|
||||||
|
@ -81,11 +80,24 @@ import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
|
||||||
|
|
||||||
import org.jboss.jandex.Index;
|
import org.jboss.jandex.Index;
|
||||||
|
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.DATASOURCE;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.DRIVER;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JACC_CONTEXT_ID;
|
import static org.hibernate.cfg.AvailableSettings.JACC_CONTEXT_ID;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JACC_PREFIX;
|
import static org.hibernate.cfg.AvailableSettings.JACC_PREFIX;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.JPA_JDBC_DRIVER;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.JPA_JDBC_PASSWORD;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.JPA_JDBC_URL;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.JPA_JDBC_USER;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.JPA_JTA_DATASOURCE;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.JPA_NON_JTA_DATASOURCE;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_MODE;
|
import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_MODE;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.JPA_TRANSACTION_TYPE;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_MODE;
|
import static org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_MODE;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.PASS;
|
||||||
import static org.hibernate.cfg.AvailableSettings.SESSION_FACTORY_NAME;
|
import static org.hibernate.cfg.AvailableSettings.SESSION_FACTORY_NAME;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.URL;
|
||||||
|
import static org.hibernate.cfg.AvailableSettings.USER;
|
||||||
import static org.hibernate.internal.HEMLogging.messageLogger;
|
import static org.hibernate.internal.HEMLogging.messageLogger;
|
||||||
import static org.hibernate.jpa.AvailableSettings.CFG_FILE;
|
import static org.hibernate.jpa.AvailableSettings.CFG_FILE;
|
||||||
import static org.hibernate.jpa.AvailableSettings.CLASS_CACHE_PREFIX;
|
import static org.hibernate.jpa.AvailableSettings.CLASS_CACHE_PREFIX;
|
||||||
|
@ -314,9 +326,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
final StrategyRegistrationProviderList strategyRegistrationProviderList
|
final StrategyRegistrationProviderList strategyRegistrationProviderList
|
||||||
= (StrategyRegistrationProviderList) integrationSettings.get( STRATEGY_REGISTRATION_PROVIDERS );
|
= (StrategyRegistrationProviderList) integrationSettings.get( STRATEGY_REGISTRATION_PROVIDERS );
|
||||||
if ( strategyRegistrationProviderList != null ) {
|
if ( strategyRegistrationProviderList != null ) {
|
||||||
for ( StrategyRegistrationProvider strategyRegistrationProvider : strategyRegistrationProviderList
|
for ( StrategyRegistrationProvider strategyRegistrationProvider : strategyRegistrationProviderList.getStrategyRegistrationProviders() ) {
|
||||||
.getStrategyRegistrationProviders() ) {
|
bsrBuilder.applyStrategySelectors( strategyRegistrationProvider );
|
||||||
bsrBuilder.withStrategySelectors( strategyRegistrationProvider );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,45 +585,45 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
|
|
||||||
private void applyJdbcConnectionProperties(StandardServiceRegistryBuilder ssrBuilder) {
|
private void applyJdbcConnectionProperties(StandardServiceRegistryBuilder ssrBuilder) {
|
||||||
if ( dataSource != null ) {
|
if ( dataSource != null ) {
|
||||||
ssrBuilder.applySetting( org.hibernate.cfg.AvailableSettings.DATASOURCE, dataSource );
|
ssrBuilder.applySetting( DATASOURCE, dataSource );
|
||||||
}
|
}
|
||||||
else if ( persistenceUnit.getJtaDataSource() != null ) {
|
else if ( persistenceUnit.getJtaDataSource() != null ) {
|
||||||
if ( ! ssrBuilder.getSettings().containsKey( org.hibernate.cfg.AvailableSettings.DATASOURCE ) ) {
|
if ( ! ssrBuilder.getSettings().containsKey( DATASOURCE ) ) {
|
||||||
ssrBuilder.applySetting( org.hibernate.cfg.AvailableSettings.DATASOURCE, persistenceUnit.getJtaDataSource() );
|
ssrBuilder.applySetting( DATASOURCE, persistenceUnit.getJtaDataSource() );
|
||||||
// HHH-8121 : make the PU-defined value available to EMF.getProperties()
|
// HHH-8121 : make the PU-defined value available to EMF.getProperties()
|
||||||
configurationValues.put( AvailableSettings.JTA_DATASOURCE, persistenceUnit.getJtaDataSource() );
|
configurationValues.put( JPA_JTA_DATASOURCE, persistenceUnit.getJtaDataSource() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( persistenceUnit.getNonJtaDataSource() != null ) {
|
else if ( persistenceUnit.getNonJtaDataSource() != null ) {
|
||||||
if ( ! ssrBuilder.getSettings().containsKey( org.hibernate.cfg.AvailableSettings.DATASOURCE ) ) {
|
if ( ! ssrBuilder.getSettings().containsKey( DATASOURCE ) ) {
|
||||||
ssrBuilder.applySetting( org.hibernate.cfg.AvailableSettings.DATASOURCE, persistenceUnit.getNonJtaDataSource() );
|
ssrBuilder.applySetting( DATASOURCE, persistenceUnit.getNonJtaDataSource() );
|
||||||
// HHH-8121 : make the PU-defined value available to EMF.getProperties()
|
// HHH-8121 : make the PU-defined value available to EMF.getProperties()
|
||||||
configurationValues.put( AvailableSettings.NON_JTA_DATASOURCE, persistenceUnit.getNonJtaDataSource() );
|
configurationValues.put( JPA_NON_JTA_DATASOURCE, persistenceUnit.getNonJtaDataSource() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final String driver = (String) configurationValues.get( AvailableSettings.JDBC_DRIVER );
|
final String driver = (String) configurationValues.get( JPA_JDBC_DRIVER );
|
||||||
if ( StringHelper.isNotEmpty( driver ) ) {
|
if ( StringHelper.isNotEmpty( driver ) ) {
|
||||||
ssrBuilder.applySetting( org.hibernate.cfg.AvailableSettings.DRIVER, driver );
|
ssrBuilder.applySetting( DRIVER, driver );
|
||||||
}
|
}
|
||||||
final String url = (String) configurationValues.get( AvailableSettings.JDBC_URL );
|
final String url = (String) configurationValues.get( JPA_JDBC_URL );
|
||||||
if ( StringHelper.isNotEmpty( url ) ) {
|
if ( StringHelper.isNotEmpty( url ) ) {
|
||||||
ssrBuilder.applySetting( org.hibernate.cfg.AvailableSettings.URL, url );
|
ssrBuilder.applySetting( URL, url );
|
||||||
}
|
}
|
||||||
final String user = (String) configurationValues.get( AvailableSettings.JDBC_USER );
|
final String user = (String) configurationValues.get( JPA_JDBC_USER );
|
||||||
if ( StringHelper.isNotEmpty( user ) ) {
|
if ( StringHelper.isNotEmpty( user ) ) {
|
||||||
ssrBuilder.applySetting( org.hibernate.cfg.AvailableSettings.USER, user );
|
ssrBuilder.applySetting( USER, user );
|
||||||
}
|
}
|
||||||
final String pass = (String) configurationValues.get( AvailableSettings.JDBC_PASSWORD );
|
final String pass = (String) configurationValues.get( JPA_JDBC_PASSWORD );
|
||||||
if ( StringHelper.isNotEmpty( pass ) ) {
|
if ( StringHelper.isNotEmpty( pass ) ) {
|
||||||
ssrBuilder.applySetting( org.hibernate.cfg.AvailableSettings.PASS, pass );
|
ssrBuilder.applySetting( PASS, pass );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyTransactionProperties(StandardServiceRegistryBuilder ssrBuilder, SettingsImpl settings) {
|
private void applyTransactionProperties(StandardServiceRegistryBuilder ssrBuilder, SettingsImpl settings) {
|
||||||
PersistenceUnitTransactionType txnType = PersistenceUnitTransactionTypeHelper.interpretTransactionType(
|
PersistenceUnitTransactionType txnType = PersistenceUnitTransactionTypeHelper.interpretTransactionType(
|
||||||
configurationValues.get( AvailableSettings.TRANSACTION_TYPE )
|
configurationValues.get( JPA_TRANSACTION_TYPE )
|
||||||
);
|
);
|
||||||
if ( txnType == null ) {
|
if ( txnType == null ) {
|
||||||
txnType = persistenceUnit.getTransactionType();
|
txnType = persistenceUnit.getTransactionType();
|
||||||
|
@ -622,31 +633,20 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
txnType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
|
txnType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
|
||||||
}
|
}
|
||||||
settings.setTransactionType( txnType );
|
settings.setTransactionType( txnType );
|
||||||
boolean hasTxStrategy = configurationValues.containsKey( Environment.TRANSACTION_COORDINATOR_STRATEGY );
|
boolean hasTxStrategy = configurationValues.containsKey( TRANSACTION_COORDINATOR_STRATEGY );
|
||||||
if ( hasTxStrategy ) {
|
if ( hasTxStrategy ) {
|
||||||
LOG.overridingTransactionStrategyDangerous( Environment.TRANSACTION_COORDINATOR_STRATEGY );
|
LOG.overridingTransactionStrategyDangerous( TRANSACTION_COORDINATOR_STRATEGY );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( txnType == PersistenceUnitTransactionType.JTA ) {
|
if ( txnType == PersistenceUnitTransactionType.JTA ) {
|
||||||
ssrBuilder.applySetting( Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class );
|
ssrBuilder.applySetting( TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class );
|
||||||
}
|
}
|
||||||
else if ( txnType == PersistenceUnitTransactionType.RESOURCE_LOCAL ) {
|
else if ( txnType == PersistenceUnitTransactionType.RESOURCE_LOCAL ) {
|
||||||
ssrBuilder.applySetting( Environment.TRANSACTION_COORDINATOR_STRATEGY, JdbcResourceLocalTransactionCoordinatorBuilderImpl.class );
|
ssrBuilder.applySetting( TRANSACTION_COORDINATOR_STRATEGY, JdbcResourceLocalTransactionCoordinatorBuilderImpl.class );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private Class<? extends Interceptor> loadSessionInterceptorClass(Object value, StrategySelector strategySelector) {
|
|
||||||
if ( value == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Class.class.isInstance( value )
|
|
||||||
? (Class<? extends Interceptor>) value
|
|
||||||
: strategySelector.selectStrategyImplementor( Interceptor.class, value.toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void configure(StandardServiceRegistry ssr, MergedSettings mergedSettings) {
|
private void configure(StandardServiceRegistry ssr, MergedSettings mergedSettings) {
|
||||||
final StrategySelector strategySelector = ssr.getService( StrategySelector.class );
|
final StrategySelector strategySelector = ssr.getService( StrategySelector.class );
|
||||||
|
|
||||||
|
@ -722,7 +722,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
for ( Class cls : loadedAnnotatedClasses ) {
|
for ( Class cls : loadedAnnotatedClasses ) {
|
||||||
if ( AttributeConverter.class.isAssignableFrom( cls ) ) {
|
if ( AttributeConverter.class.isAssignableFrom( cls ) ) {
|
||||||
if ( attributeConverterDefinitions == null ) {
|
if ( attributeConverterDefinitions == null ) {
|
||||||
attributeConverterDefinitions = new ArrayList<AttributeConverterDefinition>();
|
attributeConverterDefinitions = new ArrayList<>();
|
||||||
}
|
}
|
||||||
attributeConverterDefinitions.add( AttributeConverterDefinition.from( (Class<? extends AttributeConverter>) cls ) );
|
attributeConverterDefinitions.add( AttributeConverterDefinition.from( (Class<? extends AttributeConverter>) cls ) );
|
||||||
}
|
}
|
||||||
|
@ -902,7 +902,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class ServiceRegistryCloser implements SessionFactoryObserver {
|
private static class ServiceRegistryCloser implements SessionFactoryObserver {
|
||||||
/**
|
/**
|
||||||
* Singleton access
|
* Singleton access
|
||||||
*/
|
*/
|
||||||
|
@ -937,22 +937,22 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
return "[PersistenceUnit: " + persistenceUnit.getName() + "] ";
|
return "[PersistenceUnit: " + persistenceUnit.getName() + "] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MergedSettings {
|
private static class MergedSettings {
|
||||||
private final Map configurationValues = new ConcurrentHashMap( 16, 0.75f, 1 );
|
private final Map configurationValues = new ConcurrentHashMap( 16, 0.75f, 1 );
|
||||||
|
|
||||||
private Map<String, JaccPermissionDeclarations> jaccPermissionsByContextId;
|
private Map<String, JaccPermissionDeclarations> jaccPermissionsByContextId;
|
||||||
private List<CacheRegionDefinition> cacheRegionDefinitions;
|
private List<CacheRegionDefinition> cacheRegionDefinitions;
|
||||||
|
|
||||||
public MergedSettings() {
|
private MergedSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getConfigurationValues() {
|
public Map getConfigurationValues() {
|
||||||
return configurationValues;
|
return configurationValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JaccPermissionDeclarations getJaccPermissions(String jaccContextId) {
|
private JaccPermissionDeclarations getJaccPermissions(String jaccContextId) {
|
||||||
if ( jaccPermissionsByContextId == null ) {
|
if ( jaccPermissionsByContextId == null ) {
|
||||||
jaccPermissionsByContextId = new HashMap<String, JaccPermissionDeclarations>();
|
jaccPermissionsByContextId = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
JaccPermissionDeclarations jaccPermissions = jaccPermissionsByContextId.get( jaccContextId );
|
JaccPermissionDeclarations jaccPermissions = jaccPermissionsByContextId.get( jaccContextId );
|
||||||
|
@ -963,9 +963,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
return jaccPermissions;
|
return jaccPermissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition) {
|
private void addCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition) {
|
||||||
if ( this.cacheRegionDefinitions == null ) {
|
if ( this.cacheRegionDefinitions == null ) {
|
||||||
this.cacheRegionDefinitions = new ArrayList<CacheRegionDefinition>();
|
this.cacheRegionDefinitions = new ArrayList<>();
|
||||||
}
|
}
|
||||||
this.cacheRegionDefinitions.add( cacheRegionDefinition );
|
this.cacheRegionDefinitions.add( cacheRegionDefinition );
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,10 +49,8 @@ import org.hibernate.procedure.ProcedureOutputs;
|
||||||
import org.hibernate.procedure.spi.ParameterRegistrationImplementor;
|
import org.hibernate.procedure.spi.ParameterRegistrationImplementor;
|
||||||
import org.hibernate.procedure.spi.ParameterStrategy;
|
import org.hibernate.procedure.spi.ParameterStrategy;
|
||||||
import org.hibernate.procedure.spi.ProcedureCallImplementor;
|
import org.hibernate.procedure.spi.ProcedureCallImplementor;
|
||||||
import org.hibernate.query.ParameterMetadata;
|
|
||||||
import org.hibernate.query.QueryParameter;
|
import org.hibernate.query.QueryParameter;
|
||||||
import org.hibernate.query.internal.AbstractProducedQuery;
|
import org.hibernate.query.internal.AbstractProducedQuery;
|
||||||
import org.hibernate.query.spi.QueryParameterBindings;
|
|
||||||
import org.hibernate.result.NoMoreReturnsException;
|
import org.hibernate.result.NoMoreReturnsException;
|
||||||
import org.hibernate.result.Output;
|
import org.hibernate.result.Output;
|
||||||
import org.hibernate.result.ResultSetOutput;
|
import org.hibernate.result.ResultSetOutput;
|
||||||
|
@ -785,18 +783,12 @@ public class ProcedureCallImpl<R>
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T unwrap(Class<T> cls) {
|
public <T> T unwrap(Class<T> cls) {
|
||||||
if ( ProcedureCall.class.isAssignableFrom( cls ) ) {
|
if ( cls.isInstance( this ) ) {
|
||||||
return (T) this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
else if ( ProcedureOutputs.class.isAssignableFrom( cls ) ) {
|
else if ( cls.isInstance( outputs ) ) {
|
||||||
return (T) outputs();
|
return (T) outputs();
|
||||||
}
|
}
|
||||||
else if ( ParameterMetadata.class.isAssignableFrom( cls ) ) {
|
|
||||||
return (T) getParameterMetadata();
|
|
||||||
}
|
|
||||||
else if ( QueryParameterBindings.class.isAssignableFrom( cls ) ) {
|
|
||||||
return (T) getQueryParameterBindings();
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.unwrap( cls );
|
return super.unwrap( cls );
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.hibernate.FlushMode;
|
||||||
import org.hibernate.Incubating;
|
import org.hibernate.Incubating;
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.LockOptions;
|
import org.hibernate.LockOptions;
|
||||||
|
import org.hibernate.engine.spi.RowSelection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an HQL/JPQL query or a compiled Criteria query. Also acts as the Hibernate
|
* Represents an HQL/JPQL query or a compiled Criteria query. Also acts as the Hibernate
|
||||||
|
@ -40,6 +41,15 @@ public interface Query<R> extends TypedQuery<R>, org.hibernate.Query<R>, BasicQu
|
||||||
*/
|
*/
|
||||||
QueryProducer getProducer();
|
QueryProducer getProducer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "QueryOptions" is a better name, I think, than "RowSelection" -> 6.0
|
||||||
|
*
|
||||||
|
* @return Return the encapsulation of this query's options, which includes access to
|
||||||
|
* firstRow, maxRows, timeout and fetchSize. Important because this gives access to
|
||||||
|
* those values in their Integer form rather than the primitive form (int) required by JPA.
|
||||||
|
*/
|
||||||
|
RowSelection getQueryOptions();
|
||||||
|
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// covariant overrides
|
// covariant overrides
|
||||||
|
|
|
@ -90,21 +90,18 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
||||||
|
|
||||||
private FlushMode flushMode;
|
private FlushMode flushMode;
|
||||||
private CacheMode cacheMode;
|
private CacheMode cacheMode;
|
||||||
private Integer timeout;
|
|
||||||
private boolean cacheable;
|
private boolean cacheable;
|
||||||
private String cacheRegion;
|
private String cacheRegion;
|
||||||
private Boolean readOnly;
|
private Boolean readOnly;
|
||||||
|
|
||||||
private LockOptions lockOptions = new LockOptions();
|
private LockOptions lockOptions = new LockOptions();
|
||||||
|
|
||||||
private Integer fetchSize;
|
|
||||||
|
|
||||||
private String comment;
|
private String comment;
|
||||||
private final List<String> dbHints = new ArrayList<>();
|
private final List<String> dbHints = new ArrayList<>();
|
||||||
private Map<String, Object> hints;
|
private Map<String, Object> hints;
|
||||||
|
|
||||||
private ResultTransformer resultTransformer;
|
private ResultTransformer resultTransformer;
|
||||||
private RowSelection selection = new RowSelection();
|
private RowSelection queryOptions = new RowSelection();
|
||||||
private HQLQueryPlan entityGraphHintedQueryPlan;
|
private HQLQueryPlan entityGraphHintedQueryPlan;
|
||||||
|
|
||||||
private Object optionalObject;
|
private Object optionalObject;
|
||||||
|
@ -194,25 +191,25 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getTimeout() {
|
public Integer getTimeout() {
|
||||||
return timeout;
|
return queryOptions.getTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public QueryImplementor setTimeout(int timeout) {
|
public QueryImplementor setTimeout(int timeout) {
|
||||||
this.timeout = timeout;
|
queryOptions.setTimeout( timeout );
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getFetchSize() {
|
public Integer getFetchSize() {
|
||||||
return fetchSize;
|
return queryOptions.getFetchSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public QueryImplementor setFetchSize(int fetchSize) {
|
public QueryImplementor setFetchSize(int fetchSize) {
|
||||||
this.fetchSize = fetchSize;
|
queryOptions.setFetchSize( fetchSize );
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,9 +307,21 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
||||||
else if ( value instanceof Collection ) {
|
else if ( value instanceof Collection ) {
|
||||||
setParameterList( (QueryParameter) parameter, (Collection) value );
|
setParameterList( (QueryParameter) parameter, (Collection) value );
|
||||||
}
|
}
|
||||||
else {
|
else if ( parameter instanceof QueryParameter ) {
|
||||||
queryParameterBindings.getBinding( (QueryParameter) parameter ).setBindValue( value );
|
queryParameterBindings.getBinding( (QueryParameter) parameter ).setBindValue( value );
|
||||||
}
|
}
|
||||||
|
else if ( parameter.getName() != null ) {
|
||||||
|
queryParameterBindings.getBinding( parameter.getName() ).setBindValue( value );
|
||||||
|
}
|
||||||
|
else if ( parameter.getPosition() != null ) {
|
||||||
|
queryParameterBindings.getBinding( parameter.getPosition() ).setBindValue( value );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw getExceptionConverter().convert(
|
||||||
|
new IllegalArgumentException( "Could not resolve parameter instance [" + parameter + "] as query parameter" )
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,9 +612,16 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RowSelection getQueryOptions() {
|
||||||
|
return queryOptions;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxResults() {
|
public int getMaxResults() {
|
||||||
return selection.getMaxRows();
|
// to be JPA compliant this method returns an int - specifically the "magic number" Integer.MAX_VALUE defined by the spec.
|
||||||
|
// For access to the Integer (for checking), use #getQueryOptions#getMaxRows instead
|
||||||
|
return queryOptions.getMaxRows() == null ? Integer.MAX_VALUE : queryOptions.getMaxRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -613,23 +629,25 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
||||||
public QueryImplementor setMaxResults(int maxResult) {
|
public QueryImplementor setMaxResults(int maxResult) {
|
||||||
if ( maxResult <= 0 ) {
|
if ( maxResult <= 0 ) {
|
||||||
// treat zero and negatives specially as meaning no limit...
|
// treat zero and negatives specially as meaning no limit...
|
||||||
selection.setMaxRows( null );
|
queryOptions.unsetMaxRows();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
selection.setMaxRows( maxResult );
|
queryOptions.setMaxRows( maxResult );
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFirstResult() {
|
public int getFirstResult() {
|
||||||
return selection.getFirstRow();
|
// to be JPA compliant this method returns an int - specifically the "magic number" 0 (ZERO) defined by the spec.
|
||||||
|
// For access to the Integer (for checking), use #getQueryOptions#getFirstRow instead
|
||||||
|
return queryOptions.getFirstRow() == null ? 0 : queryOptions.getFirstRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public QueryImplementor setFirstResult(int startPosition) {
|
public QueryImplementor setFirstResult(int startPosition) {
|
||||||
selection.setFirstRow( startPosition );
|
queryOptions.setFirstRow( startPosition );
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -964,7 +982,8 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
||||||
return (T) this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException( "Could not unwrap this [" + toString() + "] as requested Java type [" + cls.getName() + "]" );
|
throw new HibernateException( "Could not unwrap this [" + toString() + "] as requested Java type [" + cls.getName() + "]" );
|
||||||
|
// throw new IllegalArgumentException( "Could not unwrap this [" + toString() + "] as requested Java type [" + cls.getName() + "]" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryParameters getQueryParameters() {
|
public QueryParameters getQueryParameters() {
|
||||||
|
@ -973,7 +992,7 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
||||||
getPositionalParameterValues(),
|
getPositionalParameterValues(),
|
||||||
getNamedParameterMap(),
|
getNamedParameterMap(),
|
||||||
getLockOptions(),
|
getLockOptions(),
|
||||||
selection,
|
queryOptions,
|
||||||
true,
|
true,
|
||||||
isReadOnly(),
|
isReadOnly(),
|
||||||
cacheable,
|
cacheable,
|
||||||
|
|
|
@ -16,7 +16,6 @@ import org.hibernate.FlushMode;
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.engine.spi.NamedQueryDefinition;
|
import org.hibernate.engine.spi.NamedQueryDefinition;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.jpa.HibernateQuery;
|
|
||||||
import org.hibernate.jpa.QueryHints;
|
import org.hibernate.jpa.QueryHints;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.jpa.test.Distributor;
|
import org.hibernate.jpa.test.Distributor;
|
||||||
|
@ -116,24 +115,29 @@ public class AddNamedQueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
Query query = em.createNamedQuery( name );
|
Query query = em.createNamedQuery( name );
|
||||||
org.hibernate.Query hibernateQuery = ( (HibernateQuery) query ).getHibernateQuery();
|
org.hibernate.query.Query hibernateQuery = (org.hibernate.query.Query) query;
|
||||||
// assert the state of the query config settings based on the initial named query
|
// assert the state of the query config settings based on the initial named query
|
||||||
assertNull( hibernateQuery.getFirstResult() );
|
//
|
||||||
assertNull( hibernateQuery.getMaxResults() );
|
// NOTE: here we check "query options" via the Hibernate contract (allowing nullness checking); see below for access via the JPA contract
|
||||||
assertEquals( FlushMode.AUTO, hibernateQuery.getFlushMode() );
|
assertNull( hibernateQuery.getQueryOptions().getFirstRow() );
|
||||||
|
assertNull( hibernateQuery.getQueryOptions().getMaxRows() );
|
||||||
|
assertEquals( FlushMode.AUTO, hibernateQuery.getHibernateFlushMode() );
|
||||||
assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() );
|
assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() );
|
||||||
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
|
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
|
||||||
assertEquals( (Integer) 3, hibernateQuery.getTimeout() ); // jpa timeout is in milliseconds, whereas Hibernate's is in seconds
|
// jpa timeout is in milliseconds, whereas Hibernate's is in seconds
|
||||||
|
assertEquals( (Integer) 3, hibernateQuery.getTimeout() );
|
||||||
|
|
||||||
query.setHint( QueryHints.HINT_TIMEOUT, 10 );
|
query.setHint( QueryHints.HINT_TIMEOUT, 10 );
|
||||||
em.getEntityManagerFactory().addNamedQuery( name, query );
|
em.getEntityManagerFactory().addNamedQuery( name, query );
|
||||||
|
|
||||||
query = em.createNamedQuery( name );
|
query = em.createNamedQuery( name );
|
||||||
hibernateQuery = ( (HibernateQuery) query ).getHibernateQuery();
|
hibernateQuery = (org.hibernate.query.Query) query;
|
||||||
// assert the state of the query config settings based on the initial named query
|
// assert the state of the query config settings based on the initial named query
|
||||||
assertNull( hibernateQuery.getFirstResult() );
|
//
|
||||||
assertNull( hibernateQuery.getMaxResults() );
|
// NOTE: here we check "query options" via the JPA contract
|
||||||
assertEquals( FlushMode.AUTO, hibernateQuery.getFlushMode() );
|
assertEquals( 0, hibernateQuery.getFirstResult() );
|
||||||
|
assertEquals( Integer.MAX_VALUE, hibernateQuery.getMaxResults() );
|
||||||
|
assertEquals( FlushModeType.AUTO, hibernateQuery.getFlushMode() );
|
||||||
assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() );
|
assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() );
|
||||||
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
|
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
|
||||||
assertEquals( (Integer) 10, hibernateQuery.getTimeout() );
|
assertEquals( (Integer) 10, hibernateQuery.getTimeout() );
|
||||||
|
@ -142,11 +146,11 @@ public class AddNamedQueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.getEntityManagerFactory().addNamedQuery( name, query );
|
em.getEntityManagerFactory().addNamedQuery( name, query );
|
||||||
|
|
||||||
query = em.createNamedQuery( name );
|
query = em.createNamedQuery( name );
|
||||||
hibernateQuery = ( (HibernateQuery) query ).getHibernateQuery();
|
hibernateQuery = (org.hibernate.query.Query) query;
|
||||||
// assert the state of the query config settings based on the initial named query
|
// assert the state of the query config settings based on the initial named query
|
||||||
assertNull( hibernateQuery.getFirstResult() );
|
assertEquals( 0, hibernateQuery.getFirstResult() );
|
||||||
assertNull( hibernateQuery.getMaxResults() );
|
assertEquals( Integer.MAX_VALUE, hibernateQuery.getMaxResults() );
|
||||||
assertEquals( FlushMode.AUTO, hibernateQuery.getFlushMode() );
|
assertEquals( FlushModeType.AUTO, hibernateQuery.getFlushMode() );
|
||||||
assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() );
|
assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() );
|
||||||
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
|
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
|
||||||
assertEquals( (Integer) 10, hibernateQuery.getTimeout() );
|
assertEquals( (Integer) 10, hibernateQuery.getTimeout() );
|
||||||
|
@ -155,11 +159,11 @@ public class AddNamedQueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.getEntityManagerFactory().addNamedQuery( name, query );
|
em.getEntityManagerFactory().addNamedQuery( name, query );
|
||||||
|
|
||||||
query = em.createNamedQuery( name );
|
query = em.createNamedQuery( name );
|
||||||
hibernateQuery = ( (HibernateQuery) query ).getHibernateQuery();
|
hibernateQuery = (org.hibernate.query.Query) query;
|
||||||
// assert the state of the query config settings based on the initial named query
|
// assert the state of the query config settings based on the initial named query
|
||||||
assertEquals( 51, hibernateQuery.getFirstResult() );
|
assertEquals( 51, hibernateQuery.getFirstResult() );
|
||||||
assertNull( hibernateQuery.getMaxResults() );
|
assertEquals( Integer.MAX_VALUE, hibernateQuery.getMaxResults() );
|
||||||
assertEquals( FlushMode.AUTO, hibernateQuery.getFlushMode() );
|
assertEquals( FlushModeType.AUTO, hibernateQuery.getFlushMode() );
|
||||||
assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() );
|
assertEquals( CacheMode.IGNORE, hibernateQuery.getCacheMode() );
|
||||||
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
|
assertEquals( LockMode.PESSIMISTIC_WRITE, hibernateQuery.getLockOptions().getLockMode() );
|
||||||
assertEquals( (Integer) 10, hibernateQuery.getTimeout() );
|
assertEquals( (Integer) 10, hibernateQuery.getTimeout() );
|
||||||
|
|
|
@ -26,6 +26,11 @@ The hibernate-entitymanager module has also been merged into hibernate-core.
|
||||||
* `org.hibernate.Session` now extends `javax.persistence.EntityManager` - temporarily it
|
* `org.hibernate.Session` now extends `javax.persistence.EntityManager` - temporarily it
|
||||||
technically extends `org.hibernate.jpa.HibernateEntityManager` (which in turn extends
|
technically extends `org.hibernate.jpa.HibernateEntityManager` (which in turn extends
|
||||||
`javax.persistence.EntityManager`) for backwards compatibility. `HibernateEntityManager` is deprecated.
|
`javax.persistence.EntityManager`) for backwards compatibility. `HibernateEntityManager` is deprecated.
|
||||||
|
* `org.hibernate.Query` (deprecated in favor of new `org.hibernate.query.Query`) now extends the JPA contracts
|
||||||
|
`javax.persistence.Query` and `javax.persistence.TypedQuery`. `ProcedureCall` and `StoredProcedureQuery` as well.
|
||||||
|
* `org.hibernate.HibernateException` now extends `javax.persistence.PersistenceExceptions`. Hibernate methods
|
||||||
|
that "override" methods from their JPA counterparts now will also throw various JDK defined RuntimeExceptions
|
||||||
|
(such as `IllegalArgumentException`, `IllegalStateException`, etc) as required by the JPA contract.
|
||||||
* Persister/type access is now exposed through `org.hibernate.Metamodel`, which extends
|
* Persister/type access is now exposed through `org.hibernate.Metamodel`, which extends
|
||||||
`javax.persistence.metamodel.Metamodel`. MetamodelImpl now manages all aspects of type system (see below).
|
`javax.persistence.metamodel.Metamodel`. MetamodelImpl now manages all aspects of type system (see below).
|
||||||
* Cache management has also been consolidated. `org.hibernate.Cache` now extends `javax.persistence.Cache`. CacheImpl
|
* Cache management has also been consolidated. `org.hibernate.Cache` now extends `javax.persistence.Cache`. CacheImpl
|
||||||
|
|
Loading…
Reference in New Issue