Skip to content

Commit

Permalink
Changes for Hibernate RX
Browse files Browse the repository at this point in the history
Mostly just expose some operations and constructors that were previously inaccessible.
  • Loading branch information
gavinking committed Jan 18, 2020
1 parent 63a96e3 commit 850c0d6
Show file tree
Hide file tree
Showing 26 changed files with 324 additions and 213 deletions.
Expand Up @@ -69,6 +69,30 @@ public EntityDeleteAction(
);
}

public Object getVersion() {
return version;
}

public boolean isCascadeDeleteEnabled() {
return isCascadeDeleteEnabled;
}

public Object[] getState() {
return state;
}

protected Object[] getNaturalIdValues() {
return naturalIdValues;
}

protected SoftLock getLock() {
return lock;
}

protected void setLock(SoftLock lock) {
this.lock = lock;
}

@Override
public void execute() throws HibernateException {
final Serializable id = getId();
Expand Down Expand Up @@ -128,7 +152,7 @@ public void execute() throws HibernateException {
}
}

private boolean preDelete() {
protected boolean preDelete() {
boolean veto = false;
final EventListenerGroup<PreDeleteEventListener> listenerGroup = listenerGroup( EventType.PRE_DELETE );
if ( listenerGroup.isEmpty() ) {
Expand All @@ -141,7 +165,7 @@ private boolean preDelete() {
return veto;
}

private void postDelete() {
protected void postDelete() {
final EventListenerGroup<PostDeleteEventListener> listenerGroup = listenerGroup( EventType.POST_DELETE );
if ( listenerGroup.isEmpty() ) {
return;
Expand All @@ -158,7 +182,7 @@ private void postDelete() {
}
}

private void postCommitDelete(boolean success) {
protected void postCommitDelete(boolean success) {
final EventListenerGroup<PostDeleteEventListener> listenerGroup = listenerGroup( EventType.POST_COMMIT_DELETE );
if ( listenerGroup.isEmpty() ) {
return;
Expand Down
Expand Up @@ -29,7 +29,7 @@
*
* @see EntityInsertAction
*/
public final class EntityIdentityInsertAction extends AbstractEntityInsertAction {
public class EntityIdentityInsertAction extends AbstractEntityInsertAction {

private final boolean isDelayed;
private final EntityKey delayedEntityKey;
Expand Down Expand Up @@ -141,7 +141,7 @@ public void doAfterTransactionCompletion(boolean success, SharedSessionContractI
postCommitInsert( success );
}

private void postInsert() {
protected void postInsert() {
final EventSource eventSource = eventSource();
if ( isDelayed ) {
eventSource.getPersistenceContextInternal().replaceDelayedEntityIdentityInsertKeys( delayedEntityKey, generatedId );
Expand All @@ -163,7 +163,7 @@ private void postInsert() {
}
}

private void postCommitInsert(boolean success) {
protected void postCommitInsert(boolean success) {
final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup( EventType.POST_COMMIT_INSERT );
if ( listenerGroup.isEmpty() ) {
return;
Expand Down Expand Up @@ -191,7 +191,7 @@ private void postCommitInsert(boolean success) {
}
}

private boolean preInsert() {
protected boolean preInsert() {
final EventListenerGroup<PreInsertEventListener> listenerGroup = listenerGroup( EventType.PRE_INSERT );
if ( listenerGroup.isEmpty() ) {
// NO_VETO
Expand Down Expand Up @@ -241,7 +241,7 @@ private static DelayedPostInsertIdentifier generateDelayedPostInsertIdentifier()
return new DelayedPostInsertIdentifier();
}

private EntityKey generateDelayedEntityKey() {
protected EntityKey generateDelayedEntityKey() {
if ( !isDelayed ) {
throw new AssertionFailure( "cannot request delayed entity-key for early-insert post-insert-id generation" );
}
Expand Down
Expand Up @@ -35,7 +35,7 @@
*
* @see EntityIdentityInsertAction
*/
public final class EntityInsertAction extends AbstractEntityInsertAction {
public class EntityInsertAction extends AbstractEntityInsertAction {
private Object version;
private Object cacheEntry;

Expand All @@ -62,6 +62,22 @@ public EntityInsertAction(
this.version = version;
}

public Object getVersion() {
return version;
}

public void setVersion(Object version) {
this.version = version;
}

protected Object getCacheEntry() {
return cacheEntry;
}

protected void setCacheEntry(Object cacheEntry) {
this.cacheEntry = cacheEntry;
}

@Override
public boolean isEarlyInsert() {
return false;
Expand Down Expand Up @@ -143,7 +159,7 @@ public void execute() throws HibernateException {
markExecuted();
}

private boolean cacheInsert(EntityPersister persister, Object ck) {
protected boolean cacheInsert(EntityPersister persister, Object ck) {
SharedSessionContractImplementor session = getSession();
try {
session.getEventListenerManager().cachePutStart();
Expand All @@ -154,7 +170,7 @@ private boolean cacheInsert(EntityPersister persister, Object ck) {
}
}

private void postInsert() {
protected void postInsert() {
final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup( EventType.POST_INSERT );
if ( listenerGroup.isEmpty() ) {
return;
Expand All @@ -171,7 +187,7 @@ private void postInsert() {
}
}

private void postCommitInsert(boolean success) {
protected void postCommitInsert(boolean success) {
final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup( EventType.POST_COMMIT_INSERT );
if ( listenerGroup.isEmpty() ) {
return;
Expand Down Expand Up @@ -199,7 +215,7 @@ private void postCommitInsert(boolean success) {
}
}

private boolean preInsert() {
protected boolean preInsert() {
boolean veto = false;

final EventListenerGroup<PreInsertEventListener> listenerGroup = listenerGroup( EventType.PRE_INSERT );
Expand Down Expand Up @@ -233,7 +249,7 @@ public void doAfterTransactionCompletion(boolean success, SharedSessionContractI
postCommitInsert( success );
}

private boolean cacheAfterInsert(EntityDataAccess cache, Object ck) {
protected boolean cacheAfterInsert(EntityDataAccess cache, Object ck) {
SharedSessionContractImplementor session = getSession();
final SessionEventListenerManager eventListenerManager = session.getEventListenerManager();
try {
Expand All @@ -256,8 +272,8 @@ protected boolean hasPostCommitEventListeners() {

return false;
}
private boolean isCachePutEnabled(EntityPersister persister, SharedSessionContractImplementor session) {

protected boolean isCachePutEnabled(EntityPersister persister, SharedSessionContractImplementor session) {
return persister.canWriteToCache()
&& !persister.isCacheInvalidationRequired()
&& session.getCacheMode().isPutEnabled();
Expand Down
Expand Up @@ -37,7 +37,7 @@
/**
* The action for performing entity updates.
*/
public final class EntityUpdateAction extends EntityAction {
public class EntityUpdateAction extends EntityAction {
private final Object[] state;
private final Object[] previousState;
private final Object previousVersion;
Expand Down Expand Up @@ -112,6 +112,58 @@ private Object[] determinePreviousNaturalIdValues(
return persistenceContext.getNaturalIdSnapshot( id, persister );
}

public Object[] getState() {
return state;
}

public Object[] getPreviousState() {
return previousState;
}

public Object getPreviousVersion() {
return previousVersion;
}

public Object getNextVersion() {
return nextVersion;
}

public void setNextVersion(Object nextVersion) {
this.nextVersion = nextVersion;
}

public int[] getDirtyFields() {
return dirtyFields;
}

public boolean hasDirtyCollection() {
return hasDirtyCollection;
}

public Object getRowId() {
return rowId;
}

public Object[] getPreviousNaturalIdValues() {
return previousNaturalIdValues;
}

protected Object getCacheEntry() {
return cacheEntry;
}

protected void setCacheEntry(Object cacheEntry) {
this.cacheEntry = cacheEntry;
}

protected SoftLock getLock() {
return lock;
}

protected void setLock(SoftLock lock) {
this.lock = lock;
}

@Override
public void execute() throws HibernateException {
final Serializable id = getId();
Expand Down Expand Up @@ -223,7 +275,7 @@ else if ( session.getCacheMode().isPutEnabled() ) {
}
}

private boolean cacheUpdate(EntityPersister persister, Object previousVersion, Object ck) {
protected boolean cacheUpdate(EntityPersister persister, Object previousVersion, Object ck) {
final SharedSessionContractImplementor session = getSession();
try {
session.getEventListenerManager().cachePutStart();
Expand All @@ -234,7 +286,7 @@ private boolean cacheUpdate(EntityPersister persister, Object previousVersion, O
}
}

private boolean preUpdate() {
protected boolean preUpdate() {
boolean veto = false;
final EventListenerGroup<PreUpdateEventListener> listenerGroup = listenerGroup( EventType.PRE_UPDATE );
if ( listenerGroup.isEmpty() ) {
Expand All @@ -254,7 +306,7 @@ private boolean preUpdate() {
return veto;
}

private void postUpdate() {
protected void postUpdate() {
final EventListenerGroup<PostUpdateEventListener> listenerGroup = listenerGroup( EventType.POST_UPDATE );
if ( listenerGroup.isEmpty() ) {
return;
Expand All @@ -273,7 +325,7 @@ private void postUpdate() {
}
}

private void postCommitUpdate(boolean success) {
protected void postCommitUpdate(boolean success) {
final EventListenerGroup<PostUpdateEventListener> listenerGroup = listenerGroup( EventType.POST_COMMIT_UPDATE );
if ( listenerGroup.isEmpty() ) {
return;
Expand Down Expand Up @@ -350,7 +402,7 @@ public void doAfterTransactionCompletion(boolean success, SharedSessionContractI
postCommitUpdate( success );
}

private boolean cacheAfterUpdate(EntityDataAccess cache, Object ck) {
protected boolean cacheAfterUpdate(EntityDataAccess cache, Object ck) {
final SharedSessionContractImplementor session = getSession();
SessionEventListenerManager eventListenerManager = session.getEventListenerManager();
try {
Expand Down
Expand Up @@ -17,7 +17,6 @@
import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.internal.Cascade;
import org.hibernate.engine.internal.CascadePoint;
import org.hibernate.engine.internal.ForeignKeys;
import org.hibernate.engine.internal.Versioning;
import org.hibernate.engine.spi.CascadingAction;
import org.hibernate.engine.spi.EntityEntry;
Expand Down Expand Up @@ -49,10 +48,6 @@ public abstract class AbstractSaveEventListener
implements CallbackRegistryConsumer {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractSaveEventListener.class );

public enum EntityState {
PERSISTENT, TRANSIENT, DETACHED, DELETED
}

private CallbackRegistry callbackRegistry;

public void injectCallbackRegistry(CallbackRegistry callbackRegistry) {
Expand Down Expand Up @@ -477,60 +472,4 @@ protected void cascadeAfterSave(

protected abstract CascadingAction getCascadeAction();

/**
* Determine whether the entity is persistent, detached, or transient
*
* @param entity The entity to check
* @param entityName The name of the entity
* @param entry The entity's entry in the persistence context
* @param source The originating session.
*
* @return The state.
*/
protected EntityState getEntityState(
Object entity,
String entityName,
EntityEntry entry, //pass this as an argument only to avoid double looking
SessionImplementor source) {

if ( entry != null ) { // the object is persistent

//the entity is associated with the session, so check its status
if ( entry.getStatus() != Status.DELETED ) {
// do nothing for persistent instances
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Persistent instance of: {0}", getLoggableName( entityName, entity ) );
}
return EntityState.PERSISTENT;
}
// ie. e.status==DELETED
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Deleted instance of: {0}", getLoggableName( entityName, entity ) );
}
return EntityState.DELETED;
}
// the object is transient or detached

// the entity is not associated with the session, so
// try interceptor and unsaved-value

if ( ForeignKeys.isTransient( entityName, entity, getAssumedUnsaved(), source ) ) {
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Transient instance of: {0}", getLoggableName( entityName, entity ) );
}
return EntityState.TRANSIENT;
}
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Detached instance of: {0}", getLoggableName( entityName, entity ) );
}
return EntityState.DETACHED;
}

protected String getLoggableName(String entityName, Object entity) {
return entityName == null ? entity.getClass().getName() : entityName;
}

protected Boolean getAssumedUnsaved() {
return null;
}
}
Expand Up @@ -121,7 +121,7 @@ else if ( type.isComponentType() ) {
* @param persister
* @throws HibernateException
*/
void process(Object object, EntityPersister persister)
public void process(Object object, EntityPersister persister)
throws HibernateException {
processEntityPropertyValues(
persister.getPropertyValues( object ),
Expand Down

0 comments on commit 850c0d6

Please sign in to comment.