本文整理汇总了Java中org.hibernate.event.spi.EventSource类的典型用法代码示例。如果您正苦于以下问题:Java EventSource类的具体用法?Java EventSource怎么用?Java EventSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventSource类属于org.hibernate.event.spi包,在下文中一共展示了EventSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cascade
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
@Override
public void cascade(
EventSource session,
Object child,
String entityName,
Object anything,
boolean isCascadeDeleteEnabled) {
LOG.tracev( "Cascading to lock: {0}", entityName );
LockMode lockMode = LockMode.NONE;
LockOptions lr = new LockOptions();
if ( anything instanceof LockOptions ) {
LockOptions lockOptions = (LockOptions) anything;
lr.setTimeOut( lockOptions.getTimeOut() );
lr.setScope( lockOptions.getScope() );
if ( lockOptions.getScope() ) {
lockMode = lockOptions.getLockMode();
}
}
lr.setLockMode( lockMode );
session.buildLockRequest( lr ).lock( entityName, child );
}
示例2: saveWithRequestedId
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
/**
* Prepares the save call using the given requested id.
*
* @param entity The entity to be saved.
* @param requestedId The id to which to associate the entity.
* @param entityName The name of the entity being saved.
* @param anything Generally cascade-specific information.
* @param source The session which is the source of this save event.
*
* @return The id used to save the entity.
*/
protected Serializable saveWithRequestedId(
Object entity,
Serializable requestedId,
String entityName,
Object anything,
EventSource source) {
return performSave(
entity,
requestedId,
source.getEntityPersister( entityName, entity ),
false,
anything,
source,
true
);
}
示例3: cascadeBeforeSave
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
/**
* Handles the calls needed to perform pre-save cascades for the given entity.
*
* @param source The session from whcih the save event originated.
* @param persister The entity's persister instance.
* @param entity The entity to be saved.
* @param anything Generally cascade-specific data
*/
protected void cascadeBeforeSave(
EventSource source,
EntityPersister persister,
Object entity,
Object anything) {
// cascade-save to many-to-one BEFORE the parent is saved
source.getPersistenceContext().incrementCascadeLevel();
try {
new Cascade( getCascadeAction(), CascadePoint.BEFORE_INSERT_AFTER_DELETE, source ).cascade(
persister,
entity,
anything
);
}
finally {
source.getPersistenceContext().decrementCascadeLevel();
}
}
示例4: IteratorImpl
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
public IteratorImpl(
ResultSet rs,
PreparedStatement ps,
EventSource sess,
boolean readOnly,
Type[] types,
String[][] columnNames,
HolderInstantiator holderInstantiator)
throws HibernateException, SQLException {
this.rs=rs;
this.ps=ps;
this.session = sess;
this.readOnly = readOnly;
this.types = types;
this.names = columnNames;
this.holderInstantiator = holderInstantiator;
single = types.length==1;
postNext();
}
示例5: deleteTransientEntity
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
/**
* We encountered a delete request on a transient instance.
* <p/>
* This is a deviation from historical Hibernate (pre-3.2) behavior to
* align with the JPA spec, which states that transient entities can be
* passed to remove operation in which case cascades still need to be
* performed.
*
* @param session The session which is the source of the event
* @param entity The entity being delete processed
* @param cascadeDeleteEnabled Is cascading of deletes enabled
* @param persister The entity persister
* @param transientEntities A cache of already visited transient entities
* (to avoid infinite recursion).
*/
protected void deleteTransientEntity(
EventSource session,
Object entity,
boolean cascadeDeleteEnabled,
EntityPersister persister,
Set transientEntities) {
LOG.handlingTransientEntity();
if ( transientEntities.contains( entity ) ) {
LOG.trace( "Already handled transient entity; skipping" );
return;
}
transientEntities.add( entity );
cascadeBeforeDelete( session, persister, entity, null, transientEntities );
cascadeAfterDelete( session, persister, entity, transientEntities );
}
示例6: cascadeBeforeDelete
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
protected void cascadeBeforeDelete(
EventSource session,
EntityPersister persister,
Object entity,
EntityEntry entityEntry,
Set transientEntities) throws HibernateException {
CacheMode cacheMode = session.getCacheMode();
session.setCacheMode( CacheMode.GET );
session.getPersistenceContext().incrementCascadeLevel();
try {
// cascade-delete to collections BEFORE the collection owner is deleted
new Cascade( CascadingActions.DELETE, CascadePoint.AFTER_INSERT_BEFORE_DELETE, session ).cascade(
persister,
entity,
transientEntities
);
}
finally {
session.getPersistenceContext().decrementCascadeLevel();
session.setCacheMode( cacheMode );
}
}
示例7: cascadeAfterDelete
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
protected void cascadeAfterDelete(
EventSource session,
EntityPersister persister,
Object entity,
Set transientEntities) throws HibernateException {
CacheMode cacheMode = session.getCacheMode();
session.setCacheMode( CacheMode.GET );
session.getPersistenceContext().incrementCascadeLevel();
try {
// cascade-delete to many-to-one AFTER the parent was deleted
new Cascade( CascadingActions.DELETE, CascadePoint.BEFORE_INSERT_AFTER_DELETE, session ).cascade(
persister,
entity,
transientEntities
);
}
finally {
session.getPersistenceContext().decrementCascadeLevel();
session.setCacheMode( cacheMode );
}
}
示例8: wrapCollections
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
private boolean wrapCollections(
EventSource session,
EntityPersister persister,
Type[] types,
Object[] values
) {
if ( persister.hasCollections() ) {
// wrap up any new collections directly referenced by the object
// or its components
// NOTE: we need to do the wrap here even if its not "dirty",
// because collections need wrapping but changes to _them_
// don't dirty the container. Also, for versioned data, we
// need to wrap before calling searchForDirtyCollections
WrapVisitor visitor = new WrapVisitor( session );
// substitutes into values by side-effect
visitor.processEntityPropertyValues( values, types );
return visitor.isSubstitutionRequired();
}
else {
return false;
}
}
示例9: entityIsDeleted
import org.hibernate.event.spi.EventSource; //导入依赖的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 );
}
}
示例10: entityIsTransient
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
/**
* The given save-update event named a transient entity.
* <p/>
* Here, we will perform the save processing.
*
* @param event The save event to be handled.
*
* @return The entity's identifier after saving.
*/
protected Serializable entityIsTransient(SaveOrUpdateEvent event) {
LOG.trace( "Saving transient instance" );
final EventSource source = event.getSession();
EntityEntry entityEntry = event.getEntry();
if ( entityEntry != null ) {
if ( entityEntry.getStatus() == Status.DELETED ) {
source.forceFlush( entityEntry );
}
else {
throw new AssertionFailure( "entity was persistent" );
}
}
Serializable id = saveWithGeneratedOrRequestedId( event );
source.getPersistenceContext().reassociateProxy( event.getObject(), id );
return id;
}
示例11: entityCopyDetected
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
@Override
public void entityCopyDetected(
Object managedEntity,
Object mergeEntity1,
Object mergeEntity2,
EventSource session) {
if ( mergeEntity1 == managedEntity && mergeEntity2 == managedEntity) {
throw new AssertionFailure( "entity1 and entity2 are the same as managedEntity; must be different." );
}
final String managedEntityString = MessageHelper.infoString(
session.getEntityName( managedEntity ),
session.getIdentifier( managedEntity )
);
throw new IllegalStateException(
"Multiple representations of the same entity " + managedEntityString + " are being merged. " +
getManagedOrDetachedEntityString( managedEntity, mergeEntity1 ) + "; " +
getManagedOrDetachedEntityString( managedEntity, mergeEntity2 )
);
}
示例12: logFlushResults
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
@SuppressWarnings( value = {"unchecked"} )
private void logFlushResults(FlushEvent event) {
if ( !LOG.isDebugEnabled() ) {
return;
}
final EventSource session = event.getSession();
final PersistenceContext persistenceContext = session.getPersistenceContext();
LOG.debugf(
"Flushed: %s insertions, %s updates, %s deletions to %s objects",
session.getActionQueue().numberOfInsertions(),
session.getActionQueue().numberOfUpdates(),
session.getActionQueue().numberOfDeletions(),
persistenceContext.getNumberOfManagedEntities()
);
LOG.debugf(
"Flushed: %s (re)creations, %s updates, %s removals to %s collections",
session.getActionQueue().numberOfCollectionCreations(),
session.getActionQueue().numberOfCollectionUpdates(),
session.getActionQueue().numberOfCollectionRemovals(),
persistenceContext.getCollectionEntries().size()
);
new EntityPrinter( session.getFactory() ).toString(
persistenceContext.getEntitiesByKey().entrySet()
);
}
示例13: prepareEntityFlushes
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
/**
* process cascade save/update at the start of a flush to discover
* any newly referenced entity that must be passed to saveOrUpdate(),
* and also apply orphan delete
*/
private void prepareEntityFlushes(EventSource session, PersistenceContext persistenceContext) throws HibernateException {
LOG.debug( "Processing flush-time cascades" );
final Object anything = getAnything();
//safe from concurrent modification because of how concurrentEntries() is implemented on IdentityMap
for ( Map.Entry<Object,EntityEntry> me : persistenceContext.reentrantSafeEntityEntries() ) {
// for ( Map.Entry me : IdentityMap.concurrentEntries( persistenceContext.getEntityEntries() ) ) {
EntityEntry entry = (EntityEntry) me.getValue();
Status status = entry.getStatus();
if ( status == Status.MANAGED || status == Status.SAVING || status == Status.READ_ONLY ) {
cascadeOnFlush( session, entry.getPersister(), me.getKey(), anything );
}
}
}
示例14: saveTransientEntity
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
private void saveTransientEntity(
Object entity,
String entityName,
Serializable requestedId,
EventSource source,
Map copyCache) {
//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
if ( requestedId == null ) {
saveWithGeneratedId( entity, entityName, copyCache, source, false );
}
else {
saveWithRequestedId( entity, requestedId, entityName, copyCache, source );
}
}
示例15: isVersionChanged
import org.hibernate.event.spi.EventSource; //导入依赖的package包/类
private boolean isVersionChanged(Object entity, EventSource source, EntityPersister persister, Object target) {
if ( !persister.isVersioned() ) {
return false;
}
// for merging of versioned entities, we consider the version having
// been changed only when:
// 1) the two version values are different;
// *AND*
// 2) The target actually represents database state!
//
// This second condition is a special case which allows
// an entity to be merged during the same transaction
// (though during a seperate operation) in which it was
// originally persisted/saved
boolean changed = !persister.getVersionType().isSame(
persister.getVersion( target ),
persister.getVersion( entity )
);
// TODO : perhaps we should additionally require that the incoming entity
// version be equivalent to the defined unsaved-value?
return changed && existsInDatabase( target, source, persister );
}