本文整理汇总了Java中org.hibernate.event.spi.PersistEvent类的典型用法代码示例。如果您正苦于以下问题:Java PersistEvent类的具体用法?Java PersistEvent怎么用?Java PersistEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistEvent类属于org.hibernate.event.spi包,在下文中一共展示了PersistEvent类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: entityIsDeleted
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
@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 );
}
}
示例2: firePersist
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
private void firePersist(Map copiedAlready, PersistEvent event) {
errorIfClosed();
checkTransactionSynchStatus();
for ( PersistEventListener listener : listeners( EventType.PERSIST ) ) {
listener.onPersist( event, copiedAlready );
}
delayedAfterCompletion();
}
示例3: firePersistOnFlush
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
private void firePersistOnFlush(Map copiedAlready, PersistEvent event) {
errorIfClosed();
checkTransactionSynchStatus();
for ( PersistEventListener listener : listeners( EventType.PERSIST_ONFLUSH ) ) {
listener.onPersist( event, copiedAlready );
}
delayedAfterCompletion();
}
示例4: entityIsPersistent
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
@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 );
}
}
示例5: entityIsTransient
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
/**
* 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 );
}
}
示例6: onPersist
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
@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);
}
}
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:13,代码来源:OptimisticLockingBidirectionalChildUpdatesRootVersionTest.java
示例7: onPersist
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
@Override
public void onPersist(PersistEvent event) throws HibernateException {
Object originalEntity = event.getObject();
if (originalEntity instanceof Generatable && ((Generatable)originalEntity).isGenerated()) {
throw new GeneratedEntityPersistException(originalEntity);
}
}
示例8: getIdentifier
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
@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;
}
示例9: persist
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
@Override
public void persist(String entityName, Object object) throws HibernateException {
firePersist( new PersistEvent( entityName, object, this ) );
}
示例10: persistOnFlush
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
public void persistOnFlush(String entityName, Object object)
throws HibernateException {
firePersistOnFlush( new PersistEvent( entityName, object, this ) );
}
示例11: onPersist
import org.hibernate.event.spi.PersistEvent; //导入依赖的package包/类
/**
* 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 ) );
}