Java 类org.hibernate.event.MergeEvent 实例源码

项目:lams    文件:IdTransferringMergeEventListener.java   
/**
 * Hibernate 3.1 implementation of ID transferral.
 */
@Override
protected void entityIsTransient(MergeEvent event, Map copyCache) {
    super.entityIsTransient(event, copyCache);
    SessionImplementor session = event.getSession();
    EntityPersister persister = session.getEntityPersister(event.getEntityName(), event.getEntity());
    // Extract id from merged copy (which is currently registered with Session).
    Serializable id = persister.getIdentifier(event.getResult(), session.getEntityMode());
    // Set id on original object (which remains detached).
    persister.setIdentifier(event.getOriginal(), id, session.getEntityMode());
}
项目:spring4-understanding    文件:IdTransferringMergeEventListener.java   
/**
 * Hibernate 3.1 implementation of ID transferral.
 */
@Override
protected void entityIsTransient(MergeEvent event, Map copyCache) {
    super.entityIsTransient(event, copyCache);
    SessionImplementor session = event.getSession();
    EntityPersister persister = session.getEntityPersister(event.getEntityName(), event.getEntity());
    // Extract id from merged copy (which is currently registered with Session).
    Serializable id = persister.getIdentifier(event.getResult(), session.getEntityMode());
    // Set id on original object (which remains detached).
    persister.setIdentifier(event.getOriginal(), id, session.getEntityMode());
}
项目:cacheonix-core    文件:SessionImpl.java   
private Object fireMerge(MergeEvent event) {
    errorIfClosed();
    checkTransactionSynchStatus();
    MergeEventListener[] mergeEventListener = listeners.getMergeEventListeners();
    for ( int i = 0; i < mergeEventListener.length; i++ ) {
        mergeEventListener[i].onMerge(event);
    }
    return event.getResult();
}
项目:cacheonix-core    文件:SessionImpl.java   
private void fireMerge(Map copiedAlready, MergeEvent event) {
    errorIfClosed();
    checkTransactionSynchStatus();
    MergeEventListener[] mergeEventListener = listeners.getMergeEventListeners();
    for ( int i = 0; i < mergeEventListener.length; i++ ) {
        mergeEventListener[i].onMerge(event, copiedAlready);
    }
}
项目:cacheonix-core    文件:SessionImpl.java   
private void fireSaveOrUpdateCopy(Map copiedAlready, MergeEvent event) {
    errorIfClosed();
    checkTransactionSynchStatus();
    MergeEventListener[] saveOrUpdateCopyEventListener = listeners.getSaveOrUpdateCopyEventListeners();
    for ( int i = 0; i < saveOrUpdateCopyEventListener.length; i++ ) {
        saveOrUpdateCopyEventListener[i].onMerge(event, copiedAlready);
    }
}
项目:cacheonix-core    文件:SessionImpl.java   
private Object fireSaveOrUpdateCopy(MergeEvent event) {
    errorIfClosed();
    checkTransactionSynchStatus();
    MergeEventListener[] saveOrUpdateCopyEventListener = listeners.getSaveOrUpdateCopyEventListeners();
    for ( int i = 0; i < saveOrUpdateCopyEventListener.length; i++ ) {
        saveOrUpdateCopyEventListener[i].onMerge(event);
    }
    return event.getResult();
}
项目:class-guard    文件:IdTransferringMergeEventListener.java   
/**
 * Hibernate 3.1 implementation of ID transferral.
 */
