本文整理汇总了Java中org.hibernate.event.spi.EventType类的典型用法代码示例。如果您正苦于以下问题:Java EventType类的具体用法?Java EventType怎么用?Java EventType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventType类属于org.hibernate.event.spi包,在下文中一共展示了EventType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preUpdate
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
private boolean preUpdate() {
boolean veto = false;
final EventListenerGroup<PreUpdateEventListener> listenerGroup = listenerGroup( EventType.PRE_UPDATE );
if ( listenerGroup.isEmpty() ) {
return veto;
}
final PreUpdateEvent event = new PreUpdateEvent(
getInstance(),
getId(),
state,
previousState,
getPersister(),
eventSource()
);
for ( PreUpdateEventListener listener : listenerGroup.listeners() ) {
veto |= listener.onPreUpdate( event );
}
return veto;
}
示例2: postLoad
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
/**
* PostLoad cannot occur during initializeEntity, as that call occurs *before*
* the Set collections are added to the persistence context by Loader.
* Without the split, LazyInitializationExceptions can occur in the Entity's
* postLoad if it acts upon the collection.
*
* HHH-6043
*
* @param entity The entity
* @param session The Session
* @param postLoadEvent The (re-used) post-load event
*/
public static void postLoad(
final Object entity,
final SessionImplementor session,
final PostLoadEvent postLoadEvent) {
if ( session.isEventSource() ) {
final PersistenceContext persistenceContext
= session.getPersistenceContext();
final EntityEntry entityEntry = persistenceContext.getEntry( entity );
postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() );
final EventListenerGroup<PostLoadEventListener> listenerGroup = session.getFactory()
.getServiceRegistry()
.getService( EventListenerRegistry.class )
.getEventListenerGroup( EventType.POST_LOAD );
for ( PostLoadEventListener listener : listenerGroup.listeners() ) {
listener.onPostLoad( postLoadEvent );
}
}
}
示例3: isDirty
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
@Override
public boolean isDirty() throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
LOG.debug( "Checking session dirtiness" );
if ( actionQueue.areInsertionsOrDeletionsQueued() ) {
LOG.debug( "Session dirty (scheduled updates and insertions)" );
return true;
}
DirtyCheckEvent event = new DirtyCheckEvent( this );
for ( DirtyCheckEventListener listener : listeners( EventType.DIRTY_CHECK ) ) {
listener.onDirtyCheck( event );
}
delayedAfterCompletion();
return event.isDirty();
}
示例4: EventListenerGroupImpl
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
public EventListenerGroupImpl(EventType<T> eventType) {
this.eventType = eventType;
duplicationStrategies.add(
// At minimum make sure we do not register the same exact listener class multiple times.
new DuplicationStrategy() {
@Override
public boolean areMatch(Object listener, Object original) {
return listener.getClass().equals( original.getClass() );
}
@Override
public Action getAction() {
return Action.ERROR;
}
}
);
}
示例5: prepareListeners
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
private static <T> void prepareListeners(EventType<T> type, T defaultListener, Map<EventType,EventListenerGroupImpl> map) {
final EventListenerGroupImpl<T> listenerGroup;
if ( type == EventType.POST_COMMIT_DELETE
|| type == EventType.POST_COMMIT_INSERT
|| type == EventType.POST_COMMIT_UPDATE ) {
listenerGroup = new PostCommitEventListenerGroupImpl<T>( type );
}
else {
listenerGroup = new EventListenerGroupImpl<T>( type );
}
if ( defaultListener != null ) {
listenerGroup.appendListener( defaultListener );
}
map.put( type, listenerGroup );
}
示例6: PostCommitEventListenerGroupImpl
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
public PostCommitEventListenerGroupImpl(EventType<T> eventType) {
super( eventType );
if ( eventType == EventType.POST_COMMIT_DELETE ) {
this.extendedListenerContract = PostCommitDeleteEventListener.class;
}
else if ( eventType == EventType.POST_COMMIT_INSERT ) {
this.extendedListenerContract = PostCommitInsertEventListener.class;
}
else if ( eventType == EventType.POST_COMMIT_UPDATE ) {
this.extendedListenerContract = PostCommitUpdateEventListener.class;
}
else {
throw new IllegalStateException( "Unexpected usage of PostCommitEventListenerGroupImpl" );
}
}
示例7: postDelete
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
private void postDelete() {
final EventListenerGroup<PostDeleteEventListener> listenerGroup = listenerGroup( EventType.POST_DELETE );
if ( listenerGroup.isEmpty() ) {
return;
}
final PostDeleteEvent event = new PostDeleteEvent(
getInstance(),
getId(),
state,
getPersister(),
eventSource()
);
for ( PostDeleteEventListener listener : listenerGroup.listeners() ) {
listener.onPostDelete( event );
}
}
示例8: postInsert
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
private void postInsert() {
final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup( EventType.POST_INSERT );
if ( listenerGroup.isEmpty() ) {
return;
}
final PostInsertEvent event = new PostInsertEvent(
getInstance(),
getId(),
getState(),
getPersister(),
eventSource()
);
for ( PostInsertEventListener listener : listenerGroup.listeners() ) {
listener.onPostInsert( event );
}
}
示例9: postInsert
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
private void postInsert() {
if ( isDelayed ) {
getSession().getPersistenceContext().replaceDelayedEntityIdentityInsertKeys( delayedEntityKey, generatedId );
}
final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup( EventType.POST_INSERT );
if ( listenerGroup.isEmpty() ) {
return;
}
final PostInsertEvent event = new PostInsertEvent(
getInstance(),
generatedId,
getState(),
getPersister(),
eventSource()
);
for ( PostInsertEventListener listener : listenerGroup.listeners() ) {
listener.onPostInsert( event );
}
}
示例10: postUpdate
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
private void postUpdate() {
final EventListenerGroup<PostUpdateEventListener> listenerGroup = listenerGroup( EventType.POST_UPDATE );
if ( listenerGroup.isEmpty() ) {
return;
}
final PostUpdateEvent event = new PostUpdateEvent(
getInstance(),
getId(),
state,
previousState,
dirtyFields,
getPersister(),
eventSource()
);
for ( PostUpdateEventListener listener : listenerGroup.listeners() ) {
listener.onPostUpdate( event );
}
}
示例11: registerListeners
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
@PostConstruct
public void registerListeners() {
// TODO: This method of getting a reference to the SessionFactory (and thereforce the ServiceRegistry) is Deprecated. Find out the right Hibernate 5.2 way to do this.
EventListenerRegistry registry = entityManagerFactory.getSessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
if (preInsertEventListeners != null) {
registry.appendListeners(EventType.PRE_INSERT, preInsertEventListeners.toArray(new PreInsertEventListener[preInsertEventListeners.size()]));
}
if (postInsertEventListeners != null) {
registry.appendListeners(EventType.POST_INSERT, postInsertEventListeners.toArray(new PostInsertEventListener[postInsertEventListeners.size()]));
}
if (preUpdateEventListeners != null) {
registry.appendListeners(EventType.PRE_UPDATE, preUpdateEventListeners.toArray(new PreUpdateEventListener[preUpdateEventListeners.size()]));
}
if (postUpdateEventListeners != null) {
registry.appendListeners(EventType.POST_UPDATE, postUpdateEventListeners.toArray(new PostUpdateEventListener[postUpdateEventListeners.size()]));
}
if (preDeleteEventListeners != null) {
registry.appendListeners(EventType.PRE_DELETE, preDeleteEventListeners.toArray(new PreDeleteEventListener[preDeleteEventListeners.size()]));
}
if (postDeleteEventListeners != null) {
registry.appendListeners(EventType.POST_DELETE, postDeleteEventListeners.toArray(new PostDeleteEventListener[postDeleteEventListeners.size()]));
}
}
示例12: integrate
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
EventListenerRegistry service = serviceRegistry.getService(org.hibernate.event.service.spi.EventListenerRegistry.class);
StandardPBEStringEncryptor encrypt = new StandardPBEStringEncryptor();
encrypt.setPassword("test_password");
RenderedMessageEncryptEventListener encryptListener = new RenderedMessageEncryptEventListener();
encryptListener.setStringEncryptor(encrypt);
RenderedMessageDecryptEventListener decryptListener = new RenderedMessageDecryptEventListener();
decryptListener.setStringEncryptor(encrypt);
FullTextIndexEventListener fullTextListener = new FullTextIndexEventListener();
service.appendListeners(EventType.PRE_UPDATE, encryptListener);
service.prependListeners(EventType.POST_UPDATE, decryptListener);
service.appendListeners(EventType.PRE_INSERT, encryptListener);
service.prependListeners(EventType.POST_INSERT, decryptListener);
service.appendListeners(EventType.POST_LOAD, decryptListener);
}
示例13: integrate
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
System.out.println("Integrating......");
//final AuditService auditService = serviceRegistry.getService(AuditService.class);
final AuditService auditService = new AuditServiceImpl();
auditService.init();
if (!auditService.isInitialized()) {
throw new InitializationException(
"Audit4j hibernate integration can not be initialized..");
}
// Register listeners..
final EventListenerRegistry listenerRegistry = serviceRegistry
.getService(EventListenerRegistry.class);
listenerRegistry.appendListeners(EventType.POST_INSERT,
new AuditPostInsertEventListenerImpl(auditService));
listenerRegistry.appendListeners(EventType.POST_UPDATE,
new AuditPostUpdateEventListenerImpl(auditService));
listenerRegistry.appendListeners(EventType.POST_DELETE,
new AuditPostDeleteEventListenerImpl(auditService));
}
示例14: appendListeners
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
protected <T> void appendListeners(EventListenerRegistry listenerRegistry,
EventType<T> eventType, Collection<T> listeners) {
EventListenerGroup<T> group = listenerRegistry.getEventListenerGroup(eventType);
for (T listener : listeners) {
if (listener != null) {
if(shouldOverrideListeners(eventType, listener)) {
// since ClosureEventTriggeringInterceptor extends DefaultSaveOrUpdateEventListener we want to override instead of append the listener here
// to avoid there being 2 implementations which would impact performance too
group.clear();
group.appendListener(listener);
}
else {
group.appendListener(listener);
}
}
}
}
示例15: integrate
import org.hibernate.event.spi.EventType; //导入依赖的package包/类
@Override
public void integrate(org.hibernate.cfg.Configuration configuration,
org.hibernate.engine.spi.SessionFactoryImplementor sessionFactory,
org.hibernate.service.spi.SessionFactoryServiceRegistry serviceRegistry)
{
final EventListenerRegistry eventRegistry =
serviceRegistry.getService(EventListenerRegistry.class);
eventRegistry.prependListeners(EventType.POST_COMMIT_INSERT, listener);
final AuditConfiguration enversConfiguration = AuditConfiguration.getFor( configuration );
AuditStrategy auditStrategy = enversConfiguration.getAuditStrategy();
if (enversConfiguration.getEntCfg().hasAuditedEntities()) {
listenerRegistry.appendListeners( EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl( enversConfiguration ) );
listenerRegistry.appendListeners( EventType.POST_INSERT, new EnversPostInsertEventListenerImpl( enversConfiguration ) );
listenerRegistry.appendListeners( EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl( enversConfiguration ) );
listenerRegistry.appendListeners( EventType.POST_COLLECTION_RECREATE, new EnversPostCollectionRecreateEventListenerImpl( enversConfiguration ) );
listenerRegistry.appendListeners( EventType.PRE_COLLECTION_REMOVE, new EnversPreCollectionRemoveEventListenerImpl( enversConfiguration ) );
listenerRegistry.appendListeners( EventType.PRE_COLLECTION_UPDATE, new EnversPreCollectionUpdateEventListenerImpl( enversConfiguration ) );
}
}