Search in sources :

Example 1 with Database

use of org.openremote.container.persistence.Database in project openremote by openremote.

the class SchemaExporter method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        throw new IllegalArgumentException("Missing target file path argument");
    }
    File schemaFile = new File(args[0]);
    Container container = new Container(new ManagerExecutorService(), new ManagerPersistenceService() {

        @Override
        protected void openDatabase(Container container, Database database) {
        // Ignore, we don't want to connect to the database when exporting schema
        }

        @Override
        public void start(Container container) throws Exception {
            Map<String, Object> createSchemaProperties = new HashMap<>(persistenceUnitProperties);
            createSchemaProperties.put("javax.persistence.schema-generation.scripts.action", "create");
            createSchemaProperties.put("javax.persistence.schema-generation.scripts.create-target", schemaFile.getAbsolutePath());
            if (schemaFile.exists()) {
                LOG.info("Deleting existing schema file: " + schemaFile.getAbsolutePath());
                schemaFile.delete();
            }
            LOG.info("Exporting database schema for persistence unit: " + persistenceUnitName);
            Persistence.generateSchema(persistenceUnitName, createSchemaProperties);
            LOG.fine("Schema export complete: " + schemaFile.getAbsolutePath());
        }
    });
    container.start();
}
Also used : Container(org.openremote.container.Container) ManagerPersistenceService(org.openremote.manager.persistence.ManagerPersistenceService) Database(org.openremote.container.persistence.Database) ManagerExecutorService(org.openremote.manager.concurrent.ManagerExecutorService) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Container (org.openremote.container.Container)1 Database (org.openremote.container.persistence.Database)1 ManagerExecutorService (org.openremote.manager.concurrent.ManagerExecutorService)1 ManagerPersistenceService (org.openremote.manager.persistence.ManagerPersistenceService)1