As mentioned previously, Artemis has support to persistence lifecycle to update and save an Entity. This lifecycle order is managed by a WorkFlow class. The default workflow is:
firePreEntity: The Object received from Artemis.
firePreEntityDataBaseType: Just like the previous event, however, to a specific database, in other words, each database has a particular event.
firePreAPI: The object converted to a communication layer.
firePostAPI: The entity connection as a response from the database.
firePostEntity: The entity model from the API low level from the firePostAPI.
firePostEntityDataBaseType: Just like the previous event, however, to a specific database, in other words, each database has a particular event.
Tha watch this event, just need to use an @Observes, a form of CDI itself.
ColumnWorkFlow
@ApplicationScopedpublicclassPersonEvent {privatestaticfinalLogger LOGGER =Logger.getLogger(PersonEvent.class.getName());publicvoidobserver(@ObservesEntityPrePersist event) {LOGGER.info("Event to pre persistence"+event.getValue()); }publicvoidobserver(@ObservesEntityColumnPrePersist event) {LOGGER.info("Event to pre document persistence"+event.getValue()); }publicvoidobserver(@ObservesColumnEntityPrePersist event) {LOGGER.info("Event to pre document entity"+event.getEntity()); }publicvoidobserver(@ObservesColumnEntityPostPersist event) {LOGGER.info("Event to post document entity"+event.getEntity()); }publicvoidobserver(@ObservesEntityPostPersit event) {LOGGER.info("Event to post persistence"+event.getValue()); }publicvoidobserver(@ObservesEntityColumnPostPersist event) {LOGGER.info("Event to post document entity"+event.getValue()); }}
DocumentWorkFlow
@ApplicationScopedpublicclassPersonEvent {privatestaticfinalLogger LOGGER =Logger.getLogger(PersonEvent.class.getName());publicvoidobserver(@ObservesEntityPrePersist event) {LOGGER.info("Event to pre persistence"+event.getValue()); }publicvoidobserver(@ObservesEntityDocumentPrePersist event) {LOGGER.info("Event to pre document persistence"+event.getValue()); }publicvoidobserver(@ObservesDocumentEntityPrePersist event) {LOGGER.info("Event to pre document entity"+event.getEntity()); }publicvoidobserver(@ObservesDocumentEntityPostPersist event) {LOGGER.info("Event to post document entity"+event.getEntity()); }publicvoidobserver(@ObservesEntityPostPersit event) {LOGGER.info("Event to post persistence"+event.getValue()); }publicvoidobserver(@ObservesEntityDocumentPostPersist event) {LOGGER.info("Event to post document entity"+event.getValue()); }}
KeyValueWorkFlow
@ApplicationScopedpublicclassUserEvent {privatestaticfinalLogger LOGGER =Logger.getLogger(UserEvent.class.getName());publicvoidobserver(@ObservesEntityPrePersist event) {LOGGER.info("Event to pre persistence"+event.getValue()); }publicvoidobserver(@ObservesEntityKeyValuePrePersist event) {LOGGER.info("Event to pre document persistence"+event.getValue()); }publicvoidobserver(@ObservesKeyValueEntityPrePersist event) {LOGGER.info("Event to pre document entity"+event.getEntity()); }publicvoidobserver(@ObservesKeyValueEntityPostPersist event) {LOGGER.info("Event to post document entity"+event.getEntity()); }publicvoidobserver(@ObservesEntityPostPersit event) {LOGGER.info("Event to post persistence"+event.getValue()); }publicvoidobserver(@ObservesEntityKeyValuePostPersist event) {LOGGER.info("Event to post document entity"+event.getValue()); }}
Events to search and remove information
Beyond the events for insert and update, in the document and column APIs, Artemis has also a specific event for search queries and deletions.
publicclassColumnQueryEvent {privatestaticfinalLogger LOGGER =Logger.getLogger(ColumnQueryEvent.class.getName());publicvoidobserver(@ObservesColumnQueryExecute event) {ColumnQuery query =event.getQuery();LOGGER.info("Event to pre persistence"+ query); }publicvoidobserver(@ObservesColumnDeleteQueryExecute event) {ColumnDeleteQuery query =event.getQuery();LOGGER.info("Event to pre persistence"+ query); }}publicclassDocumentQueryEvent {privatestaticfinalLogger LOGGER =Logger.getLogger(DocumentQueryEvent.class.getName());publicvoidobserver(@ObservesDocumentQueryExecute event) {DocumentQuery query =event.getQuery();LOGGER.info("Event to pre persistence"+ query); }publicvoidobserver(@ObservesDocumentDeleteQueryExecute event) {DocumentDeleteQuery query =event.getQuery();LOGGER.info("Event to pre persistence"+ query); }}