Reset connection pool after changing system TZ. Don't use distinct predicate when comparing primary keys in envers
This commit is contained in:
parent
dcd4479cf1
commit
360fec82f1
|
@ -31,6 +31,7 @@ import org.hibernate.dialect.H2Dialect;
|
|||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.jdbc.SharedDriverManagerConnectionProviderImpl;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.junit4.CustomParameterized;
|
||||
import org.hibernate.testing.orm.junit.DialectContext;
|
||||
|
@ -199,6 +200,8 @@ public abstract class AbstractJavaTimeTypeTest<T, E> extends BaseCoreFunctionalT
|
|||
protected final void withDefaultTimeZone(Runnable runnable) {
|
||||
TimeZone timeZoneBefore = TimeZone.getDefault();
|
||||
TimeZone.setDefault( toTimeZone( env.defaultJvmTimeZone ) );
|
||||
// Clear the connection pool to avoid issues with drivers that initialize the session TZ to the system TZ
|
||||
SharedDriverManagerConnectionProviderImpl.getInstance().reset();
|
||||
/*
|
||||
* Run the code in a new thread, because some libraries (looking at you, h2 JDBC driver)
|
||||
* cache data dependent on the default timezone in thread local variables,
|
||||
|
@ -227,6 +230,8 @@ public abstract class AbstractJavaTimeTypeTest<T, E> extends BaseCoreFunctionalT
|
|||
}
|
||||
finally {
|
||||
TimeZone.setDefault( timeZoneBefore );
|
||||
// Clear the connection pool to avoid issues with drivers that initialize the session TZ to the system TZ
|
||||
SharedDriverManagerConnectionProviderImpl.getInstance().reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
junit.jupiter.testclass.order.default=org.junit.jupiter.api.ClassOrderer$ClassName
|
|
@ -65,6 +65,29 @@ public abstract class AbstractIdMapper extends AbstractMapper implements IdMappe
|
|||
|
||||
final Parameters parametersToUse = getParametersToUse( parameters, paramDatas1 );
|
||||
|
||||
final Iterator<QueryParameterData> paramDataIter1 = paramDatas1.iterator();
|
||||
final Iterator<QueryParameterData> paramDataIter2 = paramDatas2.iterator();
|
||||
while ( paramDataIter1.hasNext() ) {
|
||||
final QueryParameterData paramData1 = paramDataIter1.next();
|
||||
final QueryParameterData paramData2 = paramDataIter2.next();
|
||||
|
||||
parametersToUse.addWhere(
|
||||
paramData1.getProperty( prefix1 ),
|
||||
false,
|
||||
"=",
|
||||
paramData2.getProperty( prefix2 ),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNullableIdsEqualToQuery(Parameters parameters, String prefix1, IdMapper mapper2, String prefix2) {
|
||||
final List<QueryParameterData> paramDatas1 = mapToQueryParametersFromId( null );
|
||||
final List<QueryParameterData> paramDatas2 = mapper2.mapToQueryParametersFromId( null );
|
||||
|
||||
final Parameters parametersToUse = getParametersToUse( parameters, paramDatas1 );
|
||||
|
||||
final Iterator<QueryParameterData> paramDataIter1 = paramDatas1.iterator();
|
||||
final Iterator<QueryParameterData> paramDataIter2 = paramDatas2.iterator();
|
||||
while ( paramDataIter1.hasNext() ) {
|
||||
|
|
|
@ -83,6 +83,19 @@ public interface IdMapper {
|
|||
*/
|
||||
void addIdsEqualToQuery(Parameters parameters, String prefix1, IdMapper mapper2, String prefix2);
|
||||
|
||||
/**
|
||||
* Adds query statements, which contains restrictions, which express the property that the id of the entity
|
||||
* with alias prefix1, is equal to the id of the entity with alias prefix2 mapped by the second mapper
|
||||
* (the second mapper must be for the same entity, but it can have, for example, prefixed properties).
|
||||
*
|
||||
* @param parameters Parameters, to which to add the statements.
|
||||
* @param prefix1 First alias of the entity + prefix to add to the properties.
|
||||
* @param mapper2 Second mapper for the same entity, which will be used to get properties for the right side
|
||||
* of the equation.
|
||||
* @param prefix2 Second alias of the entity + prefix to add to the properties.
|
||||
*/
|
||||
void addNullableIdsEqualToQuery(Parameters parameters, String prefix1, IdMapper mapper2, String prefix2);
|
||||
|
||||
/**
|
||||
* Adds query statements, which contains restrictions, which express the property that the id of the entity
|
||||
* with alias prefix, is equal to the given object.
|
||||
|
|
|
@ -193,7 +193,7 @@ public class ToOneIdMapper extends AbstractToOneMapper {
|
|||
String prefix1,
|
||||
String idPrefix2,
|
||||
String prefix2) {
|
||||
delegate.addIdsEqualToQuery( parameters, prefix1, delegate, prefix2 );
|
||||
delegate.addNullableIdsEqualToQuery( parameters, prefix1, delegate, prefix2 );
|
||||
}
|
||||
|
||||
// todo: is referenced entity needed any longer?
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.TimeZone;
|
|||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
|
||||
import org.hibernate.testing.jdbc.ConnectionProviderDelegate;
|
||||
import org.hibernate.testing.jdbc.SharedDriverManagerConnectionProviderImpl;
|
||||
|
||||
/**
|
||||
* This {@link ConnectionProvider} extends any other ConnectionProvider that would be used by default taken the current configuration properties, and it
|
||||
|
@ -28,6 +29,8 @@ public class TimeZoneConnectionProvider
|
|||
this.customTimeZone = customTimeZone;
|
||||
this.defaultTimeZone = System.setProperty( "user.timezone", customTimeZone);
|
||||
TimeZone.setDefault(TimeZone.getTimeZone( customTimeZone ));
|
||||
// Clear the connection pool to avoid issues with drivers that initialize the session TZ to the system TZ
|
||||
SharedDriverManagerConnectionProviderImpl.getInstance().reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,5 +38,7 @@ public class TimeZoneConnectionProvider
|
|||
super.stop();
|
||||
System.setProperty( "user.timezone", defaultTimeZone);
|
||||
TimeZone.setDefault(TimeZone.getTimeZone( defaultTimeZone ));
|
||||
// Clear the connection pool to avoid issues with drivers that initialize the session TZ to the system TZ
|
||||
SharedDriverManagerConnectionProviderImpl.getInstance().reset();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue