Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 8cc6db6

Browse files
committed
5.2 only cleanup
1 parent 8f13724 commit 8cc6db6

12 files changed

+276
-103
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ groovyVersion=2.4.11
44
springBootVersion=1.4.5.RELEASE
55
springVersion=4.3.9.RELEASE
66
hibernateVersion=4.3.11
7-
hibernate5Version=5.1.9.Final
7+
hibernate5Version=5.2.11.Final
88
hibernateValidatorVersion=5.2.5.Final
99
mongodbRxDriverVersion=1.3.1

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/GrailsHibernateTemplate.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
2121
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
22-
import org.grails.orm.hibernate.support.HibernateVersionSupport;
2322
import org.hibernate.*;
2423
import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl;
2524
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
@@ -665,7 +664,7 @@ protected FlushMode applyFlushMode(Session session, boolean existingTransaction)
665664

666665
if (getFlushMode() == FLUSH_NEVER) {
667666
if (existingTransaction) {
668-
FlushMode previousFlushMode = HibernateVersionSupport.getFlushMode(session);
667+
FlushMode previousFlushMode = session.getHibernateFlushMode();
669668
if (!previousFlushMode.lessThan(FlushMode.COMMIT)) {
670669
session.setFlushMode(FlushMode.MANUAL);
671670
return previousFlushMode;
@@ -675,7 +674,7 @@ protected FlushMode applyFlushMode(Session session, boolean existingTransaction)
675674
}
676675
} else if (getFlushMode() == FLUSH_EAGER) {
677676
if (existingTransaction) {
678-
FlushMode previousFlushMode = HibernateVersionSupport.getFlushMode(session);
677+
FlushMode previousFlushMode = session.getHibernateFlushMode();
679678
if (!previousFlushMode.equals(FlushMode.AUTO)) {
680679
session.setFlushMode(FlushMode.AUTO);
681680
return previousFlushMode;
@@ -685,7 +684,7 @@ protected FlushMode applyFlushMode(Session session, boolean existingTransaction)
685684
}
686685
} else if (getFlushMode() == FLUSH_COMMIT) {
687686
if (existingTransaction) {
688-
FlushMode previousFlushMode = HibernateVersionSupport.getFlushMode(session);
687+
FlushMode previousFlushMode = session.getHibernateFlushMode();
689688
if (previousFlushMode.equals(FlushMode.AUTO) || previousFlushMode.equals(FlushMode.ALWAYS)) {
690689
session.setFlushMode(FlushMode.COMMIT);
691690
return previousFlushMode;
@@ -695,7 +694,7 @@ protected FlushMode applyFlushMode(Session session, boolean existingTransaction)
695694
}
696695
} else if (getFlushMode() == FLUSH_ALWAYS) {
697696
if (existingTransaction) {
698-
FlushMode previousFlushMode = HibernateVersionSupport.getFlushMode(session);
697+
FlushMode previousFlushMode = session.getHibernateFlushMode();
699698
if (!previousFlushMode.equals(FlushMode.ALWAYS)) {
700699
session.setFlushMode(FlushMode.ALWAYS);
701700
return previousFlushMode;

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/GrailsHibernateTransactionManager.groovy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package org.grails.orm.hibernate
1717

1818
import groovy.transform.CompileStatic
1919
import groovy.util.logging.Slf4j
20-
import org.grails.orm.hibernate.support.HibernateVersionSupport
2120
import org.hibernate.FlushMode
2221
import org.hibernate.Session
2322
import org.hibernate.SessionFactory
@@ -70,11 +69,11 @@ class GrailsHibernateTransactionManager extends HibernateTransactionManager {
7069
// always set to manual; the base class doesn't because the OSIV has already registered a session
7170

7271
SessionHolder holder = (SessionHolder)TransactionSynchronizationManager.getResource(sessionFactory)
73-
HibernateVersionSupport.setFlushMode(holder.getSession(), FlushMode.MANUAL)
72+
holder.session.setHibernateFlushMode(FlushMode.MANUAL)
7473
}
7574
else if(defaultFlushMode != FlushMode.AUTO) {
7675
SessionHolder holder = (SessionHolder)TransactionSynchronizationManager.getResource(sessionFactory)
77-
HibernateVersionSupport.setFlushMode(holder.getSession(), defaultFlushMode)
76+
holder.session.setHibernateFlushMode(defaultFlushMode)
7877
}
7978
}
8079

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/GrailsSessionContext.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717

1818
import org.apache.commons.logging.Log;
1919
import org.apache.commons.logging.LogFactory;
20-
import org.grails.orm.hibernate.support.HibernateVersionSupport;
2120
import org.hibernate.FlushMode;
2221
import org.hibernate.HibernateException;
2322
import org.hibernate.Session;
2423
import org.hibernate.SessionFactory;
2524
import org.hibernate.context.spi.CurrentSessionContext;
2625
import org.hibernate.engine.spi.SessionFactoryImplementor;
2726
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
28-
import org.hibernate.internal.util.ReflectHelper;
2927
import org.hibernate.service.spi.ServiceBinding;
3028
import org.springframework.dao.DataAccessResourceFailureException;
3129
import org.springframework.orm.hibernate5.SessionHolder;
@@ -35,13 +33,10 @@
3533
import org.springframework.transaction.jta.SpringJtaSynchronizationAdapter;
3634
import org.springframework.transaction.support.TransactionSynchronization;
3735
import org.springframework.transaction.support.TransactionSynchronizationManager;
38-
import org.springframework.util.ReflectionUtils;
3936

4037
import javax.transaction.Status;
4138
import javax.transaction.Transaction;
4239
import javax.transaction.TransactionManager;
43-
import java.lang.reflect.Constructor;
44-
import java.lang.reflect.InvocationTargetException;
4540

4641
/**
4742
* Based on org.springframework.orm.hibernate4.SpringSessionContext.
@@ -92,9 +87,9 @@ public Session currentSession() throws HibernateException {
9287
sessionHolder.setSynchronizedWithTransaction(true);
9388
// Switch to FlushMode.AUTO, as we have to assume a thread-bound Session
9489
// with FlushMode.MANUAL, which needs to allow flushing within the transaction.
95-
FlushMode flushMode = HibernateVersionSupport.getFlushMode(session);
90+
FlushMode flushMode = session.getHibernateFlushMode();
9691
if (flushMode.equals(FlushMode.MANUAL) && !TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
97-
HibernateVersionSupport.setFlushMode(session, FlushMode.AUTO);
92+
session.setHibernateFlushMode(FlushMode.AUTO);
9893
sessionHolder.setPreviousFlushMode(flushMode);
9994
}
10095
}
@@ -138,7 +133,7 @@ private Session createSession(Object resource) {
138133
// holderToUse.addSession(session);
139134
}
140135
if (TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
141-
session.setFlushMode(FlushMode.MANUAL);
136+
session.setHibernateFlushMode(FlushMode.MANUAL);
142137
}
143138
TransactionSynchronizationManager.registerSynchronization(createSpringSessionSynchronization(holderToUse));
144139
holderToUse.setSynchronizedWithTransaction(true);

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/HibernateDatastore.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,12 @@
5151
import org.grails.orm.hibernate.event.listener.HibernateEventListener;
5252
import org.grails.orm.hibernate.multitenancy.MultiTenantEventListener;
5353
import org.grails.orm.hibernate.support.ClosureEventTriggeringInterceptor;
54-
import org.grails.orm.hibernate.support.HibernateVersionSupport;
55-
import org.hibernate.FlushMode;
5654
import org.hibernate.SessionFactory;
5755
import org.hibernate.boot.SchemaAutoTooling;
5856
import org.hibernate.cfg.Environment;
5957
import org.slf4j.Logger;
6058
import org.slf4j.LoggerFactory;
61-
import org.springframework.beans.BeanUtils;
6259
import org.springframework.beans.BeansException;
63-
import org.springframework.beans.factory.annotation.Autowired;
6460
import org.springframework.context.*;
6561
import org.springframework.context.support.StaticMessageSource;
6662
import org.springframework.core.env.PropertyResolver;
@@ -473,8 +469,8 @@ public void withFlushMode(FlushMode flushMode, Callable<Boolean> callable) {
473469
Boolean reset = true;
474470
try {
475471
if (session != null) {
476-
previousMode = HibernateVersionSupport.getFlushMode(session);
477-
HibernateVersionSupport.setFlushMode(session, org.hibernate.FlushMode.valueOf(flushMode.name()));
472+
previousMode = session.getHibernateFlushMode();
473+
session.setHibernateFlushMode(org.hibernate.FlushMode.valueOf(flushMode.name()));
478474
}
479475
try {
480476
reset = callable.call();
@@ -484,15 +480,15 @@ public void withFlushMode(FlushMode flushMode, Callable<Boolean> callable) {
484480
}
485481
finally {
486482
if (session != null && previousMode != null && reset) {
487-
HibernateVersionSupport.setFlushMode(session, previousMode);
483+
session.setHibernateFlushMode(previousMode);
488484
}
489485
}
490486
}
491487

492488
@Override
493489
public org.hibernate.Session openSession() {
494490
org.hibernate.Session session = this.sessionFactory.openSession();
495-
HibernateVersionSupport.setFlushMode(session, org.hibernate.FlushMode.valueOf(defaultFlushModeName));
491+
session.setHibernateFlushMode(org.hibernate.FlushMode.valueOf(defaultFlushModeName));
496492
return session;
497493
}
498494

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import org.grails.orm.hibernate.exceptions.GrailsQueryException
2929
import org.grails.orm.hibernate.query.GrailsHibernateQueryUtils
3030
import org.grails.orm.hibernate.query.HibernateHqlQuery
3131
import org.grails.orm.hibernate.query.HibernateQuery
32-
import org.grails.orm.hibernate.support.HibernateVersionSupport
3332
import org.hibernate.*
33+
import org.hibernate.query.Query
3434
import org.springframework.core.convert.ConversionService
3535
import org.springframework.orm.hibernate5.SessionHolder
3636
import org.springframework.transaction.PlatformTransactionManager
@@ -121,7 +121,7 @@ class HibernateGormStaticApi<D> extends AbstractHibernateGormStaticApi<D> {
121121
def template = hibernateTemplate
122122
SessionFactory sessionFactory = this.sessionFactory
123123
return (Integer) template.execute { Session session ->
124-
Query q = HibernateVersionSupport.createQuery(session,query.toString())
124+
Query q = session.createQuery(query.toString())
125125
template.applySettings(q)
126126
def sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource( sessionFactory )
127127
if (sessionHolder && sessionHolder.hasTimeout()) {
@@ -148,7 +148,7 @@ class HibernateGormStaticApi<D> extends AbstractHibernateGormStaticApi<D> {
148148
SessionFactory sessionFactory = this.sessionFactory
149149

150150
return (Integer) template.execute { Session session ->
151-
Query q = HibernateVersionSupport.createQuery(session,query.toString())
151+
Query q = session.createQuery(query.toString())
152152
template.applySettings(q)
153153
def sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource( sessionFactory )
154154
if (sessionHolder && sessionHolder.hasTimeout()) {
@@ -203,7 +203,7 @@ class HibernateGormStaticApi<D> extends AbstractHibernateGormStaticApi<D> {
203203
@Override
204204
protected HibernateHqlQuery createHqlQuery(Session session, Query q) {
205205
HibernateSession hibernateSession = new HibernateSession((HibernateDatastore) datastore, sessionFactory)
206-
FlushMode hibernateMode = HibernateVersionSupport.getFlushMode(session)
206+
FlushMode hibernateMode = session.getHibernateFlushMode()
207207
switch (hibernateMode) {
208208
case FlushMode.AUTO:
209209
hibernateSession.setFlushMode(FlushModeType.AUTO)

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/HibernateGormValidationApi.groovy

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package org.grails.orm.hibernate
1717

1818
import groovy.transform.CompileStatic
19-
import org.grails.orm.hibernate.support.HibernateRuntimeUtils
20-
import org.grails.orm.hibernate.support.HibernateVersionSupport
2119
import org.hibernate.FlushMode
2220
import org.hibernate.Session
2321

@@ -32,17 +30,17 @@ class HibernateGormValidationApi<D> extends AbstractHibernateGormValidationApi<D
3230
@Override
3331
void restoreFlushMode(Session session, Object previousFlushMode) {
3432
if(previousFlushMode != null) {
35-
HibernateVersionSupport.setFlushMode(session, (FlushMode)previousFlushMode)
33+
session.setHibernateFlushMode((FlushMode)previousFlushMode)
3634
}
3735
}
3836

3937
@Override
4038
Object readPreviousFlushMode(Session session) {
41-
return HibernateVersionSupport.getFlushMode(session)
39+
return session.getHibernateFlushMode()
4240
}
4341

4442
@Override
4543
def applyManualFlush(Session session) {
46-
HibernateVersionSupport.setFlushMode(session, FlushMode.MANUAL)
44+
session.setHibernateFlushMode(FlushMode.MANUAL)
4745
}
4846
}

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/HibernateSession.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.grails.datastore.mapping.query.jpa.JpaQueryBuilder;
3838
import org.grails.datastore.mapping.query.jpa.JpaQueryInfo;
3939
import org.grails.datastore.mapping.reflect.ClassPropertyFetcher;
40-
import org.grails.orm.hibernate.support.HibernateVersionSupport;
4140
import org.hibernate.*;
4241
import org.hibernate.criterion.Restrictions;
4342
import org.hibernate.proxy.HibernateProxy;
@@ -92,7 +91,7 @@ public Integer doInHibernate(Session session) throws HibernateException, SQLExce
9291
builder.setHibernateCompatible(true);
9392
JpaQueryInfo jpaQueryInfo = builder.buildDelete();
9493

95-
org.hibernate.Query query = HibernateVersionSupport.createQuery(session, jpaQueryInfo.getQuery());
94+
org.hibernate.query.Query query = session.createQuery(jpaQueryInfo.getQuery());
9695
getHibernateTemplate().applySettings(query);
9796

9897
List parameters = jpaQueryInfo.getParameters();
@@ -133,7 +132,7 @@ public Integer doInHibernate(Session session) throws HibernateException, SQLExce
133132

134133
JpaQueryInfo jpaQueryInfo = builder.buildUpdate(properties);
135134

136-
org.hibernate.Query query = HibernateVersionSupport.createQuery(session, jpaQueryInfo.getQuery());
135+
org.hibernate.query.Query query = session.createQuery(jpaQueryInfo.getQuery());
137136
getHibernateTemplate().applySettings(query);
138137
List parameters = jpaQueryInfo.getParameters();
139138
if (parameters != null) {

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ protected void bindEnumType(PersistentProperty property, Class<?> propertyType,
20582058
enumProperties.put(EnumType.NAMED, Boolean.TRUE.toString());
20592059
}
20602060
else if("identity".equals(enumType)) {
2061-
simpleValue.setTypeName(HibernateUtils.buildIdentityEnumTypeFactory().getName());
2061+
simpleValue.setTypeName(IdentityEnumType.class.getName());
20622062
}
20632063
else if (!"ordinal".equalsIgnoreCase(enumType)) {
20642064
simpleValue.setTypeName(enumType);

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/cfg/HibernateUtils.groovy

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -34,70 +34,7 @@ import org.springframework.beans.PropertyAccessorFactory
3434
@CompileStatic
3535
class HibernateUtils {
3636

37-
private static Class identityEnumTypeFactory
3837

39-
/**
40-
* Build the identity enum type factory. We dynamically implement the UserType interface to avoid the differences between different Hibernate versions
41-
*/
42-
static Class buildIdentityEnumTypeFactory() {
43-
if(identityEnumTypeFactory == null) {
44-
try {
45-
String superClassName = AbstractIdentityEnumType.name
46-
ClassPool pool = ClassPool.default
47-
CtClass superClass = pool.getOrNull(superClassName)
48-
if(superClass == null) {
49-
pool.appendClassPath(
50-
new LoaderClassPath(HibernateUtils.classLoader)
51-
)
52-
}
53-
54-
superClass = pool.get(superClassName)
55-
CtClass clz = pool.makeClass("${AbstractIdentityEnumType.package.name}.IdentityEnumType", superClass)
56-
57-
CtMethod[] superClassMethods = superClass.getMethods()
58-
CtMethod nullSafeGetMethod = superClassMethods.find { CtMethod m -> m.name == 'nullSafeGet' }
59-
CtClass[] parameterTypes = nullSafeGetMethod.getParameterTypes()
60-
CtMethod newNullSafeGetMethod = new CtMethod(nullSafeGetMethod.getReturnType(), nullSafeGetMethod.name, parameterTypes, clz)
61-
newNullSafeGetMethod.setBody(
62-
'''{
63-
Object id = type.nullSafeGet($1, $2[0], $3);
64-
if ((!$1.wasNull()) && id != null) {
65-
return bidiMap.getEnumValue(id);
66-
}
67-
return null;
68-
}'''
69-
)
70-
71-
clz.addMethod(
72-
newNullSafeGetMethod
73-
)
74-
75-
CtMethod nullSafeSetMethod = superClassMethods.find { CtMethod m -> m.name == 'nullSafeSet' }
76-
def nullSafeSetParams = nullSafeSetMethod.getParameterTypes()
77-
CtMethod newNullSafeSetMethod = new CtMethod(nullSafeSetMethod.getReturnType(), nullSafeSetMethod.name, nullSafeSetParams, clz)
78-
newNullSafeSetMethod.setBody(
79-
'''{
80-
if ($2 == null) {
81-
$1.setNull($3, sqlTypes[0]);
82-
}
83-
else {
84-
type.nullSafeSet($1, bidiMap.getKey($2), $3, $4);
85-
}
86-
}'''
87-
)
88-
89-
clz.addMethod(
90-
newNullSafeSetMethod
91-
)
92-
93-
94-
identityEnumTypeFactory = clz.toClass()
95-
} catch (Throwable e) {
96-
throw new ConfigurationException("Unable to build identity enum type factory, probably due to a classpath conflict. Check the version of Hibernate on the path is correct (should be Hibernate 5+): ${e.message}", e)
97-
}
98-
}
99-
return identityEnumTypeFactory
100-
}
10138

10239
/**
10340
* Overrides a getter on a property that is a Hibernate proxy in order to make sure the initialized object is returned hence avoiding Hibernate proxy hell.

0 commit comments

Comments
 (0)