/** * Generates the database schema for the current configured database. * * @param filename Write the schema to the given file. No file output, if null. * @param script Print the DDL to the console. * @param export If true, the script will be executed (export the script to the database). */ public void exportSchema(String filename) { Map<String, String> props = new HashMap<>(); props.put("javax.persistence.schema-generation.scripts.action", "create"); props.put("javax.persistence.schema-generation.scripts.create-target", filename); Persistence.generateSchema(PfEmgrFactory.get().getUnitName(), props); }
@Override public void doExecute() { try { StringBuffer res = new StringBuffer(); HashMap<String, String> initProps = new HashMap<String, String>(); initProps.put("hibernate.hbm2ddl.auto", "create"); MCRJPABootstrapper.initializeJPA(MCRJPABootstrapper.PERSISTENCE_UNIT_NAME, initProps); doSchemaOperation(schema -> "create schema " + schema); Map<String, Object> schemaProperties = new HashMap<>(); schemaProperties.put("javax.persistence.schema-generation.database.action", ACTION); try (StringWriter output = new StringWriter()) { schemaProperties.put("javax.persistence.schema-generation.scripts.action", ACTION); schemaProperties.put("javax.persistence.schema-generation.scripts." + ACTION + "-target", output); Persistence.generateSchema(MCRJPABootstrapper.PERSISTENCE_UNIT_NAME, schemaProperties); res.append(output.toString()); } this.result.setSuccess(true); this.result.setResult(res.toString()); } catch (IOException | PersistenceException ex) { ex.printStackTrace(); this.result.setSuccess(false); this.result.setResult(ex.getMessage()); } }
if (getVendor() == null) { Persistence.generateSchema(this.persistenceUnitName, map); } else { PersistenceProvider provider = getProviderClass().newInstance();