Skip to content

Commit

Permalink
patch play master on hibernate 5.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Chatiron authored and flybyray committed Sep 12, 2018
1 parent 97af7c4 commit 8ecee3c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ public String onPrepareStatement(String sql) {
}

@Override
public void onCollectionRemove(Object collection, Serializable key) throws CallbackException {
public boolean onCollectionRemove(Object collection, Serializable key) throws CallbackException {
return true;
}

@Override
public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
public boolean onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
return true;
}

@Override
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
public boolean onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
return true;
}
}
6 changes: 3 additions & 3 deletions hibernate-core/src/main/java/org/hibernate/Interceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ boolean onFlushDirty(
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
void onCollectionRecreate(Object collection, Serializable key) throws CallbackException;
boolean onCollectionRecreate(Object collection, Serializable key) throws CallbackException;

/**
* Called before a collection is deleted.
Expand All @@ -131,7 +131,7 @@ boolean onFlushDirty(
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
void onCollectionRemove(Object collection, Serializable key) throws CallbackException;
boolean onCollectionRemove(Object collection, Serializable key) throws CallbackException;

/**
* Called before a collection is updated.
Expand All @@ -141,7 +141,7 @@ boolean onFlushDirty(
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
void onCollectionUpdate(Object collection, Serializable key) throws CallbackException;
boolean onCollectionUpdate(Object collection, Serializable key) throws CallbackException;

/**
* Called before a flush.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,27 @@ private void prepareEntityFlushes(EventSource session, PersistenceContext persis
// for ( Map.Entry me : IdentityMap.concurrentEntries( persistenceContext.getEntityEntries() ) ) {
EntityEntry entry = (EntityEntry) me.getValue();
Status status = entry.getStatus();

// This entity will be saved?
boolean willBeSaved = true;
try {
Object o = me.getKey();
Class c = o.getClass();
Class jpaBase = Class.forName("play.db.jpa.JPABase");
while(!c.equals(Object.class)) {
if(c.equals(jpaBase)) {
willBeSaved = (Boolean)(jpaBase.getDeclaredField("willBeSaved").get(o));
break;
}
c = c.getSuperclass();
}
if(!willBeSaved) {
continue;
}
} catch(Exception e) {
e.printStackTrace();
}

if ( status == Status.MANAGED || status == Status.SAVING || status == Status.READ_ONLY ) {
cascadeOnFlush( session, entry.getPersister(), me.getKey(), anything );
}
Expand Down Expand Up @@ -274,19 +295,20 @@ private int flushCollections(final EventSource session, final PersistenceContext
CollectionEntry ce = me.getValue();

if ( ce.isDorecreate() ) {
session.getInterceptor().onCollectionRecreate( coll, ce.getCurrentKey() );
actionQueue.addAction(
if(session.getInterceptor().onCollectionRecreate( coll, ce.getCurrentKey() )){
actionQueue.addAction(
new CollectionRecreateAction(
coll,
ce.getCurrentPersister(),
ce.getCurrentKey(),
session
)
);
}
}
if ( ce.isDoremove() ) {
session.getInterceptor().onCollectionRemove( coll, ce.getLoadedKey() );
actionQueue.addAction(
if(session.getInterceptor().onCollectionRemove( coll, ce.getLoadedKey() )){
actionQueue.addAction(
new CollectionRemoveAction(
coll,
ce.getLoadedPersister(),
Expand All @@ -295,10 +317,11 @@ private int flushCollections(final EventSource session, final PersistenceContext
session
)
);
}
}
if ( ce.isDoupdate() ) {
session.getInterceptor().onCollectionUpdate( coll, ce.getLoadedKey() );
actionQueue.addAction(
if(session.getInterceptor().onCollectionUpdate( coll, ce.getLoadedKey() )){
actionQueue.addAction(
new CollectionUpdateAction(
coll,
ce.getLoadedPersister(),
Expand All @@ -307,6 +330,7 @@ private int flushCollections(final EventSource session, final PersistenceContext
session
)
);
}
}

// todo : I'm not sure the !wasInitialized part should really be part of this check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public String onPrepareStatement(String sql) {
return sql;
}

public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {}
public void onCollectionRemove(Object collection, Serializable key) throws CallbackException {}
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {}
public boolean onCollectionRecreate(Object collection, Serializable key) throws CallbackException { return true;}
public boolean onCollectionRemove(Object collection, Serializable key) throws CallbackException { return true;}
public boolean onCollectionUpdate(Object collection, Serializable key) throws CallbackException { return true;}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ public String onPrepareStatement(String sql) {
return sql;
}

public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
public boolean onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
return true;
}

public void onCollectionRemove(Object collection, Serializable key) throws CallbackException {
public boolean onCollectionRemove(Object collection, Serializable key) throws CallbackException {
return true;
}

public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
public boolean onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
return true;
}
}

0 comments on commit 8ecee3c

Please sign in to comment.