private static String getUrlUncached(String dbName, boolean persistToFile) { if (persistToFile) { try { File tmpPlaceholder = File.createTempFile("hsqldb" + dbName, HSQL_FILE_PLACEHOLDER); File tmpDbFile = new File(tmpPlaceholder.getParentFile(), tmpPlaceholder.getName().substring(0, tmpPlaceholder.getName().length() - HSQL_FILE_PLACEHOLDER.length())); return String.format("jdbc:hsqldb:file:%1$s", tmpDbFile.getAbsolutePath()); } catch (IOException exc) { throw new DeployerRuntimeException(exc); } } else { return String.format("jdbc:hsqldb:mem:%1$s", dbName); } } }
private static String getUrlUncached(String dbName, boolean persistToFile) { if (persistToFile) { try { File tmpPlaceholder = File.createTempFile("hsqldb" + dbName, HSQL_FILE_PLACEHOLDER); File tmpDbFile = new File(tmpPlaceholder.getParentFile(), tmpPlaceholder.getName().substring(0, tmpPlaceholder.getName().length() - HSQL_FILE_PLACEHOLDER.length())); return String.format("jdbc:hsqldb:file:%1$s", tmpDbFile.getAbsolutePath()); } catch (IOException exc) { throw new DeployerRuntimeException(exc); } } else { return String.format("jdbc:hsqldb:mem:%1$s", dbName); } } }
public Platform valueOf(String dbPlatformStr) { try { ImmutableHierarchicalConfiguration platformConfig = platformConfigs.get(dbPlatformStr); String resolvedDbPlatformClass = null; if (platformConfig != null) { resolvedDbPlatformClass = platformConfig.getString("class"); } if (resolvedDbPlatformClass == null) { resolvedDbPlatformClass = dbPlatformStr; } return (Platform) Class.forName(resolvedDbPlatformClass).newInstance(); } catch (InstantiationException e) { throw new DeployerRuntimeException(e); } catch (IllegalAccessException e) { throw new DeployerRuntimeException(e); } catch (ClassNotFoundException e) { throw new DeployerRuntimeException("Could not find platform named " + dbPlatformStr + "; no class found and name was not in the list of default platform strings: " + platformConfigs.keysView()); } }
public Platform valueOf(String dbPlatformStr) { try { ImmutableHierarchicalConfiguration platformConfig = platformConfigs.get(dbPlatformStr); String resolvedDbPlatformClass = null; if (platformConfig != null) { resolvedDbPlatformClass = platformConfig.getString("class"); } if (resolvedDbPlatformClass == null) { resolvedDbPlatformClass = dbPlatformStr; } return (Platform) Class.forName(resolvedDbPlatformClass).newInstance(); } catch (InstantiationException e) { throw new DeployerRuntimeException(e); } catch (IllegalAccessException e) { throw new DeployerRuntimeException(e); } catch (ClassNotFoundException e) { throw new DeployerRuntimeException("Could not find platform named " + dbPlatformStr + "; no class found and name was not in the list of default platform strings: " + platformConfigs.keysView()); } }
private static DataSource ds(String driverClassName, String url, String username, String password) { Class<? extends Driver> driverClass; try { driverClass = (Class<? extends Driver>) Class.forName(driverClassName); return JdbcDataSourceFactory.createFromJdbcUrl(driverClass, url, new Credential(username, password)); } catch (ClassNotFoundException e) { throw new DeployerRuntimeException(e); } }
private static DataSource ds(String driverClassName, String url, String username, String password) { Class<? extends Driver> driverClass; try { driverClass = (Class<? extends Driver>) Class.forName(driverClassName); return JdbcDataSourceFactory.createFromJdbcUrl(driverClass, url, new Credential(username, password)); } catch (ClassNotFoundException e) { throw new DeployerRuntimeException(e); } }
public DeployerAppContext getAppContextBuilder() { DeployerAppContext deployerAppContext; try { if (appContextBuilderClass != null) { deployerAppContext = this.appContextBuilderClass.newInstance(); } else { deployerAppContext = this.platform.getAppContextBuilderClass().newInstance(); } } catch (InstantiationException e) { throw new DeployerRuntimeException(e); } catch (IllegalAccessException e) { throw new DeployerRuntimeException(e); } deployerAppContext.setEnvironment(this); if (defaultUserId != null && defaultPassword != null) { deployerAppContext.setCredential(new Credential(defaultUserId, defaultPassword)); } return deployerAppContext; }
public DeployerAppContext getAppContextBuilder() { DeployerAppContext deployerAppContext; try { if (appContextBuilderClass != null) { deployerAppContext = this.appContextBuilderClass.newInstance(); } else { deployerAppContext = this.platform.getAppContextBuilderClass().newInstance(); } } catch (InstantiationException e) { throw new DeployerRuntimeException(e); } catch (IllegalAccessException e) { throw new DeployerRuntimeException(e); } deployerAppContext.setEnvironment(this); if (defaultUserId != null && defaultPassword != null) { deployerAppContext.setCredential(new Credential(defaultUserId, defaultPassword)); } return deployerAppContext; }
private static DeployerAppContext getAppContextBuilder(Environment env, Credential credential) { DeployerAppContext deployerAppContext; try { deployerAppContext = env.getPlatform().getAppContextBuilderClass().newInstance(); } catch (InstantiationException e) { throw new DeployerRuntimeException(e); } catch (IllegalAccessException e) { throw new DeployerRuntimeException(e); } deployerAppContext.setEnvironment(env); if (credential == null) { credential = getDefaultCredential(env); } deployerAppContext.setCredential(credential); return deployerAppContext; }
private static DeployerAppContext getAppContextBuilder(Environment env, Credential credential) { DeployerAppContext deployerAppContext; try { deployerAppContext = env.getPlatform().getAppContextBuilderClass().newInstance(); } catch (InstantiationException e) { throw new DeployerRuntimeException(e); } catch (IllegalAccessException e) { throw new DeployerRuntimeException(e); } deployerAppContext.setEnvironment(env); if (credential == null) { credential = getDefaultCredential(env); } deployerAppContext.setCredential(credential); return deployerAppContext; }
@Override public <T> T executeWithinContext(PhysicalSchema schema, ThrowingFunction<Connection, T> callable) { Connection conn = null; try { conn = ds.getConnection(); setDataSourceSchema(conn, schema); return callable.safeValueOf(conn); } catch (DeployerRuntimeException e) { throw e; // rethrowing DeployerRuntimeException to avoid excessive stack trace outputs } catch (Exception e) { throw new DeployerRuntimeException(e); } finally { DbUtils.closeQuietly(conn); } }
@Override public void executeWithinContext(PhysicalSchema schema, Procedure<Connection> runnable) { Connection conn = null; try { conn = ds.getConnection(); setDataSourceSchema(conn, schema); runnable.value(conn); } catch (RuntimeException e) { throw e; // rethrowing DeployerRuntimeException to avoid excessive stack trace outputs } catch (Exception e) { throw new DeployerRuntimeException(e); } finally { DbUtils.closeQuietly(conn); } }
@Override public void executeWithinContext(PhysicalSchema schema, Procedure<Connection> runnable) { Connection conn = null; try { conn = ds.getConnection(); setDataSourceSchema(conn, schema); runnable.value(conn); } catch (RuntimeException e) { throw e; // rethrowing DeployerRuntimeException to avoid excessive stack trace outputs } catch (Exception e) { throw new DeployerRuntimeException(e); } finally { DbUtils.closeQuietly(conn); } }
@Override public <T> T executeWithinContext(PhysicalSchema schema, ThrowingFunction<Connection, T> callable) { Connection conn = null; try { conn = ds.getConnection(); setDataSourceSchema(conn, schema); return callable.safeValueOf(conn); } catch (DeployerRuntimeException e) { throw e; // rethrowing DeployerRuntimeException to avoid excessive stack trace outputs } catch (Exception e) { throw new DeployerRuntimeException(e); } finally { DbUtils.closeQuietly(conn); } }
void deployArtifact(Connection conn, Change artifact) { MutableList<String> sqls = MultiLineStringSplitter.createSplitterOnSpaceAndLine("GO").valueOf(artifact.getConvertedContent()); int index = 0; for (String sql : sqls) { index++; if (StringUtils.isBlank(sql)) { LOG.debug("Skipping blank sql"); } else { LOG.debug("Executing change #{} in the artifact", index); try { dialect.doTryBlockForArtifact(conn, this.sqlExecutor, artifact); this.sqlExecutor.getJdbcTemplate().update(conn, sql); } catch (DataAccessException e) { throw new DeployerRuntimeException("Could not execute DDL:\nfor artifact [[[" + artifact.getDisplayString() + "]]] while executing SQL: [[[\n" + sql + "\n]]]", e); } finally { dialect.doFinallyBlockForArtifact(conn, this.sqlExecutor, artifact); } } } } }
void deployArtifact(Connection conn, Change artifact) { MutableList<String> sqls = MultiLineStringSplitter.createSplitterOnSpaceAndLine("GO").valueOf(artifact.getConvertedContent()); int index = 0; for (String sql : sqls) { index++; if (StringUtils.isBlank(sql)) { LOG.debug("Skipping blank sql"); } else { LOG.debug("Executing change #{} in the artifact", index); try { dialect.doTryBlockForArtifact(conn, this.sqlExecutor, artifact); this.sqlExecutor.getJdbcTemplate().update(conn, sql); } catch (DataAccessException e) { throw new DeployerRuntimeException("Could not execute DDL:\nfor artifact [[[" + artifact.getDisplayString() + "]]] while executing SQL: [[[\n" + sql + "\n]]]", e); } finally { dialect.doFinallyBlockForArtifact(conn, this.sqlExecutor, artifact); } } } } }
private HierarchicalConfiguration<ImmutableNode> loadPropertiesFromUrl(FileObject file) { try { return new FileBasedConfigurationBuilder<>(FixedYAMLConfiguration.class) .configure(new Parameters().hierarchical().setURL(file.getURLDa())) .getConfiguration(); } catch (ConfigurationException e) { throw new DeployerRuntimeException(e); } }
private HierarchicalConfiguration<ImmutableNode> loadPropertiesFromUrl(FileObject file) { try { return new FileBasedConfigurationBuilder<>(FixedYAMLConfiguration.class) .configure(new Parameters().hierarchical().setURL(file.getURLDa())) .getConfiguration(); } catch (ConfigurationException e) { throw new DeployerRuntimeException(e); } }
public void execute(DbFileMergerArgs args) { PropertiesConfiguration config; RichIterable<DbMergeInfo> dbNameLocationPairs; try { config = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) .configure(new Parameters().properties() .setFile(args.getDbMergeConfigFile()) .setListDelimiterHandler(new LegacyListDelimiterHandler(',')) ) .getConfiguration(); dbNameLocationPairs = DbMergeInfo.parseFromProperties(config); } catch (Exception e) { throw new DeployerRuntimeException("Exception reading configs from file " + args.getDbMergeConfigFile(), e); } DbPlatform dialect = DbPlatformConfiguration.getInstance().valueOf(config.getString("dbType")); this.generateDiffs(dialect, dbNameLocationPairs, args.getOutputDir()); }
public void execute(DbFileMergerArgs args) { PropertiesConfiguration config; RichIterable<DbMergeInfo> dbNameLocationPairs; try { config = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) .configure(new Parameters().properties() .setFile(args.getDbMergeConfigFile()) .setListDelimiterHandler(new LegacyListDelimiterHandler(',')) ) .getConfiguration(); dbNameLocationPairs = DbMergeInfo.parseFromProperties(config); } catch (Exception e) { throw new DeployerRuntimeException("Exception reading configs from file " + args.getDbMergeConfigFile(), e); } DbPlatform dialect = DbPlatformConfiguration.getInstance().valueOf(config.getString("dbType")); this.generateDiffs(dialect, dbNameLocationPairs, args.getOutputDir()); }