List of usage examples for org.hibernate.dialect Dialect getDefaultProperties
public final Properties getDefaultProperties()
From source file:com.ironiacorp.persistence.hibernate.GenericHibernateDataSource.java
License:Open Source License
/** * Get the DDL script to update the database. *///from www . j a v a 2 s . c om public String getUpdateDDLScript() { Dialect dialect = Dialect.getDialect(hibernateConfig.getProperties()); Properties props = new Properties(); // ConnectionProvider connectionProvider = null; DatabaseMetadata dm = null; props.putAll(dialect.getDefaultProperties()); props.putAll(hibernateConfig.getProperties()); /* connectionProvider = ConnectionProviderFactory.newConnectionProvider(props); try { dm = new DatabaseMetadata(connectionProvider.getConnection(), dialect); } catch ( SQLException e ) { log.debug("Could not get database DDL script", e); } */ String[] script = hibernateConfig.generateSchemaUpdateScript(dialect, dm); return ArrayUtil.toString(script); }
From source file:com.ironiacorp.persistence.hibernate.HibernateBootstrap.java
License:Open Source License
/** * Get the DDL script to update the database. *//*www . j a va 2 s . c o m*/ public String getUpdateDDLScript() { Dialect dialect = Dialect.getDialect(config.getProperties()); Properties props = new Properties(); // ConnectionProvider connectionProvider = null; DatabaseMetadata dm = null; props.putAll(dialect.getDefaultProperties()); props.putAll(config.getProperties()); /* connectionProvider = ConnectionProviderFactory.newConnectionProvider(props); try { dm = new DatabaseMetadata(connectionProvider.getConnection(), dialect); } catch (SQLException e) { log.debug("Could not get database DDL script", e); } */ String[] script = config.generateSchemaUpdateScript(dialect, dm); return ArrayUtil.toString(script); }
From source file:org.kuali.mobility.database.service.DatabaseServiceImpl.java
License:Open Source License
private String execute(String dialectStr, String delimiter, boolean overrideAlterTable) { PersistenceUnitInfo persistenceUnitInfo = entityManagerFactory.getPersistenceUnitInfo(); Map<String, Object> jpaPropertyMap = entityManagerFactory.getJpaPropertyMap(); jpaPropertyMap.put("hibernate.dialect", dialectStr); Configuration configuration = new Ejb3Configuration().configure(persistenceUnitInfo, jpaPropertyMap) .getHibernateConfiguration(); // KMEDatabaseConfiguration c = (KMEDatabaseConfiguration) configuration; if (overrideAlterTable) { Iterator iter = configuration.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); if (table.isPhysicalTable()) { Iterator subIter = table.getForeignKeyIterator(); while (subIter.hasNext()) { ForeignKey fk = (ForeignKey) subIter.next(); if (fk.isPhysicalConstraint()) { subIter.remove(); }// w w w .ja va 2 s.c o m } } } } Properties configurationProperties = configuration.getProperties(); Dialect dialect = Dialect.getDialect(configurationProperties); // if (dialect instanceof KMEDialect) { // KMEDialect d = (KMEDialect) dialect; // d.setOverrideAlterTable(overrideAlterTable); // } Properties props = new Properties(); props.putAll(dialect.getDefaultProperties()); props.putAll(configurationProperties); String[] dropSQL = configuration.generateDropSchemaScript(dialect); String[] createSQL = configuration.generateSchemaCreationScript(dialect); Formatter formatter = (PropertiesHelper.getBoolean(Environment.FORMAT_SQL, props) ? FormatStyle.DDL : FormatStyle.NONE).getFormatter(); boolean format = true; formatter = (format ? FormatStyle.DDL : FormatStyle.NONE).getFormatter(); // String delimiter = ";"; StringBuffer output = new StringBuffer(); for (String s : dropSQL) { output.append(formatMe(s, formatter, delimiter)); output.append("\n"); } for (String s : createSQL) { output.append(formatMe(s, formatter, delimiter)); output.append("\n"); } SchemaExport schema = new SchemaExport(configuration); // schema.setFormat(true); // schema.setDelimiter(";"); // schema.setOutputFile("/tmp/schema.sql"); // schema.create(false, false); //org.hibernate.dialect.Oracle10gDialect //org.hibernate.dialect.MySQL5Dialect return output.toString(); }