HHH-6379 create EntityState enum to replace int constants in AbstractSaveEventListener
This commit is contained in:
parent
0c757327bd
commit
babeacefb0
|
@ -59,11 +59,9 @@ import org.hibernate.type.TypeHelper;
|
|||
* @author Steve Ebersole.
|
||||
*/
|
||||
public abstract class AbstractSaveEventListener extends AbstractReassociateEventListener {
|
||||
|
||||
protected static final int PERSISTENT = 0;
|
||||
protected static final int TRANSIENT = 1;
|
||||
protected static final int DETACHED = 2;
|
||||
protected static final int DELETED = 3;
|
||||
public enum EntityState{
|
||||
PERSISTENT, TRANSIENT, DETACHED, DELETED;
|
||||
}
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
AbstractSaveEventListener.class.getName());
|
||||
|
@ -475,7 +473,7 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
*
|
||||
* @return The state.
|
||||
*/
|
||||
protected int getEntityState(
|
||||
protected EntityState getEntityState(
|
||||
Object entity,
|
||||
String entityName,
|
||||
EntityEntry entry, //pass this as an argument only to avoid double looking
|
||||
|
@ -487,11 +485,11 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
if ( entry.getStatus() != Status.DELETED ) {
|
||||
// do nothing for persistent instances
|
||||
if (LOG.isTraceEnabled()) LOG.trace("Persistent instance of: " + getLoggableName(entityName, entity));
|
||||
return PERSISTENT;
|
||||
return EntityState.PERSISTENT;
|
||||
}
|
||||
// ie. e.status==DELETED
|
||||
if (LOG.isTraceEnabled()) LOG.trace("Deleted instance of: " + getLoggableName(entityName, entity));
|
||||
return DELETED;
|
||||
return EntityState.DELETED;
|
||||
|
||||
}
|
||||
// the object is transient or detached
|
||||
|
@ -501,10 +499,10 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
|
||||
if ( ForeignKeys.isTransient( entityName, entity, getAssumedUnsaved(), source )) {
|
||||
if (LOG.isTraceEnabled()) LOG.trace("Transient instance of: " + getLoggableName(entityName, entity));
|
||||
return TRANSIENT;
|
||||
return EntityState.TRANSIENT;
|
||||
}
|
||||
if (LOG.isTraceEnabled()) LOG.trace("Detached instance of: " + getLoggableName(entityName, entity));
|
||||
return DETACHED;
|
||||
return EntityState.DETACHED;
|
||||
}
|
||||
|
||||
protected String getLoggableName(String entityName, Object entity) {
|
||||
|
|
|
@ -219,7 +219,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
copyCache.setOperatedOn( entity, true );
|
||||
}
|
||||
event.setEntity( entity );
|
||||
int entityState = -1;
|
||||
EntityState entityState = null;
|
||||
|
||||
// Check the persistence context for an entry relating to this
|
||||
// entity to be merged...
|
||||
|
@ -237,12 +237,12 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
// have an incoming entity instance which has a corresponding
|
||||
// entry in the current persistence context, but registered
|
||||
// under a different entity instance
|
||||
entityState = DETACHED;
|
||||
entityState = EntityState.DETACHED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( entityState == -1 ) {
|
||||
if ( entityState == null ) {
|
||||
entityState = getEntityState( entity, event.getEntityName(), entry, source );
|
||||
}
|
||||
|
||||
|
|
|
@ -102,8 +102,8 @@ public class DefaultPersistEventListener extends AbstractSaveEventListener imple
|
|||
}
|
||||
|
||||
final EntityEntry entityEntry = source.getPersistenceContext().getEntry( entity );
|
||||
int entityState = getEntityState( entity, entityName, entityEntry, source );
|
||||
if ( entityState == DETACHED ) {
|
||||
EntityState entityState = getEntityState( entity, entityName, entityEntry, source );
|
||||
if ( entityState == EntityState.DETACHED ) {
|
||||
// JPA 2, in its version of a "foreign generated", allows the id attribute value
|
||||
// to be manually set by the user, even though this manual value is irrelevant.
|
||||
// The issue is that this causes problems with the Hibernate unsaved-value strategy
|
||||
|
|
|
@ -96,7 +96,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
|||
}
|
||||
|
||||
protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
|
||||
int entityState = getEntityState(
|
||||
EntityState entityState = getEntityState(
|
||||
event.getEntity(),
|
||||
event.getEntityName(),
|
||||
event.getEntry(),
|
||||
|
|
Loading…
Reference in New Issue