@Override public void drop(boolean export, String outputFile, boolean append) { final String[] dropSQL = configuration.generateDropSchemaScript(dialect); perform(dropSQL, export, outputFile, append, false); }
public String[] getDropSql() { return configuration.generateDropSchemaScript(getDialect()); }
/** * Create a schema exporter for the given Configuration, with the given * database connection properties. */ public SchemaExport(Configuration cfg, Properties connectionProperties) throws HibernateException { dialect = Dialect.getDialect( connectionProperties ); Properties props = new Properties(); props.putAll( dialect.getDefaultProperties() ); props.putAll( connectionProperties ); connectionHelper = new ProviderConnectionHelper( props ); dropSQL = cfg.generateDropSchemaScript( dialect ); createSQL = cfg.generateSchemaCreationScript( dialect ); exceptions = new ArrayList(); }
/** * The main method. * * @param args the arguments */ public static void main(String[] args) { Configuration cfg = new Configuration(); String folderAbsPath = ClassLoader.getSystemResource(hbmFolder).getFile(); cfg.addDirectory(new File(folderAbsPath)); String[] createLines = cfg.generateSchemaCreationScript(sqlDialect); System.out.println("*** CREATE ***"); for (String line : createLines) { System.out.println(line + ";"); } String[] dropLines = cfg.generateDropSchemaScript(sqlDialect); System.out.println("*** DROP ***"); for (String line : dropLines) { System.out.println(line + ";"); } // You can also play with the following snippet if need to generate // database scripts from Spring UserCatalog configuration. // ApplicationContext ctx = new ClassPathXmlApplicationContext( // "/pl/edu/icm/yadda/service2/user/hibernate/usercatalog-beans.xml"); // LocalSessionFactoryBean lsfb = (LocalSessionFactoryBean) // ctx.getBean("&sessionFactory"); // Configuration cfg = lsfb.getConfiguration(); // new SchemaExport(cfg).execute(true, false, false, true); // new SchemaExport(cfg).drop(true, false); }
public SchemaExport(Configuration cfg, Connection connection) { this.connectionHelper = new SuppliedConnectionHelper( connection ); dialect = Dialect.getDialect( cfg.getProperties() ); dropSQL = cfg.generateDropSchemaScript( dialect ); createSQL = cfg.generateSchemaCreationScript( dialect ); exceptions = new ArrayList(); }
/** * Generates the DDL schema * @param dialect the dialect to use (complete class name for the hibernate dialect object) * @return an array containing the SQL statements */ public static String[] generateDropSchemaDDL(String dialect) { Configuration cfg = ((AbstractHibernateDataConfig) IntactContext.getCurrentInstance().getConfig().getDefaultDataConfig()).getConfiguration(); Properties props = new Properties(); props.put(Environment.DIALECT, dialect); return cfg.generateDropSchemaScript(Dialect.getDialect(props)); }
@Override public Object doInHibernate(Session session) throws HibernateException, SQLException { Connection con = session.connection(); String[] sql = getConfiguration().generateDropSchemaScript(dialect); executeSchemaScript(con, sql); return null; } }
/** * Create a schema exporter for the given Configuration, with the given * database connection properties. * * @deprecated properties may be specified via the Configuration object */ public SchemaExport(Configuration cfg, Properties properties) throws HibernateException { dialect = Dialect.getDialect( properties ); Properties props = new Properties(); props.putAll( dialect.getDefaultProperties() ); props.putAll( properties ); connectionHelper = new ManagedProviderConnectionHelper( props ); dropSQL = cfg.generateDropSchemaScript( dialect ); createSQL = cfg.generateSchemaCreationScript( dialect ); format = PropertiesHelper.getBoolean( Environment.FORMAT_SQL, props ); }
public SchemaExport(Configuration cfg, Connection connection) { this.connectionHelper = new SuppliedConnectionHelper( connection ); dialect = Dialect.getDialect( cfg.getProperties() ); dropSQL = cfg.generateDropSchemaScript( dialect ); createSQL = cfg.generateSchemaCreationScript( dialect ); }
/** * Create a schema exporter for the given Configuration, with the given * database connection properties. * * @param configuration The configuration from which to build a schema export. * @param properties The properties from which to configure connectivity etc. * @throws HibernateException Indicates problem preparing for schema export. * * @deprecated properties may be specified via the Configuration object */ @Deprecated public SchemaExport(Configuration configuration, Properties properties) throws HibernateException { final Dialect dialect = Dialect.getDialect( properties ); Properties props = new Properties(); props.putAll( dialect.getDefaultProperties() ); props.putAll( properties ); this.connectionHelper = new ManagedProviderConnectionHelper( props ); this.sqlStatementLogger = new SqlStatementLogger( false, true ); this.formatter = FormatStyle.DDL.getFormatter(); this.sqlExceptionHelper = new SqlExceptionHelper(); this.importFiles = ConfigurationHelper.getString( AvailableSettings.HBM2DDL_IMPORT_FILES, properties, DEFAULT_IMPORT_FILE ); this.dropSQL = configuration.generateDropSchemaScript( dialect ); this.createSQL = configuration.generateSchemaCreationScript( dialect ); }
/** * Create a schema exporter for the given Configuration, with the given * database connection properties. * * @param configuration The configuration from which to build a schema export. * @param properties The properties from which to configure connectivity etc. * @throws HibernateException Indicates problem preparing for schema export. * * @deprecated properties may be specified via the Configuration object */ @Deprecated public SchemaExport(Configuration configuration, Properties properties) throws HibernateException { final Dialect dialect = Dialect.getDialect( properties ); Properties props = new Properties(); props.putAll( dialect.getDefaultProperties() ); props.putAll( properties ); this.connectionHelper = new ManagedProviderConnectionHelper( props ); this.sqlStatementLogger = new SqlStatementLogger( false, true ); this.formatter = FormatStyle.DDL.getFormatter(); this.sqlExceptionHelper = new SqlExceptionHelper(); this.importFiles = ConfigurationHelper.getString( AvailableSettings.HBM2DDL_IMPORT_FILES, properties, DEFAULT_IMPORT_FILE ); this.dropSQL = configuration.generateDropSchemaScript( dialect ); this.createSQL = configuration.generateSchemaCreationScript( dialect ); }
/** * Create a schema exporter for the given Configuration * and given settings */ public SchemaExport(Configuration cfg, Settings settings) throws HibernateException { dialect = settings.getDialect(); connectionHelper = new SuppliedConnectionProviderConnectionHelper( settings.getConnectionProvider() ); dropSQL = cfg.generateDropSchemaScript( dialect ); createSQL = cfg.generateSchemaCreationScript( dialect ); format = settings.isFormatSqlEnabled(); }
public void export(OutputStream out, boolean generateCreateQueries, boolean generateDropQueries) { Dialect hibDialect = Dialect.getDialect(hibernateConfiguration.getProperties()); try (PrintWriter writer = new PrintWriter(out)) { if (generateCreateQueries) { String[] createSQL = hibernateConfiguration.generateSchemaCreationScript(hibDialect); write(writer, createSQL, FormatStyle.DDL.getFormatter()); } if (generateDropQueries) { String[] dropSQL = hibernateConfiguration.generateDropSchemaScript(hibDialect); write(writer, dropSQL, FormatStyle.DDL.getFormatter()); } } }
@Override public void apply(final Object target, final WireContext wireContext) { final Configuration configuration = (Configuration) target; final Properties cfgProperties = configuration.getProperties(); final Dialect dialect = Dialect.getDialect(cfgProperties); final ConnectionProvider connectionProvider = ConnectionProviderFactory.newConnectionProvider(cfgProperties); try { final Connection connection = connectionProvider.getConnection(); try { if (LOG.isLoggable(Level.FINE)) { LOG.fine("dropping db schema"); } final String[] dropScript = configuration.generateDropSchemaScript(dialect); executeScript(connection, dropScript); if (LOG.isLoggable(Level.FINE)) { LOG.fine("creating db schema"); } final String[] createScript = configuration.generateSchemaCreationScript(dialect); executeScript(connection, createScript); } finally { connectionProvider.closeConnection(connection); } } catch (final SQLException e) { final String message = ExceptionManager.getInstance().getFullMessage("bp_HCD_4"); throw new JDBCException(message, e); } finally { connectionProvider.close(); } }
/** * Create a schema exporter for the given Configuration, using the supplied connection for connectivity. * * @param configuration The configuration to use. * @param connection The JDBC connection to use. * @throws HibernateException Indicates problem preparing for schema export. */ public SchemaExport(Configuration configuration, Connection connection) throws HibernateException { this.connectionHelper = new SuppliedConnectionHelper( connection ); this.sqlStatementLogger = new SqlStatementLogger( false, true ); this.formatter = FormatStyle.DDL.getFormatter(); this.sqlExceptionHelper = new SqlExceptionHelper(); this.importFiles = ConfigurationHelper.getString( AvailableSettings.HBM2DDL_IMPORT_FILES, configuration.getProperties(), DEFAULT_IMPORT_FILE ); final Dialect dialect = Dialect.getDialect( configuration.getProperties() ); this.dropSQL = configuration.generateDropSchemaScript( dialect ); this.createSQL = configuration.generateSchemaCreationScript( dialect ); }
/** * Create a schema exporter for the given Configuration, using the supplied connection for connectivity. * * @param configuration The configuration to use. * @param connection The JDBC connection to use. * @throws HibernateException Indicates problem preparing for schema export. */ public SchemaExport(Configuration configuration, Connection connection) throws HibernateException { this.connectionHelper = new SuppliedConnectionHelper( connection ); this.sqlStatementLogger = new SqlStatementLogger( false, true ); this.formatter = FormatStyle.DDL.getFormatter(); this.sqlExceptionHelper = new SqlExceptionHelper(); this.importFiles = ConfigurationHelper.getString( AvailableSettings.HBM2DDL_IMPORT_FILES, configuration.getProperties(), DEFAULT_IMPORT_FILE ); final Dialect dialect = Dialect.getDialect( configuration.getProperties() ); this.dropSQL = configuration.generateDropSchemaScript( dialect ); this.createSQL = configuration.generateSchemaCreationScript( dialect ); }
public void apply(Object target, WireContext wireContext) { Configuration configuration = (Configuration) target; Properties cfgProperties = configuration.getProperties(); Dialect dialect = Dialect.getDialect(cfgProperties); ConnectionProvider connectionProvider = ConnectionProviderFactory .newConnectionProvider(cfgProperties); try { Connection connection = connectionProvider.getConnection(); try { LOG.debug("dropping db schema"); String[] dropScript = configuration.generateDropSchemaScript(dialect); executeScript(connection, dropScript); LOG.debug("creating db schema"); String[] createScript = configuration .generateSchemaCreationScript(dialect); executeScript(connection, createScript); } finally { connectionProvider.closeConnection(connection); } } catch (SQLException e) { throw new JDBCException("error creating schema", e); } finally { connectionProvider.close(); } }
public void apply(Object target, WireContext wireContext) { Configuration configuration = (Configuration) target; Properties cfgProperties = configuration.getProperties(); Dialect dialect = Dialect.getDialect(cfgProperties); ConnectionProvider connectionProvider = ConnectionProviderFactory.newConnectionProvider(cfgProperties); try { Connection connection = connectionProvider.getConnection(); try { log.debug("dropping db schema"); String[] dropScript = configuration.generateDropSchemaScript(dialect); executeScript(connection, dropScript); log.debug("creating db schema"); String[] createScript = configuration.generateSchemaCreationScript(dialect); executeScript(connection, createScript); } finally { connectionProvider.closeConnection(connection); } } catch (SQLException e) { throw new JDBCException("error creating schema", e); } finally { connectionProvider.close(); } }
public SchemaExport(ServiceRegistry serviceRegistry, Configuration configuration) { this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( serviceRegistry.getService( ConnectionProvider.class ) ); this.sqlStatementLogger = serviceRegistry.getService( JdbcServices.class ).getSqlStatementLogger(); this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter(); this.sqlExceptionHelper = serviceRegistry.getService( JdbcServices.class ).getSqlExceptionHelper(); this.importFiles = ConfigurationHelper.getString( AvailableSettings.HBM2DDL_IMPORT_FILES, configuration.getProperties(), DEFAULT_IMPORT_FILE ); final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect(); this.dropSQL = configuration.generateDropSchemaScript( dialect ); this.createSQL = configuration.generateSchemaCreationScript( dialect ); }
public SchemaExport(ServiceRegistry serviceRegistry, Configuration configuration) { this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( serviceRegistry.getService( ConnectionProvider.class ) ); this.sqlStatementLogger = serviceRegistry.getService( JdbcServices.class ).getSqlStatementLogger(); this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter(); this.sqlExceptionHelper = serviceRegistry.getService( JdbcServices.class ).getSqlExceptionHelper(); this.importFiles = ConfigurationHelper.getString( AvailableSettings.HBM2DDL_IMPORT_FILES, configuration.getProperties(), DEFAULT_IMPORT_FILE ); final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect(); this.dropSQL = configuration.generateDropSchemaScript( dialect ); this.createSQL = configuration.generateSchemaCreationScript( dialect ); }