Class PersistenceService
java.lang.Object
org.openremote.container.persistence.PersistenceService
- All Implemented Interfaces:
Consumer<org.openremote.model.PersistenceEvent<?>>,org.openremote.model.ContainerService
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classProgrammatic definition of OpenRemotePU for hibernate -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Databaseprotected javax.persistence.EntityManagerFactoryprotected org.flywaydb.core.Flywayprotected booleanstatic final Stringprotected MessageBrokerServicestatic final Stringstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final intstatic final Stringstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringWe must use a different schema than Keycloak to store our tables, or FlywayDB will wipe Keycloak tables.static final Stringstatic final Stringstatic final Stringprotected Stringprotected Propertiesstatic final intFields inherited from interface org.openremote.model.ContainerService
DEFAULT_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, MED_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(org.openremote.model.PersistenceEvent<?> persistenceEvent) protected voidappendSchemaLocations(List<String> locations) protected voidappendSchemas(List<String> schemas) javax.persistence.EntityManager<R> RdoReturningTransaction(Function<javax.persistence.EntityManager, R> entityManagerFunction) voiddoTransaction(Consumer<javax.persistence.EntityManager> entityManagerConsumer) javax.persistence.EntityManagerFactoryprotected javax.persistence.EntityManagerFactorygetEntityManagerFactory(Properties properties, List<String> classNames) intGets the priority of this service which is used to determine initialization order when services are auto discovered; services with a lower priority are initialized and started first.voidinit(org.openremote.model.Container container) All services are initialized in the order they have been added to the container (if container started with explicit list of services) otherwise they are initialized in order ofContainerService.getPriority().booleanstatic org.apache.camel.PredicateisPersistenceEventForEntityType(Class<?> type) protected voidopenDatabase(org.openremote.model.Container container, Database database, String username, String password, String connectionUrl) protected voidprepareSchema(String connectionUrl, String databaseUsername, String databasePassword, String schemaName) voidpublishPersistenceEvent(org.openremote.model.PersistenceEvent.Cause cause, Object currentEntity, Object previousEntity, Field[] propertyFields) GeneratePersistenceEvents for entities not managed by JPA (i.e.voidpublishPersistenceEvent(org.openremote.model.PersistenceEvent.Cause cause, Object entity, String[] propertyNames, Object[] currentState, Object[] previousState) GeneratePersistenceEvents for entities not managed by JPA (i.e.voidstart(org.openremote.model.Container container) After initialization, services are started in the order they have been added to the container (if container started with explicit list of services) otherwise they are started in order ofContainerService.getPriority().voidstop(org.openremote.model.Container container) When the container is shutting down, it stops all services in the reverse order they were started.toString()
-
Field Details
-
PERSISTENCE_TOPIC
- See Also:
-
HEADER_ENTITY_TYPE
-
OR_SETUP_RUN_ON_RESTART
We must use a different schema than Keycloak to store our tables, or FlywayDB will wipe Keycloak tables. And since Keycloak doesn't call CREATE SCHEMA IF NOT EXISTS on startup (Liquibase is not as good as FlywayDB? They both seem to suck... can't exclude database artifacts from wipe/migrate in FlywayDB...) you must have it in the 'public' schema. Hence we need a different schema here.- See Also:
-
PERSISTENCE_UNIT_NAME
- See Also:
-
PERSISTENCE_UNIT_NAME_DEFAULT
- See Also:
-
OR_DB_VENDOR
- See Also:
-
OR_DB_VENDOR_DEFAULT
-
OR_DB_HOST
- See Also:
-
OR_DB_HOST_DEFAULT
- See Also:
-
OR_DB_PORT
- See Also:
-
OR_DB_PORT_DEFAULT
public static final int OR_DB_PORT_DEFAULT- See Also:
-
OR_DB_NAME
- See Also:
-
OR_DB_NAME_DEFAULT
- See Also:
-
OR_DB_SCHEMA
- See Also:
-
OR_DB_SCHEMA_DEFAULT
- See Also:
-
OR_DB_USER
- See Also:
-
OR_DB_USER_DEFAULT
- See Also:
-
OR_DB_PASSWORD
- See Also:
-
OR_DB_PASSWORD_DEFAULT
- See Also:
-
OR_DB_MIN_POOL_SIZE
- See Also:
-
OR_DB_MIN_POOL_SIZE_DEFAULT
public static final int OR_DB_MIN_POOL_SIZE_DEFAULT- See Also:
-
OR_DB_MAX_POOL_SIZE
- See Also:
-
OR_DB_MAX_POOL_SIZE_DEFAULT
public static final int OR_DB_MAX_POOL_SIZE_DEFAULT- See Also:
-
OR_DB_CONNECTION_TIMEOUT_SECONDS
- See Also:
-
OR_DB_CONNECTION_TIMEOUT_SECONDS_DEFAULT
public static final int OR_DB_CONNECTION_TIMEOUT_SECONDS_DEFAULT- See Also:
-
PRIORITY
public static final int PRIORITY- See Also:
-
messageBrokerService
-
database
-
persistenceUnitName
-
persistenceUnitProperties
-
entityManagerFactory
protected javax.persistence.EntityManagerFactory entityManagerFactory -
flyway
protected org.flywaydb.core.Flyway flyway -
forceClean
protected boolean forceClean -
defaultSchemaLocations
-
schemas
-
-
Constructor Details
-
PersistenceService
public PersistenceService()
-
-
Method Details
-
isPersistenceEventForEntityType
-
getPriority
public int getPriority()Description copied from interface:org.openremote.model.ContainerServiceGets the priority of this service which is used to determine initialization order when services are auto discovered; services with a lower priority are initialized and started first.- Specified by:
getPriorityin interfaceorg.openremote.model.ContainerService
-
init
Description copied from interface:org.openremote.model.ContainerServiceAll services are initialized in the order they have been added to the container (if container started with explicit list of services) otherwise they are initialized in order ofContainerService.getPriority().- Specified by:
initin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
getEntityManagerFactory
protected javax.persistence.EntityManagerFactory getEntityManagerFactory(Properties properties, List<String> classNames) -
start
Description copied from interface:org.openremote.model.ContainerServiceAfter initialization, services are started in the order they have been added to the container (if container started with explicit list of services) otherwise they are started in order ofContainerService.getPriority().- Specified by:
startin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
stop
Description copied from interface:org.openremote.model.ContainerServiceWhen the container is shutting down, it stops all services in the reverse order they were started.- Specified by:
stopin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
isCleanInstall
public boolean isCleanInstall() -
createEntityManager
public javax.persistence.EntityManager createEntityManager() -
doTransaction
-
doReturningTransaction
public <R> R doReturningTransaction(Function<javax.persistence.EntityManager, R> entityManagerFunction) -
getEntityManagerFactory
public javax.persistence.EntityManagerFactory getEntityManagerFactory() -
getDefaultSchemaLocations
-
getSchemas
-
publishPersistenceEvent
public void publishPersistenceEvent(org.openremote.model.PersistenceEvent.Cause cause, Object currentEntity, Object previousEntity, Field[] propertyFields) GeneratePersistenceEvents for entities not managed by JPA (i.e. Keycloak entities) -
publishPersistenceEvent
public void publishPersistenceEvent(org.openremote.model.PersistenceEvent.Cause cause, Object entity, String[] propertyNames, Object[] currentState, Object[] previousState) GeneratePersistenceEvents for entities not managed by JPA (i.e. Keycloak entities) -
openDatabase
-
prepareSchema
-
appendSchemaLocations
-
appendSchemas
-
accept
public void accept(org.openremote.model.PersistenceEvent<?> persistenceEvent) -
toString
-