List of usage examples for org.hibernate.tool.hbm2ddl SchemaExport create
public void create(EnumSet<TargetType> targetTypes, Metadata metadata)
From source file:org.stanwood.media.database.DBHelper.java
License:Open Source License
/** * Uses to get the database schema for a given dialect * @param dialect The dialect/*from w w w .j a v a2 s. c o m*/ * @return The schema * @throws DatabaseException Thrown if their is a problem with hibernate */ public String getSchema(String dialect) throws DatabaseException { try { Configuration config = getConfiguration("", "", "", dialect, SchemaCheck.NONE); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ SchemaExport exporter = new SchemaExport(config); exporter.setFormat(true); File file = FileHelper.createTempFile("schema", ".sql"); //$NON-NLS-1$//$NON-NLS-2$ try { exporter.setOutputFile(file.getAbsolutePath()); exporter.create(true, false); return FileHelper.readFileContents(file); } finally { FileHelper.delete(file); } } catch (HibernateException e) { throw new DatabaseException(Messages.getString("DBHelper.UnablePrintSchema"), e); //$NON-NLS-1$ } catch (XMLParserException e) { throw new DatabaseException(Messages.getString("DBHelper.UnablePrintSchema"), e); //$NON-NLS-1$ } catch (IOException e) { throw new DatabaseException(Messages.getString("DBHelper.UnablePrintSchema"), e); //$NON-NLS-1$ } }
From source file:org.thelq.stackexchange.dbimport.DatabaseWriter.java
License:Apache License
public static void createTables(DumpContainer container) { SchemaExport exporter = new SchemaExport(container.getServiceRegistry(), container.getHibernateConfiguration()); exporter.setHaltOnError(true);/*from w w w. ja v a 2 s . c om*/ exporter.create(false, true); log.info("Finished creating tables for " + Utils.getLongLocation(container)); }
From source file:org.traffic.database.Database.java
License:Open Source License
/** * Resets the connection to the default-values. *//*from w w w .j a v a2s . c o m*/ public static void reset() { if (hibernate_config == null) throw new ExceptionInInitializerError("No config present, cant reset!"); SchemaExport ex = new SchemaExport(hibernate_config); ex.create(false, true); }
From source file:ru.appliedtech.storage.hibernate.DDLGeneratorUtil.java
License:Open Source License
public static void execute(String dialectClassName, String packageName, String outputFilePath) { Configuration configuration = new Configuration(); configuration.addPackage(packageName); configuration.setProperty(Environment.DIALECT, dialectClassName); Collection<Class<? extends Object>> classes = getPackageClasses(packageName); for (Class<?> entityClass : classes) { configuration.addAnnotatedClass(entityClass); }//from ww w .j a v a 2 s .c o m SchemaExport schemaExport = new SchemaExport(configuration); schemaExport.setDelimiter(";"); schemaExport.setOutputFile(outputFilePath); schemaExport.create(true, false); }
From source file:ru.runa.wfe.commons.logic.InitializerLogic.java
License:Open Source License
/** * Initialize database.//w ww . jav a 2 s. c om * * @param daoHolder * Helper object for getting DAO's. */ protected void initializeDatabase(UserTransaction transaction) { log.info("database is not initialized. initializing..."); SchemaExport schemaExport = new SchemaExport(ApplicationContextFactory.getConfiguration()); schemaExport.create(true, true); try { transaction.begin(); insertInitialData(); constantDAO.setDatabaseVersion(dbPatches.size()); transaction.commit(); } catch (Throwable th) { Utils.rollbackTransaction(transaction); throw Throwables.propagate(th); } }
From source file:uk.co.modularaudio.util.hibernate.generator.GeneratorHelper.java
License:Open Source License
/** * Method to configure necessary hibernate properties and generate DDL for a supplied configuration * @param dialectName Which hibernate dialect should be used * @param destinationDirectory The output directory * @param outputFileName The output filename * @param configuration The hibernate configuration setup with the appropriate schema objects */// w w w.j a v a 2 s . c o m private void configureAndGenerate(final String dialectName, final String destinationDirectory, final String outputFileName, final Configuration configuration) { final Properties dialect = new Properties(); dialect.setProperty("hibernate.dialect", dialectName); configuration.addProperties(dialect); final SchemaExport se = new SchemaExport(configuration); se.setOutputFile(destinationDirectory + outputFileName); se.setDelimiter(";\n"); se.create(true, false); }
From source file:util.CriarBanco.java
public static void criarBanco() { AnnotationConfiguration cfg = new AnnotationConfiguration(); cfg.configure("hibernate.cfg.xml"); SchemaExport se = new SchemaExport(cfg); se.create(true, true); }
From source file:util.HibernateDDLGenerator.java
private void execute(Dialect dialect, Class<?>... classes) { AnnotationConfiguration configuration = new AnnotationConfiguration(); configuration.setProperty(Environment.DIALECT, dialect.getClassName()); for (Class<?> entityClass : classes) { configuration.addAnnotatedClass(entityClass); }/*from w ww. j a v a 2s.c o m*/ configuration.configure("hibernate.cfg.xml"); SchemaExport schemaExport = new SchemaExport(configuration); schemaExport.setDelimiter(";"); schemaExport.setOutputFile( String.format("%s_%s.%s ", new Object[] { "ddl", dialect.name().toLowerCase(), "sql" })); boolean consolePrint = true; boolean exportInDatabase = true; schemaExport.create(consolePrint, exportInDatabase); }