org.hibernate.event.spi.PreUpdateEventListener Java Examples
The following examples show how to use
org.hibernate.event.spi.PreUpdateEventListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityUpdateAction.java From lams with GNU General Public License v2.0 | 6 votes |
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; }
Example #2
Source File: EventIntegrator.java From micronaut-data with Apache License 2.0 | 4 votes |
@Override public void integrate( Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class); Collection<PersistentClass> entityBindings = metadata.getEntityBindings(); Map<Class, BeanProperty> lastUpdates = new HashMap<>(entityBindings.size()); Map<Class, BeanProperty> dateCreated = new HashMap<>(entityBindings.size()); entityBindings.forEach(e -> { Class<?> mappedClass = e.getMappedClass(); if (mappedClass != null) { BeanIntrospection<?> introspection = BeanIntrospector.SHARED.findIntrospection(mappedClass).orElse(null); if (introspection != null) { introspection.getIndexedProperty(DateCreated.class).ifPresent(bp -> dateCreated.put(mappedClass, bp) ); introspection.getIndexedProperty(DateUpdated.class).ifPresent(bp -> lastUpdates.put(mappedClass, bp) ); } } } ); ConversionService<?> conversionService = ConversionService.SHARED; if (CollectionUtils.isNotEmpty(dateCreated)) { eventListenerRegistry.getEventListenerGroup(EventType.PRE_INSERT) .appendListener((PreInsertEventListener) event -> { Object[] state = event.getState(); timestampIfNecessary( dateCreated, lastUpdates, conversionService, event, state, true ); return false; }); } if (CollectionUtils.isNotEmpty(lastUpdates)) { eventListenerRegistry.getEventListenerGroup(EventType.PRE_UPDATE) .appendListener((PreUpdateEventListener) event -> { timestampIfNecessary( dateCreated, lastUpdates, conversionService, event, event.getState(), false ); return false; }); } }