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 class
Programmatic definition of OpenRemotePU for hibernate -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Database
protected jakarta.persistence.EntityManagerFactory
protected org.flywaydb.core.Flyway
protected boolean
static final String
protected MessageBrokerService
static final String
static final int
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final String
static final int
static final String
static final int
static final String
static final String
static final String
static final String
static final String
static final String
static final String
We must use a different schema than Keycloak to store our tables, or FlywayDB will wipe Keycloak tables.static final String
static final String
static final String
static final String
static final String
protected String
protected Properties
static final int
protected Path
Fields inherited from interface org.openremote.model.ContainerService
DEFAULT_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, MED_PRIORITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(org.openremote.model.PersistenceEvent<?> persistenceEvent) protected void
appendSchemaLocations
(List<String> locations) protected void
appendSchemas
(List<String> schemas) jakarta.persistence.EntityManager
<R> R
doReturningTransaction
(Function<jakarta.persistence.EntityManager, R> entityManagerFunction) void
doTransaction
(Consumer<jakarta.persistence.EntityManager> entityManagerConsumer) jakarta.persistence.EntityManagerFactory
protected jakarta.persistence.EntityManagerFactory
getEntityManagerFactory
(Properties properties, List<String> classNames) static Field[]
int
Gets 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.void
init
(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()
.boolean
static org.apache.camel.Predicate
isPersistenceEventForEntityType
(Class<?> type) protected void
openDatabase
(org.openremote.model.Container container, Database database, String username, String password, String connectionUrl) protected void
prepareSchema
(org.openremote.model.Container container, String connectionUrl, String databaseUsername, String databasePassword, String schemaName) void
publishPersistenceEvent
(org.openremote.model.PersistenceEvent.Cause cause, Object currentEntity, Object previousEntity, Class<?> clazz, List<String> includeFields, List<String> excludeFields) GeneratePersistenceEvent
s for entities not managed by JPA (i.e.void
publishPersistenceEvent
(org.openremote.model.PersistenceEvent.Cause cause, Object entity, String[] propertyNames, Object[] currentState, Object[] previousState) GeneratePersistenceEvent
s for entities not managed by JPA (i.e.resolvePath
(String path) Will resolve relative paths relative togetStorageDir()
resolvePath
(Path path) Will resolve relative paths relative togetStorageDir()
void
start
(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()
.void
stop
(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_POOL_MIN_SIZE
- See Also:
-
OR_DB_POOL_MIN_SIZE_DEFAULT
public static final int OR_DB_POOL_MIN_SIZE_DEFAULT- See Also:
-
OR_DB_POOL_MAX_SIZE
- See Also:
-
OR_DB_POOL_MAX_SIZE_DEFAULT
public static final int OR_DB_POOL_MAX_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:
-
OR_STORAGE_DIR
- See Also:
-
OR_STORAGE_DIR_DEFAULT
- See Also:
-
OR_DB_FLYWAY_OUT_OF_ORDER
- See Also:
-
PRIORITY
public static final int PRIORITY- See Also:
-
messageBrokerService
-
database
-
persistenceUnitName
-
persistenceUnitProperties
-
entityManagerFactory
protected jakarta.persistence.EntityManagerFactory entityManagerFactory -
flyway
protected org.flywaydb.core.Flyway flyway -
forceClean
protected boolean forceClean -
defaultSchemaLocations
-
schemas
-
storageDir
-
-
Constructor Details
-
PersistenceService
public PersistenceService()
-
-
Method Details
-
isPersistenceEventForEntityType
-
getPriority
public int getPriority()Description copied from interface:org.openremote.model.ContainerService
Gets 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:
getPriority
in interfaceorg.openremote.model.ContainerService
-
init
Description copied from interface:org.openremote.model.ContainerService
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()
.- Specified by:
init
in interfaceorg.openremote.model.ContainerService
- Throws:
Exception
-
getEntityManagerFactory
protected jakarta.persistence.EntityManagerFactory getEntityManagerFactory(Properties properties, List<String> classNames) -
start
Description copied from interface:org.openremote.model.ContainerService
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()
.- Specified by:
start
in interfaceorg.openremote.model.ContainerService
- Throws:
Exception
-
stop
Description copied from interface:org.openremote.model.ContainerService
When the container is shutting down, it stops all services in the reverse order they were started.- Specified by:
stop
in interfaceorg.openremote.model.ContainerService
- Throws:
Exception
-
isCleanInstall
public boolean isCleanInstall() -
createEntityManager
public jakarta.persistence.EntityManager createEntityManager() -
doTransaction
-
doReturningTransaction
public <R> R doReturningTransaction(Function<jakarta.persistence.EntityManager, R> entityManagerFunction) -
getEntityManagerFactory
public jakarta.persistence.EntityManagerFactory getEntityManagerFactory() -
getDefaultSchemaLocations
-
getSchemas
-
publishPersistenceEvent
public void publishPersistenceEvent(org.openremote.model.PersistenceEvent.Cause cause, Object currentEntity, Object previousEntity, Class<?> clazz, List<String> includeFields, List<String> excludeFields) GeneratePersistenceEvent
s 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) GeneratePersistenceEvent
s for entities not managed by JPA (i.e. Keycloak entities) -
openDatabase
-
prepareSchema
-
appendSchemaLocations
-
appendSchemas
-
accept
public void accept(org.openremote.model.PersistenceEvent<?> persistenceEvent) -
toString
-
getStorageDir
-
resolvePath
Will resolve relative paths relative togetStorageDir()
-
resolvePath
Will resolve relative paths relative togetStorageDir()
-
getEntityPropertyFields
-