Skip to content

Commit

Permalink
Merge pull request #871 from xael-fry/1944_hibernateUpdateMaster
Browse files Browse the repository at this point in the history
[#1944] hibernate update to v4.2.19
  • Loading branch information
xael-fry committed May 13, 2015
2 parents 0575956 + 2ce4af5 commit fbe5d8d
Show file tree
Hide file tree
Showing 15 changed files with 643 additions and 535 deletions.
8 changes: 8 additions & 0 deletions documentation/manual/configuration.textile
Original file line number Diff line number Diff line change
Expand Up @@ -951,4 +951,12 @@ A comma-separated list of IP addresses that are allowed @X-Forwarded-For@ HTTP r

Default: @127.0.0.1@

h2(#enhancers). Enhancers

h3(#play.propertiesEnhancer.enabled). play.propertiesEnhancer.enabled

Used to disable play enhancing of play class (can be used to switch off getter/setter generation). For example:

bc. play.propertiesEnhancer.enabled=false

Default: @true@
6 changes: 3 additions & 3 deletions framework/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ require: &allDependencies
- org.bouncycastle -> bcprov-jdk15 1.45
- org.codehaus.groovy -> groovy-all 2.3.9
- org.eclipse.jdt.core 3.10.0.v20140604-1726
- org.hibernate -> hibernate-core 4.2.15.Final
- org.hibernate -> hibernate-core 4.2.19.Final
- org.hibernate -> hibernate-commons-annotations 4.0.2.Final
- org.hibernate -> hibernate-entitymanager 4.2.15.Final
- org.hibernate -> hibernate-entitymanager 4.2.19.Final
- org.hibernate -> hibernate-validator 4.1.0.Final
- org.hibernate -> jboss-logging 3.1.0.GA
- org.hibernate -> jboss-transaction-api_1.1_spec 1.0.1.Final
- org.hibernate.javax.persistence -> hibernate-jpa-2.0-api 1.0.1.Final
- org.hibernate -> hibernate-c3p0 4.2.15.Final
- org.hibernate -> hibernate-c3p0 4.2.19.Final
- com.mchange -> mchange-commons-java 0.2.9
- org.javassist -> javassist 3.19.0-GA
- org.jboss.netty -> netty 3.9.4.Final
Expand Down
Binary file removed framework/lib/hibernate-c3p0-4.2.15.Final.jar
Binary file not shown.
Binary file added framework/lib/hibernate-c3p0-4.2.19.Final.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 0 additions & 6 deletions framework/patches/hibernate-4.2.15-patch-play.README

This file was deleted.

6 changes: 6 additions & 0 deletions framework/patches/hibernate-4.2.19-patch-play.README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
----
Download Hibernate 4.2.19.Final source code, apply the patch, and build with gradle (tip use export GRADLE_OPTS=-Xmx1G -XX:MaxPermSize=512m)
----

DRY RUN -> patch --dry-run -p1 -i hibernate-4.2.19-patch-play.patch
APPLY -> patch -p1 -i hibernate-4.2.19-patch-play.patch
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class PropertiesEnhancer extends Enhancer {
@Override
public void enhanceThisClass(ApplicationClass applicationClass) throws Exception {

if(!Boolean.parseBoolean(Play.configuration.getProperty("play.propertiesEnhancer.enabled", "true"))) return;

final CtClass ctClass = makeClass(applicationClass);
if (ctClass.isInterface()) {
return;
Expand Down
102 changes: 102 additions & 0 deletions framework/src/play/db/jpa/HibernateInterceptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package play.db.jpa;

import java.io.Serializable;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.CallbackException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.type.Type;

//Explicit SAVE for JPABase is implemented here
// ~~~~~~
// We've hacked the org.hibernate.event.def.AbstractFlushingEventListener line 271, to flush collection update,remove,recreation
// only if the owner will be saved or if the targeted entity will be saved (avoid the org.hibernate.HibernateException: Found two representations of same collection)
// As is:
// if (session.getInterceptor().onCollectionUpdate(coll, ce.getLoadedKey())) {
// actionQueue.addAction(...);
// }
//
// This is really hacky. We should move to something better than Hibernate like EBEAN
public class HibernateInterceptor extends EmptyInterceptor {

public HibernateInterceptor() {

}

@Override
public int[] findDirty(Object o, Serializable id, Object[] arg2, Object[] arg3, String[] arg4, Type[] arg5) {
if (o instanceof JPABase && !((JPABase) o).willBeSaved) {
return new int[0];
}
return null;
}

@Override
public boolean onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
if (collection instanceof PersistentCollection) {
Object o = ((PersistentCollection) collection).getOwner();
if (o instanceof JPABase) {
if (entities.get() != null) {
return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
} else {
return ((JPABase) o).willBeSaved;
}
}
} else {
System.out.println("HOO: Case not handled !!!");
}
return super.onCollectionUpdate(collection, key);
}

@Override
public boolean onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
if (collection instanceof PersistentCollection) {
Object o = ((PersistentCollection) collection).getOwner();
if (o instanceof JPABase) {
if (entities.get() != null) {
return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
} else {
return ((JPABase) o).willBeSaved;
}
}
} else {
System.out.println("HOO: Case not handled !!!");
}
return super.onCollectionRecreate(collection, key);
}

@Override
public boolean onCollectionRemove(Object collection, Serializable key) throws CallbackException {
if (collection instanceof PersistentCollection) {
Object o = ((PersistentCollection) collection).getOwner();
if (o instanceof JPABase) {
if (entities.get() != null) {
return ((JPABase) o).willBeSaved || ((JPABase) entities.get()).willBeSaved;
} else {
return ((JPABase) o).willBeSaved;
}
}
} else {
System.out.println("HOO: Case not handled !!!");
}
return super.onCollectionRemove(collection, key);
}

protected ThreadLocal<Object> entities = new ThreadLocal<Object>();

@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
entities.set(entity);
return super.onSave(entity, id, state, propertyNames, types);
}

@Override
public void afterTransactionCompletion(org.hibernate.Transaction tx) {
entities.remove();
}

}
Loading

0 comments on commit fbe5d8d

Please sign in to comment.