Class PersistenceService

java.lang.Object
org.openremote.container.persistence.PersistenceService
All Implemented Interfaces:
Consumer<org.openremote.model.PersistenceEvent<?>>, org.openremote.model.ContainerService

public class PersistenceService extends Object implements org.openremote.model.ContainerService, Consumer<org.openremote.model.PersistenceEvent<?>>
  • Field Details

    • PERSISTENCE_TOPIC

      public static final String PERSISTENCE_TOPIC
      See Also:
    • HEADER_ENTITY_TYPE

      public static final String HEADER_ENTITY_TYPE
    • OR_SETUP_RUN_ON_RESTART

      public static final String 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

      public static final String PERSISTENCE_UNIT_NAME
      See Also:
    • PERSISTENCE_UNIT_NAME_DEFAULT

      public static final String PERSISTENCE_UNIT_NAME_DEFAULT
      See Also:
    • OR_DB_VENDOR

      public static final String OR_DB_VENDOR
      See Also:
    • OR_DB_VENDOR_DEFAULT

      public static final String OR_DB_VENDOR_DEFAULT
    • OR_DB_HOST

      public static final String OR_DB_HOST
      See Also:
    • OR_DB_HOST_DEFAULT

      public static final String OR_DB_HOST_DEFAULT
      See Also:
    • OR_DB_PORT

      public static final String OR_DB_PORT
      See Also:
    • OR_DB_PORT_DEFAULT

      public static final int OR_DB_PORT_DEFAULT
      See Also:
    • OR_DB_NAME

      public static final String OR_DB_NAME
      See Also:
    • OR_DB_NAME_DEFAULT

      public static final String OR_DB_NAME_DEFAULT
      See Also:
    • OR_DB_SCHEMA

      public static final String OR_DB_SCHEMA
      See Also:
    • OR_DB_SCHEMA_DEFAULT

      public static final String OR_DB_SCHEMA_DEFAULT
      See Also:
    • OR_DB_USER

      public static final String OR_DB_USER
      See Also:
    • OR_DB_USER_DEFAULT

      public static final String OR_DB_USER_DEFAULT
      See Also:
    • OR_DB_PASSWORD

      public static final String OR_DB_PASSWORD
      See Also:
    • OR_DB_PASSWORD_DEFAULT

      public static final String OR_DB_PASSWORD_DEFAULT
      See Also:
    • OR_DB_MIN_POOL_SIZE

      public static final String 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

      public static final String 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

      public static final String 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

      protected MessageBrokerService messageBrokerService
    • database

      protected Database database
    • persistenceUnitName

      protected String persistenceUnitName
    • persistenceUnitProperties

      protected Properties persistenceUnitProperties
    • entityManagerFactory

      protected javax.persistence.EntityManagerFactory entityManagerFactory
    • flyway

      protected org.flywaydb.core.Flyway flyway
    • forceClean

      protected boolean forceClean
    • defaultSchemaLocations

      protected Set<String> defaultSchemaLocations
    • schemas

      protected Set<String> schemas
  • Constructor Details

    • PersistenceService

      public PersistenceService()
  • Method Details

    • isPersistenceEventForEntityType

      public static org.apache.camel.Predicate isPersistenceEventForEntityType(Class<?> type)
    • 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 interface org.openremote.model.ContainerService
    • init

      public void init(org.openremote.model.Container container) throws Exception
      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 of ContainerService.getPriority().
      Specified by:
      init in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • getEntityManagerFactory

      protected javax.persistence.EntityManagerFactory getEntityManagerFactory(Properties properties, List<String> classNames)
    • start

      public void start(org.openremote.model.Container container) throws Exception
      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 of ContainerService.getPriority().
      Specified by:
      start in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • stop

      public void stop(org.openremote.model.Container container) throws Exception
      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 interface org.openremote.model.ContainerService
      Throws:
      Exception
    • isCleanInstall

      public boolean isCleanInstall()
    • createEntityManager

      public javax.persistence.EntityManager createEntityManager()
    • doTransaction

      public void doTransaction(Consumer<javax.persistence.EntityManager> entityManagerConsumer)
    • doReturningTransaction

      public <R> R doReturningTransaction(Function<javax.persistence.EntityManager,R> entityManagerFunction)
    • getEntityManagerFactory

      public javax.persistence.EntityManagerFactory getEntityManagerFactory()
    • getDefaultSchemaLocations

      public Set<String> getDefaultSchemaLocations()
    • getSchemas

      public Set<String> getSchemas()
    • publishPersistenceEvent

      public void publishPersistenceEvent(org.openremote.model.PersistenceEvent.Cause cause, Object currentEntity, Object previousEntity, Field[] propertyFields)
      Generate PersistenceEvents 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)
      Generate PersistenceEvents for entities not managed by JPA (i.e. Keycloak entities)
    • openDatabase

      protected void openDatabase(org.openremote.model.Container container, Database database, String username, String password, String connectionUrl)
    • prepareSchema

      protected void prepareSchema(String connectionUrl, String databaseUsername, String databasePassword, String schemaName)
    • appendSchemaLocations

      protected void appendSchemaLocations(List<String> locations)
    • appendSchemas

      protected void appendSchemas(List<String> schemas)
    • accept

      public void accept(org.openremote.model.PersistenceEvent<?> persistenceEvent)
      Specified by:
      accept in interface Consumer<org.openremote.model.PersistenceEvent<?>>
    • toString

      public String toString()
      Overrides:
      toString in class Object