Java 类org.hibernate.event.spi.PersistEvent 实例源码

项目:lams    文件:DefaultPersistEventListener.java   
@SuppressWarnings({"unchecked"})
private void entityIsDeleted(PersistEvent event, Map createCache) {
    final EventSource source = event.getSession();

    final Object entity = source.getPersistenceContext().unproxy( event.getObject() );
    final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );

    LOG.tracef(
            "un-scheduling entity deletion [%s]",
            MessageHelper.infoString(
                    persister,
                    persister.getIdentifier( entity, source ),
                    source.getFactory()
            )
    );

    if ( createCache.put( entity, entity ) == null ) {
        justCascade( createCache, source, entity, persister );
    }
}
项目:lams    文件:SessionImpl.java   
private void firePersist(Map copiedAlready, PersistEvent event) {
    errorIfClosed();
    checkTransactionSynchStatus();
    for ( PersistEventListener listener : listeners( EventType.PERSIST ) ) {
        listener.onPersist( event, copiedAlready );
    }
    delayedAfterCompletion();
}
项目:lams    文件:SessionImpl.java   
private void firePersist(PersistEvent event) {
    errorIfClosed();
    checkTransactionSynchStatus();
    checkNoUnresolvedActionsBeforeOperation();
    for ( PersistEventListener listener : listeners( EventType.PERSIST ) ) {
        listener.onPersist( event );
    }
    checkNoUnresolvedActionsAfterOperation();
}
项目:lams    文件:SessionImpl.java   
private void firePersistOnFlush(Map copiedAlready, PersistEvent event) {
    errorIfClosed();
    checkTransactionSynchStatus();
    for ( PersistEventListener listener : listeners( EventType.PERSIST_ONFLUSH ) ) {
        listener.onPersist( event, copiedAlready );
    }
    delayedAfterCompletion();
}
项目:lams    文件:SessionImpl.java   
private void firePersistOnFlush(PersistEvent event) {
    errorIfClosed();
    checkTransactionSynchStatus();
    checkNoUnresolvedActionsBeforeOperation();
    for ( PersistEventListener listener : listeners( EventType.PERSIST_ONFLUSH ) ) {
        listener.onPersist( event );
    }
    checkNoUnresolvedActionsAfterOperation();
}
项目:lams    文件:DefaultPersistEventListener.java   
@SuppressWarnings({"unchecked"})
protected void entityIsPersistent(PersistEvent event, Map createCache) {
    LOG.trace( "Ignoring persistent instance" );
    final EventSource source = event.getSession();

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

    final Object entity = source.getPersistenceContext().unproxy( event.getObject() );
    final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );

    if ( createCache.put( entity, entity ) == null ) {
        justCascade( createCache, source, entity, persister );

    }
}
项目:lams    文件:DefaultPersistEventListener.java   
/**
 * Handle the given create event.
 *
 * @param event The save event to be handled.
 * @param createCache The copy cache of entity instance to merge/copy instance.
 */
