public void convertDdlsToDaFormat(final DbPlatform platform, File inputPath, File outputPath, final String dbSchema, boolean generateBaseline, String excludeObjects) { ReladomoDdlReveng reladomoDdlReveng = new ReladomoDdlReveng(platform); AquaRevengArgs args = new AquaRevengArgs(); args.setInputPath(inputPath); args.setOutputPath(outputPath); args.setDbSchema(dbSchema); args.setGenerateBaseline(generateBaseline); args.setExcludeObjects(excludeObjects); reladomoDdlReveng.reveng(args); } }
private String getCommandWithDefaults(AquaRevengArgs args, String username, String password, String dbHost, String dbSchema, String outputFile) { return " SqlServerDdlReveng " + " " + ObjectUtils.defaultIfNull(args.getOutputPath(), outputFile) + " " + ObjectUtils.defaultIfNull(args.getDbHost(), dbHost) + " " + ObjectUtils.defaultIfNull(args.getDbSchema(), dbSchema) + " " + ObjectUtils.defaultIfNull(args.getUsername(), username) + " " + ObjectUtils.defaultIfNull(args.getPassword(), password); } }
private String getCommandWithDefaults(AquaRevengArgs args, String username, String password, String dbHost, String dbPort, String dbName, String dbSchema, String outputDirectory) { return "pg_dump -O --disable-dollar-quoting -s" + " -h " + ObjectUtils.defaultIfNull(args.getDbHost(), dbHost) + " -p " + ObjectUtils.defaultIfNull(args.getDbPort(), dbPort) + " --username=" + ObjectUtils.defaultIfNull(args.getUsername(), username) + " -d " + ObjectUtils.defaultIfNull(args.getDbServer(), dbName) + " -n " + ObjectUtils.defaultIfNull(args.getDbSchema(), dbSchema) + " -f " + ObjectUtils.defaultIfNull(args.getOutputPath(), outputDirectory); } }
@Test public void testReveng() throws Exception { AquaRevengArgs args = new AquaRevengArgs(); args.setDbSchema("DBDEPLOY01"); //args.setInputPath(new File("./src/test/resources/reveng/db2look/input/db2input.txt")); args.setGenerateBaseline(false); args.setJdbcUrl("jdbc:oracle:thin:@localhost:1521/ORCLPDB1.localdomain"); args.setUsername("deploydba"); args.setPassword("MyPassword"); File outputDir = new File("./target/outputReveng"); FileUtils.deleteDirectory(outputDir); args.setOutputPath(outputDir); new OracleReveng().reveng(args); }
@Test @Override public void testReverseEngineeringFromFile() throws Exception { AquaRevengArgs args = new AquaRevengArgs(); args.setDbSchema("myschema01"); args.setGenerateBaseline(false); args.setDbHost("myhost.me.com"); args.setDbPort(1234); args.setDbServer("myserver"); args.setUsername("myuser"); args.setPassword("mypass"); File outputDir = new File("./target/outputReveng"); FileUtils.deleteDirectory(outputDir); args.setOutputPath(outputDir); args.setInputPath(new File("./src/test/resources/reveng/pgdump/input/input.sql")); new PostgreSqlDbPlatform().getDdlReveng().reveng(args); DirectoryAssert.assertDirectoriesEqual(new File("./src/test/resources/reveng/pgdump/expected"), new File(outputDir, "final")); } }
@Test public void test() { this.jdbc.execute(conn, "INSERT INTO " + schema + "." + table + " (INT1, STR1, DATE1, TIMESTAMP1) " + "VALUES (1, 'val1', '2017-01-01', '2016-02-02 22:22:22.2')"); this.jdbc.execute(conn, "INSERT INTO " + schema + "." + table + " (INT1, STR1, DATE1, TIMESTAMP1) " + "VALUES (2, null, '2017-02-02', null)"); this.jdbc.execute(conn, "INSERT INTO " + schema + "." + table + " (INT1, STR1, DATE1, TIMESTAMP1) " + "VALUES (null, 'val\\3', null, '2016-03-03 22:22:22.2')"); AquaRevengArgs args = new AquaRevengArgs(); args.setDbTypeStr("H2"); args.setJdbcUrl(url); args.setDriverClass(org.h2.Driver.class.getName()); args.setDbSchema(schema); args.setTables(new String[] { table }); args.setUsername("sa"); args.setPassword(""); File outputPath = new File("./target/csvoutput"); args.setOutputPath(outputPath); CsvStaticDataWriter.start(args, new File("./target/csvoutputwork")); FileAssert.assertEquals(new File("./src/test/resources/CsvStaticDataWriter/TABLE1.expected.csv"), new File(outputPath, "staticdata/TABLE1.csv")); }
public static void start(final AquaRevengArgs args, File workDir) { final DbEnvironment env = new DbEnvironment(); env.setPlatform(args.getDbPlatform()); env.setSystemDbPlatform(args.getDbPlatform()); if (args.getJdbcUrl() != null) { env.setJdbcUrl(args.getJdbcUrl()); } else { env.setDbHost(args.getDbHost()); env.setDbPort(args.getDbPort()); env.setDbServer(args.getDbServer()); if (args.getDriverClass() != null) { env.setDriverClassName(args.getDriverClass()); final PhysicalSchema physicalSchema = PhysicalSchema.parseFromString(args.getDbSchema()); final Schema schema = new Schema(physicalSchema.getPhysicalName()); // use the physical name as the schema name for the reverse-engineering env.setSchemas(Sets.immutable.with(schema)); Credential credential = credentialReader.getCredential(args.getUsername(), args.getPassword(), false, null, null, null); if (args.getTables() != null && args.getTables().length > 0) { dataTables = Lists.mutable.with(args.getTables()); } else { dataTables = FileUtilsCobra.readLines(new File(args.getInputDir(), STATIC_DATA_TABLES_FILE_NAME)); new File(args.getOutputPath(), env.getPlatform().getChangeType(ChangeType.STATICDATA_STR).getDirectoryName()), args.getUpdateTimeColumns(), csvFormat);
private void doExecute(final AquaRevengArgs args) { File input = args.getInputDir(); File outputDir = args.getOutputDir(); Validate.notNull(args.getDbSchema(), "dbSchema argument must be specified"); Validate.notNull(input, "Directory " + input + " was not found"); // Maven supplies a null File value in this case if (args.getDbHost() != null) { DbEnvironment env = new DbEnvironment(); env.setPlatform(args.getDbPlatform()); env.setSystemDbPlatform(args.getDbPlatform()); env.setDbHost(args.getDbHost()); env.setDbPort(args.getDbPort()); env.setDbServer(args.getDbServer()); if (args.getDriverClass() != null) { env.setDriverClassName(args.getDriverClass()); Schema schema = new Schema(args.getDbSchema()); env.setSchemas(Sets.immutable.with(schema)); Credential credential = credentialReader.getCredential(args.getUsername(), args.getPassword(), false, null, null, null); DaCatalog database = ctxt.getDbMetadataManager().getDatabase(args.getDbSchema(), new DaSchemaInfoLevel().setRetrieveRuleBindings(true), false, false); ImmutableCollection<RuleBinding> ruleBindings = database.getRuleBindings(); files = preprocessSchemaTokens(files, args.getDbSchema(), new File(outputDir, "interim-schemaReplaced"), args.getDbPlatform()); this.patternMap = initPatternMap(args.getDbPlatform()); MutableList<ChangeEntry> allRevEngDestinations = Lists.mutable.empty();
private String getCommandWithDefaults(AquaRevengArgs args, String username, String password, String dbHost, String dbPort, String dbSchema, String outputDirectory) { return " C:\\Sybase_15_5_x64\\ASEP\\bin\\ddlgen " + "-U " + ObjectUtils.defaultIfNull(args.getUsername(), username) + " " + "-P " + ObjectUtils.defaultIfNull(args.getPassword(), password) + " " + "-S " + ObjectUtils.defaultIfNull(args.getDbHost(), dbHost) + ":" + ObjectUtils.defaultIfNull(args.getDbPort(), dbPort) + " " + "-D " + ObjectUtils.defaultIfNull(args.getDbSchema(), dbSchema) + " " + "-O " + ObjectUtils.defaultIfNull(args.getOutputDir(), outputDirectory); } }
@Override public void value(String[] argSubset) { AquaRevengArgs argsObj = new ArgsParser().parse(argSubset, new AquaRevengArgs()); new AquaRevengMain().execute(argsObj); } });
@Override protected File printInstructions(PrintStream out, AquaRevengArgs args) { DbEnvironment env = getDbEnvironment(args); JdbcDataSourceFactory jdbcFactory = new HsqlJdbcDataSourceFactory(); DataSource ds = jdbcFactory.createDataSource(env, new Credential(args.getUsername(), args.getPassword()), 1); JdbcHelper jdbc = new JdbcHelper(null, false); Path interim = new File(args.getOutputPath(), "interim").toPath(); interim.toFile().mkdirs(); try (Connection conn = ds.getConnection()) { // https://docs.oracle.com/database/121/ARPLS/d_metada.htm#BGBJBFGE // Note - can't remap schema name, object name, tablespace name within JDBC calls; we will leave that to the existing code in AbstractDdlReveng File outputFile = interim.resolve("output.sql").toFile(); outputFile.delete(); // clean before creating jdbc.update(conn, "SCRIPT '" + outputFile.getCanonicalPath() + "'"); } catch (SQLException | IOException e) { throw new RuntimeException(e); } return interim.toFile(); } }
new RevengWriter().write(platform, changeEntries, new File(args.getOutputPath(), "final"), args.isGenerateBaseline(), RevengWriter.defaultShouldOverwritePredicate(), args.getJdbcUrl(), args.getDbHost(), args.getDbPort(), args.getDbServer(), args.getExcludeObjects());
@Override public void value(String[] argSubset) { AquaRevengArgs newArgsObj = new ArgsParser().parse(argSubset, new AquaRevengArgs()); AbstractDdlReveng ddlReveng = newArgsObj.getDbPlatform().getDdlReveng(); ddlReveng.reveng(newArgsObj); } });
/** * @deprecated Use {@link #setOutputPath(File)} */ @Deprecated @Argument(value = "outputDir", required = false) public void setOutputDir(File outputDir) { this.setOutputPath(outputDir); }
/** * @deprecated Use {@link #setInputPath(File)} */ @Deprecated @Argument(value = "inputDir", required = false) public void setInputDir(File inputDir) { this.setInputPath(inputDir); }
public void reveng(AquaRevengArgs args) { if (args.getInputPath() == null) { File file = printInstructions(System.out, args); System.out.println(""); System.out.println(""); if (file != null) { System.out.println("Interim reverse-engineering from the vendor tool is complete."); System.out.println("Content was written to: " + file); System.out.println("Proceeding with full reverse-engineering: " + file); System.out.println(""); System.out.println("*** In case the interim content had issues when reverse-engineering to the final output, you can update the interim files and restart from there (without going back to the DB) by specifying the following argument:"); System.out.println(" -inputPath " + ObjectUtils.defaultIfNull(args.getOutputPath(), "<outputFile>")); revengMain(file, args); } else { System.out.println("***********"); System.out.println(""); System.out.println("Once those steps are done, rerun the reverse-engineering command you just ran, but add the following argument based on the <outputDirectory> value passed in above the argument:"); System.out.println(" -inputPath " + ObjectUtils.defaultIfNull(args.getOutputPath(), "<outputFile>")); System.out.println(""); System.out.println("If you need more information on the vendor reverse engineer process, see the doc: https://goldmansachs.github.io/obevo/reverse-engineer-dbmstools.html"); } } else { revengMain(args.getInputPath(), args); } }
@Override public Iterable<ChangeEntry> valueOf(FileProcessingContext fileProcessingContext) { String schema = getObjectSchema(args.getDbSchema(), fileProcessingContext.getFile().getName()); return revengFile(schemaObjectReplacer, fileProcessingContext.getSnippetPatternMatchPairs(), schema); } });
/** * @deprecated Use {@link #getOutputPath()} */ @Deprecated public File getOutputDir() { return this.getOutputPath(); }
@Test public void testReveng() throws Exception { AquaRevengArgs args = new AquaRevengArgs(); args.setDbSchema("DBDEPLOY01"); //args.setInputPath(new File("./src/test/resources/reveng/db2look/input/db2input.txt")); args.setGenerateBaseline(false); args.setJdbcUrl("jdbc:oracle:thin:@localhost:1521/ORCLPDB1.localdomain"); args.setUsername("deploydba"); args.setPassword("MyPassword"); File outputDir = new File("./target/outputReveng"); FileUtils.deleteDirectory(outputDir); args.setOutputPath(outputDir); new OracleReveng().reveng(args); }
@Test @Override public void testReverseEngineeringFromFile() throws Exception { AquaRevengArgs args = new AquaRevengArgs(); args.setDbSchema("myschema01"); args.setGenerateBaseline(false); args.setDbHost("myhost.me.com"); args.setDbPort(1234); args.setDbServer("myserver"); args.setUsername("myuser"); args.setPassword("mypass"); File outputDir = new File("./target/outputReveng"); FileUtils.deleteDirectory(outputDir); args.setOutputPath(outputDir); args.setInputPath(new File("./src/test/resources/reveng/pgdump/input/input.sql")); new PostgreSqlDbPlatform().getDdlReveng().reveng(args); DirectoryAssert.assertDirectoriesEqual(new File("./src/test/resources/reveng/pgdump/expected"), new File(outputDir, "final")); } }