Move tests to orm/test and fix query cache stats, native query variable substitution and named query support as loader
This commit is contained in:
parent
3e32e15c0a
commit
5b0b822717
|
@ -50,20 +50,13 @@ ext {
|
|||
'jdbc.url' : 'jdbc:postgresql://127.0.0.1/hibernate_orm_test?preparedStatementCacheQueries=0'
|
||||
],
|
||||
pgsql_ci : [
|
||||
'db.dialect' : 'org.hibernate.dialect.PostgreSQL95Dialect',
|
||||
'db.dialect' : 'org.hibernate.dialect.PostgreSQLDialect',
|
||||
'jdbc.driver': 'org.postgresql.Driver',
|
||||
'jdbc.user' : 'hibernate_orm_test',
|
||||
'jdbc.pass' : 'hibernate_orm_test',
|
||||
// Disable prepared statement caching due to https://www.postgresql.org/message-id/CAEcMXhmmRd4-%2BNQbnjDT26XNdUoXdmntV9zdr8%3DTu8PL9aVCYg%40mail.gmail.com
|
||||
'jdbc.url' : 'jdbc:postgresql://' + dbHost + '/hibernate_orm_test?preparedStatementCacheQueries=0'
|
||||
],
|
||||
pgsql_ci : [
|
||||
'db.dialect' : 'org.hibernate.dialect.PostgreSQLDialect',
|
||||
'jdbc.driver': 'org.postgresql.Driver',
|
||||
'jdbc.user' : 'hibernate_orm_test',
|
||||
'jdbc.pass' : 'hibernate_orm_test',
|
||||
'jdbc.url' : 'jdbc:postgresql://' + dbHost + '/hibernate_orm_test'
|
||||
],
|
||||
mysql : [
|
||||
'db.dialect' : 'org.hibernate.dialect.MySQLDialect',
|
||||
'jdbc.driver': 'com.mysql.jdbc.Driver',
|
||||
|
|
|
@ -136,6 +136,13 @@ public interface Metadata extends Mapping {
|
|||
*/
|
||||
void visitNamedNativeQueryDefinitions(Consumer<NamedNativeQueryDefinition> definitionConsumer);
|
||||
|
||||
/**
|
||||
* Retrieve named procedure metadata.
|
||||
*
|
||||
* @return The named procedure metadata, or {@code null}
|
||||
*/
|
||||
NamedProcedureCallDefinition getNamedProcedureCallMapping(String name);
|
||||
|
||||
/**
|
||||
* Visit all named callable query definitions
|
||||
*/
|
||||
|
|
|
@ -634,6 +634,11 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
|
|||
// Named stored-procedure handling
|
||||
|
||||
|
||||
@Override
|
||||
public NamedProcedureCallDefinition getNamedProcedureCallMapping(String name) {
|
||||
return namedProcedureCallMap.get( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNamedProcedureCallDefinition(Consumer<NamedProcedureCallDefinition> definitionConsumer) {
|
||||
namedProcedureCallMap.values().forEach( definitionConsumer );
|
||||
|
|
|
@ -251,6 +251,11 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
namedNativeQueryMap.values().forEach( definitionConsumer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamedProcedureCallDefinition getNamedProcedureCallMapping(String name) {
|
||||
return namedProcedureCallMap.get( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNamedProcedureCallDefinition(Consumer<NamedProcedureCallDefinition> definitionConsumer) {
|
||||
namedProcedureCallMap.values().forEach( definitionConsumer );
|
||||
|
|
|
@ -139,6 +139,11 @@ public abstract class AbstractDelegatingMetadata implements MetadataImplementor
|
|||
delegate.visitNamedNativeQueryDefinitions( definitionConsumer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamedProcedureCallDefinition getNamedProcedureCallMapping(String name) {
|
||||
return delegate.getNamedProcedureCallMapping( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNamedProcedureCallDefinition(Consumer<NamedProcedureCallDefinition> definitionConsumer) {
|
||||
delegate.visitNamedProcedureCallDefinition( definitionConsumer );
|
||||
|
|
|
@ -795,7 +795,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
|||
|
||||
if ( namedHqlDescriptor != null ) {
|
||||
HqlQueryImplementor query = namedHqlDescriptor.toQuery( this, resultType );
|
||||
query.setComment( "dynamic native SQL query" );
|
||||
query.setComment( "dynamic HQL query" );
|
||||
applyQuerySettingsAndHints( query );
|
||||
return query;
|
||||
}
|
||||
|
|
|
@ -111,6 +111,7 @@ import org.hibernate.persister.entity.Loadable;
|
|||
import org.hibernate.procedure.spi.ProcedureCallImplementor;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.proxy.HibernateProxyHelper;
|
||||
import org.hibernate.query.QueryLogging;
|
||||
import org.hibernate.query.hql.spi.HqlQueryImplementor;
|
||||
import org.hibernate.query.spi.QueryEngine;
|
||||
import org.hibernate.query.spi.QueryImplementor;
|
||||
|
@ -312,7 +313,18 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
this.queryEngine.prepare( this, bootMetamodel, bootstrapContext );
|
||||
|
||||
if ( options.isNamedQueryStartupCheckingEnabled() ) {
|
||||
queryEngine.getNamedObjectRepository().checkNamedQueries( queryEngine );
|
||||
final Map<String, HibernateException> errors = queryEngine.getNamedObjectRepository().checkNamedQueries( queryEngine );
|
||||
|
||||
if ( !errors.isEmpty() ) {
|
||||
StringBuilder failingQueries = new StringBuilder( "Errors in named queries: " );
|
||||
String sep = "";
|
||||
for ( Map.Entry<String, HibernateException> entry : errors.entrySet() ) {
|
||||
QueryLogging.QUERY_MESSAGE_LOGGER.namedQueryError( entry.getKey(), entry.getValue() );
|
||||
failingQueries.append( sep ).append( entry.getKey() );
|
||||
sep = ", ";
|
||||
}
|
||||
throw new HibernateException( failingQueries.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
SchemaManagementToolCoordinator.process(
|
||||
|
@ -814,7 +826,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
cacheAccess.close();
|
||||
}
|
||||
|
||||
if ( runtimeMetamodels != null ) {
|
||||
if ( runtimeMetamodels != null && runtimeMetamodels.getMappingMetamodel() != null ) {
|
||||
final JdbcConnectionAccess jdbcConnectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess();
|
||||
runtimeMetamodels.getMappingMetamodel().visitEntityDescriptors(
|
||||
entityPersister -> {
|
||||
|
|
|
@ -7,15 +7,12 @@
|
|||
package org.hibernate.loader.ast.internal;
|
||||
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.loader.ast.spi.SingleIdEntityLoader;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.query.named.NamedQueryMemento;
|
||||
import org.hibernate.query.named.NamedObjectRepository;
|
||||
import org.hibernate.query.spi.QueryImplementor;
|
||||
import org.hibernate.query.sql.spi.NamedNativeQueryMemento;
|
||||
|
||||
/**
|
||||
* Implementation of SingleIdEntityLoader for cases where the application has
|
||||
|
@ -29,27 +26,9 @@ public class SingleIdEntityLoaderProvidedQueryImpl<T> implements SingleIdEntityL
|
|||
|
||||
public SingleIdEntityLoaderProvidedQueryImpl(
|
||||
EntityMappingType entityDescriptor,
|
||||
String loadQueryName,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
NamedQueryMemento namedQueryMemento) {
|
||||
this.entityDescriptor = entityDescriptor;
|
||||
|
||||
this.namedQueryMemento = resolveNamedQuery( loadQueryName, sessionFactory );
|
||||
if ( namedQueryMemento == null ) {
|
||||
throw new IllegalArgumentException( "Could not resolve named load-query [" + entityDescriptor.getEntityName() + "] : " + loadQueryName );
|
||||
}
|
||||
}
|
||||
|
||||
private static NamedQueryMemento resolveNamedQuery(
|
||||
String queryName,
|
||||
SessionFactoryImplementor sf) {
|
||||
final NamedObjectRepository namedObjectRepository = sf.getQueryEngine().getNamedObjectRepository();
|
||||
|
||||
final NamedNativeQueryMemento nativeQueryMemento = namedObjectRepository.getNativeQueryMemento( queryName );
|
||||
if ( nativeQueryMemento != null ) {
|
||||
return nativeQueryMemento;
|
||||
}
|
||||
|
||||
return namedObjectRepository.getHqlQueryMemento( queryName );
|
||||
this.namedQueryMemento = namedQueryMemento;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,7 +44,7 @@ public class SingleIdEntityLoaderProvidedQueryImpl<T> implements SingleIdEntityL
|
|||
entityDescriptor.getMappedJavaTypeDescriptor().getJavaTypeClass()
|
||||
);
|
||||
|
||||
query.setParameter( 0, pkValue );
|
||||
query.setParameter( 1, pkValue );
|
||||
|
||||
return query.uniqueResult();
|
||||
}
|
||||
|
|
|
@ -135,6 +135,7 @@ import org.hibernate.mapping.BasicValue;
|
|||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.mapping.Component;
|
||||
import org.hibernate.mapping.DependantValue;
|
||||
import org.hibernate.mapping.Formula;
|
||||
import org.hibernate.mapping.IndexedConsumer;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
|
@ -188,6 +189,8 @@ import org.hibernate.property.access.spi.PropertyAccess;
|
|||
import org.hibernate.property.access.spi.Setter;
|
||||
import org.hibernate.query.ComparisonOperator;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.query.named.NamedQueryMemento;
|
||||
import org.hibernate.query.sql.internal.SQLQueryParser;
|
||||
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
|
||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||
import org.hibernate.sql.Alias;
|
||||
|
@ -748,10 +751,15 @@ public abstract class AbstractEntityPersister
|
|||
rowIdName = bootDescriptor.getRootTable().getRowId();
|
||||
|
||||
if ( bootDescriptor.getLoaderName() != null ) {
|
||||
// We must resolve the named query on-demand through the boot model because it isn't initialized yet
|
||||
final NamedQueryMemento namedQueryMemento = factory.getQueryEngine().getNamedObjectRepository()
|
||||
.resolve( factory, creationContext.getBootModel(), bootDescriptor.getLoaderName() );
|
||||
if ( namedQueryMemento == null ) {
|
||||
throw new IllegalArgumentException( "Could not resolve named load-query [" + getEntityName() + "] : " + bootDescriptor.getLoaderName() );
|
||||
}
|
||||
singleIdEntityLoader = new SingleIdEntityLoaderProvidedQueryImpl(
|
||||
this,
|
||||
bootDescriptor.getLoaderName(),
|
||||
factory
|
||||
namedQueryMemento
|
||||
);
|
||||
}
|
||||
else if ( batchSize > 1 ) {
|
||||
|
@ -849,8 +857,7 @@ public abstract class AbstractEntityPersister
|
|||
colAliases[k] = thing.getAlias( dialect, prop.getValue().getTable() );
|
||||
if ( thing.isFormula() ) {
|
||||
foundFormula = true;
|
||||
// ( (Formula) thing ).setFormula( substituteBrackets( ( (Formula) thing ).getFormula() ) );
|
||||
// TODO: uncomment the above statement when this#substituteBrackets(String) is implemented
|
||||
( (Formula) thing ).setFormula( substituteBrackets( ( (Formula) thing ).getFormula() ) );
|
||||
formulaTemplates[k] = thing.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
|
||||
}
|
||||
else {
|
||||
|
@ -4562,7 +4569,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
|
||||
private String substituteBrackets(String sql) {
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
return new SQLQueryParser( sql, null, getFactory() ).process();
|
||||
}
|
||||
|
||||
public final void postInstantiate() throws MappingException {
|
||||
|
|
|
@ -11,6 +11,9 @@ import java.util.Map;
|
|||
import java.util.function.Consumer;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.boot.query.NamedHqlQueryDefinition;
|
||||
import org.hibernate.boot.query.NamedNativeQueryDefinition;
|
||||
import org.hibernate.boot.query.NamedProcedureCallDefinition;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -18,6 +21,7 @@ import org.hibernate.procedure.spi.NamedCallableQueryMemento;
|
|||
import org.hibernate.query.hql.HqlTranslator;
|
||||
import org.hibernate.query.hql.spi.NamedHqlQueryMemento;
|
||||
import org.hibernate.query.named.NamedObjectRepository;
|
||||
import org.hibernate.query.named.NamedQueryMemento;
|
||||
import org.hibernate.query.named.NamedResultSetMappingMemento;
|
||||
import org.hibernate.query.spi.QueryEngine;
|
||||
import org.hibernate.query.spi.QueryInterpretationCache;
|
||||
|
@ -127,6 +131,44 @@ public class NamedObjectRepositoryImpl implements NamedObjectRepository {
|
|||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Prepare repository for use
|
||||
|
||||
@Override
|
||||
public NamedQueryMemento resolve(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
MetadataImplementor bootMetamodel,
|
||||
String registrationName) {
|
||||
NamedQueryMemento namedQuery = hqlMementoMap.get( registrationName );
|
||||
if ( namedQuery != null ) {
|
||||
return namedQuery;
|
||||
}
|
||||
namedQuery = sqlMementoMap.get( registrationName );
|
||||
if ( namedQuery != null ) {
|
||||
return namedQuery;
|
||||
}
|
||||
namedQuery = callableMementoMap.get( registrationName );
|
||||
if ( namedQuery != null ) {
|
||||
return namedQuery;
|
||||
}
|
||||
final NamedHqlQueryDefinition namedHqlQueryDefinition = bootMetamodel.getNamedHqlQueryMapping( registrationName );
|
||||
if ( namedHqlQueryDefinition != null ) {
|
||||
final NamedHqlQueryMemento resolved = namedHqlQueryDefinition.resolve( sessionFactory );
|
||||
hqlMementoMap.put( namedHqlQueryDefinition.getRegistrationName(), resolved );
|
||||
return resolved;
|
||||
}
|
||||
final NamedNativeQueryDefinition namedNativeQueryDefinition = bootMetamodel.getNamedNativeQueryMapping( registrationName );
|
||||
if ( namedNativeQueryDefinition != null ) {
|
||||
final NamedNativeQueryMemento resolved = namedNativeQueryDefinition.resolve( sessionFactory );
|
||||
sqlMementoMap.put( namedNativeQueryDefinition.getRegistrationName(), resolved );
|
||||
return resolved;
|
||||
}
|
||||
final NamedProcedureCallDefinition namedCallableQueryDefinition = bootMetamodel.getNamedProcedureCallMapping( registrationName );
|
||||
if ( namedCallableQueryDefinition != null ) {
|
||||
final NamedCallableQueryMemento resolved = namedCallableQueryDefinition.resolve( sessionFactory );
|
||||
callableMementoMap.put( namedCallableQueryDefinition.getRegistrationName(), resolved );
|
||||
return resolved;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
|
@ -184,10 +226,11 @@ public class NamedObjectRepositoryImpl implements NamedObjectRepository {
|
|||
for ( NamedHqlQueryMemento hqlMemento : hqlMementoMap.values() ) {
|
||||
try {
|
||||
log.debugf( "Checking named HQL query: %s", hqlMemento.getRegistrationName() );
|
||||
hqlMemento.validate( queryEngine );
|
||||
|
||||
// todo (6.0) : need to cache these; however atm that requires producing a SqmQueryImpl
|
||||
// queryEngine.getQueryInterpretationCache().getHQLQueryPlan( hqlMemento.getQueryString(), false, Collections.EMPTY_MAP );
|
||||
String queryString = hqlMemento.getHqlString();
|
||||
interpretationCache.resolveHqlInterpretation(
|
||||
queryString,
|
||||
s -> queryEngine.getHqlTranslator().translate( queryString )
|
||||
);
|
||||
}
|
||||
catch ( HibernateException e ) {
|
||||
errors.put( hqlMemento.getRegistrationName(), e );
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.query.internal;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -17,15 +18,18 @@ import org.hibernate.query.spi.SelectQueryPlan;
|
|||
import org.hibernate.query.sql.spi.ParameterInterpretation;
|
||||
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
||||
import org.hibernate.query.sqm.tree.SqmStatement;
|
||||
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class QueryInterpretationCacheDisabledImpl implements QueryInterpretationCache {
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
public static final QueryInterpretationCacheDisabledImpl INSTANCE = new QueryInterpretationCacheDisabledImpl();
|
||||
|
||||
private final Supplier<StatisticsImplementor> statisticsSupplier;
|
||||
|
||||
public QueryInterpretationCacheDisabledImpl(Supplier<StatisticsImplementor> statisticsSupplier) {
|
||||
this.statisticsSupplier = statisticsSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfCachedHqlInterpretations() {
|
||||
|
@ -53,6 +57,9 @@ public class QueryInterpretationCacheDisabledImpl implements QueryInterpretation
|
|||
|
||||
@Override
|
||||
public HqlInterpretation resolveHqlInterpretation(String queryString, Function<String, SqmStatement<?>> creator) {
|
||||
StatisticsImplementor statistics = statisticsSupplier.get();
|
||||
final boolean stats = statistics.isStatisticsEnabled();
|
||||
final long startTime = ( stats ) ? System.nanoTime() : 0L;
|
||||
final SqmStatement<?> sqmStatement = creator.apply( queryString );
|
||||
|
||||
final DomainParameterXref domainParameterXref;
|
||||
|
@ -66,6 +73,12 @@ public class QueryInterpretationCacheDisabledImpl implements QueryInterpretation
|
|||
parameterMetadata = new ParameterMetadataImpl( domainParameterXref.getQueryParameters() );
|
||||
}
|
||||
|
||||
if ( stats ) {
|
||||
final long endTime = System.nanoTime();
|
||||
final long microseconds = TimeUnit.MICROSECONDS.convert( endTime - startTime, TimeUnit.NANOSECONDS );
|
||||
statistics.queryCompiled( queryString, microseconds );
|
||||
}
|
||||
|
||||
return new HqlInterpretation() {
|
||||
@Override
|
||||
public SqmStatement getSqmStatement() {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.query.internal;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -21,6 +22,7 @@ import org.hibernate.query.spi.SimpleHqlInterpretationImpl;
|
|||
import org.hibernate.query.sql.spi.ParameterInterpretation;
|
||||
import org.hibernate.query.sqm.internal.DomainParameterXref;
|
||||
import org.hibernate.query.sqm.tree.SqmStatement;
|
||||
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
|
@ -52,13 +54,15 @@ public class QueryInterpretationCacheStandardImpl implements QueryInterpretation
|
|||
|
||||
private final BoundedConcurrentHashMap<String, HqlInterpretation> hqlInterpretationCache;
|
||||
private final BoundedConcurrentHashMap<String, ParameterInterpretation> nativeQueryParamCache;
|
||||
private final Supplier<StatisticsImplementor> statisticsSupplier;
|
||||
|
||||
public QueryInterpretationCacheStandardImpl(int maxQueryPlanCount) {
|
||||
public QueryInterpretationCacheStandardImpl(int maxQueryPlanCount, Supplier<StatisticsImplementor> statisticsSupplier) {
|
||||
log.debugf( "Starting QueryPlanCache(%s)", maxQueryPlanCount );
|
||||
|
||||
queryPlanCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
||||
hqlInterpretationCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
||||
nativeQueryParamCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
||||
this.queryPlanCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
||||
this.hqlInterpretationCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
||||
this.nativeQueryParamCache = new BoundedConcurrentHashMap<>( maxQueryPlanCount, 20, BoundedConcurrentHashMap.Eviction.LIRS );
|
||||
this.statisticsSupplier = statisticsSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -103,9 +107,14 @@ public class QueryInterpretationCacheStandardImpl implements QueryInterpretation
|
|||
String queryString,
|
||||
Function<String, SqmStatement<?>> creator) {
|
||||
log.tracef( "QueryPlan#resolveHqlInterpretation( `%s` )", queryString );
|
||||
|
||||
final StatisticsImplementor statistics = statisticsSupplier.get();
|
||||
final boolean stats = statistics.isStatisticsEnabled();
|
||||
final long startTime = ( stats ) ? System.nanoTime() : 0L;
|
||||
final HqlInterpretation cached = hqlInterpretationCache.get( queryString );
|
||||
if ( cached != null ) {
|
||||
if ( stats ) {
|
||||
statistics.queryPlanCacheHit( queryString );
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
|
@ -129,6 +138,12 @@ public class QueryInterpretationCacheStandardImpl implements QueryInterpretation
|
|||
parameterMetadata,
|
||||
domainParameterXref);
|
||||
hqlInterpretationCache.put( queryString, interpretation );
|
||||
|
||||
if ( stats ) {
|
||||
final long endTime = System.nanoTime();
|
||||
final long microseconds = TimeUnit.MICROSECONDS.convert( endTime - startTime, TimeUnit.NANOSECONDS );
|
||||
statistics.queryCompiled( queryString, microseconds );
|
||||
}
|
||||
return interpretation;
|
||||
}
|
||||
|
||||
|
@ -155,6 +170,8 @@ public class QueryInterpretationCacheStandardImpl implements QueryInterpretation
|
|||
@Override
|
||||
public void close() {
|
||||
// todo (6.0) : clear maps/caches and LOG
|
||||
hqlInterpretationCache.clear();
|
||||
nativeQueryParamCache.clear();
|
||||
queryPlanCache.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,14 @@ public interface NamedObjectRepository {
|
|||
*/
|
||||
Map<String, HibernateException> checkNamedQueries(QueryEngine queryPlanCache);
|
||||
|
||||
/**
|
||||
* Resolve the named query with the given name.
|
||||
*/
|
||||
NamedQueryMemento resolve(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
MetadataImplementor bootMetamodel,
|
||||
String registrationName);
|
||||
|
||||
/**
|
||||
* Prepare for runtime use
|
||||
*/
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.query.spi;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Incubating;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
|
@ -18,7 +17,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.query.QueryLogging;
|
||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||
import org.hibernate.query.hql.HqlTranslator;
|
||||
import org.hibernate.query.hql.internal.StandardHqlTranslator;
|
||||
|
@ -34,6 +32,7 @@ import org.hibernate.query.sqm.spi.SqmCreationContext;
|
|||
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
|
||||
import org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -75,7 +74,7 @@ public class QueryEngine {
|
|||
hqlTranslator,
|
||||
sqmTranslatorFactory,
|
||||
sessionFactory.getServiceRegistry().getService( NativeQueryInterpreter.class ),
|
||||
buildInterpretationCache( sessionFactory.getProperties() ),
|
||||
buildInterpretationCache( sessionFactory::getStatistics, sessionFactory.getProperties() ),
|
||||
dialect,
|
||||
queryEngineOptions.getCustomSqmFunctionRegistry(),
|
||||
sessionFactory.getServiceRegistry()
|
||||
|
@ -196,6 +195,7 @@ public class QueryEngine {
|
|||
);
|
||||
|
||||
this.interpretationCache = buildInterpretationCache(
|
||||
() -> serviceRegistry.getService( StatisticsImplementor.class ),
|
||||
serviceRegistry.getService( ConfigurationService.class ).getSettings()
|
||||
);
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ public class QueryEngine {
|
|||
return new StandardSqmTranslatorFactory();
|
||||
}
|
||||
|
||||
private static QueryInterpretationCache buildInterpretationCache(Map properties) {
|
||||
private static QueryInterpretationCache buildInterpretationCache(Supplier<StatisticsImplementor> statisticsSupplier, Map properties) {
|
||||
final boolean explicitUseCache = ConfigurationHelper.getBoolean(
|
||||
AvailableSettings.QUERY_PLAN_CACHE_ENABLED,
|
||||
properties,
|
||||
|
@ -293,11 +293,11 @@ public class QueryEngine {
|
|||
? explicitMaxPlanSize
|
||||
: QueryInterpretationCacheStandardImpl.DEFAULT_QUERY_PLAN_MAX_COUNT;
|
||||
|
||||
return new QueryInterpretationCacheStandardImpl( size );
|
||||
return new QueryInterpretationCacheStandardImpl( size, statisticsSupplier );
|
||||
}
|
||||
else {
|
||||
// disabled
|
||||
return QueryInterpretationCacheDisabledImpl.INSTANCE;
|
||||
return new QueryInterpretationCacheDisabledImpl( statisticsSupplier );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,22 +306,6 @@ public class QueryEngine {
|
|||
MetadataImplementor bootMetamodel,
|
||||
BootstrapContext bootstrapContext) {
|
||||
namedObjectRepository.prepare( sessionFactory, bootMetamodel, bootstrapContext );
|
||||
|
||||
//checking for named queries
|
||||
if ( sessionFactory.getSessionFactoryOptions().isNamedQueryStartupCheckingEnabled() ) {
|
||||
final Map<String, HibernateException> errors = namedObjectRepository.checkNamedQueries( this );
|
||||
|
||||
if ( !errors.isEmpty() ) {
|
||||
StringBuilder failingQueries = new StringBuilder( "Errors in named queries: " );
|
||||
String sep = "";
|
||||
for ( Map.Entry<String, HibernateException> entry : errors.entrySet() ) {
|
||||
QueryLogging.QUERY_MESSAGE_LOGGER.namedQueryError( entry.getKey(), entry.getValue() );
|
||||
failingQueries.append( sep ).append( entry.getKey() );
|
||||
sep = ", ";
|
||||
}
|
||||
throw new HibernateException( failingQueries.toString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NamedObjectRepository getNamedObjectRepository() {
|
||||
|
|
|
@ -289,12 +289,13 @@ public class NativeQueryImpl<R>
|
|||
sqlString,
|
||||
s -> {
|
||||
final ParameterRecognizerImpl parameterRecognizer = new ParameterRecognizerImpl( session.getFactory() );
|
||||
final String sql = new SQLQueryParser( sqlString, null, session.getFactory() ).process();
|
||||
|
||||
session.getFactory().getServiceRegistry()
|
||||
.getService( NativeQueryInterpreter.class )
|
||||
.recognizeParameters( sqlString, parameterRecognizer );
|
||||
.recognizeParameters( sql, parameterRecognizer );
|
||||
|
||||
return new ParameterInterpretationImpl( sqlString, parameterRecognizer );
|
||||
return new ParameterInterpretationImpl( sql, parameterRecognizer );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,261 @@
|
|||
/*
|
||||
* 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.query.sql.internal;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.persister.collection.SQLLoadableCollection;
|
||||
import org.hibernate.persister.entity.SQLLoadable;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
* @author Max Andersen
|
||||
* @author Steve Ebersole
|
||||
* @author Paul Benedict
|
||||
*/
|
||||
public class SQLQueryParser {
|
||||
private static final Pattern PREPARED_STATEMENT_PATTERN = Pattern.compile( "^\\{.*?\\}$" );
|
||||
private static final String HIBERNATE_PLACEHOLDER_PREFIX = "h-";
|
||||
private static final String DOMAIN_PLACEHOLDER = "h-domain";
|
||||
private static final String CATALOG_PLACEHOLDER = "h-catalog";
|
||||
private static final String SCHEMA_PLACEHOLDER = "h-schema";
|
||||
|
||||
private final SessionFactoryImplementor factory;
|
||||
private final String originalQueryString;
|
||||
private final ParserContext context;
|
||||
|
||||
private long aliasesFound;
|
||||
|
||||
interface ParserContext {
|
||||
boolean isEntityAlias(String aliasName);
|
||||
SQLLoadable getEntityPersisterByAlias(String alias);
|
||||
String getEntitySuffixByAlias(String alias);
|
||||
boolean isCollectionAlias(String aliasName);
|
||||
SQLLoadableCollection getCollectionPersisterByAlias(String alias);
|
||||
String getCollectionSuffixByAlias(String alias);
|
||||
Map getPropertyResultsMapByAlias(String alias);
|
||||
}
|
||||
|
||||
public SQLQueryParser(String queryString, ParserContext context, SessionFactoryImplementor factory) {
|
||||
this.originalQueryString = queryString;
|
||||
this.context = context;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public boolean queryHasAliases() {
|
||||
return aliasesFound>0;
|
||||
}
|
||||
|
||||
protected String getOriginalQueryString() {
|
||||
return originalQueryString;
|
||||
}
|
||||
|
||||
public String process() {
|
||||
return substituteBrackets( originalQueryString );
|
||||
}
|
||||
|
||||
// TODO: should "record" how many properties we have referred to - and if we
|
||||
// don't get them all we throw an exception! Way better than trial and error ;)
|
||||
protected String substituteBrackets(String sqlQuery) throws QueryException {
|
||||
|
||||
if ( PREPARED_STATEMENT_PATTERN.matcher( sqlQuery.trim() ).matches() ) {
|
||||
return sqlQuery;
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder( sqlQuery.length() + 20 );
|
||||
int left, right;
|
||||
|
||||
// replace {....} with corresponding column aliases
|
||||
for ( int curr = 0; curr < sqlQuery.length(); curr = right + 1 ) {
|
||||
if ( ( left = sqlQuery.indexOf( '{', curr ) ) < 0 ) {
|
||||
// No additional open braces found in the string, append the
|
||||
// rest of the string in its entirety and quit this loop
|
||||
result.append( sqlQuery.substring( curr ) );
|
||||
break;
|
||||
}
|
||||
|
||||
// append everything up until the next encountered open brace
|
||||
result.append( sqlQuery.substring( curr, left ) );
|
||||
|
||||
if ( ( right = sqlQuery.indexOf( '}', left + 1 ) ) < 0 ) {
|
||||
throw new QueryException( "Unmatched braces for alias path", sqlQuery );
|
||||
}
|
||||
|
||||
final String aliasPath = sqlQuery.substring( left + 1, right );
|
||||
boolean isPlaceholder = aliasPath.startsWith( HIBERNATE_PLACEHOLDER_PREFIX );
|
||||
|
||||
if ( isPlaceholder ) {
|
||||
// Domain replacement
|
||||
if ( DOMAIN_PLACEHOLDER.equals( aliasPath ) ) {
|
||||
final String catalogName = factory.getSettings().getDefaultCatalogName();
|
||||
if ( catalogName != null ) {
|
||||
result.append( catalogName );
|
||||
result.append( "." );
|
||||
}
|
||||
final String schemaName = factory.getSettings().getDefaultSchemaName();
|
||||
if ( schemaName != null ) {
|
||||
result.append( schemaName );
|
||||
result.append( "." );
|
||||
}
|
||||
}
|
||||
// Schema replacement
|
||||
else if ( SCHEMA_PLACEHOLDER.equals( aliasPath ) ) {
|
||||
final String schemaName = factory.getSettings().getDefaultSchemaName();
|
||||
if ( schemaName != null ) {
|
||||
result.append(schemaName);
|
||||
result.append(".");
|
||||
}
|
||||
}
|
||||
// Catalog replacement
|
||||
else if ( CATALOG_PLACEHOLDER.equals( aliasPath ) ) {
|
||||
final String catalogName = factory.getSettings().getDefaultCatalogName();
|
||||
if ( catalogName != null ) {
|
||||
result.append( catalogName );
|
||||
result.append( "." );
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new QueryException( "Unknown placeholder ", aliasPath );
|
||||
}
|
||||
}
|
||||
else if (context != null) {
|
||||
int firstDot = aliasPath.indexOf( '.' );
|
||||
if ( firstDot == -1 ) {
|
||||
if ( context.isEntityAlias( aliasPath ) ) {
|
||||
// it is a simple table alias {foo}
|
||||
result.append( aliasPath );
|
||||
aliasesFound++;
|
||||
}
|
||||
else {
|
||||
// passing through anything we do not know : to support jdbc escape sequences HB-898
|
||||
result.append( '{' ).append(aliasPath).append( '}' );
|
||||
}
|
||||
}
|
||||
else {
|
||||
final String aliasName = aliasPath.substring( 0, firstDot );
|
||||
if ( context.isCollectionAlias( aliasName ) ) {
|
||||
// The current alias is referencing the collection to be eagerly fetched
|
||||
String propertyName = aliasPath.substring( firstDot + 1 );
|
||||
result.append( resolveCollectionProperties( aliasName, propertyName ) );
|
||||
aliasesFound++;
|
||||
}
|
||||
else if ( context.isEntityAlias( aliasName ) ) {
|
||||
// it is a property reference {foo.bar}
|
||||
String propertyName = aliasPath.substring( firstDot + 1 );
|
||||
result.append( resolveProperties( aliasName, propertyName ) );
|
||||
aliasesFound++;
|
||||
}
|
||||
else {
|
||||
// passing through anything we do not know : to support jdbc escape sequences HB-898
|
||||
result.append( '{' ).append(aliasPath).append( '}' );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
result.append( '{' ).append(aliasPath).append( '}' );
|
||||
}
|
||||
}
|
||||
|
||||
// Possibly handle :something parameters for the query ?
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private String resolveCollectionProperties(
|
||||
String aliasName,
|
||||
String propertyName) {
|
||||
|
||||
Map fieldResults = context.getPropertyResultsMapByAlias( aliasName );
|
||||
SQLLoadableCollection collectionPersister = context.getCollectionPersisterByAlias( aliasName );
|
||||
String collectionSuffix = context.getCollectionSuffixByAlias( aliasName );
|
||||
|
||||
if ( "*".equals( propertyName ) ) {
|
||||
if( !fieldResults.isEmpty() ) {
|
||||
throw new QueryException("Using return-propertys together with * syntax is not supported.");
|
||||
}
|
||||
|
||||
String selectFragment = collectionPersister.selectFragment( aliasName, collectionSuffix );
|
||||
aliasesFound++;
|
||||
return selectFragment
|
||||
+ ", "
|
||||
+ resolveProperties( aliasName, propertyName );
|
||||
}
|
||||
else if ( "element.*".equals( propertyName ) ) {
|
||||
return resolveProperties( aliasName, "*" );
|
||||
}
|
||||
else {
|
||||
String[] columnAliases;
|
||||
|
||||
// Let return-properties override whatever the persister has for aliases.
|
||||
columnAliases = ( String[] ) fieldResults.get(propertyName);
|
||||
if ( columnAliases==null ) {
|
||||
columnAliases = collectionPersister.getCollectionPropertyColumnAliases( propertyName, collectionSuffix );
|
||||
}
|
||||
|
||||
if ( columnAliases == null || columnAliases.length == 0 ) {
|
||||
throw new QueryException(
|
||||
"No column name found for property [" + propertyName + "] for alias [" + aliasName + "]",
|
||||
originalQueryString
|
||||
);
|
||||
}
|
||||
if ( columnAliases.length != 1 ) {
|
||||
// TODO: better error message since we actually support composites if names are explicitly listed.
|
||||
throw new QueryException(
|
||||
"SQL queries only support properties mapped to a single column - property [" +
|
||||
propertyName + "] is mapped to " + columnAliases.length + " columns.",
|
||||
originalQueryString
|
||||
);
|
||||
}
|
||||
aliasesFound++;
|
||||
return columnAliases[0];
|
||||
|
||||
}
|
||||
}
|
||||
private String resolveProperties(String aliasName, String propertyName) {
|
||||
Map fieldResults = context.getPropertyResultsMapByAlias( aliasName );
|
||||
SQLLoadable persister = context.getEntityPersisterByAlias( aliasName );
|
||||
String suffix = context.getEntitySuffixByAlias( aliasName );
|
||||
|
||||
if ( "*".equals( propertyName ) ) {
|
||||
if( !fieldResults.isEmpty() ) {
|
||||
throw new QueryException("Using return-propertys together with * syntax is not supported.");
|
||||
}
|
||||
aliasesFound++;
|
||||
return persister.selectFragment( aliasName, suffix ) ;
|
||||
}
|
||||
else {
|
||||
|
||||
String[] columnAliases;
|
||||
|
||||
// Let return-propertiess override whatever the persister has for aliases.
|
||||
columnAliases = (String[]) fieldResults.get( propertyName );
|
||||
if ( columnAliases == null ) {
|
||||
columnAliases = persister.getSubclassPropertyColumnAliases( propertyName, suffix );
|
||||
}
|
||||
|
||||
if ( columnAliases == null || columnAliases.length == 0 ) {
|
||||
throw new QueryException(
|
||||
"No column name found for property [" + propertyName + "] for alias [" + aliasName + "]",
|
||||
originalQueryString
|
||||
);
|
||||
}
|
||||
if ( columnAliases.length != 1 ) {
|
||||
// TODO: better error message since we actually support composites if names are explicitly listed.
|
||||
throw new QueryException(
|
||||
"SQL queries only support properties mapped to a single column - property [" + propertyName + "] is mapped to " + columnAliases.length + " columns.",
|
||||
originalQueryString
|
||||
);
|
||||
}
|
||||
aliasesFound++;
|
||||
return columnAliases[0];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -45,6 +45,7 @@ import org.hibernate.query.spi.HqlInterpretation;
|
|||
import org.hibernate.query.spi.MutableQueryOptions;
|
||||
import org.hibernate.query.spi.NonSelectQueryPlan;
|
||||
import org.hibernate.query.spi.ParameterMetadataImplementor;
|
||||
import org.hibernate.query.spi.QueryEngine;
|
||||
import org.hibernate.query.spi.QueryInterpretationCache;
|
||||
import org.hibernate.query.spi.QueryOptions;
|
||||
import org.hibernate.query.spi.QueryParameterBindings;
|
||||
|
@ -110,8 +111,14 @@ public class QuerySqmImpl<R>
|
|||
this.hqlString = memento.getHqlString();
|
||||
|
||||
final SessionFactoryImplementor factory = producer.getFactory();
|
||||
final QueryEngine queryEngine = factory.getQueryEngine();
|
||||
final QueryInterpretationCache interpretationCache = queryEngine.getInterpretationCache();
|
||||
final HqlInterpretation hqlInterpretation = interpretationCache.resolveHqlInterpretation(
|
||||
hqlString,
|
||||
s -> queryEngine.getHqlTranslator().translate( hqlString )
|
||||
);
|
||||
|
||||
this.sqmStatement = factory.getQueryEngine().getHqlTranslator().translate( hqlString );
|
||||
this.sqmStatement = hqlInterpretation.getSqmStatement();
|
||||
|
||||
if ( resultType != null ) {
|
||||
if ( sqmStatement instanceof SqmDmlStatement ) {
|
||||
|
@ -119,15 +126,8 @@ public class QuerySqmImpl<R>
|
|||
}
|
||||
}
|
||||
this.resultType = resultType;
|
||||
|
||||
if ( sqmStatement.getSqmParameters().isEmpty() ) {
|
||||
this.domainParameterXref = DomainParameterXref.empty();
|
||||
this.parameterMetadata = ParameterMetadataImpl.EMPTY;
|
||||
}
|
||||
else {
|
||||
this.domainParameterXref = DomainParameterXref.from( sqmStatement );
|
||||
this.parameterMetadata = new ParameterMetadataImpl( domainParameterXref.getQueryParameters() );
|
||||
}
|
||||
this.domainParameterXref = hqlInterpretation.getDomainParameterXref();
|
||||
this.parameterMetadata = hqlInterpretation.getParameterMetadata();
|
||||
|
||||
this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, producer.getFactory() );
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public class QueryStatisticsImpl implements QueryStatistics {
|
|||
private final Lock readLock;
|
||||
private final Lock writeLock;
|
||||
|
||||
QueryStatisticsImpl(String query) {
|
||||
public QueryStatisticsImpl(String query) {
|
||||
this.query = query;
|
||||
ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
this.readLock = lock.readLock();
|
||||
|
@ -159,7 +159,7 @@ public class QueryStatisticsImpl implements QueryStatistics {
|
|||
* @param rows rows count returned
|
||||
* @param time time taken
|
||||
*/
|
||||
void executed(long rows, long time) {
|
||||
public void executed(long rows, long time) {
|
||||
// read lock is enough, concurrent updates are supported by the underlying type AtomicLong
|
||||
// this only guards executed(long, long) to be called, when another thread is executing getExecutionAvgTime()
|
||||
readLock.lock();
|
||||
|
|
|
@ -23,21 +23,21 @@ import org.hibernate.internal.util.collections.BoundedConcurrentHashMap;
|
|||
*
|
||||
* @author Sanne Grinovero
|
||||
*/
|
||||
final class StatsNamedContainer<V> {
|
||||
public final class StatsNamedContainer<V> {
|
||||
|
||||
private final ConcurrentMap<String,V> map;
|
||||
|
||||
/**
|
||||
* Creates a bounded container - based on BoundedConcurrentHashMap
|
||||
*/
|
||||
StatsNamedContainer(int capacity, int concurrencyLevel) {
|
||||
public StatsNamedContainer(int capacity, int concurrencyLevel) {
|
||||
this.map = new BoundedConcurrentHashMap( capacity, concurrencyLevel, BoundedConcurrentHashMap.Eviction.LRU );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an unbounded container - based on ConcurrentHashMap
|
||||
*/
|
||||
StatsNamedContainer() {
|
||||
public StatsNamedContainer() {
|
||||
this.map = new ConcurrentHashMap<>( );
|
||||
}
|
||||
|
||||
|
|
|
@ -1,65 +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.connection;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
public class DriverManagerConnectionProviderValidationConfigTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Event.class
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addConfigOptions(Map options) {
|
||||
options.put( DriverManagerConnectionProviderImpl.VALIDATION_INTERVAL, 1L );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Event event = new Event();
|
||||
entityManager.persist( event );
|
||||
|
||||
assertTrue( Thread.getAllStackTraces()
|
||||
.keySet()
|
||||
.stream()
|
||||
.filter( thread -> thread.getName()
|
||||
.equals( "Hibernate Connection Pool Validation Thread" ) && thread.isDaemon() )
|
||||
.map( Thread::isDaemon )
|
||||
.findAny()
|
||||
.isPresent() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Entity(name = "Event")
|
||||
public static class Event {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* 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.connection;
|
||||
package org.hibernate.orm.test.connection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.connection;
|
||||
package org.hibernate.orm.test.connection;
|
||||
|
||||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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.orm.test.connection;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@Jpa(
|
||||
annotatedClasses = { DriverManagerConnectionProviderValidationConfigTest.Event.class },
|
||||
integrationSettings = @Setting(name = DriverManagerConnectionProviderImpl.VALIDATION_INTERVAL, value = "1")
|
||||
)
|
||||
public class DriverManagerConnectionProviderValidationConfigTest {
|
||||
|
||||
@Test
|
||||
public void test(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
Event event = new Event();
|
||||
entityManager.persist( event );
|
||||
|
||||
assertTrue( Thread.getAllStackTraces()
|
||||
.keySet()
|
||||
.stream()
|
||||
.filter( thread -> thread.getName()
|
||||
.equals( "Hibernate Connection Pool Validation Thread" ) && thread.isDaemon() )
|
||||
.map( Thread::isDaemon )
|
||||
.findAny()
|
||||
.isPresent() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Entity(name = "Event")
|
||||
public static class Event {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* 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.connection;
|
||||
package org.hibernate.orm.test.connection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
|
@ -34,7 +34,7 @@ public class DriverManagerRegistrationTest extends BaseUnitTestCase {
|
|||
|
||||
@Test
|
||||
public void testDriverRegistrationUsingLoadClassFails() {
|
||||
final String driverClassName = "org.hibernate.connection.DriverManagerRegistrationTest$TestDriver1";
|
||||
final String driverClassName = "org.hibernate.orm.test.connection.DriverManagerRegistrationTest$TestDriver1";
|
||||
final String url = "jdbc:hibernate:test";
|
||||
|
||||
try {
|
||||
|
@ -55,7 +55,7 @@ public class DriverManagerRegistrationTest extends BaseUnitTestCase {
|
|||
|
||||
@Test
|
||||
public void testDriverRegistrationUsingClassForNameSucceeds() {
|
||||
final String driverClassName = "org.hibernate.connection.DriverManagerRegistrationTest$TestDriver2";
|
||||
final String driverClassName = "org.hibernate.orm.test.connection.DriverManagerRegistrationTest$TestDriver2";
|
||||
final String url = "jdbc:hibernate:test2";
|
||||
try {
|
||||
Class.forName( driverClassName, true, determineClassLoader() );
|
|
@ -4,7 +4,7 @@
|
|||
* 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.connection;
|
||||
package org.hibernate.orm.test.connection;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Assert;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.graph;
|
||||
package org.hibernate.orm.test.graph;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -14,6 +14,7 @@ import javax.persistence.EntityGraph;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Subgraph;
|
||||
|
||||
import org.hibernate.graph.GraphParser;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
|
@ -4,11 +4,12 @@
|
|||
* 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.graph;
|
||||
package org.hibernate.orm.test.graph;
|
||||
|
||||
import javax.persistence.EntityGraph;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.graph.EntityGraphs;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.graph;
|
||||
package org.hibernate.orm.test.graph;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.persistence.Basic;
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.graph;
|
||||
package org.hibernate.orm.test.graph;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.persister.entity;
|
||||
package org.hibernate.orm.test.persister.entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
@ -14,31 +14,39 @@ import javax.persistence.ManyToOne;
|
|||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Formula;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Mykhaylo Gnylorybov
|
||||
*/
|
||||
public abstract class AbstractSchemaSubstitutionFormulaTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(annotatedClasses = {
|
||||
AbstractSchemaSubstitutionFormulaTest.FooBar.class,
|
||||
AbstractSchemaSubstitutionFormulaTest.Bar.class,
|
||||
AbstractSchemaSubstitutionFormulaTest.Foo.class
|
||||
})
|
||||
@SessionFactory
|
||||
public abstract class AbstractSchemaSubstitutionFormulaTest {
|
||||
|
||||
protected static final String SCHEMA_PLACEHOLDER = "h-schema";
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test(SessionFactoryScope scope) {
|
||||
final String className = FooBar.class.getName();
|
||||
final AbstractEntityPersister persister = (AbstractEntityPersister) sessionFactory()
|
||||
final AbstractEntityPersister persister = (AbstractEntityPersister) scope.getSessionFactory()
|
||||
.getMetamodel().entityPersister( className );
|
||||
final String formula = persister.getSubclassFormulaTemplateClosure()[0];
|
||||
final String formula = persister.getSubclassPropertyFormulaTemplateClosure()[persister.getPropertyIndex( "isValid" )][0];
|
||||
validate( formula );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
Foo foo = new Foo();
|
||||
foo.id = 1;
|
||||
foo.name = "fooName";
|
||||
|
@ -57,7 +65,7 @@ public abstract class AbstractSchemaSubstitutionFormulaTest extends BaseCoreFunc
|
|||
session.persist( fooBar );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
FooBar entity = session.find( FooBar.class, 3 );
|
||||
assertTrue( "Invalid result of formula expression: ", entity.isValid );
|
||||
} );
|
||||
|
@ -67,15 +75,6 @@ public abstract class AbstractSchemaSubstitutionFormulaTest extends BaseCoreFunc
|
|||
|
||||
abstract void validate(String formula);
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
FooBar.class,
|
||||
Bar.class,
|
||||
Foo.class
|
||||
};
|
||||
}
|
||||
|
||||
@Entity(name = "FOOBAR")
|
||||
@Table(name = "FOOBAR")
|
||||
public static class FooBar {
|
|
@ -4,7 +4,7 @@
|
|||
* 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.persister.entity;
|
||||
package org.hibernate.orm.test.persister.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
|
@ -20,12 +20,18 @@ import org.hibernate.annotations.SQLDelete;
|
|||
import org.hibernate.annotations.SQLInsert;
|
||||
import org.hibernate.annotations.SQLUpdate;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||
import org.hibernate.persister.entity.SingleTableEntityPersister;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -33,22 +39,19 @@ import static org.junit.Assert.assertNull;
|
|||
/**
|
||||
* @author Laabidi RAISSI
|
||||
*/
|
||||
@DomainModel(annotatedClasses = {
|
||||
CustomSqlSchemaResolvingIdentityTest.CustomEntity.class, CustomSqlSchemaResolvingIdentityTest.Dummy.class
|
||||
})
|
||||
@SessionFactory
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
public class CustomSqlSchemaResolvingIdentityTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
CustomEntity.class, Dummy.class
|
||||
};
|
||||
}
|
||||
public class CustomSqlSchemaResolvingIdentityTest {
|
||||
|
||||
@Test
|
||||
public void testSchemaNotReplacedInCustomSQL() throws Exception {
|
||||
public void testSchemaNotReplacedInCustomSQL(SessionFactoryScope scope) throws Exception {
|
||||
|
||||
String className = CustomEntity.class.getName();
|
||||
|
||||
final AbstractEntityPersister persister = (AbstractEntityPersister) sessionFactory().getEntityPersister( className );
|
||||
final AbstractEntityPersister persister = (AbstractEntityPersister) scope.getSessionFactory().getEntityPersister( className );
|
||||
String insertQuery = persister.getSQLInsertStrings()[0];
|
||||
String updateQuery = persister.getSQLUpdateStrings()[0];
|
||||
String deleteQuery = persister.getSQLDeleteStrings()[0];
|
||||
|
@ -62,26 +65,26 @@ public class CustomSqlSchemaResolvingIdentityTest extends BaseCoreFunctionalTest
|
|||
assertEquals( "Incorrect custom SQL for update in Entity: " + className,
|
||||
"UPDATE FOO SET name = ? WHERE id = ? ", updateQuery );
|
||||
|
||||
CustomEntity _entitty = doInHibernate( this::sessionFactory, session -> {
|
||||
CustomEntity _entitty = scope.fromTransaction( session -> {
|
||||
CustomEntity entity = new CustomEntity();
|
||||
session.persist( entity );
|
||||
|
||||
return entity;
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
||||
assertNotNull(entity);
|
||||
|
||||
entity.name = "Vlad";
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
CustomEntity entity = session.find( CustomEntity.class, _entitty.id );
|
||||
session.delete( entity );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
CustomEntity entity = session.find( CustomEntity.class, _entitty.id );
|
||||
assertNull(entity);
|
||||
} );
|
|
@ -4,7 +4,7 @@
|
|||
* 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.persister.entity;
|
||||
package org.hibernate.orm.test.persister.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
@ -17,11 +17,16 @@ import org.hibernate.annotations.ResultCheckStyle;
|
|||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.SQLInsert;
|
||||
import org.hibernate.annotations.SQLUpdate;
|
||||
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||
import org.hibernate.persister.entity.SingleTableEntityPersister;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -29,21 +34,18 @@ import static org.junit.Assert.assertNull;
|
|||
/**
|
||||
* @author Laabidi RAISSI
|
||||
*/
|
||||
public class CustomSqlSchemaResolvingTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
CustomEntity.class, Dummy.class
|
||||
};
|
||||
}
|
||||
@DomainModel(annotatedClasses = {
|
||||
CustomSqlSchemaResolvingTest.CustomEntity.class, CustomSqlSchemaResolvingTest.Dummy.class
|
||||
})
|
||||
@SessionFactory
|
||||
public class CustomSqlSchemaResolvingTest {
|
||||
|
||||
@Test
|
||||
public void testSchemaNotReplacedInCustomSQL() throws Exception {
|
||||
public void testSchemaNotReplacedInCustomSQL(SessionFactoryScope scope) throws Exception {
|
||||
|
||||
String className = CustomEntity.class.getName();
|
||||
|
||||
final AbstractEntityPersister persister = (AbstractEntityPersister) sessionFactory().getEntityPersister( className );
|
||||
final AbstractEntityPersister persister = (AbstractEntityPersister) scope.getSessionFactory().getEntityPersister( className );
|
||||
String insertQuery = persister.getSQLInsertStrings()[0];
|
||||
String updateQuery = persister.getSQLUpdateStrings()[0];
|
||||
String deleteQuery = persister.getSQLDeleteStrings()[0];
|
||||
|
@ -57,25 +59,25 @@ public class CustomSqlSchemaResolvingTest extends BaseCoreFunctionalTestCase {
|
|||
assertEquals( "Incorrect custom SQL for update in Entity: " + className,
|
||||
"UPDATE FOO SET name = ? WHERE id = ? ", updateQuery );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
CustomEntity entity = new CustomEntity();
|
||||
entity.id = 1;
|
||||
session.persist( entity );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
||||
assertNotNull(entity);
|
||||
|
||||
entity.name = "Vlad";
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
||||
session.delete( entity );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
scope.inTransaction( session -> {
|
||||
CustomEntity entity = session.find( CustomEntity.class, 1 );
|
||||
assertNull(entity);
|
||||
} );
|
|
@ -4,11 +4,12 @@
|
|||
* 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.persister.entity;
|
||||
package org.hibernate.orm.test.persister.entity;
|
||||
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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.orm.test.persister.entity;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
@ServiceRegistry(settings = {
|
||||
@Setting( name = AvailableSettings.DEFAULT_SCHEMA, value = FormulaTemplateSchemaSubstitutionTest.CUSTOM_SCHEMA),
|
||||
@Setting( name = AvailableSettings.HBM2DDL_CREATE_SCHEMAS, value = "true")
|
||||
})
|
||||
public class FormulaTemplateSchemaSubstitutionTest extends AbstractSchemaSubstitutionFormulaTest {
|
||||
|
||||
static final String CUSTOM_SCHEMA = "CUSTOM_SCHEMA";
|
||||
|
||||
@Override
|
||||
void validate(String formula) {
|
||||
assertEquals( "Formula should not contain {} characters",
|
||||
4, formula.split( CUSTOM_SCHEMA + ".", -1 ).length - 1
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,6 @@
|
|||
package org.hibernate.persister.entity;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
package org.hibernate.orm.test.persister.entity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
|
@ -18,31 +14,25 @@ import org.hibernate.annotations.JoinColumnOrFormula;
|
|||
import org.hibernate.annotations.JoinColumnsOrFormulas;
|
||||
import org.hibernate.annotations.JoinFormula;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@TestForIssue(jiraKey = "HHH-14223")
|
||||
public class JoinFormulaImplicitJoinTest extends BaseEntityManagerFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Person.class, PersonVersion.class
|
||||
};
|
||||
}
|
||||
@Jpa(annotatedClasses = {
|
||||
JoinFormulaImplicitJoinTest.Person.class, JoinFormulaImplicitJoinTest.PersonVersion.class
|
||||
}, properties = {
|
||||
@Setting(name = AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, value = "true")
|
||||
})
|
||||
public class JoinFormulaImplicitJoinTest {
|
||||
|
||||
@Override
|
||||
protected void addConfigOptions(Map options) {
|
||||
options.put(
|
||||
AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS,
|
||||
Boolean.TRUE
|
||||
);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
@BeforeEach
|
||||
public void setUp(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(entityManager -> {
|
||||
final Person person = new Person();
|
||||
entityManager.persist(person);
|
||||
|
||||
|
@ -61,8 +51,8 @@ public class JoinFormulaImplicitJoinTest extends BaseEntityManagerFunctionalTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testImplicitJoin() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testImplicitJoin(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(entityManager -> {
|
||||
entityManager.createQuery(
|
||||
"SELECT person\n" +
|
||||
"FROM Person AS person\n" +
|
|
@ -0,0 +1,34 @@
|
|||
package org.hibernate.orm.test.procedure.internal;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Nathan Xu
|
||||
*/
|
||||
@Jpa
|
||||
public class ProcedureCallImplTest {
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13644" )
|
||||
@RequiresDialect( H2Dialect.class )
|
||||
@NotImplementedYet(reason = "org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs not yet implemented")
|
||||
public void testNoNullPointerExceptionThrown(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( em -> {
|
||||
em.createNativeQuery("CREATE ALIAS GET_RANDOM_VALUE FOR \"java.lang.Math.random\";").executeUpdate();
|
||||
Query query = em.createStoredProcedureQuery("GET_RANDOM_VALUE");
|
||||
Stream stream = query.getResultStream();
|
||||
Assert.assertEquals(1, stream.count());
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* 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.property;
|
||||
package org.hibernate.orm.test.property;
|
||||
|
||||
import org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl;
|
||||
import org.hibernate.property.access.spi.PropertyAccess;
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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.orm.test.property;
|
||||
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Michael Rudolf
|
||||
*/
|
||||
@DomainModel(annotatedClasses = {
|
||||
Order.class,
|
||||
Item.class
|
||||
})
|
||||
@SessionFactory
|
||||
public class DirectPropertyAccessorTest {
|
||||
@Test
|
||||
@TestForIssue( jiraKey="HHH-3718" )
|
||||
public void testDirectIdPropertyAccess(SessionFactoryScope scope) throws Exception {
|
||||
scope.inTransaction( s -> {
|
||||
Item i = new Item();
|
||||
s.persist( i );
|
||||
Order o = new Order();
|
||||
o.setOrderNumber( 1 );
|
||||
o.getItems().add( i );
|
||||
s.persist( o );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
o = ( Order ) s.load( Order.class, 1 );
|
||||
assertFalse( Hibernate.isInitialized( o ) );
|
||||
o.getOrderNumber();
|
||||
// If you mapped with field access, any method, except id, call initializes the proxy
|
||||
assertFalse( Hibernate.isInitialized( o ) );
|
||||
o.getName();
|
||||
assertTrue( Hibernate.isInitialized( o ) );
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* 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.property;
|
||||
package org.hibernate.orm.test.property;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.property;
|
||||
package org.hibernate.orm.test.property;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
@ -12,9 +12,11 @@ import javax.persistence.Table;
|
|||
import javax.persistence.Transient;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.transaction.TransactionUtil;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNull.nullValue;
|
||||
|
@ -23,49 +25,49 @@ import static org.junit.Assert.assertThat;
|
|||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@SessionFactory
|
||||
@DomainModel(annotatedClasses = {
|
||||
GetAndIsVariantGetterWithTransientAnnotationTest.TestEntity.class,
|
||||
GetAndIsVariantGetterWithTransientAnnotationTest.SecondTestEntity.class
|
||||
})
|
||||
@TestForIssue(jiraKey = "HHH-11716")
|
||||
public class GetAndIsVariantGetterWithTransientAnnotationTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {TestEntity.class, SecondTestEntity.class};
|
||||
}
|
||||
public class GetAndIsVariantGetterWithTransientAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void testGetAndIsVariantCanHaveDifferentReturnValueWhenOneHasATransientAnnotation() {
|
||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
||||
public void testGetAndIsVariantCanHaveDifferentReturnValueWhenOneHasATransientAnnotation(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session1 -> {
|
||||
TestEntity entity = new TestEntity();
|
||||
entity.setId( 1L );
|
||||
entity.setChecked( true );
|
||||
session1.save( entity );
|
||||
} );
|
||||
|
||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
||||
scope.inTransaction( session1 -> {
|
||||
final TestEntity entity = session1.find( TestEntity.class, 1L );
|
||||
assertThat( entity.isChecked(), is( true ) );
|
||||
} );
|
||||
|
||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
||||
scope.inTransaction( session1 -> {
|
||||
final TestEntity entity = session1.find( TestEntity.class, 1L );
|
||||
entity.setChecked( null );
|
||||
} );
|
||||
|
||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
||||
scope.inTransaction( session1 -> {
|
||||
final TestEntity entity = session1.find( TestEntity.class, 1L );
|
||||
assertThat( entity.isChecked(), is( nullValue() ) );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBothGetterAndIsVariantAreIgnoredWhenMarkedTransient() {
|
||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
||||
public void testBothGetterAndIsVariantAreIgnoredWhenMarkedTransient(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session1 -> {
|
||||
SecondTestEntity entity = new SecondTestEntity();
|
||||
entity.setId( 1L );
|
||||
entity.setChecked( true );
|
||||
session1.save( entity );
|
||||
} );
|
||||
|
||||
TransactionUtil.doInHibernate( this::sessionFactory, session1 -> {
|
||||
scope.inTransaction( session1 -> {
|
||||
final SecondTestEntity entity = session1.find( SecondTestEntity.class, 1L );
|
||||
assertThat( entity.getChecked(), is( nullValue() ) );
|
||||
} );
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// $Id$
|
||||
|
||||
package org.hibernate.property;
|
||||
package org.hibernate.orm.test.property;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Entity;
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
// $Id$
|
||||
|
||||
package org.hibernate.property;
|
||||
package org.hibernate.orm.test.property;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.property;
|
||||
package org.hibernate.orm.test.property;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
|
@ -1,7 +1,11 @@
|
|||
package org.hibernate.property.access.spi;
|
||||
package org.hibernate.orm.test.property.access.spi;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.hibernate.property.access.spi.Getter;
|
||||
import org.hibernate.property.access.spi.GetterFieldImpl;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -15,13 +19,13 @@ public class GetterFieldImplTest {
|
|||
public void testGet() throws Exception {
|
||||
Target target = new Target();
|
||||
|
||||
assertEquals( true, getter( "active" ).get( target ) );
|
||||
assertEquals( (byte) 2, getter( "children" ).get( target ) );
|
||||
assertEquals( 'M', getter( "gender" ).get( target ) );
|
||||
assertEquals( Integer.MAX_VALUE, getter( "code" ).get( target ) );
|
||||
assertEquals( Long.MAX_VALUE, getter( "id" ).get( target ) );
|
||||
assertEquals( (short) 34, getter( "age" ).get( target ) );
|
||||
assertEquals( "John Doe", getter( "name" ).get( target ) );
|
||||
Assert.assertEquals( true, getter( "active" ).get( target ) );
|
||||
Assert.assertEquals( (byte) 2, getter( "children" ).get( target ) );
|
||||
Assert.assertEquals( 'M', getter( "gender" ).get( target ) );
|
||||
Assert.assertEquals( Integer.MAX_VALUE, getter( "code" ).get( target ) );
|
||||
Assert.assertEquals( Long.MAX_VALUE, getter( "id" ).get( target ) );
|
||||
Assert.assertEquals( (short) 34, getter( "age" ).get( target ) );
|
||||
Assert.assertEquals( "John Doe", getter( "name" ).get( target ) );
|
||||
}
|
||||
|
||||
private static class Target {
|
|
@ -4,7 +4,7 @@
|
|||
* 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.secure;
|
||||
package org.hibernate.orm.test.secure;
|
||||
|
||||
import java.security.CodeSource;
|
||||
import java.security.Permission;
|
||||
|
@ -13,7 +13,6 @@ import java.security.Policy;
|
|||
import java.security.ProtectionDomain;
|
||||
import java.security.Provider;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.security.auth.Subject;
|
||||
|
@ -22,37 +21,33 @@ import javax.security.jacc.PolicyContextException;
|
|||
import javax.security.jacc.PolicyContextHandler;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@Jpa(annotatedClasses = {
|
||||
JaccIntegratorTest.Person.class
|
||||
}, properties = {
|
||||
@Setting( name = AvailableSettings.JACC_ENABLED, value = "true"),
|
||||
@Setting( name = AvailableSettings.JACC_CONTEXT_ID, value = "JACC_CONTEXT_ID"),
|
||||
@Setting( name = "hibernate.jacc.allowed.org.hibernate.secure.Customer", value = "insert")
|
||||
})
|
||||
@TestForIssue( jiraKey = "HHH-11805" )
|
||||
public class JaccIntegratorTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public class JaccIntegratorTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Person.class,
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addConfigOptions(Map options) {
|
||||
options.put( AvailableSettings.JACC_ENABLED, Boolean.TRUE.toString() );
|
||||
options.put( AvailableSettings.JACC_CONTEXT_ID, "JACC_CONTEXT_ID" );
|
||||
options.put( "hibernate.jacc.allowed.org.hibernate.secure.Customer", "insert" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterEntityManagerFactoryBuilt() {
|
||||
@BeforeEach
|
||||
protected void afterEntityManagerFactoryBuilt(EntityManagerFactoryScope scope) {
|
||||
scope.getEntityManagerFactory();
|
||||
PolicyContextHandler policyContextHandler = new PolicyContextHandler() {
|
||||
@Override
|
||||
public Object getContext(String key, Object data) throws PolicyContextException {
|
||||
|
@ -129,10 +124,10 @@ public class JaccIntegratorTest extends BaseEntityManagerFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAllow() {
|
||||
public void testAllow(EntityManagerFactoryScope scope) {
|
||||
setPolicy( true );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
Person person = new Person();
|
||||
person.id = 1L;
|
||||
person.name = "John Doe";
|
||||
|
@ -142,11 +137,11 @@ public class JaccIntegratorTest extends BaseEntityManagerFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDisallow() {
|
||||
public void testDisallow(EntityManagerFactoryScope scope) {
|
||||
setPolicy( false );
|
||||
|
||||
try {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
Person person = new Person();
|
||||
person.id = 1L;
|
||||
person.name = "John Doe";
|
|
@ -4,11 +4,10 @@
|
|||
* 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.serialization;
|
||||
package org.hibernate.orm.test.serialization;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
|
@ -18,8 +17,6 @@ import javax.persistence.ManyToOne;
|
|||
import javax.persistence.OneToMany;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
|
@ -27,46 +24,41 @@ import org.hibernate.annotations.LazyCollectionOption;
|
|||
import org.hibernate.annotations.LazyToOne;
|
||||
import org.hibernate.annotations.LazyToOneOption;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.internal.util.SerializationHelper;
|
||||
import org.hibernate.proxy.AbstractLazyInitializer;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Selaron
|
||||
*/
|
||||
public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { SimpleEntity.class, ChildEntity.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(final Configuration configuration) {
|
||||
// enable LL without TX, which used to cause problems when serializing proxies (see HHH-12720)
|
||||
configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, Boolean.TRUE.toString() );
|
||||
}
|
||||
@DomainModel(annotatedClasses = {
|
||||
EntityProxySerializationTest.SimpleEntity.class, EntityProxySerializationTest.ChildEntity.class
|
||||
})
|
||||
@SessionFactory
|
||||
@ServiceRegistry(settings = {
|
||||
@Setting( name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "true" )
|
||||
})
|
||||
public class EntityProxySerializationTest {
|
||||
|
||||
/**
|
||||
* Prepare and persist a {@link SimpleEntity} with two {@link ChildEntity}.
|
||||
*/
|
||||
@Before
|
||||
public void prepare() {
|
||||
final Session s = openSession();
|
||||
|
||||
final Transaction t = s.beginTransaction();
|
||||
|
||||
try {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
final Number count = (Number) s.createQuery("SELECT count(ID) FROM SimpleEntity").getSingleResult();
|
||||
if (count.longValue() > 0L) {
|
||||
// entity already added previously
|
||||
|
@ -88,23 +80,15 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
s.save( entity );
|
||||
s.save( c1 );
|
||||
s.save( c2 );
|
||||
}
|
||||
finally {
|
||||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that serializing an initialized proxy will serialize the target instead.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testInitializedProxySerializationIfTargetInPersistenceContext() {
|
||||
final Session s = openSession();
|
||||
|
||||
final Transaction t = s.beginTransaction();
|
||||
try {
|
||||
public void testInitializedProxySerializationIfTargetInPersistenceContext(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
||||
|
||||
final SimpleEntity parent = child.getParent();
|
||||
|
@ -123,13 +107,7 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
||||
assertFalse( deserializedParent instanceof HibernateProxy );
|
||||
assertEquals( "TheParent", deserializedParent.getName() );
|
||||
}
|
||||
finally {
|
||||
if ( t.isActive() ) {
|
||||
t.rollback();
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,13 +115,9 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
* but whose target has been (separately) added to the persistence context
|
||||
* will serialize the target instead.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testUninitializedProxySerializationIfTargetInPersistenceContext() {
|
||||
final Session s = openSession();
|
||||
|
||||
final Transaction t = s.beginTransaction();
|
||||
try {
|
||||
public void testUninitializedProxySerializationIfTargetInPersistenceContext(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
||||
|
||||
final SimpleEntity parent = child.getParent();
|
||||
|
@ -166,13 +140,7 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
||||
assertFalse( deserializedParent instanceof HibernateProxy );
|
||||
assertEquals( "TheParent", deserializedParent.getName() );
|
||||
}
|
||||
finally {
|
||||
if ( t.isActive() ) {
|
||||
t.rollback();
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,19 +148,12 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
* working. The magic is done by {@link AbstractLazyInitializer} who opens a
|
||||
* temporary session.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testProxyInitializationWithoutTX() {
|
||||
final Session s = openSession();
|
||||
|
||||
final Transaction t = s.beginTransaction();
|
||||
try {
|
||||
public void testProxyInitializationWithoutTX(SessionFactoryScope scope) {
|
||||
final SimpleEntity parent = scope.fromTransaction( s -> {
|
||||
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
||||
|
||||
final SimpleEntity parent = child.getParent();
|
||||
|
||||
t.rollback();
|
||||
session.close();
|
||||
return child.getParent();
|
||||
});
|
||||
|
||||
// assert we have an uninitialized proxy
|
||||
assertTrue( parent instanceof HibernateProxy );
|
||||
|
@ -203,37 +164,21 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
// assert we have an initialized proxy now
|
||||
assertTrue( Hibernate.isInitialized( parent ) );
|
||||
}
|
||||
finally {
|
||||
if ( t.isActive() ) {
|
||||
t.rollback();
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that lazy loading without transaction nor open session is generally
|
||||
* working. The magic is done by {@link AbstractLazyInitializer} who opens a
|
||||
* temporary session.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12720")
|
||||
public void testProxyInitializationWithoutTXAfterDeserialization() {
|
||||
final Session s = openSession();
|
||||
|
||||
final Transaction t = s.beginTransaction();
|
||||
try {
|
||||
public void testProxyInitializationWithoutTXAfterDeserialization(SessionFactoryScope scope) {
|
||||
final SimpleEntity deserializedParent = scope.fromTransaction( s -> {
|
||||
final ChildEntity child = s.find( ChildEntity.class, 1L );
|
||||
|
||||
final SimpleEntity parent = child.getParent();
|
||||
|
||||
// destroy AbstractLazyInitializer internal state
|
||||
final SimpleEntity deserializedParent = (SimpleEntity) SerializationHelper.clone( parent );
|
||||
|
||||
t.rollback();
|
||||
session.close();
|
||||
|
||||
return (SimpleEntity) SerializationHelper.clone( parent );
|
||||
});
|
||||
// assert we have an uninitialized proxy
|
||||
assertTrue( deserializedParent instanceof HibernateProxy );
|
||||
assertFalse( Hibernate.isInitialized( deserializedParent ) );
|
||||
|
@ -243,13 +188,6 @@ public class EntityProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
// assert we have an initialized proxy now
|
||||
assertTrue( Hibernate.isInitialized( deserializedParent ) );
|
||||
}
|
||||
finally {
|
||||
if ( t.isActive() ) {
|
||||
t.rollback();
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "SimpleEntity")
|
||||
static class SimpleEntity implements Serializable {
|
|
@ -4,7 +4,7 @@
|
|||
* 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.serialization;
|
||||
package org.hibernate.orm.test.serialization;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -14,14 +14,15 @@ import java.io.ObjectOutputStream;
|
|||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.orm.test.serialization.entity.AnEntity;
|
||||
import org.hibernate.orm.test.serialization.entity.PK;
|
||||
import org.hibernate.property.access.spi.Getter;
|
||||
import org.hibernate.property.access.spi.GetterFieldImpl;
|
||||
import org.hibernate.property.access.spi.GetterMethodImpl;
|
||||
import org.hibernate.property.access.spi.Setter;
|
||||
import org.hibernate.property.access.spi.SetterFieldImpl;
|
||||
import org.hibernate.property.access.spi.SetterMethodImpl;
|
||||
import org.hibernate.serialization.entity.AnEntity;
|
||||
import org.hibernate.serialization.entity.PK;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
|
@ -4,58 +4,48 @@
|
|||
* 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.serialization;
|
||||
package org.hibernate.orm.test.serialization;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.internal.util.SerializationHelper;
|
||||
import org.hibernate.proxy.AbstractLazyInitializer;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.map.MapProxy;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Selaron
|
||||
*/
|
||||
public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(xmlMappings = {
|
||||
"org/hibernate/orm/test/serialization/DynamicMapMappings.hbm.xml"
|
||||
})
|
||||
@SessionFactory
|
||||
@ServiceRegistry(settings = {
|
||||
@Setting( name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "true" ),
|
||||
@Setting( name = AvailableSettings.DEFAULT_ENTITY_MODE, value = "dynamic-map" )
|
||||
})
|
||||
public class MapProxySerializationTest {
|
||||
|
||||
@Override
|
||||
protected String[] getMappings() {
|
||||
return new String[] { "serialization/DynamicMapMappings.hbm.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(final Configuration configuration) {
|
||||
// enable LL without TX, which used to cause problems when serializing proxies (see HHH-12720)
|
||||
configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, Boolean.TRUE.toString() );
|
||||
|
||||
// dynamic-map by default.
|
||||
configuration.setProperty( AvailableSettings.DEFAULT_ENTITY_MODE, EntityMode.MAP.getExternalName() );
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
final Session s = openSession();
|
||||
|
||||
final Transaction t = s.beginTransaction();
|
||||
|
||||
try {
|
||||
@BeforeEach
|
||||
public void prepare(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
final Number count = (Number) s.createQuery("SELECT count(ID) FROM SimpleEntity").getSingleResult();
|
||||
if (count.longValue() > 0L) {
|
||||
// entity already added previously
|
||||
|
@ -72,11 +62,7 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
s.save( "SimpleEntity", entity );
|
||||
s.save( "ChildEntity", c1 );
|
||||
}
|
||||
finally {
|
||||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,11 +71,8 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7686")
|
||||
public void testInitializedProxySerializationIfTargetInPersistenceContext() {
|
||||
final Session s = openSession();
|
||||
|
||||
final Transaction t = s.beginTransaction();
|
||||
try {
|
||||
public void testInitializedProxySerializationIfTargetInPersistenceContext(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
||||
|
||||
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
||||
|
@ -109,13 +92,7 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
||||
assertFalse( deserializedParent instanceof HibernateProxy );
|
||||
assertEquals( "TheParent", deserializedParent.get( "name" ) );
|
||||
}
|
||||
finally {
|
||||
if ( t.isActive() ) {
|
||||
t.rollback();
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,11 +103,8 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7686")
|
||||
public void testUninitializedProxySerializationIfTargetInPersistenceContext() {
|
||||
final Session s = openSession();
|
||||
|
||||
final Transaction t = s.beginTransaction();
|
||||
try {
|
||||
public void testUninitializedProxySerializationIfTargetInPersistenceContext(SessionFactoryScope scope) {
|
||||
scope.inTransaction( s -> {
|
||||
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
||||
|
||||
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
||||
|
@ -154,13 +128,7 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
// assert the deserialized object is no longer a proxy, but the target of the proxy
|
||||
assertFalse( deserializedParent instanceof HibernateProxy );
|
||||
assertEquals( "TheParent", deserializedParent.get( "name" ) );
|
||||
}
|
||||
finally {
|
||||
if ( t.isActive() ) {
|
||||
t.rollback();
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,18 +138,11 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testProxyInitializationWithoutTX() {
|
||||
final Session s = openSession();
|
||||
|
||||
final Transaction t = s.beginTransaction();
|
||||
try {
|
||||
public void testProxyInitializationWithoutTX(SessionFactoryScope scope) {
|
||||
final Map<String, Object> parent = scope.fromTransaction( s -> {
|
||||
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
||||
|
||||
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
||||
|
||||
t.rollback();
|
||||
session.close();
|
||||
|
||||
return (Map<String, Object>) child.get( "parent" );
|
||||
});
|
||||
// assert we have an uninitialized proxy
|
||||
assertTrue( parent instanceof MapProxy );
|
||||
assertFalse( Hibernate.isInitialized( parent ) );
|
||||
|
@ -191,13 +152,6 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
// assert we have an initialized proxy now
|
||||
assertTrue( Hibernate.isInitialized( parent ) );
|
||||
}
|
||||
finally {
|
||||
if ( t.isActive() ) {
|
||||
t.rollback();
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that lazy loading without transaction nor open session is generally
|
||||
|
@ -207,21 +161,14 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-7686")
|
||||
public void testProxyInitializationWithoutTXAfterDeserialization() {
|
||||
final Session s = openSession();
|
||||
|
||||
final Transaction t = s.beginTransaction();
|
||||
try {
|
||||
public void testProxyInitializationWithoutTXAfterDeserialization(SessionFactoryScope scope) {
|
||||
final Map<String, Object> deserializedParent = scope.fromTransaction( s -> {
|
||||
final Map<String, Object> child = (Map<String, Object>) s.load( "ChildEntity", 1L );
|
||||
|
||||
final Map<String, Object> parent = (Map<String, Object>) child.get( "parent" );
|
||||
|
||||
// destroy AbstractLazyInitializer internal state
|
||||
final Map<String, Object> deserializedParent =
|
||||
(Map<String, Object>) SerializationHelper.clone( (Serializable) parent );
|
||||
|
||||
t.rollback();
|
||||
session.close();
|
||||
return (Map<String, Object>) SerializationHelper.clone( (Serializable) parent );
|
||||
});
|
||||
|
||||
// assert we have an uninitialized proxy
|
||||
assertTrue( deserializedParent instanceof MapProxy );
|
||||
|
@ -232,12 +179,5 @@ public class MapProxySerializationTest extends BaseCoreFunctionalTestCase {
|
|||
// assert we have an initialized proxy now
|
||||
assertTrue( Hibernate.isInitialized( deserializedParent ) );
|
||||
}
|
||||
finally {
|
||||
if ( t.isActive() ) {
|
||||
t.rollback();
|
||||
}
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* 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.serialization;
|
||||
package org.hibernate.orm.test.serialization;
|
||||
|
||||
|
||||
import javax.naming.Reference;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.serialization.entity;
|
||||
package org.hibernate.orm.test.serialization.entity;
|
||||
|
||||
/**
|
||||
* The class should be in a package that is different from the test
|
|
@ -4,7 +4,7 @@
|
|||
* 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.serialization.entity;
|
||||
package org.hibernate.orm.test.serialization.entity;
|
||||
|
||||
/**
|
||||
* This class should be in a package that is different from the test
|
|
@ -4,7 +4,7 @@
|
|||
* 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.service;
|
||||
package org.hibernate.orm.test.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.service;
|
||||
package org.hibernate.orm.test.service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -10,6 +10,9 @@ import java.util.concurrent.FutureTask;
|
|||
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.service.NullServiceException;
|
||||
import org.hibernate.service.Service;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.service.spi.Configurable;
|
||||
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.service.internal;
|
||||
package org.hibernate.orm.test.service.internal;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.session;
|
||||
package org.hibernate.orm.test.session;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
|
@ -14,33 +14,30 @@ import javax.persistence.ManyToOne;
|
|||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.proxy.AbstractLazyInitializer;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||
import org.hibernate.testing.logger.Triggerable;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
public class AssociateEntityWithTwoSessionsTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Location.class,
|
||||
Event.class
|
||||
};
|
||||
}
|
||||
@Jpa(annotatedClasses = {
|
||||
AssociateEntityWithTwoSessionsTest.Location.class,
|
||||
AssociateEntityWithTwoSessionsTest.Event.class
|
||||
})
|
||||
public class AssociateEntityWithTwoSessionsTest {
|
||||
|
||||
@Rule
|
||||
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
||||
|
@ -48,7 +45,7 @@ public class AssociateEntityWithTwoSessionsTest extends BaseEntityManagerFunctio
|
|||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-12216" )
|
||||
public void test() {
|
||||
public void test(EntityManagerFactoryScope scope) {
|
||||
|
||||
final Location location = new Location();
|
||||
location.setCity( "Cluj" );
|
||||
|
@ -56,7 +53,7 @@ public class AssociateEntityWithTwoSessionsTest extends BaseEntityManagerFunctio
|
|||
final Event event = new Event();
|
||||
event.setLocation( location );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
entityManager.persist( location );
|
||||
entityManager.persist( event );
|
||||
} );
|
||||
|
@ -64,12 +61,12 @@ public class AssociateEntityWithTwoSessionsTest extends BaseEntityManagerFunctio
|
|||
final Triggerable triggerable = logInspection.watchForLogMessages( "HHH000485" );
|
||||
triggerable.reset();
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
Event event1 = entityManager.find( Event.class, event.id );
|
||||
Location location1 = event1.getLocation();
|
||||
|
||||
try {
|
||||
doInJPA( this::entityManagerFactory, _entityManager -> {
|
||||
scope.inTransaction( _entityManager -> {
|
||||
_entityManager.unwrap( Session.class ).update( location1 );
|
||||
} );
|
||||
|
||||
|
@ -80,7 +77,7 @@ public class AssociateEntityWithTwoSessionsTest extends BaseEntityManagerFunctio
|
|||
} );
|
||||
|
||||
assertEquals(
|
||||
"HHH000485: Illegally attempted to associate a proxy for entity [org.hibernate.session.AssociateEntityWithTwoSessionsTest$Location] with id [1] with two open sessions.",
|
||||
"HHH000485: Illegally attempted to associate a proxy for entity [org.hibernate.orm.test.session.AssociateEntityWithTwoSessionsTest$Location] with id [1] with two open sessions.",
|
||||
triggerable.triggerMessage()
|
||||
);
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
* 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.sharedSession;
|
||||
package org.hibernate.orm.test.sharedSession;
|
||||
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.IrrelevantEntity;
|
||||
|
@ -18,8 +18,9 @@ import org.hibernate.persister.entity.EntityPersister;
|
|||
|
||||
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
|
@ -27,6 +28,8 @@ import java.util.Collection;
|
|||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
@ -36,11 +39,13 @@ import static org.junit.Assert.assertTrue;
|
|||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(annotatedClasses = IrrelevantEntity.class)
|
||||
@SessionFactory
|
||||
public class SessionWithSharedConnectionTest {
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-7090" )
|
||||
public void testSharedTransactionContextSessionClosing() {
|
||||
Session session = sessionFactory().openSession();
|
||||
public void testSharedTransactionContextSessionClosing(SessionFactoryScope scope) {
|
||||
Session session = scope.getSessionFactory().openSession();
|
||||
session.getTransaction().begin();
|
||||
|
||||
Session secondSession = session.sessionWithOptions()
|
||||
|
@ -81,8 +86,8 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
|||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-7090" )
|
||||
public void testSharedTransactionContextAutoClosing() {
|
||||
Session session = sessionFactory().openSession();
|
||||
public void testSharedTransactionContextAutoClosing(SessionFactoryScope scope) {
|
||||
Session session = scope.getSessionFactory().openSession();
|
||||
session.getTransaction().begin();
|
||||
|
||||
// COMMIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -108,7 +113,7 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
|||
|
||||
// ROLLBACK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
session = sessionFactory().openSession();
|
||||
session = scope.getSessionFactory().openSession();
|
||||
session.getTransaction().begin();
|
||||
|
||||
secondSession = session.sessionWithOptions()
|
||||
|
@ -134,7 +139,7 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
|||
// @Test
|
||||
// @TestForIssue( jiraKey = "HHH-7090" )
|
||||
// public void testSharedTransactionContextAutoJoining() {
|
||||
// Session session = sessionFactory().openSession();
|
||||
// Session session = scope.getSessionFactory().openSession();
|
||||
// session.getTransaction().begin();
|
||||
//
|
||||
// Session secondSession = session.sessionWithOptions()
|
||||
|
@ -151,8 +156,8 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
|||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-7090" )
|
||||
public void testSharedTransactionContextFlushBeforeCompletion() {
|
||||
Session session = sessionFactory().openSession();
|
||||
public void testSharedTransactionContextFlushBeforeCompletion(SessionFactoryScope scope) {
|
||||
Session session = scope.getSessionFactory().openSession();
|
||||
session.getTransaction().begin();
|
||||
|
||||
Session secondSession = session.sessionWithOptions()
|
||||
|
@ -174,7 +179,7 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
|||
assertTrue( ((SessionImplementor) session).isClosed() );
|
||||
assertTrue( ((SessionImplementor) secondSession).isClosed() );
|
||||
|
||||
session = sessionFactory().openSession();
|
||||
session = scope.getSessionFactory().openSession();
|
||||
session.getTransaction().begin();
|
||||
IrrelevantEntity it = (IrrelevantEntity) session.byId( IrrelevantEntity.class ).load( id );
|
||||
assertNotNull( it );
|
||||
|
@ -185,12 +190,12 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
|||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-7239" )
|
||||
public void testChildSessionCallsAfterTransactionAction() throws Exception {
|
||||
Session session = openSession();
|
||||
public void testChildSessionCallsAfterTransactionAction(SessionFactoryScope scope) throws Exception {
|
||||
Session session = scope.getSessionFactory().openSession();
|
||||
|
||||
final String postCommitMessage = "post commit was called";
|
||||
|
||||
EventListenerRegistry eventListenerRegistry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
|
||||
EventListenerRegistry eventListenerRegistry = scope.getSessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
|
||||
//register a post commit listener
|
||||
eventListenerRegistry.appendListeners(
|
||||
EventType.POST_COMMIT_INSERT,
|
||||
|
@ -233,8 +238,8 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
|||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-7239" )
|
||||
public void testChildSessionTwoTransactions() throws Exception {
|
||||
Session session = openSession();
|
||||
public void testChildSessionTwoTransactions(SessionFactoryScope scope) throws Exception {
|
||||
Session session = scope.getSessionFactory().openSession();
|
||||
|
||||
session.getTransaction().begin();
|
||||
|
||||
|
@ -257,33 +262,33 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
|||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-11830")
|
||||
public void testSharedSessionTransactionObserver() throws Exception {
|
||||
Session session = openSession();
|
||||
|
||||
session.getTransaction().begin();
|
||||
|
||||
public void testSharedSessionTransactionObserver(SessionFactoryScope scope) throws Exception {
|
||||
scope.inTransaction( session -> {
|
||||
Field field = null;
|
||||
Class<?> clazz = ((JdbcSessionOwner) session).getTransactionCoordinator().getClass();
|
||||
while (clazz != null) {
|
||||
Class<?> clazz = ( (JdbcSessionOwner) session ).getTransactionCoordinator().getClass();
|
||||
while ( clazz != null ) {
|
||||
try {
|
||||
field = clazz.getDeclaredField("observers");
|
||||
field.setAccessible(true);
|
||||
field = clazz.getDeclaredField( "observers" );
|
||||
field.setAccessible( true );
|
||||
break;
|
||||
} catch (NoSuchFieldException e) {
|
||||
}
|
||||
catch (NoSuchFieldException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException( e );
|
||||
}
|
||||
}
|
||||
assertNotNull("Observers field was not found", field);
|
||||
assertNotNull( "Observers field was not found", field );
|
||||
|
||||
try {
|
||||
//Some of these collections could be lazily initialize: check for null before invoking size()
|
||||
final Collection collection = (Collection) field.get( ( (SessionImplementor) session ).getTransactionCoordinator() );
|
||||
assertTrue(collection == null || collection.size() == 0 );
|
||||
final Collection collection = (Collection) field.get( session.getTransactionCoordinator() );
|
||||
assertTrue( collection == null || collection.size() == 0 );
|
||||
|
||||
//open secondary sessions with managed options and immediately close
|
||||
Session secondarySession;
|
||||
for (int i = 0; i < 10; i++){
|
||||
for ( int i = 0; i < 10; i++ ) {
|
||||
secondarySession = session.sessionWithOptions()
|
||||
.connection()
|
||||
.flushMode( FlushMode.COMMIT )
|
||||
|
@ -291,18 +296,24 @@ public class SessionWithSharedConnectionTest extends BaseCoreFunctionalTestCase
|
|||
.openSession();
|
||||
|
||||
//when the shared session is opened it should register an observer
|
||||
assertEquals(1, ((Collection) field.get(((JdbcSessionOwner) session).getTransactionCoordinator())).size());
|
||||
assertEquals(
|
||||
1,
|
||||
( (Collection) field.get( session.getTransactionCoordinator() ) ).size()
|
||||
);
|
||||
|
||||
//observer should be released
|
||||
secondarySession.close();
|
||||
|
||||
assertEquals(0, ((Collection) field.get(((JdbcSessionOwner) session).getTransactionCoordinator())).size());
|
||||
assertEquals(
|
||||
0,
|
||||
( (Collection) field.get( session.getTransactionCoordinator() ) ).size()
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException( e );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { IrrelevantEntity.class };
|
||||
}
|
||||
}
|
|
@ -4,7 +4,9 @@
|
|||
* 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.stat.internal;
|
||||
package org.hibernate.orm.test.stat.internal;
|
||||
|
||||
import org.hibernate.stat.internal.QueryStatisticsImpl;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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.orm.test.stat.internal;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.stat.SecondLevelCacheStatistics;
|
||||
import org.hibernate.stat.internal.StatisticsImpl;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNull.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@DomainModel
|
||||
@ServiceRegistry(settings = {
|
||||
@Setting( name = Environment.CACHE_REGION_PREFIX, value = ConcurrentStatisticsTest.REGION_PREFIX),
|
||||
@Setting( name = Environment.USE_SECOND_LEVEL_CACHE, value = "false")
|
||||
})
|
||||
@SessionFactory
|
||||
public class ConcurrentStatisticsTest {
|
||||
static final String REGION_PREFIX = "my-app";
|
||||
static final String TRIVIAL_REGION_NAME = "noname";
|
||||
|
||||
@Test
|
||||
public void testThatGetSecondLevelCacheStatisticsWhenSecondLevelCacheIsNotEnabledReturnsNull(SessionFactoryScope scope) {
|
||||
final SecondLevelCacheStatistics secondLevelCacheStatistics = new StatisticsImpl( scope.getSessionFactory() )
|
||||
.getSecondLevelCacheStatistics( StringHelper.qualify( REGION_PREFIX, TRIVIAL_REGION_NAME ) );
|
||||
assertThat( secondLevelCacheStatistics, is( nullValue() ) );
|
||||
}
|
||||
}
|
|
@ -4,11 +4,9 @@
|
|||
* 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.stat.internal;
|
||||
package org.hibernate.orm.test.stat.internal;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
@ -17,15 +15,20 @@ import javax.persistence.NamedQuery;
|
|||
import javax.persistence.Tuple;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.stat.QueryStatistics;
|
||||
import org.hibernate.stat.Statistics;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -33,33 +36,24 @@ import static org.junit.Assert.assertTrue;
|
|||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@DomainModel(annotatedClasses = {
|
||||
QueryPlanCacheStatisticsTest.Employee.class
|
||||
})
|
||||
@ServiceRegistry(settings = {
|
||||
@Setting( name = Environment.GENERATE_STATISTICS, value = "true")
|
||||
})
|
||||
@SessionFactory
|
||||
@TestForIssue(jiraKey = "HHH-12855")
|
||||
public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTestCase {
|
||||
public class QueryPlanCacheStatisticsTest {
|
||||
|
||||
private Statistics statistics;
|
||||
|
||||
@Override
|
||||
public Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Employee.class
|
||||
};
|
||||
}
|
||||
@BeforeAll
|
||||
protected void afterEntityManagerFactoryBuilt(SessionFactoryScope scope) {
|
||||
statistics = scope.getSessionFactory().getStatistics();
|
||||
|
||||
@Override
|
||||
protected void addConfigOptions(Map options) {
|
||||
options.put( Environment.GENERATE_STATISTICS, "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterEntityManagerFactoryBuilt() {
|
||||
SessionFactory sessionFactory = entityManagerFactory().unwrap( SessionFactory.class );
|
||||
statistics = sessionFactory.getStatistics();
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
for ( long i = 1; i <= 5; i++ ) {
|
||||
if ( i % 3 == 0 ) {
|
||||
entityManager.flush();
|
||||
}
|
||||
Employee employee = new Employee();
|
||||
employee.setName( String.format( "Employee: %d", i ) );
|
||||
entityManager.persist( employee );
|
||||
|
@ -67,14 +61,18 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
|||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
@BeforeEach
|
||||
protected void cleanup(SessionFactoryScope scope) {
|
||||
scope.getSessionFactory().getQueryEngine().getInterpretationCache().close();
|
||||
statistics.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test(SessionFactoryScope scope) {
|
||||
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
|
||||
assertEquals( 0, statistics.getQueryPlanCacheMissCount() );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
final String FIRST_QUERY = "select e from Employee e";
|
||||
|
||||
entityManager.createQuery( FIRST_QUERY );
|
||||
|
@ -125,10 +123,8 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
|||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13077" )
|
||||
public void testCreateQueryHitCount() {
|
||||
statistics.clear();
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testCreateQueryHitCount(SessionFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
||||
List<Employee> employees = entityManager.createQuery(
|
||||
"select e from Employee e", Employee.class )
|
||||
|
@ -142,7 +138,7 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
|||
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
|
||||
} );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
||||
List<Employee> employees = entityManager.createQuery(
|
||||
"select e from Employee e", Employee.class )
|
||||
|
@ -156,7 +152,7 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
|||
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
|
||||
} );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
||||
List<Employee> employees = entityManager.createQuery(
|
||||
"select e from Employee e", Employee.class )
|
||||
|
@ -173,12 +169,11 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
|||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13077" )
|
||||
public void testCreateNamedQueryHitCount() {
|
||||
//This is for the NamedQuery that gets compiled
|
||||
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
|
||||
public void testCreateNamedQueryHitCount(SessionFactoryScope scope) {
|
||||
// Compile the named queries
|
||||
scope.getSessionFactory().getQueryEngine().getNamedObjectRepository().checkNamedQueries( scope.getSessionFactory().getQueryEngine() );
|
||||
statistics.clear();
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
||||
Employee employees = entityManager.createNamedQuery(
|
||||
"find_employee_by_name", Employee.class )
|
||||
|
@ -191,7 +186,7 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
|||
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
|
||||
} );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
||||
Employee employees = entityManager.createNamedQuery(
|
||||
"find_employee_by_name", Employee.class )
|
||||
|
@ -207,10 +202,8 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
|||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13077" )
|
||||
public void testCreateQueryTupleHitCount() {
|
||||
statistics.clear();
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testCreateQueryTupleHitCount(SessionFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
||||
List<Tuple> employees = entityManager.createQuery(
|
||||
"select e.id, e.name from Employee e", Tuple.class )
|
||||
|
@ -224,7 +217,7 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
|||
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
|
||||
} );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
||||
List<Tuple> employees = entityManager.createQuery(
|
||||
"select e.id, e.name from Employee e", Tuple.class )
|
||||
|
@ -238,7 +231,7 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
|||
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
|
||||
} );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
|
||||
List<Tuple> employees = entityManager.createQuery(
|
||||
"select e.id, e.name from Employee e", Tuple.class )
|
||||
|
@ -255,10 +248,8 @@ public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTes
|
|||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-13077")
|
||||
public void testLockModeHitCount() {
|
||||
statistics.clear();
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testLockModeHitCount(SessionFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
TypedQuery<Employee> typedQuery = entityManager.createQuery( "select e from Employee e", Employee.class );
|
||||
|
||||
List<Employee> employees = typedQuery.getResultList();
|
|
@ -4,7 +4,9 @@
|
|||
* 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.stat.internal;
|
||||
package org.hibernate.orm.test.stat.internal;
|
||||
|
||||
import org.hibernate.stat.internal.StatsNamedContainer;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
|
@ -1,45 +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.persister.entity;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
public class FormulaTemplateSchemaSubstitutionTest extends AbstractSchemaSubstitutionFormulaTest {
|
||||
|
||||
private static final String CUSTOM_SCHEMA = "CUSTOM_SCHEMA";
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
final Properties properties = new Properties();
|
||||
properties.put( "hibernate.default_schema", CUSTOM_SCHEMA );
|
||||
configuration.addProperties( properties );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createSecondSchema() {
|
||||
return CUSTOM_SCHEMA;
|
||||
}
|
||||
|
||||
@Override
|
||||
void validate(String formula) {
|
||||
assertEquals( "Formula should not contain {} characters",
|
||||
4, formula.split( CUSTOM_SCHEMA + ".", -1 ).length - 1
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package org.hibernate.procedure.internal;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Nathan Xu
|
||||
*/
|
||||
public class ProcedureCallImplTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13644" )
|
||||
@RequiresDialect( H2Dialect.class )
|
||||
public void testNoNullPointerExceptionThrown() {
|
||||
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
||||
em.getTransaction().begin();
|
||||
|
||||
em.createNativeQuery("CREATE ALIAS GET_RANDOM_VALUE FOR \"java.lang.Math.random\";").executeUpdate();
|
||||
|
||||
Query query = em.createStoredProcedureQuery("GET_RANDOM_VALUE");
|
||||
|
||||
Stream stream = query.getResultStream();
|
||||
|
||||
Assert.assertEquals(1, stream.count());
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.close();
|
||||
}
|
||||
}
|
|
@ -1,55 +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.property;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Michael Rudolf
|
||||
*/
|
||||
public class DirectPropertyAccessorTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
@TestForIssue( jiraKey="HHH-3718" )
|
||||
public void testDirectIdPropertyAccess() throws Exception {
|
||||
Session s = openSession();
|
||||
final Transaction transaction = s.beginTransaction();
|
||||
Item i = new Item();
|
||||
s.persist( i );
|
||||
Order o = new Order();
|
||||
o.setOrderNumber( 1 );
|
||||
o.getItems().add( i );
|
||||
s.persist( o );
|
||||
transaction.commit();
|
||||
s.clear();
|
||||
|
||||
o = ( Order ) s.load( Order.class, 1 );
|
||||
assertFalse( Hibernate.isInitialized( o ) );
|
||||
o.getOrderNumber();
|
||||
// If you mapped with field access, any method, except id, call initializes the proxy
|
||||
assertFalse( Hibernate.isInitialized( o ) );
|
||||
o.getName();
|
||||
assertTrue( Hibernate.isInitialized( o ) );
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Order.class,
|
||||
Item.class,
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,59 +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.stat.internal;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.stat.SecondLevelCacheStatistics;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNull.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class ConcurrentStatisticsTest extends BaseCoreFunctionalTestCase {
|
||||
private static final String REGION_PREFIX = "my-app";
|
||||
private static final String TRIVIAL_REGION_NAME = "noname";
|
||||
|
||||
private StatisticsImpl statistics;
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
sessionFactory = sessionFactory();
|
||||
statistics = new StatisticsImpl( (SessionFactoryImplementor) sessionFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
configuration.setProperty( AvailableSettings.CACHE_REGION_PREFIX, REGION_PREFIX );
|
||||
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" );
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
sessionFactory.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatGetSecondLevelCacheStatisticsWhenSecondLevelCacheIsNotEnabledReturnsNull() {
|
||||
final SecondLevelCacheStatistics secondLevelCacheStatistics = statistics
|
||||
.getSecondLevelCacheStatistics( StringHelper.qualify( REGION_PREFIX, TRIVIAL_REGION_NAME ) );
|
||||
assertThat( secondLevelCacheStatistics, is( nullValue() ) );
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
-->
|
||||
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping">
|
||||
<class name="org.hibernate.property.GetAndIsVariantGetterTest$TheEntity">
|
||||
<class name="org.hibernate.orm.test.property.GetAndIsVariantGetterTest$TheEntity">
|
||||
<id name="id"/>
|
||||
</class>
|
||||
</hibernate-mapping>
|
|
@ -35,11 +35,6 @@ dependencies {
|
|||
testRuntime( libraries.log4j )
|
||||
}
|
||||
|
||||
// resources inherently exclude sources
|
||||
sourceSets.test.resources {
|
||||
setSrcDirs( ['src/test/java'] )
|
||||
}
|
||||
|
||||
// todo : Fold into hibernate-core and publish in separate publications
|
||||
// once http://issues.gradle.org/browse/GRADLE-2966 is resolved;
|
||||
// that will allow us to keep the same artifactId and publish the pom
|
||||
|
|
|
@ -6,11 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.testing.annotations;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
@ -19,16 +16,7 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||
@Jpa(
|
||||
annotatedClasses = {
|
||||
AnEntity.class
|
||||
},
|
||||
properties = {
|
||||
@Setting( name = AvailableSettings.JPA_JDBC_URL, value = "jdbc:h2:mem:test_db" ),
|
||||
@Setting( name = AvailableSettings.JPA_JDBC_USER, value = "tester" )
|
||||
}
|
||||
// works with either
|
||||
// integrationSettings = {
|
||||
// @Setting( name = AvailableSettings.JPA_JDBC_URL, value = "jdbc:h2:mem:test_db" ),
|
||||
// @Setting( name = AvailableSettings.JPA_JDBC_USER, value = "tester" )
|
||||
// }
|
||||
)
|
||||
public class BasicEntityManagerFactoryScopeTests {
|
||||
@Test
|
||||
|
|
|
@ -6,19 +6,18 @@
|
|||
*/
|
||||
package org.hibernate.testing.annotations;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@ServiceRegistry( settings = @Setting( name = AvailableSettings.URL, value = "jdbc:h2:mem:test_db" ) )
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
@DomainModel( annotatedClasses = AnEntity.class )
|
||||
@SessionFactory
|
||||
public class BasicSessionFactoryScopeTests {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# 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>.
|
||||
#
|
||||
|
||||
hibernate.dialect @db.dialect@
|
||||
hibernate.connection.driver_class @jdbc.driver@
|
||||
hibernate.connection.url @jdbc.url@
|
||||
hibernate.connection.username @jdbc.user@
|
||||
hibernate.connection.password @jdbc.pass@
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql false
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||
|
||||
javax.persistence.validation.mode=NONE
|
||||
hibernate.service.allow_crawling=false
|
||||
hibernate.session.events.log=true
|
||||
hibernate.hql.bulk_id_strategy.global_temporary.drop_tables=true
|
Loading…
Reference in New Issue