List of usage examples for org.hibernate.tool.hbm2ddl SchemaExport setOutputFile
public SchemaExport setOutputFile(String filename)
From source file:com.mobileman.projecth.InitDbTest.java
License:Apache License
protected void export() throws Exception { SchemaExport export = new SchemaExport(sessionFactory.getConfiguration()); export.setOutputFile("sql.ddl"); export.setDelimiter(";"); //export.drop(false, true); //export.create(false, true); }
From source file:com.netspective.medigy.model.TestCase.java
License:Open Source License
protected void setUp() throws Exception { System.out.println("here in setup"); super.setUp(); final String systemTempDir = System.getProperty("java.io.tmpdir"); final String systemFileSep = System.getProperty("file.separator"); final String testDbDir = System.getProperty("project.test.db.dir", systemTempDir); databaseDirectory = new File(testDbDir + systemFileSep + getClassNameWithoutPackage()); System.out.println("Database directory: " + databaseDirectory.getAbsolutePath()); loadServiceLocator();/*w w w .jav a 2 s. com*/ final HibernateConfiguration hibernateConfiguration = getHibernateConfiguration(); HibernateUtil.setConfiguration(hibernateConfiguration); if (initializeModelData) new ModelInitializer(HibernateUtil.getSession(), ModelInitializer.SeedDataPopulationType.AUTO, hibernateConfiguration).initialize(); // Generate the DDL into a file so we can review it SchemaExport se = new SchemaExport(hibernateConfiguration); final String dialectName = hibernateConfiguration.getProperties().getProperty(Environment.DIALECT); final String dialectShortName = dialectName.substring(dialectName.lastIndexOf('.') + 1); se.setOutputFile( databaseDirectory.getAbsolutePath() + systemFileSep + "medigy-" + dialectShortName + ".ddl"); se.create(false, false); // setup a person here so that we can add a contact information for him/her Session session = new ProcessSession(); session.setProcessName(getClass().getName() + "." + getName()); SessionManager.getInstance().pushActiveSession(session); HibernateUtil.getSession().save(session); }
From source file:com.oneandone.relesia.tools.SQLScriptGenerator.java
License:Apache License
public static void main(String[] args) throws MappingException, IOException { String createSQLFile = "dbscripts/createTables.sql"; String dropSQLFile = "dbscripts/dropTables.sql"; String hibernateCfgFile = "/db/hibernate.cfg.xml"; final EnumSet<TargetType> targetTypes = EnumSet.noneOf(TargetType.class); targetTypes.add(TargetType.SCRIPT);//from w ww . j a va2 s . co m System.out.println("Initialize Hibernate configuration from " + hibernateCfgFile); Configuration cfg = new Configuration().configure(hibernateCfgFile); Metadata metadata = MetadataHelper.getMetadata(cfg); SchemaExport export = new SchemaExport(); export.setHaltOnError(true); export.setFormat(true); export.setDelimiter(";"); System.out.println("Generating create SQL to file " + createSQLFile); if (new File(createSQLFile).exists()) { Files.delete(Paths.get(createSQLFile)); } export.setOutputFile(createSQLFile); export.execute(targetTypes, Action.CREATE, metadata); System.out.println("Generating drop SQL to file " + dropSQLFile); export.setOutputFile(dropSQLFile); if (new File(dropSQLFile).exists()) { Files.delete(Paths.get(dropSQLFile)); } export.execute(targetTypes, Action.DROP, metadata); System.out.println("Done!"); }
From source file:com.premiumminds.persistence.utils.HibernateEnversDDL.java
License:Open Source License
private static void createCommand(String[] args) { String unitName;/*from w ww. j ava 2 s .c o m*/ String filename = null; if (args.length < 2) System.out.println("Expected unitName"); else { unitName = args[1]; if (args.length > 2) filename = args[2]; EnversSchemaGenerator esg = new EnversSchemaGenerator(HibernateDDL.getConfiguration(unitName)); org.hibernate.tool.hbm2ddl.SchemaExport se = esg.export(); se.setOutputFile(filename); se.setFormat(true); se.setDelimiter(";"); se.execute(false, false, false, true); } }
From source file:com.premiumminds.persistence.utils.HibernateEnversDDL.java
License:Open Source License
private static void createDropCommand(String[] args) { String unitName;/*from ww w . j ava 2 s .com*/ String filename = null; if (args.length < 2) System.out.println("Expected unitName"); else { unitName = args[1]; if (args.length > 2) filename = args[2]; EnversSchemaGenerator esg = new EnversSchemaGenerator(HibernateDDL.getConfiguration(unitName)); org.hibernate.tool.hbm2ddl.SchemaExport se = esg.export(); se.setOutputFile(filename); se.setFormat(true); se.setDelimiter(";"); se.execute(false, false, true, true); } }
From source file:com.siemens.scr.avt.ad.util.HibernateUtil.java
License:Open Source License
public static void main(String[] args) { Configuration cfg = new Configuration().configure(); SchemaExport schemaExport = new SchemaExport(cfg); schemaExport.setDelimiter(";"); schemaExport.setFormat(true);//from ww w . j ava 2 s.co m schemaExport.setOutputFile("createSchema.sql"); schemaExport.create(true, false); }
From source file:com.socialsite.scripts.SchemaCreator.java
License:Open Source License
public static void create() { final Configuration cfg = new Configuration().configure(); final SchemaExport schemaExport = new SchemaExport(cfg); schemaExport.setDelimiter(";"); schemaExport.setFormat(true);/* ww w .j av a2 s . c om*/ final File f = new File("src/main/scripts"); f.mkdirs(); schemaExport.setOutputFile("src/main/scripts/schema.sql"); schemaExport.drop(true, true); schemaExport.create(true, true); }
From source file:com.ttech.cordovabuild.infrastructure.DDLExport.java
License:Apache License
@Test public void exportDDL() { Formatter formatter = FormatStyle.DDL.getFormatter(); Ejb3Configuration jpaConfiguration = new Ejb3Configuration().configure("cordova", null); Configuration hibernateConfiguration = jpaConfiguration.getHibernateConfiguration(); SchemaExport export = new SchemaExport(hibernateConfiguration); export.setOutputFile("my-schema.sql"); export.setDelimiter(";"); export.execute(true, false, false, true); }
From source file:com.userweave.config.MPSchemaExport.java
License:Open Source License
/** * @param args/*w w w .j ava 2 s.co m*/ */ public static void main(String[] args) { // if (args.length != 1) { // System.out.println("please specify output filename"); // } // String filename = "schema.ddl";//args[0]; final AnnotationConfiguration configuration = new AnnotationConfiguration(); final Properties properties = new Properties(); properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); configuration.setProperties(properties); SchemaExport export = new SchemaExport(configuration); export.setDelimiter(";"); export.setFormat(true); File outputFile = new File(filename); export.setOutputFile(outputFile.toString()); export.execute(false, false, false, true); }
From source file:com.vecna.maven.hibernate.HibernateSchemaExportMojo.java
License:Apache License
/** * Exports the schema.//from w w w .j a v a 2s. c o m * {@inheritDoc} */ @Override protected void executeWithMappings(Configuration configuration) throws MojoExecutionException, MojoFailureException { SchemaExport schemaExport = new SchemaExport(configuration); schemaExport.setFormat(format); if (outputFile != null) { initializePath(); schemaExport.setOutputFile(outputFile); schemaExport.setDelimiter(delimiter); } schemaExport.execute(print, export, false, !drop); }