@Override
protected void entityIsTransient(MergeEvent event, Map copyCache) {
    super.entityIsTransient(event, copyCache);
    SessionImplementor session = event.getSession();
    EntityPersister persister = session.getEntityPersister(event.getEntityName(), event.getEntity());
    // Extract id from merged copy (which is currently registered with Session).
    Serializable id = persister.getIdentifier(event.getResult(), session.getEntityMode());
    // Set id on original object (which remains detached).
    persister.setIdentifier(event.getOriginal(), id, session.getEntityMode());
}
项目:spring4-understanding    文件:LocalSessionFactoryBeanTests.java   
@Override
public void onMerge(MergeEvent event) throws HibernateException {
}
项目:spring4-understanding    文件:LocalSessionFactoryBeanTests.java   
@Override
public void onMerge(MergeEvent event, Map copiedAlready) throws HibernateException {
}
项目:cacheonix-core    文件:DefaultMergeEventListener.java   
protected void entityIsPersistent(MergeEvent event, Map copyCache) {
    log.trace("ignoring persistent instance");

    //TODO: check that entry.getIdentifier().equals(requestedId)

    final Object entity = event.getEntity();
    final EventSource source = event.getSession();
    final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );

    copyCache.put(entity, entity); //before cascade!

    cascadeOnMerge(source, persister, entity, copyCache);
    copyValues(persister, entity, entity, source, copyCache);

    event.setResult(entity);
}
项目:cacheonix-core    文件:DefaultMergeEventListener.java   
protected void entityIsTransient(MergeEvent event, Map copyCache) {

    log.trace("merging transient instance");

    final Object entity = event.getEntity();
    final EventSource source = event.getSession();

    final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
    final String entityName = persister.getEntityName();

    final Serializable id = persister.hasIdentifierProperty() ?
            persister.getIdentifier( entity, source.getEntityMode() ) :
            null;

    final Object copy = persister.instantiate( id, source.getEntityMode() );  //TODO: should this be Session.instantiate(Persister, ...)?
    copyCache.put(entity, copy); //before cascade!

    // cascade first, so that all unsaved objects get their
    // copy created before we actually copy
    //cascadeOnMerge(event, persister, entity, copyCache, Cascades.CASCADE_BEFORE_MERGE);
    super.cascadeBeforeSave(source, persister, entity, copyCache);
    copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT);

    //this bit is only *really* absolutely necessary for handling 
    //requestedId, but is also good if we merge multiple object 
    //graphs, since it helps ensure uniqueness
    final Serializable requestedId = event.getRequestedId();
    if (requestedId==null) {
        saveWithGeneratedId( copy, entityName, copyCache, source, false );
    }
    else {
        saveWithRequestedId( copy, requestedId, entityName, copyCache, source );
    }

    // cascade first, so that all unsaved objects get their 
    // copy created before we actually copy
    super.cascadeAfterSave(source, persister, entity, copyCache);
    copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_TO_PARENT);

    event.setResult(copy);

}
项目:cacheonix-core    文件:DefaultMergeEventListener.java   
protected void entityIsDetached(MergeEvent event, Map copyCache) {

    log.trace("merging detached instance");

    final Object entity = event.getEntity();
    final EventSource source = event.getSession();

    final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
    final String entityName = persister.getEntityName();

    Serializable id = event.getRequestedId();
    if ( id == null ) {
        id = persister.getIdentifier( entity, source.getEntityMode() );
    }
    else {
        // check that entity id = requestedId
        Serializable entityId = persister.getIdentifier( entity, source.getEntityMode() );
        if ( !persister.getIdentifierType().isEqual( id, entityId, source.getEntityMode(), source.getFactory() ) ) {
            throw new HibernateException( "merge requested with id not matching id of passed entity" );
        }
    }

    String previousFetchProfile = source.getFetchProfile();
    source.setFetchProfile("merge");
    //we must clone embedded composite identifiers, or 
    //we will get back the same instance that we pass in
    final Serializable clonedIdentifier = (Serializable) persister.getIdentifierType()
            .deepCopy( id, source.getEntityMode(), source.getFactory() );
    final Object result = source.get(entityName, clonedIdentifier);
    source.setFetchProfile(previousFetchProfile);

    if ( result == null ) {
        //TODO: we should throw an exception if we really *know* for sure  
        //      that this is a detached instance, rather than just assuming
        //throw new StaleObjectStateException(entityName, id);

        // we got here because we assumed that an instance
        // with an assigned id was detached, when it was
        // really persistent
        entityIsTransient(event, copyCache);
    }
    else {
        copyCache.put(entity, result); //before cascade!

        final Object target = source.getPersistenceContext().unproxy(result);
        if ( target == entity ) {
            throw new AssertionFailure("entity was not detached");
        }
        else if ( !source.getEntityName(target).equals(entityName) ) {
            throw new WrongClassException(
                    "class of the given object did not match class of persistent copy",
                    event.getRequestedId(),
                    entityName
                );
        }
        else if ( isVersionChanged( entity, source, persister, target ) ) {
            if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
                source.getFactory().getStatisticsImplementor()
                        .optimisticFailure( entityName );
            }
            throw new StaleObjectStateException( entityName, id );
        }

        // cascade first, so that all unsaved objects get their 
        // copy created before we actually copy
        cascadeOnMerge(source, persister, entity, copyCache);
        copyValues(persister, entity, target, source, copyCache);

        //copyValues works by reflection, so explicitly mark the entity instance dirty
        markInterceptorDirty( entity, target );

        event.setResult(result);
    }

}
项目:cacheonix-core    文件:SessionImpl.java   
public Object merge(String entityName, Object object) throws HibernateException {
    return fireMerge( new MergeEvent(entityName, object, this) );
}
项目:cacheonix-core    文件:SessionImpl.java   
public void merge(String entityName, Object object, Map copiedAlready) throws HibernateException {
    fireMerge( copiedAlready, new MergeEvent(entityName, object, this) );
}
项目:cacheonix-core    文件:SessionImpl.java   
public Object saveOrUpdateCopy(String entityName, Object object)
        throws HibernateException {
    return fireSaveOrUpdateCopy( new MergeEvent(entityName, object, this) );
}
项目:cacheonix-core    文件:SessionImpl.java   
public Object saveOrUpdateCopy(String entityName, Object object, Serializable id)
        throws HibernateException {
    return fireSaveOrUpdateCopy( new MergeEvent(entityName, object, id, this) );
}
项目:cacheonix-core    文件:SessionImpl.java   
public void saveOrUpdateCopy(String entityName, Object object, Map copiedAlready)
        throws HibernateException {
    fireSaveOrUpdateCopy( copiedAlready, new MergeEvent( entityName, object, this ) );
}
项目:class-guard    文件:LocalSessionFactoryBeanTests.java   
@Override
public void onMerge(MergeEvent event) throws HibernateException {
}
项目:class-guard    文件:LocalSessionFactoryBeanTests.java   
@Override
public void onMerge(MergeEvent event, Map copiedAlready) throws HibernateException {
}
项目:screensaver    文件:AbstractManagedEventsListener.java   
@Override
public void onMerge(MergeEvent event) throws HibernateException
{
  apply(event.getEntity());
}
项目:screensaver    文件:AbstractManagedEventsListener.java   
@Override
public void onMerge(MergeEvent event, Map copiedAlready) throws HibernateException
{
  apply(event.getEntity());
}
项目:cacheonix-core    文件:DefaultMergeEventListener.java   
/** 
 * Handle the given merge event.
 *
 * @param event The merge event to be handled.
 * @throws HibernateException
 */
public void onMerge(MergeEvent event) throws HibernateException {
    onMerge( event, IdentityMap.instantiate(10) );
}