@SuppressWarnings({"unchecked"})
protected void entityIsTransient(PersistEvent event, Map createCache) {
    LOG.trace( "Saving transient instance" );

    final EventSource source = event.getSession();
    final Object entity = source.getPersistenceContext().unproxy( event.getObject() );

    if ( createCache.put( entity, entity ) == null ) {
        saveWithGeneratedId( entity, event.getEntityName(), createCache, source, false );
    }
}
项目:high-performance-java-persistence    文件:OptimisticLockingBidirectionalChildUpdatesRootVersionTest.java   
@Override
public void onPersist(PersistEvent event) throws HibernateException {
    final Object entity = event.getObject();

    if(entity instanceof RootAware) {
        RootAware rootAware = (RootAware) entity;
        Object root = rootAware.root();
        event.getSession().lock(root, LockMode.OPTIMISTIC_FORCE_INCREMENT);

        LOGGER.info("Incrementing {} entity version because a {} child entity has been inserted", root, entity);
    }
}
项目:saos    文件:GeneratedPersistEventListener.java   
@Override
public void onPersist(PersistEvent event) throws HibernateException {

    Object originalEntity = event.getObject();

    if (originalEntity instanceof Generatable && ((Generatable)originalEntity).isGenerated()) {
        throw new GeneratedEntityPersistException(originalEntity);
    }
}
项目:saos    文件:GeneratedPersistEventListener.java   
@Override
public void onPersist(PersistEvent event, @SuppressWarnings("rawtypes") Map createdAlready) throws HibernateException {

    Object originalEntity = event.getObject();

    if (originalEntity instanceof Generatable && ((Generatable)originalEntity).isGenerated()) {
        throw new GeneratedEntityPersistException(originalEntity);
    }
}
项目:lams    文件:AbstractEntityTuplizer.java   
@Override
public Object getIdentifier(Object entity, EntityMode entityMode, SessionImplementor session) {
    final Object id = mappedIdentifierType.instantiate( entityMode );
    final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode );
    final Type[] subTypes = virtualIdComponent.getSubtypes();
    final Type[] copierSubTypes = mappedIdentifierType.getSubtypes();
    final Iterable<PersistEventListener> persistEventListeners = persistEventListeners( session );
    final PersistenceContext persistenceContext = session.getPersistenceContext();
    final int length = subTypes.length;
    for ( int i = 0 ; i < length; i++ ) {
        if ( propertyValues[i] == null ) {
            throw new HibernateException( "No part of a composite identifier may be null" );
        }
        //JPA 2 @MapsId + @IdClass points to the pk of the entity
        if ( subTypes[i].isAssociationType() && ! copierSubTypes[i].isAssociationType() ) {
            // we need a session to handle this use case
            if ( session == null ) {
                throw new AssertionError(
                        "Deprecated version of getIdentifier (no session) was used but session was required"
                );
            }
            final Object subId;
            if ( HibernateProxy.class.isInstance( propertyValues[i] ) ) {
                subId = ( (HibernateProxy) propertyValues[i] ).getHibernateLazyInitializer().getIdentifier();
            }
            else {
                EntityEntry pcEntry = session.getPersistenceContext().getEntry( propertyValues[i] );
                if ( pcEntry != null ) {
                    subId = pcEntry.getId();
                }
                else {
                    LOG.debug( "Performing implicit derived identity cascade" );
                    final PersistEvent event = new PersistEvent( null, propertyValues[i], (EventSource) session );
                    for ( PersistEventListener listener : persistEventListeners ) {
                        listener.onPersist( event );
                    }
                    pcEntry = persistenceContext.getEntry( propertyValues[i] );
                    if ( pcEntry == null || pcEntry.getId() == null ) {
                        throw new HibernateException( "Unable to process implicit derived identity cascade" );
                    }
                    else {
                        subId = pcEntry.getId();
                    }
                }
            }
            propertyValues[i] = subId;
        }
    }
    mappedIdentifierType.setPropertyValues( id, propertyValues, entityMode );
    return id;
}
项目:lams    文件:SessionImpl.java   
@Override
public void persist(String entityName, Object object) throws HibernateException {
    firePersist( new PersistEvent( entityName, object, this ) );
}
项目:lams    文件:SessionImpl.java   
@Override
public void persist(String entityName, Object object, Map copiedAlready) throws HibernateException {
    firePersist( copiedAlready, new PersistEvent( entityName, object, this ) );
}
项目:lams    文件:SessionImpl.java   
public void persistOnFlush(String entityName, Object object)
        throws HibernateException {
    firePersistOnFlush( new PersistEvent( entityName, object, this ) );
}
项目:lams    文件:SessionImpl.java   
@Override
public void persistOnFlush(String entityName, Object object, Map copiedAlready)
        throws HibernateException {
    firePersistOnFlush( copiedAlready, new PersistEvent( entityName, object, this ) );
}
项目:high-performance-java-persistence    文件:OptimisticLockingBidirectionalChildUpdatesRootVersionTest.java   
@Override
public void onPersist(PersistEvent event, Map createdAlready) throws HibernateException {
    onPersist(event);
}
项目:lams    文件:DefaultPersistEventListener.java   
/**
 * Handle the given create event.
 *
 * @param event The create event to be handled.
 *
 * @throws HibernateException
 */
public void onPersist(PersistEvent event) throws HibernateException {
    onPersist( event, new IdentityHashMap( 10 ) );
}