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();
}
Aggregations