From f1565ad67b66145df3c16ca2fd92461de54b1769 Mon Sep 17 00:00:00 2001 From: qwazer Date: Sat, 3 Dec 2016 19:52:27 +0300 Subject: [PATCH 01/50] [minor] re-setup distributionManagement id and names --- pom.xml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 8d1fccb..17a7069 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 com.googlecode @@ -33,8 +34,9 @@ - bintray - https://api.bintray.com/maven/${bintray.repo}/${bintray.package} + bintray-qwazer-maven + qwazer-maven + https://api.bintray.com/maven/${bintray.repo}/${bintray.package}/;publish=1 From 5bb388500aa39c2647cb136eba2783714b192194 Mon Sep 17 00:00:00 2001 From: qwazer Date: Sat, 3 Dec 2016 20:19:05 +0300 Subject: [PATCH 02/50] release v2.4.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 17a7069..7f482dc 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.googlecode scheme2ddl - 2.3.14-SNAPSHOT + 2.4.0 jar @@ -20,7 +20,7 @@ scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git - HEAD + v2.4.0 From 74d896fb5478cdb44d92f9e4d4b645ea5e306e0f Mon Sep 17 00:00:00 2001 From: qwazer Date: Sat, 3 Dec 2016 20:20:46 +0300 Subject: [PATCH 03/50] start new dev cycle v2.4.1-SNAPSHOT --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7f482dc..53110af 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.googlecode scheme2ddl - 2.4.0 + 2.4.1-SNAPSHOT jar @@ -20,7 +20,7 @@ scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git - v2.4.0 + HEAD From 390fc91d0a65f708ffe1d544a069df46b2ba1d85 Mon Sep 17 00:00:00 2001 From: qwazer Date: Sat, 3 Dec 2016 21:39:56 +0300 Subject: [PATCH 04/50] #49 Reduce distributive size --- pom.xml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 53110af..9b04acf 100644 --- a/pom.xml +++ b/pom.xml @@ -86,15 +86,17 @@ org.springframework.boot spring-boot-starter-batch + + + org.apache.tomcat + tomcat-jdbc + + org.springframework.boot spring-boot-starter-aop - - org.springframework.boot - spring-boot-starter-jdbc - org.springframework.boot spring-boot-starter-logging @@ -102,6 +104,7 @@ org.springframework.boot spring-boot-starter-test + test commons-io From 769f101fb933b0c9c077a04868ed7ce4b856019c Mon Sep 17 00:00:00 2001 From: qwazer Date: Sat, 3 Dec 2016 21:45:25 +0300 Subject: [PATCH 05/50] [travis-ci] mvn test verify --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7f18c3f..fff08ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,4 +28,4 @@ before_install: - travis_wait sleep 10 - docker top oracle -script: "mvn verify" +script: "mvn test verify" From 177628e955f62bf613854fca4fb0a368310894fe Mon Sep 17 00:00:00 2001 From: qwazer Date: Sun, 4 Dec 2016 22:26:16 +0300 Subject: [PATCH 06/50] [minor] polish --- .gitignore | 3 ++- pom.xml | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 98e665e..222ee23 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ pom.xml.next release.properties dependency-reduced-pom.xml buildNumber.properties -output \ No newline at end of file +output +scheme2ddl.iml diff --git a/pom.xml b/pom.xml index 9b04acf..774bcd1 100644 --- a/pom.xml +++ b/pom.xml @@ -59,6 +59,7 @@ org.apache.maven.plugins maven-release-plugin + 2.5.3 v@{project.version} false From ead0ef5c7f4b4cf01a656801b91a92265bf8a148 Mon Sep 17 00:00:00 2001 From: qwazer Date: Sun, 4 Dec 2016 22:26:57 +0300 Subject: [PATCH 07/50] [maven-release-plugin] prepare release v2.4.1 --- pom.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 774bcd1..8fb46eb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 com.googlecode scheme2ddl - 2.4.1-SNAPSHOT + 2.4.1 jar @@ -20,7 +19,7 @@ scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git - HEAD + v2.4.1 From 8fbe3a178cb5d7e4473183bd8fdb8730ccef4d7a Mon Sep 17 00:00:00 2001 From: qwazer Date: Sun, 4 Dec 2016 22:27:03 +0300 Subject: [PATCH 08/50] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8fb46eb..6e15889 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.googlecode scheme2ddl - 2.4.1 + 2.4.2-SNAPSHOT jar @@ -19,7 +19,7 @@ scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git - v2.4.1 + HEAD From f19fd23994fdbcb0a032f10559854167397521bf Mon Sep 17 00:00:00 2001 From: qwazer Date: Mon, 5 Dec 2016 16:46:23 +0300 Subject: [PATCH 09/50] set up jacoco-maven-plugin, bound to phase verify, covered ratio should be greater than 50% --- pom.xml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pom.xml b/pom.xml index 6e15889..782a9f3 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,48 @@ org.apache.maven.plugins maven-failsafe-plugin + + org.jacoco + jacoco-maven-plugin + 0.7.7.201606060606 + + + default-prepare-agent + + prepare-agent + + + + default-report + verify + + report + + + + default-check + + check + + + + + + BUNDLE + + + + COMPLEXITY + COVEREDRATIO + 0.50 + + + + + + + + From f9ef0a655268b3009534df1c7a6d4a2895e84906 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 08:33:54 +0300 Subject: [PATCH 10/50] set up coveralls reports on CI --- .travis.yml | 10 +++++++--- README.md | 2 +- pom.xml | 9 +++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index fff08ce..69eb789 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,8 @@ services: - docker jdk: -# - oraclejdk8 - - openjdk6 + - oraclejdk7 +# - openjdk6 before_install: @@ -28,4 +28,8 @@ before_install: - travis_wait sleep 10 - docker top oracle -script: "mvn test verify" +script: + - mvn test verify + +after_success: + - mvn coveralls:report -Dcoveralls.repoToken=$COVERALLS_REPO_TOKEN diff --git a/README.md b/README.md index 2f7ae7a..ac8cb13 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[ ![Download](https://api.bintray.com/packages/qwazer/maven/scheme2ddl/images/download.svg) ](https://bintray.com/qwazer/maven/scheme2ddl/_latestVersion)   [![Build Status](https://travis-ci.org/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.org/qwazer/scheme2ddl) +[ ![Download](https://api.bintray.com/packages/qwazer/maven/scheme2ddl/images/download.svg) ](https://bintray.com/qwazer/maven/scheme2ddl/_latestVersion)   [![Build Status](https://travis-ci.org/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.org/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg?branch=master)](https://coveralls.io/github/qwazer/scheme2ddl?branch=master) **scheme2ddl** is command line util for export oracle schema to set of ddl scripts. Provide a lot of configurations via basic command line options or advanced XML configuartion. diff --git a/pom.xml b/pom.xml index 782a9f3..fddb1b7 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,7 @@ UTF-8 qwazer/maven scheme2ddl + yourcoverallsprojectrepositorytoken @@ -121,6 +122,14 @@ + + org.eluder.coveralls + coveralls-maven-plugin + 4.3.0 + + ${coveralls.repoToken} + + From 3d9b9ada7d884339e4540ca1427da4d2b2301d69 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 09:51:50 +0300 Subject: [PATCH 11/50] more tests --- .../googlecode/scheme2ddl/MainCLITest.java | 79 +++++++++++++++++++ .../com/googlecode/scheme2ddl/MainIT.java | 6 -- 2 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 src/test/java/com/googlecode/scheme2ddl/MainCLITest.java diff --git a/src/test/java/com/googlecode/scheme2ddl/MainCLITest.java b/src/test/java/com/googlecode/scheme2ddl/MainCLITest.java new file mode 100644 index 0000000..3d20c67 --- /dev/null +++ b/src/test/java/com/googlecode/scheme2ddl/MainCLITest.java @@ -0,0 +1,79 @@ +package com.googlecode.scheme2ddl; + +import org.springframework.test.util.ReflectionTestUtils; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.StringContains.containsString; +import static org.testng.Assert.*; + +/** + * Created by Anton Reshetnikov on 06 Dec 2016. + */ + +public class MainCLITest { + + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + + private final PrintStream outOriginal = System.out; + private final PrintStream errorOriginal = System.err; + + @BeforeMethod + public void setUp() throws Exception { + ReflectionTestUtils.setField(Main.class, "justPrintUsage", false); + ReflectionTestUtils.setField(Main.class, "justPrintVersion", false); + ReflectionTestUtils.setField(Main.class, "justTestConnection", false); + ReflectionTestUtils.setField(Main.class, "dbUrl", null); + } + + @BeforeMethod + public void setUpStreams() { + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + } + + @AfterMethod + public void cleanUpStreams() { + System.setOut(outOriginal); + System.setErr(errorOriginal); + outContent.reset(); + errContent.reset(); + } + + + @DataProvider + public static Object[][] testPrintUsageOptionsParams() { + return new Object[][]{ + new String[][]{{"-h"}}, + new String[][]{{"--help"}}, + new String[][]{{"-help"}}, + new String[][]{{"-h"}}, + new String[][]{{"-url", "1", "-tc", "-h"}}, + new String[][]{{"-tc", "--help"}}, + }; + } + + + @Test(dataProvider = "testPrintUsageOptionsParams") + public void testPrintUsageOptions(String[] args) throws Exception { + Main.main(args); + assertThat(outContent.toString(), containsString("java -jar scheme2ddl.jar")); + assertThat(outContent.toString(), containsString("example: scott/tiger@localhost:1521:ORCL")); + } + + @Test + public void testPrintVersionOption() throws Exception { + String[] args = {"-version"}; + Main.main(args); + assertThat(outContent.toString(), containsString("scheme2ddl version ")); + } + + +} \ No newline at end of file diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 1e2314a..ee5616c 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -89,12 +89,6 @@ public static Object[][] justTestConnectionParamNames() { } - @Test - public void testPrintVersionOption() throws Exception { - String[] args = {"-version"}; - Main.main(args); - assertThat(outContent.toString(), containsString("scheme2ddl version ")); - } @Test(expectedExceptions = Exception.class, expectedExceptionsMessageRegExp = "Job (.*) unsuccessful", enabled = false) public void testStopOnWarning() throws Exception { From c8e6e81fdb52ea39110b7ff92bca9c34295009e4 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 10:00:38 +0300 Subject: [PATCH 12/50] [more tests] testJustTestConnectionNegative --- .../java/com/googlecode/scheme2ddl/Main.java | 2 +- .../com/googlecode/scheme2ddl/MainIT.java | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/googlecode/scheme2ddl/Main.java b/src/main/java/com/googlecode/scheme2ddl/Main.java index f6ea978..b1694f4 100644 --- a/src/main/java/com/googlecode/scheme2ddl/Main.java +++ b/src/main/java/com/googlecode/scheme2ddl/Main.java @@ -79,7 +79,7 @@ private static void testDBConnection(ConfigurableApplicationContext context) thr if (connectionDao.isConnectionAvailable()) { System.out.println("OK success connection to " + dataSource.getURL()); } else { - System.out.println("FAIL connect to " + dataSource.getURL()); + System.out.println("FAIL connect to " + dataSource.getURL()); //todo unreacheble statement } } diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index ee5616c..8fbfa7b 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -70,8 +70,18 @@ public void cleanUpStreams() { errContent.reset(); } + + @DataProvider + public static Object[][] justTestConnectionParamNames() { + return new Object[][]{ + {"-url", "-tc"}, + {"-url", "--test-connection"}, + }; + } + + @Test(dataProvider = "justTestConnectionParamNames") - public void testMainJustTestConnectionOption(String urlParamName, String testConnParamName) throws Exception { + public void testJustTestConnectionPositive(String urlParamName, String testConnParamName) throws Exception { String[] args = {urlParamName, url, testConnParamName}; Main.main(args); Assert.assertEquals( @@ -80,12 +90,10 @@ public void testMainJustTestConnectionOption(String urlParamName, String testCon ); } - @DataProvider - public static Object[][] justTestConnectionParamNames() { - return new Object[][]{ - {"-url", "-tc"}, - {"-url", "--test-connection"}, - }; + @Test(expectedExceptions = CannotGetJdbcConnectionException.class) + public void testJustTestConnectionNegative() throws Exception { + String[] args = {"-url", "1/1@127.0.0.1:789789", "-tc"}; + Main.main(args); } From 8a07879bb8e45293485321fa5cde6528418b56bf Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 10:34:23 +0300 Subject: [PATCH 13/50] [more tests] testProcessForeignSchemas --- .../com/googlecode/scheme2ddl/MainIT.java | 77 ++++++++++++++++++- src/test/resources/test-default.properties | 2 +- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 8fbfa7b..34d172e 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -7,6 +7,7 @@ import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.springframework.test.util.ReflectionTestUtils; import org.testng.Assert; import org.testng.SkipException; import org.testng.annotations.*; @@ -33,6 +34,9 @@ public class MainIT extends AbstractTestNGSpringContextTests { @Value("${hrUrl}") private String url; + @Value("${dbaUrl}") + private String dbaUrl; + @Autowired private JdbcTemplate dbaJdbcTemplate; @@ -44,6 +48,9 @@ public class MainIT extends AbstractTestNGSpringContextTests { private final PrintStream errorOriginal = System.err; + private File tempOutput; + + @BeforeClass public void setUp() { try { @@ -56,6 +63,14 @@ public void setUp() { } + @BeforeMethod + public void resetDefaultsForStaticFields() throws Exception { + ReflectionTestUtils.setField(Main.class, "justPrintUsage", false); + ReflectionTestUtils.setField(Main.class, "justPrintVersion", false); + ReflectionTestUtils.setField(Main.class, "justTestConnection", false); + ReflectionTestUtils.setField(Main.class, "dbUrl", null); + } + @BeforeMethod public void setUpStreams() { System.setOut(new PrintStream(outContent)); @@ -63,13 +78,25 @@ public void setUpStreams() { } @AfterMethod - public void cleanUpStreams() { + public void cleanUpStreams() throws IOException { System.setOut(outOriginal); System.setErr(errorOriginal); outContent.reset(); errContent.reset(); } + @BeforeMethod + public void setUpTempOutputDir(){ + tempOutput = FileUtils.getFile(FileUtils.getTempDirectoryPath(), + "scheme2ddl-test-tmp-output", + UUID.randomUUID().toString().substring(0,8)); + } + + @AfterMethod + public void cleanUpTempOutput() throws IOException { + FileUtils.deleteDirectory(tempOutput); + } + @DataProvider public static Object[][] justTestConnectionParamNames() { @@ -162,6 +189,52 @@ public void testExportHRSchemaDefault() throws Exception { } + + @Test(expectedExceptions = RuntimeException.class, + expectedExceptionsMessageRegExp = "Cannot process schema \'PUBLIC\' with oracle user \'hr\', " + + "if it\'s not connected as sysdba") + public void testProcessForeignSchemaNegative() throws Exception { + String[] args = {"-url", url, "-s", "PUBLIC"}; + Main.main(args); + } + + @Test + public void testProcessForeignSchema() throws Exception { + String outputPath = tempOutput.getAbsolutePath(); + + String[] args = {"-url", dbaUrl, "-s", "HR,OUTLN", "-o", outputPath}; + + Main.main(args); + String out = outContent.toString(); + + assertThat(out, containsString("Will try to process schema list [HR, OUTLN]")); + assertThat(out, containsString("Found 34 items for processing in schema HR")); + assertThat(out, containsString("Found 8 items for processing in schema OUTLN")); + + assertEqualsFileContent(outputPath + "/OUTLN/procedures/ora$grant_sys_select.sql", + "CREATE OR REPLACE PROCEDURE \"OUTLN\".\"ORA$GRANT_SYS_SELECT\" as\n" + + "begin\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$ TO SELECT_CATALOG_ROLE';\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$HINTS TO SELECT_CATALOG_ROLE';\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$NODES TO SELECT_CATALOG_ROLE';\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$ TO SYS WITH GRANT OPTION';\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$HINTS TO SYS WITH GRANT OPTION';\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$NODES TO SYS WITH GRANT OPTION';\n" + + "end;\n" + + "/"); + + + assertEqualsFileContent(outputPath +"/HR/tables/regions.sql", + "CREATE TABLE \"HR\".\"REGIONS\" \n" + + " (\t\"REGION_ID\" NUMBER CONSTRAINT \"REGION_ID_NN\" NOT NULL ENABLE, \n" + + "\t\"REGION_NAME\" VARCHAR2(25)\n" + + " ) ;\n" + + " ALTER TABLE \"HR\".\"REGIONS\" ADD CONSTRAINT \"REG_ID_PK\" PRIMARY KEY (\"REGION_ID\") ENABLE;\n" + + " CREATE UNIQUE INDEX \"HR\".\"REG_ID_PK\" ON \"HR\".\"REGIONS\" (\"REGION_ID\") \n" + + " ;"); + + } + @Test public void testFilterAndReplaceSeqValue() throws Exception { File tempOutput = FileUtils.getFile(FileUtils.getTempDirectoryPath(), @@ -191,7 +264,7 @@ public void testFilterAndReplaceSeqValue() throws Exception { private static void assertEqualsFileContent(String path, String content) throws IOException { File file = new File(path); - assertTrue(file.exists()); + assertTrue(file.exists(), "file doesn't exists " + file ); String fileContent = FileUtils.readFileToString(file, "UTF-8"); assertEquals(fileContent.trim().replace("\r", ""), content.replace("\r", "")); diff --git a/src/test/resources/test-default.properties b/src/test/resources/test-default.properties index 8bbba2d..37591ae 100644 --- a/src/test/resources/test-default.properties +++ b/src/test/resources/test-default.properties @@ -2,7 +2,7 @@ #- docker run -d -p 49161:1521 -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g -dbaUrl=system as sysdba/oracle@127.0.0.1:49161/XE +dbaUrl=system/oracle@127.0.0.1:49161/XE hrUrl=hr/pass@127.0.0.1:49161/XE From 4e1d59b4def23f1ef51804160f4502c0363e5b0d Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 10:39:22 +0300 Subject: [PATCH 14/50] [more tests] test Process Foreign Schemas --- src/test/java/com/googlecode/scheme2ddl/MainIT.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 34d172e..558f2f8 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -69,6 +69,9 @@ public void resetDefaultsForStaticFields() throws Exception { ReflectionTestUtils.setField(Main.class, "justPrintVersion", false); ReflectionTestUtils.setField(Main.class, "justTestConnection", false); ReflectionTestUtils.setField(Main.class, "dbUrl", null); + ReflectionTestUtils.setField(Main.class, "objectFilter", "%"); + ReflectionTestUtils.setField(Main.class, "typeFilter", ""); + ReflectionTestUtils.setField(Main.class, "typeFilterMode", "include"); } @BeforeMethod From 04cd84f9e2d03451c4698fffc9de04ea04571d33 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 10:45:32 +0300 Subject: [PATCH 15/50] [more tests] test Unknown Argument --- src/main/java/com/googlecode/scheme2ddl/Main.java | 2 +- src/test/java/com/googlecode/scheme2ddl/MainCLITest.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/googlecode/scheme2ddl/Main.java b/src/main/java/com/googlecode/scheme2ddl/Main.java index b1694f4..237dc6b 100644 --- a/src/main/java/com/googlecode/scheme2ddl/Main.java +++ b/src/main/java/com/googlecode/scheme2ddl/Main.java @@ -337,7 +337,7 @@ private static void collectArgs(String[] args) throws Exception { String msg = "Unknown argument: " + arg; System.err.println(msg); printUsage(); - throw new Exception(""); + throw new Exception(msg); } } } diff --git a/src/test/java/com/googlecode/scheme2ddl/MainCLITest.java b/src/test/java/com/googlecode/scheme2ddl/MainCLITest.java index 3d20c67..5af9335 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainCLITest.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainCLITest.java @@ -75,5 +75,11 @@ public void testPrintVersionOption() throws Exception { assertThat(outContent.toString(), containsString("scheme2ddl version ")); } + @Test(expectedExceptions = Exception.class, expectedExceptionsMessageRegExp = "Unknown argument: .*") + public void testUnknownArgument() throws Exception { + String[] args = {"-xYx"}; + Main.main(args); + } + } \ No newline at end of file From 2f06f306060261528b029e474e8d9dd8f5895526 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 12:17:41 +0300 Subject: [PATCH 16/50] [more tests] test with default config from path --- .../com/googlecode/scheme2ddl/MainIT.java | 60 ++++++++++++------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 558f2f8..859fe82 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -72,6 +72,10 @@ public void resetDefaultsForStaticFields() throws Exception { ReflectionTestUtils.setField(Main.class, "objectFilter", "%"); ReflectionTestUtils.setField(Main.class, "typeFilter", ""); ReflectionTestUtils.setField(Main.class, "typeFilterMode", "include"); + ReflectionTestUtils.setField(Main.class, "isLaunchedByDBA", false); + ReflectionTestUtils.setField(Main.class, "schemas", null); + ReflectionTestUtils.setField(Main.class, "schemaList", null); + ReflectionTestUtils.setField(Main.class, "replaceSequenceValues", false); } @BeforeMethod @@ -139,28 +143,32 @@ public void testStopOnWarning() throws Exception { public void testExportHRSchemaDefault() throws Exception { String[] args = {"-url", url}; Main.main(args); - String out = outContent.toString(); - String pwd = FileUtils.getFile(new File("output")).getAbsolutePath(); + assertHRSchemaDefault( + FileUtils.getFile(new File("output")).getAbsolutePath(), + outContent.toString()); + } + + private static void assertHRSchemaDefault(String dirPath, String out) throws IOException { assertThat(out, containsString("Will try to process schema [HR]")); assertThat(out, containsString("Start getting of user object list in schema HR for processing")); assertThat(out, containsString("WARNING: processing of 'PUBLIC DATABASE LINK' will be skipped because HR no access to view it")); assertThat(out, containsString("Found 34 items for processing in schema HR")); - assertThat(out, containsString(String.format("Saved sequence hr.locations_seq to file %s/sequences/locations_seq.sql", pwd))); - assertThat(out, containsString(String.format("Saved sequence hr.employees_seq to file %s/sequences/employees_seq.sql", pwd))); - assertThat(out, containsString(String.format("Saved trigger hr.update_job_history to file %s/triggers/update_job_history.sql", pwd))); - assertThat(out, containsString(String.format("Saved procedure hr.add_job_history to file %s/procedures/add_job_history.sql", pwd))); - assertThat(out, containsString(String.format("Saved table hr.locations to file %s/tables/locations.sql", pwd))); - assertThat(out, containsString(String.format("Saved procedure hr.secure_dml to file %s/procedures/secure_dml.sql", pwd))); - assertThat(out, containsString(String.format("Saved view hr.emp_details_view to file %s/views/emp_details_view.sql", pwd))); + assertThat(out, containsString(String.format("Saved sequence hr.locations_seq to file %s/sequences/locations_seq.sql", dirPath))); + assertThat(out, containsString(String.format("Saved sequence hr.employees_seq to file %s/sequences/employees_seq.sql", dirPath))); + assertThat(out, containsString(String.format("Saved trigger hr.update_job_history to file %s/triggers/update_job_history.sql", dirPath))); + assertThat(out, containsString(String.format("Saved procedure hr.add_job_history to file %s/procedures/add_job_history.sql", dirPath))); + assertThat(out, containsString(String.format("Saved table hr.locations to file %s/tables/locations.sql", dirPath))); + assertThat(out, containsString(String.format("Saved procedure hr.secure_dml to file %s/procedures/secure_dml.sql", dirPath))); + assertThat(out, containsString(String.format("Saved view hr.emp_details_view to file %s/views/emp_details_view.sql", dirPath))); - assertThat(out, containsString( - "-------------------------------------------------------\n" + - " R E P O R T S K I P P E D O B J E C T S \n" + - "-------------------------------------------------------\n" + - "| skip rule | object type | count |\n" + - "-------------------------------------------------------\n" + - "| config | INDEX | 19 |")); + assertThat(out, containsString( + "-------------------------------------------------------\n" + + " R E P O R T S K I P P E D O B J E C T S \n" + + "-------------------------------------------------------\n" + + "| skip rule | object type | count |\n" + + "-------------------------------------------------------\n" + + "| config | INDEX | 19 |")); assertThat(out, containsString("Written 15 ddls with user objects from total 34 in schema HR")); @@ -168,11 +176,11 @@ public void testExportHRSchemaDefault() throws Exception { assertThat(out, containsString("scheme2ddl of schema HR completed")); - assertEqualsFileContent(pwd + "/sequences/locations_seq.sql", "CREATE SEQUENCE \"HR\".\"LOCATIONS_SEQ\"" + + assertEqualsFileContent(dirPath + "/sequences/locations_seq.sql", "CREATE SEQUENCE \"HR\".\"LOCATIONS_SEQ\"" + " MINVALUE 1 MAXVALUE 9900 INCREMENT BY 100 START WITH 3300 NOCACHE NOORDER NOCYCLE ;"); - assertEqualsFileContent(pwd + "/tables/regions.sql", "CREATE TABLE \"HR\".\"REGIONS\" \n" + + assertEqualsFileContent(dirPath + "/tables/regions.sql", "CREATE TABLE \"HR\".\"REGIONS\" \n" + " (\t\"REGION_ID\" NUMBER CONSTRAINT \"REGION_ID_NN\" NOT NULL ENABLE, \n" + "\t\"REGION_NAME\" VARCHAR2(25)\n" + " ) ;\n" + @@ -180,7 +188,7 @@ public void testExportHRSchemaDefault() throws Exception { " CREATE UNIQUE INDEX \"HR\".\"REG_ID_PK\" ON \"HR\".\"REGIONS\" (\"REGION_ID\") \n" + " ;"); - assertEqualsFileContent(pwd + "/triggers/secure_employees.sql", + assertEqualsFileContent(dirPath + "/triggers/secure_employees.sql", "CREATE OR REPLACE TRIGGER \"HR\".\"SECURE_EMPLOYEES\" \n" + " BEFORE INSERT OR UPDATE OR DELETE ON employees\n" + "BEGIN\n" + @@ -188,8 +196,6 @@ public void testExportHRSchemaDefault() throws Exception { "END secure_employees;\n" + "/\n" + "ALTER TRIGGER \"HR\".\"SECURE_EMPLOYEES\" DISABLE;"); - - } @@ -240,8 +246,6 @@ public void testProcessForeignSchema() throws Exception { @Test public void testFilterAndReplaceSeqValue() throws Exception { - File tempOutput = FileUtils.getFile(FileUtils.getTempDirectoryPath(), - "scheme2ddl-test-" + UUID.randomUUID().toString().substring(0,8)); String outputPath = tempOutput.getAbsolutePath(); String[] args = {"-url", url, "-f", "LOCATIONS_SEQ", "-o", outputPath}; @@ -264,6 +268,16 @@ public void testFilterAndReplaceSeqValue() throws Exception { } + @Test + public void testRunWithCustomConfig() throws Exception { + String outputPath = tempOutput.getAbsolutePath(); + String[] args = {"-url", url, "-c", "src/main/resources/scheme2ddl.config.xml", "-o", outputPath}; + Main.main(args); + assertHRSchemaDefault( + outputPath, + outContent.toString()); + } + private static void assertEqualsFileContent(String path, String content) throws IOException { File file = new File(path); From 536164b7deb9b285a0cc2160e705c107032259f2 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 12:38:42 +0300 Subject: [PATCH 17/50] [more tests] tests with config from path --- .../java/com/googlecode/scheme2ddl/Main.java | 2 +- .../com/googlecode/scheme2ddl/MainIT.java | 53 +++- src/test/resources/test-travis-ci.properties | 1 - src/test/resources/test.config.xml | 248 ++++++++++++++++++ 4 files changed, 294 insertions(+), 10 deletions(-) delete mode 100644 src/test/resources/test-travis-ci.properties create mode 100644 src/test/resources/test.config.xml diff --git a/src/main/java/com/googlecode/scheme2ddl/Main.java b/src/main/java/com/googlecode/scheme2ddl/Main.java index 237dc6b..3f84f8b 100644 --- a/src/main/java/com/googlecode/scheme2ddl/Main.java +++ b/src/main/java/com/googlecode/scheme2ddl/Main.java @@ -34,7 +34,7 @@ public class Main { private static boolean stopOnWarning = false; private static boolean replaceSequenceValues = false; private static String customConfigLocation = null; - private static String defaultConfigLocation = "scheme2ddl.config.xml"; + private static final String defaultConfigLocation = "scheme2ddl.config.xml"; private static String dbUrl = null; private static String schemas; private static boolean isLaunchedByDBA; diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 859fe82..5ca6d8b 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -76,6 +76,8 @@ public void resetDefaultsForStaticFields() throws Exception { ReflectionTestUtils.setField(Main.class, "schemas", null); ReflectionTestUtils.setField(Main.class, "schemaList", null); ReflectionTestUtils.setField(Main.class, "replaceSequenceValues", false); + ReflectionTestUtils.setField(Main.class, "customConfigLocation", null); + ReflectionTestUtils.setField(Main.class, "parallelCount", 4); } @BeforeMethod @@ -132,13 +134,6 @@ public void testJustTestConnectionNegative() throws Exception { - @Test(expectedExceptions = Exception.class, expectedExceptionsMessageRegExp = "Job (.*) unsuccessful", enabled = false) - public void testStopOnWarning() throws Exception { - String[] args = {"-url", url, "--stop-on-warning"}; - Main.main(args); - - } - @Test public void testExportHRSchemaDefault() throws Exception { String[] args = {"-url", url}; @@ -269,7 +264,7 @@ public void testFilterAndReplaceSeqValue() throws Exception { } @Test - public void testRunWithCustomConfig() throws Exception { + public void testRunWithConfigPath() throws Exception { String outputPath = tempOutput.getAbsolutePath(); String[] args = {"-url", url, "-c", "src/main/resources/scheme2ddl.config.xml", "-o", outputPath}; Main.main(args); @@ -278,6 +273,48 @@ public void testRunWithCustomConfig() throws Exception { outContent.toString()); } + @Test + public void testRunWithTestCustomConfig() throws Exception { + String outputPath = tempOutput.getAbsolutePath(); + String[] args = {"-url", url, "-c", "src/test/resources/test.config.xml", "-o", outputPath}; + Main.main(args); + String out = outContent.toString(); + assertThat(out, containsString("Found 68 items for processing in schema HR")); + assertThat(out, containsString( + "Cannot get DDL for object UserObject{name='SYS_C004102', type='CONSTRAINT', schema='HR', ddl='null'} " + + "with error message ConnectionCallback; uncategorized SQLException for SQL [];" + + " SQL state [99999]; error code [31603];" + + " ORA-31603: object \"SYS_C004102\" of type CONSTRAINT not found in schema \"HR\"\n")); + + + assertThat(out, containsString( + "-------------------------------------------------------\n" + + " R E P O R T S K I P P E D O B J E C T S \n" + + "-------------------------------------------------------\n" + + "| skip rule | object type | count |\n" + + "-------------------------------------------------------\n" + + "| config | INDEX | 19 |\n" + + "| sql error | CONSTRAINT | 1 |" + )); + } + + @Test + public void testStopOnWarning() throws Exception { + String outputPath = tempOutput.getAbsolutePath(); + String[] args = {"-url", url, "-c", "src/test/resources/test.config.xml", "-o", outputPath, "--stop-on-warning"}; + try { + Main.main(args); + } + catch (Exception e){ + + } + String out = outContent.toString(); + assertThat(out, containsString("Found 68 items for processing in schema HR")); + assertThat(out, containsString("scheme2ddl of schema HR failed")); + assertThat(out, containsString("com.googlecode.scheme2ddl.exception.NonSkippableException")); + + } + private static void assertEqualsFileContent(String path, String content) throws IOException { File file = new File(path); diff --git a/src/test/resources/test-travis-ci.properties b/src/test/resources/test-travis-ci.properties deleted file mode 100644 index e7d4442..0000000 --- a/src/test/resources/test-travis-ci.properties +++ /dev/null @@ -1 +0,0 @@ -url=travis/travis@localhost:1521/XE \ No newline at end of file diff --git a/src/test/resources/test.config.xml b/src/test/resources/test.config.xml new file mode 100644 index 0000000..3c49b3a --- /dev/null +++ b/src/test/resources/test.config.xml @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sql + + + + + + + + sql + + + prc + + + fnc + + + trg + + + vw + + + pks + + + pkb + + + + + + + + sql + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + COMMENT + INDEX + OBJECT_GRANT + TRIGGER + + + + + COMMENT + OBJECT_GRANT + + + + + COMMENT + INDEX + MATERIALIZED_VIEW_LOG + OBJECT_GRANT + + + + + OBJECT_GRANT + + + + + OBJECT_GRANT + + + + + OBJECT_GRANT + + + + + OBJECT_GRANT + + + + + OBJECT_GRANT + + + + + + + + + *_*_temp_* + + + + + * + * + * + + + + * + * + + + + SYSTP* + *== + + SYS_PLSQL_* + + + + + + From e133f5e85b8df89710b2c50b47afe75e0c75c4cf Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 12:53:05 +0300 Subject: [PATCH 18/50] [minor] remove unused code --- .../scheme2ddl/exception/CannotGetDDLException.java | 4 ---- .../scheme2ddl/exception/NonSkippableException.java | 2 -- 2 files changed, 6 deletions(-) diff --git a/src/main/java/com/googlecode/scheme2ddl/exception/CannotGetDDLException.java b/src/main/java/com/googlecode/scheme2ddl/exception/CannotGetDDLException.java index b489f78..90b013f 100644 --- a/src/main/java/com/googlecode/scheme2ddl/exception/CannotGetDDLException.java +++ b/src/main/java/com/googlecode/scheme2ddl/exception/CannotGetDDLException.java @@ -6,10 +6,6 @@ */ public class CannotGetDDLException extends Exception { - public CannotGetDDLException() { - super(); - } - public CannotGetDDLException(Throwable cause) { super(cause); } diff --git a/src/main/java/com/googlecode/scheme2ddl/exception/NonSkippableException.java b/src/main/java/com/googlecode/scheme2ddl/exception/NonSkippableException.java index 3403e2d..4aa75ed 100644 --- a/src/main/java/com/googlecode/scheme2ddl/exception/NonSkippableException.java +++ b/src/main/java/com/googlecode/scheme2ddl/exception/NonSkippableException.java @@ -5,8 +5,6 @@ * @since Date: 03.07.2013 */ public class NonSkippableException extends Exception { - public NonSkippableException() { - } public NonSkippableException(Throwable cause) { super(cause); From eea9c24ee54ba67da82a8198f79e5906ffdc514e Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 14:13:33 +0300 Subject: [PATCH 19/50] [minor] remove branch from coveralls badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ac8cb13..c0cefd1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[ ![Download](https://api.bintray.com/packages/qwazer/maven/scheme2ddl/images/download.svg) ](https://bintray.com/qwazer/maven/scheme2ddl/_latestVersion)   [![Build Status](https://travis-ci.org/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.org/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg?branch=master)](https://coveralls.io/github/qwazer/scheme2ddl?branch=master) +[ ![Download](https://api.bintray.com/packages/qwazer/maven/scheme2ddl/images/download.svg) ](https://bintray.com/qwazer/maven/scheme2ddl/_latestVersion)   [![Build Status](https://travis-ci.org/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.org/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg)](https://coveralls.io/github/qwazer/scheme2ddl) **scheme2ddl** is command line util for export oracle schema to set of ddl scripts. Provide a lot of configurations via basic command line options or advanced XML configuartion. From f37b0aa14e32bb1371ee3b249d1cb44f83eb0394 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 15:55:25 +0300 Subject: [PATCH 20/50] [more tests] testRunAsSysDbaTestConnection --- .../java/com/googlecode/scheme2ddl/MainIT.java | 15 +++++++++++++++ src/test/resources/test-default.properties | 1 + 2 files changed, 16 insertions(+) diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 5ca6d8b..9038093 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -37,6 +37,9 @@ public class MainIT extends AbstractTestNGSpringContextTests { @Value("${dbaUrl}") private String dbaUrl; + @Value("${dbaAsSysdbaUrl}") + private String dbaAsSysdbaUrl; + @Autowired private JdbcTemplate dbaJdbcTemplate; @@ -273,6 +276,18 @@ public void testRunWithConfigPath() throws Exception { outContent.toString()); } + + @Test + public void testRunAsSysDbaTestConnection() throws Exception { + String outputPath = tempOutput.getAbsolutePath(); + String[] args = {"-url", dbaAsSysdbaUrl, "-tc"}; + Main.main(args); + Assert.assertEquals( + outContent.toString(), + "OK success connection to jdbc:oracle:thin:" + dbaAsSysdbaUrl + "\n"); + + } + @Test public void testRunWithTestCustomConfig() throws Exception { String outputPath = tempOutput.getAbsolutePath(); diff --git a/src/test/resources/test-default.properties b/src/test/resources/test-default.properties index 37591ae..c82658d 100644 --- a/src/test/resources/test-default.properties +++ b/src/test/resources/test-default.properties @@ -3,6 +3,7 @@ dbaUrl=system/oracle@127.0.0.1:49161/XE +dbaAsSysdbaUrl=sys as sysdba/oracle@127.0.0.1:49161/XE hrUrl=hr/pass@127.0.0.1:49161/XE From acc26eec2489be4834eb49dde552ac3f9e2e5ee7 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 6 Dec 2016 17:00:03 +0300 Subject: [PATCH 21/50] [more tests] testRunAsSysDbaWithTypeFilter --- .../com/googlecode/scheme2ddl/TypeNamesUtil.java | 14 -------------- .../java/com/googlecode/scheme2ddl/MainIT.java | 13 +++++++++++++ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/googlecode/scheme2ddl/TypeNamesUtil.java b/src/main/java/com/googlecode/scheme2ddl/TypeNamesUtil.java index 4163444..cbfb0ad 100644 --- a/src/main/java/com/googlecode/scheme2ddl/TypeNamesUtil.java +++ b/src/main/java/com/googlecode/scheme2ddl/TypeNamesUtil.java @@ -28,19 +28,5 @@ public static String map2TypeForDBMS(String type) { return type.replace(" ", "_"); } - /** - * Oracle types in user_table without underscore, for example PACKAGE BODY - * but in DBMS_METADATA with underscore PACKAGE_BODY - * @param type - type name from DBMS_METADATA representation - * - * @return type name for using in advanced config - */ - public static String map2TypeForConfig(String type) { - if (type.equals("DB_LINK")) - return "DATABASE LINK"; - if (type.equals("PROCOBJ")) - return "JOB"; - return type.replace("_", " "); - } } diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 9038093..7c408dc 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -288,6 +288,19 @@ public void testRunAsSysDbaTestConnection() throws Exception { } + + @Test + public void testRunAsSysDbaWithTypeFilter() throws Exception { + String outputPath = tempOutput.getAbsolutePath(); + String[] args = {"-url", dbaAsSysdbaUrl, "--type-filter", "'SCHEDULE', 'JOB'"}; + Main.main(args); + String out = outContent.toString(); + assertThat(out, containsString("Will try to process schema [SYS]")); + assertThat(out, containsString("Found 13 items for processing in schema SYS")); + assertThat(out, containsString("Cannot get DDL for object UserObject")); + + } + @Test public void testRunWithTestCustomConfig() throws Exception { String outputPath = tempOutput.getAbsolutePath(); From 0d1a7538391efd8422c12c608cb245c7ba56639f Mon Sep 17 00:00:00 2001 From: qwazer Date: Mon, 12 Dec 2016 16:38:59 +0300 Subject: [PATCH 22/50] [more tests] public db links --- .../com/googlecode/scheme2ddl/BaseIT.java | 116 ++++++++++++++++++ .../com/googlecode/scheme2ddl/MainIT.java | 72 +---------- .../googlecode/scheme2ddl/PublicDbLinkIT.java | 96 +++++++++++++++ src/test/resources/test-default.properties | 2 + 4 files changed, 216 insertions(+), 70 deletions(-) create mode 100644 src/test/java/com/googlecode/scheme2ddl/BaseIT.java create mode 100644 src/test/java/com/googlecode/scheme2ddl/PublicDbLinkIT.java diff --git a/src/test/java/com/googlecode/scheme2ddl/BaseIT.java b/src/test/java/com/googlecode/scheme2ddl/BaseIT.java new file mode 100644 index 0000000..e8a891e --- /dev/null +++ b/src/test/java/com/googlecode/scheme2ddl/BaseIT.java @@ -0,0 +1,116 @@ +package com.googlecode.scheme2ddl; + +import org.apache.commons.io.FileUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.CannotGetJdbcConnectionException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.springframework.test.util.ReflectionTestUtils; +import org.testng.SkipException; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Created by Anton Reshetnikov on 12 Dec 2016. + */ +@SpringBootTest(classes = ConfigurationIT.class, properties = "test-default.properties") +public abstract class BaseIT extends AbstractTestNGSpringContextTests { + + @Value("${hrUrl}") + protected String url; + + @Value("${dbaUrl}") + protected String dbaUrl; + + @Value("${dbaAsSysdbaUrl}") + protected String dbaAsSysdbaUrl; + + + @Autowired + protected JdbcTemplate dbaJdbcTemplate; + + protected final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + protected final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + + protected final PrintStream outOriginal = System.out; + protected final PrintStream errorOriginal = System.err; + + + protected File tempOutput; + + + @BeforeClass + public void setUp() { + try { + dbaJdbcTemplate.execute("ALTER USER HR ACCOUNT UNLOCK IDENTIFIED BY pass"); + } + catch (CannotGetJdbcConnectionException e){ + logger.warn("Ignore all test due", e); + throw new SkipException("Ignore all test due " + e.getMessage()); + } + + } + + @BeforeMethod + public void resetDefaultsForStaticFields() throws Exception { + ReflectionTestUtils.setField(Main.class, "justPrintUsage", false); + ReflectionTestUtils.setField(Main.class, "justPrintVersion", false); + ReflectionTestUtils.setField(Main.class, "justTestConnection", false); + ReflectionTestUtils.setField(Main.class, "dbUrl", null); + ReflectionTestUtils.setField(Main.class, "objectFilter", "%"); + ReflectionTestUtils.setField(Main.class, "typeFilter", ""); + ReflectionTestUtils.setField(Main.class, "typeFilterMode", "include"); + ReflectionTestUtils.setField(Main.class, "isLaunchedByDBA", false); + ReflectionTestUtils.setField(Main.class, "schemas", null); + ReflectionTestUtils.setField(Main.class, "schemaList", null); + ReflectionTestUtils.setField(Main.class, "replaceSequenceValues", false); + ReflectionTestUtils.setField(Main.class, "customConfigLocation", null); + ReflectionTestUtils.setField(Main.class, "parallelCount", 4); + } + + @BeforeMethod + public void setUpStreams() { + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + } + + @AfterMethod + public void cleanUpStreams() throws IOException { + System.setOut(outOriginal); + System.setErr(errorOriginal); + outContent.reset(); + errContent.reset(); + } + + @BeforeMethod + public void setUpTempOutputDir(){ + tempOutput = FileUtils.getFile(FileUtils.getTempDirectoryPath(), + "scheme2ddl-test-tmp-output", + UUID.randomUUID().toString().substring(0,8)); + } + + @AfterMethod + public void cleanUpTempOutput() throws IOException { + FileUtils.deleteDirectory(tempOutput); + } + + protected static void assertEqualsFileContent(String path, String content) throws IOException { + File file = new File(path); + assertTrue(file.exists(), "file doesn't exists " + file ); + String fileContent = FileUtils.readFileToString(file, "UTF-8"); + assertEquals(fileContent.trim().replace("\r", ""), content.replace("\r", "")); + + } +} diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 7c408dc..6d935ca 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -28,30 +28,9 @@ * @since Date: 17.09.2016 */ -@SpringBootTest(classes = ConfigurationIT.class, properties = "test-default.properties") -public class MainIT extends AbstractTestNGSpringContextTests { +//@SpringBootTest(classes = ConfigurationIT.class, properties = "test-default.properties") +public class MainIT extends BaseIT { - @Value("${hrUrl}") - private String url; - - @Value("${dbaUrl}") - private String dbaUrl; - - @Value("${dbaAsSysdbaUrl}") - private String dbaAsSysdbaUrl; - - - @Autowired - private JdbcTemplate dbaJdbcTemplate; - - private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); - - private final PrintStream outOriginal = System.out; - private final PrintStream errorOriginal = System.err; - - - private File tempOutput; @BeforeClass @@ -66,48 +45,7 @@ public void setUp() { } - @BeforeMethod - public void resetDefaultsForStaticFields() throws Exception { - ReflectionTestUtils.setField(Main.class, "justPrintUsage", false); - ReflectionTestUtils.setField(Main.class, "justPrintVersion", false); - ReflectionTestUtils.setField(Main.class, "justTestConnection", false); - ReflectionTestUtils.setField(Main.class, "dbUrl", null); - ReflectionTestUtils.setField(Main.class, "objectFilter", "%"); - ReflectionTestUtils.setField(Main.class, "typeFilter", ""); - ReflectionTestUtils.setField(Main.class, "typeFilterMode", "include"); - ReflectionTestUtils.setField(Main.class, "isLaunchedByDBA", false); - ReflectionTestUtils.setField(Main.class, "schemas", null); - ReflectionTestUtils.setField(Main.class, "schemaList", null); - ReflectionTestUtils.setField(Main.class, "replaceSequenceValues", false); - ReflectionTestUtils.setField(Main.class, "customConfigLocation", null); - ReflectionTestUtils.setField(Main.class, "parallelCount", 4); - } - @BeforeMethod - public void setUpStreams() { - System.setOut(new PrintStream(outContent)); - System.setErr(new PrintStream(errContent)); - } - - @AfterMethod - public void cleanUpStreams() throws IOException { - System.setOut(outOriginal); - System.setErr(errorOriginal); - outContent.reset(); - errContent.reset(); - } - - @BeforeMethod - public void setUpTempOutputDir(){ - tempOutput = FileUtils.getFile(FileUtils.getTempDirectoryPath(), - "scheme2ddl-test-tmp-output", - UUID.randomUUID().toString().substring(0,8)); - } - - @AfterMethod - public void cleanUpTempOutput() throws IOException { - FileUtils.deleteDirectory(tempOutput); - } @DataProvider @@ -344,11 +282,5 @@ public void testStopOnWarning() throws Exception { } - private static void assertEqualsFileContent(String path, String content) throws IOException { - File file = new File(path); - assertTrue(file.exists(), "file doesn't exists " + file ); - String fileContent = FileUtils.readFileToString(file, "UTF-8"); - assertEquals(fileContent.trim().replace("\r", ""), content.replace("\r", "")); - } } \ No newline at end of file diff --git a/src/test/java/com/googlecode/scheme2ddl/PublicDbLinkIT.java b/src/test/java/com/googlecode/scheme2ddl/PublicDbLinkIT.java new file mode 100644 index 0000000..db79b5f --- /dev/null +++ b/src/test/java/com/googlecode/scheme2ddl/PublicDbLinkIT.java @@ -0,0 +1,96 @@ +package com.googlecode.scheme2ddl; + +import org.apache.commons.io.FileUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.dao.InvalidDataAccessResourceUsageException; +import org.springframework.jdbc.BadSqlGrammarException; +import org.springframework.jdbc.CannotGetJdbcConnectionException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.springframework.test.util.ReflectionTestUtils; +import org.testng.Assert; +import org.testng.SkipException; +import org.testng.annotations.*; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.sql.SQLException; +import java.util.UUID; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.StringContains.containsString; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * @author A_Reshetnikov + * @since Date: 17.09.2016 + */ + + +public class PublicDbLinkIT extends BaseIT { + + @Value("${testUserUrl}") + protected String testUserUrl; + + + @BeforeClass + public void createSchema() { + try{ + dropUser(); + }catch (InvalidDataAccessResourceUsageException e) { + logger.warn("", e); + } + try { + createUser(); + } catch (CannotGetJdbcConnectionException e) { + logger.warn("Ignore all test due", e); + throw new SkipException("Ignore all test due " + e.getMessage()); + } + + } + + private void createUser() { + dbaJdbcTemplate.execute("CREATE USER scheme2ddl_test02 IDENTIFIED BY pass"); + dbaJdbcTemplate.execute("GRANT CONNECT, SELECT_CATALOG_ROLE to scheme2ddl_test02"); + dbaJdbcTemplate.execute("ALTER USER scheme2ddl_test02 ACCOUNT UNLOCK IDENTIFIED BY pass"); + } + + + // @AfterClass(alwaysRun = true) + public void dropUser(){ + dbaJdbcTemplate.execute("drop USER scheme2ddl_test02"); + } + + @BeforeClass + public void createDBLink(){ + dbaJdbcTemplate.execute("CREATE PUBLIC DATABASE LINK remote USING 'remote'"); + } + + @AfterClass + public void dropDBLink(){ + dbaJdbcTemplate.execute("DROP PUBLIC DATABASE LINK remote"); + } + + + @Test + public void testPublicDbLinksWithSelectCatalogRole() throws Exception { + String outputPath = tempOutput.getAbsolutePath(); + String[] args = {"-url", testUserUrl, "-o", outputPath}; + Main.main(args); + String out = outContent.toString(); + + assertThat(out, containsString("Written 1 ddls with user objects from total 1 in schema")); + + assertEqualsFileContent(outputPath + "/PUBLIC/public_db_links/remote.sql", + "CREATE PUBLIC DATABASE LINK \"REMOTE\"\n" + + " USING 'remote';"); + + } + + +} \ No newline at end of file diff --git a/src/test/resources/test-default.properties b/src/test/resources/test-default.properties index c82658d..ce1298d 100644 --- a/src/test/resources/test-default.properties +++ b/src/test/resources/test-default.properties @@ -6,6 +6,8 @@ dbaUrl=system/oracle@127.0.0.1:49161/XE dbaAsSysdbaUrl=sys as sysdba/oracle@127.0.0.1:49161/XE hrUrl=hr/pass@127.0.0.1:49161/XE +testUserUrl=scheme2ddl_test02/pass@127.0.0.1:49161/XE + dba.datasource.url=jdbc:oracle:thin:@127.0.0.1:49161:XE dba.datasource.username=system From 57839f8c871d306a12cc3e675286f660cb228f78 Mon Sep 17 00:00:00 2001 From: qwazer Date: Mon, 12 Dec 2016 16:55:54 +0300 Subject: [PATCH 23/50] [more tests] findRefGroupDDL --- .../scheme2ddl/dao/UserObjectDaoImpl.java | 2 +- .../scheme2ddl/dao/UserObjectDaoImplIT.java | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImplIT.java diff --git a/src/main/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImpl.java b/src/main/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImpl.java index 3ca7a7b..ed5ece7 100644 --- a/src/main/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImpl.java +++ b/src/main/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImpl.java @@ -310,7 +310,7 @@ public String findRefGroupDDL(String type, final String name) { + " GROUP BY rname"; public Object doInConnection(Connection connection) throws SQLException, DataAccessException { - System.out.println(query); + //todo sl4j logger.debug( "query: \n {} ", query); applyTransformParameters(connection); PreparedStatement ps = connection.prepareStatement(query); diff --git a/src/test/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImplIT.java b/src/test/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImplIT.java new file mode 100644 index 0000000..c7be2ab --- /dev/null +++ b/src/test/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImplIT.java @@ -0,0 +1,57 @@ +package com.googlecode.scheme2ddl.dao; + +import com.googlecode.scheme2ddl.ConfigurationIT; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.UncategorizedSQLException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.HashMap; + +import static org.testng.Assert.*; + +/** + * Created by Anton Reshetnikov on 12 Dec 2016. + */ +@SpringBootTest(classes = ConfigurationIT.class, properties = "test-default.properties") +public class UserObjectDaoImplIT extends AbstractTestNGSpringContextTests { + + + + private UserObjectDaoImpl userObjectDao; + + @Autowired + protected JdbcTemplate dbaJdbcTemplate; + + + @BeforeClass + public void setUp() throws Exception { + userObjectDao = new UserObjectDaoImpl(); + + userObjectDao.setLaunchedByDBA(false); + userObjectDao.setJdbcTemplate(dbaJdbcTemplate); + userObjectDao.setSchemaName("NONE"); + userObjectDao.setTransformParams(new HashMap()); + + } + + @Test + public void findRefGroupDDLNotDba(){ + userObjectDao.setLaunchedByDBA(false); + String ddl = userObjectDao.findRefGroupDDL("REFRESH_GROUP", "testName"); + assertNull(ddl); + + } + + @Test(expectedExceptions = UncategorizedSQLException.class) + public void findRefGroupDDLDba(){ + userObjectDao.setLaunchedByDBA(true); + String ddl = userObjectDao.findRefGroupDDL("REFRESH_GROUP", "testName"); + + } + +} \ No newline at end of file From 263807751c3856544081c1f6db0ee4b798c791c7 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 13 Dec 2016 09:22:56 +0300 Subject: [PATCH 24/50] [more tests] testProcessForeignSchemaParallel & some clean up --- .../scheme2ddl/UserObjectJobRunner.java | 7 ------ .../com/googlecode/scheme2ddl/MainIT.java | 25 +++++++++++++++++++ .../scheme2ddl/dao/UserObjectDaoImplIT.java | 16 +++++++++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/googlecode/scheme2ddl/UserObjectJobRunner.java b/src/main/java/com/googlecode/scheme2ddl/UserObjectJobRunner.java index 39d1de1..e4b4076 100644 --- a/src/main/java/com/googlecode/scheme2ddl/UserObjectJobRunner.java +++ b/src/main/java/com/googlecode/scheme2ddl/UserObjectJobRunner.java @@ -65,13 +65,6 @@ int start(ConfigurableApplicationContext context, boolean launchedByDBA, String } } - private JobParameters getJobParameters(String schemaName, boolean launchedByDBA) { - JobParametersBuilder parametersBuilder = new JobParametersBuilder(); - parametersBuilder.addString("schemaName", schemaName.toUpperCase()); - parametersBuilder.addString("launchedByDBA", Boolean.toString(launchedByDBA)); - return parametersBuilder.toJobParameters(); - } - private void writeJobExecutionStatus(JobExecution jobExecution, JobParameters jobParameters) { StepExecution step = jobExecution.getStepExecutions().toArray(new StepExecution[]{})[0]; String schemaName = jobParameters.getString("schemaName"); diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 6d935ca..c3ab7a0 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -180,6 +180,31 @@ public void testProcessForeignSchema() throws Exception { } + @Test + public void testProcessForeignSchemaParallel() throws Exception { + String outputPath = tempOutput.getAbsolutePath(); + + String[] args = {"-url", dbaUrl, "--schemas", "OUTLN", "--output", outputPath, "--parallel", "2"}; + + Main.main(args); + String out = outContent.toString(); + + assertThat(out, containsString("Will try to process schema [OUTLN]")); + assertThat(out, containsString("Found 8 items for processing in schema OUTLN")); + + assertEqualsFileContent(outputPath + "/OUTLN/procedures/ora$grant_sys_select.sql", + "CREATE OR REPLACE PROCEDURE \"OUTLN\".\"ORA$GRANT_SYS_SELECT\" as\n" + + "begin\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$ TO SELECT_CATALOG_ROLE';\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$HINTS TO SELECT_CATALOG_ROLE';\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$NODES TO SELECT_CATALOG_ROLE';\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$ TO SYS WITH GRANT OPTION';\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$HINTS TO SYS WITH GRANT OPTION';\n" + + " EXECUTE IMMEDIATE 'GRANT SELECT ON OUTLN.OL$NODES TO SYS WITH GRANT OPTION';\n" + + "end;\n" + + "/"); + } + @Test public void testFilterAndReplaceSeqValue() throws Exception { String outputPath = tempOutput.getAbsolutePath(); diff --git a/src/test/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImplIT.java b/src/test/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImplIT.java index c7be2ab..0c82f8b 100644 --- a/src/test/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImplIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImplIT.java @@ -3,9 +3,11 @@ import com.googlecode.scheme2ddl.ConfigurationIT; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.SkipException; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -27,9 +29,21 @@ public class UserObjectDaoImplIT extends AbstractTestNGSpringContextTests { @Autowired protected JdbcTemplate dbaJdbcTemplate; + @BeforeClass + public void setUp() { + try { + dbaJdbcTemplate.execute("select 1 from dual"); + } + catch (CannotGetJdbcConnectionException e){ + logger.warn("Ignore all test due", e); + throw new SkipException("Ignore all test due " + e.getMessage()); + } + + } + @BeforeClass - public void setUp() throws Exception { + public void initDao() throws Exception { userObjectDao = new UserObjectDaoImpl(); userObjectDao.setLaunchedByDBA(false); From a5d27ae72fc4223b18aac291248d6860d27a5d7a Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 13 Dec 2016 09:36:27 +0300 Subject: [PATCH 25/50] [more tests] schema list from advanced config --- .../java/com/googlecode/scheme2ddl/Main.java | 2 +- .../com/googlecode/scheme2ddl/MainIT.java | 56 ++++ .../resources/test_schema_list.config.xml | 248 ++++++++++++++++++ 3 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/test_schema_list.config.xml diff --git a/src/main/java/com/googlecode/scheme2ddl/Main.java b/src/main/java/com/googlecode/scheme2ddl/Main.java index 3f84f8b..818568d 100644 --- a/src/main/java/com/googlecode/scheme2ddl/Main.java +++ b/src/main/java/com/googlecode/scheme2ddl/Main.java @@ -138,7 +138,7 @@ private static void processSchemas(ConfigurableApplicationContext context) { if (isLaunchedByDBA) schemaList = new ArrayList(listFromContext); else { - log.warn("Ignore 'schemaList' from advanced config, becouse oracle user is not connected as sys dba"); + log.warn("Ignore 'schemaList' from advanced config, because oracle user is not connected as sys dba"); schemaList = extactSchemaListFromUserName(context); } } diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index c3ab7a0..56bb721 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -19,6 +19,7 @@ import java.util.UUID; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.not; import static org.hamcrest.core.StringContains.containsString; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -289,6 +290,61 @@ public void testRunWithTestCustomConfig() throws Exception { )); } + + @Test + public void testCustomConfigWithSchemaList() throws Exception { + String outputPath = tempOutput.getAbsolutePath(); + String[] args = {"-url", url, "-c", "src/test/resources/test_schema_list.config.xml", "-o", outputPath}; + Main.main(args); + String out = outContent.toString(); + assertThat(out, containsString("Ignore 'schemaList' from advanced config, because oracle user is not connected as sys dba")); + assertThat(out, containsString("Found 68 items for processing in schema HR")); + assertThat(out, containsString( + "Cannot get DDL for object UserObject{name='SYS_C004102', type='CONSTRAINT', schema='HR', ddl='null'} " + + "with error message ConnectionCallback; uncategorized SQLException for SQL [];" + + " SQL state [99999]; error code [31603];" + + " ORA-31603: object \"SYS_C004102\" of type CONSTRAINT not found in schema \"HR\"\n")); + + + assertThat(out, containsString( + "-------------------------------------------------------\n" + + " R E P O R T S K I P P E D O B J E C T S \n" + + "-------------------------------------------------------\n" + + "| skip rule | object type | count |\n" + + "-------------------------------------------------------\n" + + "| config | INDEX | 19 |\n" + + "| sql error | CONSTRAINT | 1 |" + )); + } + + @Test + public void testCustomConfigWithSchemaListAsDba() throws Exception { + String outputPath = tempOutput.getAbsolutePath(); + String[] args = {"-url", dbaAsSysdbaUrl, "-c", "src/test/resources/test_schema_list.config.xml", "-o", outputPath}; + Main.main(args); + String out = outContent.toString(); + assertThat(out, not(containsString("Ignore 'schemaList' from advanced config, because oracle user is not connected as sys dba"))); + assertThat(out, containsString("Will try to process schema list [SCOTT, HR]")); + assertThat(out, containsString("Found 0 items for processing in schema SCOTT")); + assertThat(out, containsString("Found 68 items for processing in schema HR")); + assertThat(out, containsString( + "Cannot get DDL for object UserObject{name='SYS_C004102', type='CONSTRAINT', schema='HR', ddl='null'} " + + "with error message ConnectionCallback; uncategorized SQLException for SQL [];" + + " SQL state [99999]; error code [31603];" + + " ORA-31603: object \"SYS_C004102\" of type CONSTRAINT not found in schema \"HR\"\n")); + + + assertThat(out, containsString( + "-------------------------------------------------------\n" + + " R E P O R T S K I P P E D O B J E C T S \n" + + "-------------------------------------------------------\n" + + "| skip rule | object type | count |\n" + + "-------------------------------------------------------\n" + + "| config | INDEX | 19 |\n" + + "| sql error | CONSTRAINT | 1 |" + )); + } + @Test public void testStopOnWarning() throws Exception { String outputPath = tempOutput.getAbsolutePath(); diff --git a/src/test/resources/test_schema_list.config.xml b/src/test/resources/test_schema_list.config.xml new file mode 100644 index 0000000..af1c87f --- /dev/null +++ b/src/test/resources/test_schema_list.config.xml @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + SCOTT + HR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sql + + + + + + + + sql + + + prc + + + fnc + + + trg + + + vw + + + pks + + + pkb + + + + + + + + sql + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + COMMENT + INDEX + OBJECT_GRANT + TRIGGER + + + + + COMMENT + OBJECT_GRANT + + + + + COMMENT + INDEX + MATERIALIZED_VIEW_LOG + OBJECT_GRANT + + + + + OBJECT_GRANT + + + + + OBJECT_GRANT + + + + + OBJECT_GRANT + + + + + OBJECT_GRANT + + + + + OBJECT_GRANT + + + + + + + + + *_*_temp_* + + + + + * + * + * + + + + * + * + + + + SYSTP* + *== + + SYS_PLSQL_* + + + + + + From 8794b37eea965eee09c3d8ba8505b2d8ca28a708 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 13 Dec 2016 09:43:08 +0300 Subject: [PATCH 26/50] [more tests] minor fix --- src/test/java/com/googlecode/scheme2ddl/BaseIT.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/googlecode/scheme2ddl/BaseIT.java b/src/test/java/com/googlecode/scheme2ddl/BaseIT.java index e8a891e..f8b21b7 100644 --- a/src/test/java/com/googlecode/scheme2ddl/BaseIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/BaseIT.java @@ -78,6 +78,7 @@ public void resetDefaultsForStaticFields() throws Exception { ReflectionTestUtils.setField(Main.class, "replaceSequenceValues", false); ReflectionTestUtils.setField(Main.class, "customConfigLocation", null); ReflectionTestUtils.setField(Main.class, "parallelCount", 4); + ReflectionTestUtils.setField(Main.class, "outputPath", null); } @BeforeMethod From 1c37947739e54263dd0f796affc11eda56e4dfae Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 13 Dec 2016 09:46:50 +0300 Subject: [PATCH 27/50] [more tests] clean-up and improve coverage --- src/main/java/com/googlecode/scheme2ddl/Main.java | 7 ------- src/test/resources/test.config.xml | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/googlecode/scheme2ddl/Main.java b/src/main/java/com/googlecode/scheme2ddl/Main.java index 818568d..1cf89e6 100644 --- a/src/main/java/com/googlecode/scheme2ddl/Main.java +++ b/src/main/java/com/googlecode/scheme2ddl/Main.java @@ -171,13 +171,6 @@ private static List extactSchemaListFromUserName(ConfigurableApplication return list; } - private static void fillSchemaListFromUserName(ConfigurableApplicationContext context) { - OracleDataSource dataSource = (OracleDataSource) context.getBean("dataSource"); - String schemaName = dataSource.getUser().split(" ")[0]; - schemaList = new ArrayList(); - schemaList.add(schemaName); - } - /** * @param context * @return existing bean 'schemaList', if this exists, or create and register new bean diff --git a/src/test/resources/test.config.xml b/src/test/resources/test.config.xml index 3c49b3a..b0a903c 100644 --- a/src/test/resources/test.config.xml +++ b/src/test/resources/test.config.xml @@ -17,10 +17,10 @@ - + - + From 2ace1f85196a3b3e2820a5f4911071cd888366c4 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 13 Dec 2016 09:59:33 +0300 Subject: [PATCH 28/50] [more tests] rewrite `as sysdba` tests to simulate command line args --- src/test/java/com/googlecode/scheme2ddl/MainIT.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 56bb721..078962a 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -244,7 +244,9 @@ public void testRunWithConfigPath() throws Exception { @Test public void testRunAsSysDbaTestConnection() throws Exception { String outputPath = tempOutput.getAbsolutePath(); - String[] args = {"-url", dbaAsSysdbaUrl, "-tc"}; + String dba[] = dbaAsSysdbaUrl.split(" "); + assertTrue(dba.length==3); + String[] args = {"-url", dba[0], dba[1], dba[2], "-tc"}; Main.main(args); Assert.assertEquals( outContent.toString(), @@ -256,7 +258,9 @@ public void testRunAsSysDbaTestConnection() throws Exception { @Test public void testRunAsSysDbaWithTypeFilter() throws Exception { String outputPath = tempOutput.getAbsolutePath(); - String[] args = {"-url", dbaAsSysdbaUrl, "--type-filter", "'SCHEDULE', 'JOB'"}; + String dba[] = dbaAsSysdbaUrl.split(" "); + assertTrue(dba.length==3); + String[] args = {"-url", dba[0], dba[1], dba[2], "--type-filter", "'SCHEDULE', 'JOB'"}; Main.main(args); String out = outContent.toString(); assertThat(out, containsString("Will try to process schema [SYS]")); @@ -320,7 +324,9 @@ public void testCustomConfigWithSchemaList() throws Exception { @Test public void testCustomConfigWithSchemaListAsDba() throws Exception { String outputPath = tempOutput.getAbsolutePath(); - String[] args = {"-url", dbaAsSysdbaUrl, "-c", "src/test/resources/test_schema_list.config.xml", "-o", outputPath}; + String dba[] = dbaAsSysdbaUrl.split(" "); + assertTrue(dba.length==3); + String[] args = {"-url", dba[0], dba[1], dba[2], "-c", "src/test/resources/test_schema_list.config.xml", "-o", outputPath}; Main.main(args); String out = outContent.toString(); assertThat(out, not(containsString("Ignore 'schemaList' from advanced config, because oracle user is not connected as sys dba"))); From 6b7e891c3a00d50242d334c0b53b4b290ba4bd56 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 13 Dec 2016 20:40:45 +0400 Subject: [PATCH 29/50] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c0cefd1..ac8cb13 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[ ![Download](https://api.bintray.com/packages/qwazer/maven/scheme2ddl/images/download.svg) ](https://bintray.com/qwazer/maven/scheme2ddl/_latestVersion)   [![Build Status](https://travis-ci.org/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.org/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg)](https://coveralls.io/github/qwazer/scheme2ddl) +[ ![Download](https://api.bintray.com/packages/qwazer/maven/scheme2ddl/images/download.svg) ](https://bintray.com/qwazer/maven/scheme2ddl/_latestVersion)   [![Build Status](https://travis-ci.org/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.org/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg?branch=master)](https://coveralls.io/github/qwazer/scheme2ddl?branch=master) **scheme2ddl** is command line util for export oracle schema to set of ddl scripts. Provide a lot of configurations via basic command line options or advanced XML configuartion. From bf54667f2a60f1f7b731719180a27d47b1a49b9c Mon Sep 17 00:00:00 2001 From: qwazer Date: Wed, 14 Jun 2017 15:35:55 +0400 Subject: [PATCH 30/50] polish readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ac8cb13..35fb58c 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ -###Benefits +### Benefits **scheme2ddl** give ability to filter undesirable information, separate DDL in different files, pretty format output. -###How to start with minimal configuration +### How to start with minimal configuration Java must be installed on your computer. For exporting oracle scheme you must provide @@ -63,7 +63,7 @@ On Unix platform you can run `scheme2ddl.jar` as executable file: ./scheme2ddl.jar -###How it is work inside? +### How it is work inside? 1. First, get list of all user_object to export @@ -76,7 +76,7 @@ On Unix platform you can run `scheme2ddl.jar` as executable file: *scheme2ddl* build on top of [spring-batch](http://static.springsource.org/spring-batch/) framework. -###See it in action in cloud +### See it in action in cloud You can see it in action as [Jenkins build](http://jenkins-ddl2svn.rhcloud.com/job/amazon-rds-oracle-schema2ddl/lastSuccessfulBuild). Look at console output and build artifacts. > Jenkins hosting provided by Red Hat's OpenShift. From 03eccf5658f9ded2700d401b16e0eed7ee765c0e Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 19 Dec 2017 20:40:18 +0300 Subject: [PATCH 31/50] remove 'see it in action' - outdated link --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 35fb58c..75b6474 100644 --- a/README.md +++ b/README.md @@ -74,11 +74,3 @@ On Unix platform you can run `scheme2ddl.jar` as executable file: 4. print every ddl to separate file grouped in folders like tables, views, procedures etc *scheme2ddl* build on top of [spring-batch](http://static.springsource.org/spring-batch/) framework. - - -### See it in action in cloud -You can see it in action as [Jenkins build](http://jenkins-ddl2svn.rhcloud.com/job/amazon-rds-oracle-schema2ddl/lastSuccessfulBuild). Look at console output and build artifacts. - -> Jenkins hosting provided by Red Hat's OpenShift. -> Oracle hosting provided by Amazon's RDS. - From 92a2fc97e4aab6a9a95ef4fdffeb8ba29873bfe6 Mon Sep 17 00:00:00 2001 From: qwazer Date: Tue, 19 Dec 2017 21:08:59 +0300 Subject: [PATCH 32/50] Update .travis.yml build with oraclejdk8, because travis-ci doesn't support oraclejdk7 --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 69eb789..c2651e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,7 @@ services: - docker jdk: - - oraclejdk7 -# - openjdk6 - + - oraclejdk8 before_install: - docker pull wnameless/oracle-xe-11g From f476258067ebd3c52e52e899cc51155032c8ebe1 Mon Sep 17 00:00:00 2001 From: qwazer Date: Sun, 4 Nov 2018 13:34:53 +0300 Subject: [PATCH 33/50] scheme2ddl-44 CREATE (UNIQUE) INDEX statement in table files are not sorted - add new method `sortIndexesInDDL` in DDLFormatter class - add new parameter of DDLFormatter `sortCreateIndexStatements` with default value true added - invoke `sortIndexesInDDL` in UserObjectProcessor --- .../googlecode/scheme2ddl/DDLFormatter.java | 34 +++++ .../scheme2ddl/UserObjectProcessor.java | 12 +- src/main/resources/scheme2ddl.config.xml | 1 + .../scheme2ddl/DDLFormatterTest.java | 124 ++++++++++++------ 4 files changed, 127 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/googlecode/scheme2ddl/DDLFormatter.java b/src/main/java/com/googlecode/scheme2ddl/DDLFormatter.java index ea5c5d5..88c497a 100644 --- a/src/main/java/com/googlecode/scheme2ddl/DDLFormatter.java +++ b/src/main/java/com/googlecode/scheme2ddl/DDLFormatter.java @@ -1,5 +1,8 @@ package com.googlecode.scheme2ddl; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -10,6 +13,7 @@ public class DDLFormatter { private boolean noFormat; + private boolean sortCreateIndexStatements = true; private boolean statementOnNewLine; private boolean isMorePrettyFormat = false; @@ -49,6 +53,9 @@ public void setIsMorePrettyFormat(boolean isMorePrettyFormat) { this.isMorePrettyFormat = isMorePrettyFormat; } + public void setSortCreateIndexStatements(boolean sortCreateIndexStatements) { + this.sortCreateIndexStatements = sortCreateIndexStatements; + } public String replaceActualSequenceValueWithOne(String res) { @@ -65,4 +72,31 @@ public String replaceActualSequenceValueWithOne(String res) { } return output; } + + /** + * Read input string with list of 'create index' statements and, tokenize and sort alphabetically. + * @param dependentDLL -string with list of 'create index' statements + * @return string with sorted alphabetically 'create index' statements + */ + public String sortIndexesInDDL(String dependentDLL) { + if (noFormat || !sortCreateIndexStatements){ + return dependentDLL; + } + String[] parts = dependentDLL.split("(?=CREATE INDEX)|(?=CREATE UNIQUE INDEX)|(?=CREATE BITMAP INDEX)"); + List list = new ArrayList(); + for (String part : parts) { + if (part != null && !part.trim().isEmpty()) { + list.add(part.trim()); + } + } + Collections.sort(list); + StringBuilder s = new StringBuilder(); + String prefix = "\n "; //to preserve formatting of dbms_metadata.get_depended_ddl output + for (String statement:list){ + s.append(prefix); + prefix = "\n"; + s.append(statement); + } + return s.toString(); + } } diff --git a/src/main/java/com/googlecode/scheme2ddl/UserObjectProcessor.java b/src/main/java/com/googlecode/scheme2ddl/UserObjectProcessor.java index 62dded9..09d7c68 100644 --- a/src/main/java/com/googlecode/scheme2ddl/UserObjectProcessor.java +++ b/src/main/java/com/googlecode/scheme2ddl/UserObjectProcessor.java @@ -75,17 +75,21 @@ private String map2Ddl(UserObject userObject) throws CannotGetDDLException, NonS if (userObject.getType().equals("REFRESH_GROUP")) { return ddlFormatter.formatDDL(userObjectDao.findRefGroupDDL(userObject.getType(), userObject.getName())); } - String res = userObjectDao.findPrimaryDDL(map2TypeForDBMS(userObject.getType()), userObject.getName()); + StringBuilder res = new StringBuilder(userObjectDao.findPrimaryDDL(map2TypeForDBMS(userObject.getType()), userObject.getName())); if (userObject.getType().equals("SEQUENCE") && replaceSequenceValues) { - res = ddlFormatter.replaceActualSequenceValueWithOne(res); + res = new StringBuilder(ddlFormatter.replaceActualSequenceValueWithOne(res.toString())); } Set dependedTypes = dependencies.get(userObject.getType()); if (dependedTypes != null) { for (String dependedType : dependedTypes) { - res += userObjectDao.findDependentDLLByTypeName(dependedType, userObject.getName()); + String dependentDLL = userObjectDao.findDependentDLLByTypeName(dependedType, userObject.getName()); + if (dependedType.equals("INDEX")){ + dependentDLL = ddlFormatter.sortIndexesInDDL(dependentDLL); + } + res.append(dependentDLL); } } - return ddlFormatter.formatDDL(res); + return ddlFormatter.formatDDL(res.toString()); } catch (Exception e) { log.warn(String.format("Cannot get DDL for object %s with error message %s", userObject, e.getMessage())); if (stopOnWarning) { diff --git a/src/main/resources/scheme2ddl.config.xml b/src/main/resources/scheme2ddl.config.xml index c7c0762..ba261b6 100644 --- a/src/main/resources/scheme2ddl.config.xml +++ b/src/main/resources/scheme2ddl.config.xml @@ -52,6 +52,7 @@ + diff --git a/src/test/java/com/googlecode/scheme2ddl/DDLFormatterTest.java b/src/test/java/com/googlecode/scheme2ddl/DDLFormatterTest.java index 48fb11a..7f1607b 100644 --- a/src/test/java/com/googlecode/scheme2ddl/DDLFormatterTest.java +++ b/src/test/java/com/googlecode/scheme2ddl/DDLFormatterTest.java @@ -1,41 +1,85 @@ -package com.googlecode.scheme2ddl; - - -import org.testng.annotations.Test; - -import static org.testng.Assert.assertNotEquals; -import static org.testng.AssertJUnit.assertEquals; - - -/** - * @author ar - * @since Date: 18.04.2015 - */ -public class DDLFormatterTest { - - private DDLFormatter ddlFormatter = new DDLFormatter(); - - @Test - public void testReplaceActualSequenceValueWithOne() throws Exception { - - String s = "CREATE SEQUENCE \"TEST01\".\"SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 2122 CACHE 20 NOORDER NOCYCLE ;\n"; - String res = ddlFormatter.replaceActualSequenceValueWithOne(s); - assertEquals( - "CREATE SEQUENCE \"TEST01\".\"SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ;\n" + - "\r\n" + - "/* -- actual sequence value was replaced by scheme2ddl to 1 */" - , res); - - } - - @Test - public void testReplaceActualSequenceValueWithOneOnWrongDDL() throws Exception { - - String s = "CREATE TABLE \"TEST01\".\"SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 2122 CACHE 20 NOORDER NOCYCLE ;\n"; - String res = ddlFormatter.replaceActualSequenceValueWithOne(s); - assertNotEquals( - "CREATE TABLE \"TEST01\".\"SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ;\n" - , res); - - } +package com.googlecode.scheme2ddl; + + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertNotEquals; +import static org.testng.AssertJUnit.assertEquals; + + +/** + * @author ar + * @since Date: 18.04.2015 + */ +public class DDLFormatterTest { + + private DDLFormatter ddlFormatter = new DDLFormatter(); + + @Test + public void testReplaceActualSequenceValueWithOne() throws Exception { + + String s = "CREATE SEQUENCE \"TEST01\".\"SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 2122 CACHE 20 NOORDER NOCYCLE ;\n"; + String res = ddlFormatter.replaceActualSequenceValueWithOne(s); + assertEquals( + "CREATE SEQUENCE \"TEST01\".\"SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ;\n" + + "\r\n" + + "/* -- actual sequence value was replaced by scheme2ddl to 1 */" + , res); + + } + + @Test + public void testReplaceActualSequenceValueWithOneOnWrongDDL() throws Exception { + + String s = "CREATE TABLE \"TEST01\".\"SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 2122 CACHE 20 NOORDER NOCYCLE ;\n"; + String res = ddlFormatter.replaceActualSequenceValueWithOne(s); + assertNotEquals( + "CREATE TABLE \"TEST01\".\"SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ;\n" + , res); + + } + + + @Test + public void testSortPreserveOriginalDDLIfNoSort() { + String s = "\n CREATE UNIQUE INDEX \"HR\".\"REG_ID_PK\" ON \"HR\".\"REGIONS\" (\"REGION_ID\") \n" + + " ;"; + String res = ddlFormatter.sortIndexesInDDL(s); + assertEquals(s, res); + } + + @Test + public void testSortIndexes() { + String s = " CREATE INDEX \"HR\".\"A_IDX2\" ON \"HR\".\"A\" (\"C2\") \n" + + " ;\n" + + " CREATE INDEX \"HR\".\"A_IDX1\" ON \"HR\".\"A\" (\"C3\") \n" + + " ;"; + String res = ddlFormatter.sortIndexesInDDL(s); + assertEquals( + "\n CREATE INDEX \"HR\".\"A_IDX1\" ON \"HR\".\"A\" (\"C3\") \n" + + " ;\n" + + "CREATE INDEX \"HR\".\"A_IDX2\" ON \"HR\".\"A\" (\"C2\") \n" + + " ;" + , res); + } + + @Test + public void testSortIndexesUniq() { + String s = + " \n" + + "CREATE UNIQUE INDEX \"HR\".\"A_UNIQ2\" ON \"HR\".\"A\" (\"C1\", \"B2\") \n" + + " ;\n" + + " CREATE INDEX \"HR\".\"A_IDX1\" ON \"HR\".\"A\" (\"C1\") \n" + + " ; " + + "CREATE BITMAP INDEX \"HR\".\"A_BITMAP_IDX\" ON \"HR\".\"A\" (\"C1\", \"C5\") \n" + + " ;\n"; + String res = ddlFormatter.sortIndexesInDDL(s); + assertEquals("\n " + + "CREATE BITMAP INDEX \"HR\".\"A_BITMAP_IDX\" ON \"HR\".\"A\" (\"C1\", \"C5\") \n" + + " ;\n" + + "CREATE INDEX \"HR\".\"A_IDX1\" ON \"HR\".\"A\" (\"C1\") \n" + + " ;\n" + + "CREATE UNIQUE INDEX \"HR\".\"A_UNIQ2\" ON \"HR\".\"A\" (\"C1\", \"B2\") \n" + + " ;", res); + } } \ No newline at end of file From af85b94874853c93f571ba9ce823ea9042493912 Mon Sep 17 00:00:00 2001 From: qwazer Date: Sun, 4 Nov 2018 20:34:11 +0300 Subject: [PATCH 34/50] [maven-release-plugin] prepare release v2.4.2 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index fddb1b7..c21d54b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.googlecode scheme2ddl - 2.4.2-SNAPSHOT + 2.4.2 jar @@ -19,7 +19,7 @@ scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git - HEAD + v2.4.2 From cc33d5c1f5d9bdd974b47aa39a0276f21d646daa Mon Sep 17 00:00:00 2001 From: qwazer Date: Sun, 4 Nov 2018 20:45:57 +0300 Subject: [PATCH 35/50] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c21d54b..2da67cd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.googlecode scheme2ddl - 2.4.2 + 2.4.3-SNAPSHOT jar @@ -19,7 +19,7 @@ scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git - v2.4.2 + HEAD From d7623579f24c2909b62985890d230bb92c8c9318 Mon Sep 17 00:00:00 2001 From: qwazer Date: Wed, 9 Jun 2021 22:20:55 +0300 Subject: [PATCH 36/50] [minor] update readme - drop obsolete download link --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 75b6474..2548e9b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[ ![Download](https://api.bintray.com/packages/qwazer/maven/scheme2ddl/images/download.svg) ](https://bintray.com/qwazer/maven/scheme2ddl/_latestVersion)   [![Build Status](https://travis-ci.org/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.org/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg?branch=master)](https://coveralls.io/github/qwazer/scheme2ddl?branch=master) +[![Build Status](https://travis-ci.org/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.org/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg?branch=master)](https://coveralls.io/github/qwazer/scheme2ddl?branch=master) **scheme2ddl** is command line util for export oracle schema to set of ddl scripts. Provide a lot of configurations via basic command line options or advanced XML configuartion. @@ -66,8 +66,10 @@ On Unix platform you can run `scheme2ddl.jar` as executable file: ### How it is work inside? 1. First, get list of all user_object to export - - `select * from user_objects` + +```sql +select * from user_objects +``` 2. then applying [dbms_metadata.set_transform_param](http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_metada.htm#i1000135) 3. for every user object invoke [dbms_metadata.get_ddl](http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_metada.htm#i1019414) and [dbms_metadata.get_dependent_ddl](http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_metada.htm#i1019414) From 4e1dc5d862906ecf858468220f03914fecc8d8d6 Mon Sep 17 00:00:00 2001 From: qwazer Date: Wed, 14 Jul 2021 21:32:20 +0300 Subject: [PATCH 37/50] Support for Oracle 19c & update CI (#60) * Support for Oracle 19c Fix CI: * use oraclejdk11 in CI * migrate to travis-ci.com * fix docker image, use wnameless/oracle-xe-11g-r2 * mute failed test for "as sysdba" connection --- .travis.yml | 6 +-- README.md | 2 +- pom.xml | 39 +++++++++---------- .../com/googlecode/scheme2ddl/MainIT.java | 22 ++++------- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index c2651e4..90f75c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,11 @@ services: - docker jdk: - - oraclejdk8 + - oraclejdk11 before_install: - - docker pull wnameless/oracle-xe-11g - - docker run --name oracle -d -p 127.0.0.1:49161:1521 -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g + - docker pull wnameless/oracle-xe-11g-r2 + - docker run --name oracle -d -p 127.0.0.1:49161:1521 -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g-r2 # - docker inspect oracle # - docker ps -a - echo "Wait to allow Oracle to be initialized" diff --git a/README.md b/README.md index 2548e9b..d5738de 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.org/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg?branch=master)](https://coveralls.io/github/qwazer/scheme2ddl?branch=master) +[![Build Status](https://travis-ci.com/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.com/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg?branch=master)](https://coveralls.io/github/qwazer/scheme2ddl?branch=master) **scheme2ddl** is command line util for export oracle schema to set of ddl scripts. Provide a lot of configurations via basic command line options or advanced XML configuartion. diff --git a/pom.xml b/pom.xml index 2da67cd..ce2d736 100644 --- a/pom.xml +++ b/pom.xml @@ -23,14 +23,6 @@ - - - otn-maven-repo - Maven repo with artifacts from Oracle Technology Network for private usage - https://subversion.assembla.com/svn/otn-maven-repo/m2/ - - - bintray-qwazer-maven @@ -70,10 +62,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.0 + 3.8.0 - 1.6 - 1.6 + 11 + 11 @@ -83,7 +75,7 @@ org.jacoco jacoco-maven-plugin - 0.7.7.201606060606 + 0.8.4 default-prepare-agent @@ -162,16 +154,22 @@ commons-io 2.5 - - com.oracle - ojdbc5 - 11.2.0.3.0 + com.oracle.database.jdbc + ojdbc10 + 19.11.0.0 + + + + com.oracle.database.nls + orai18n + 21.1.0.0 @@ -185,6 +183,7 @@ + release diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 078962a..3b72371 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -1,27 +1,19 @@ package com.googlecode.scheme2ddl; import org.apache.commons.io.FileUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.jdbc.CannotGetJdbcConnectionException; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; -import org.springframework.test.util.ReflectionTestUtils; import org.testng.Assert; import org.testng.SkipException; -import org.testng.annotations.*; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; import static org.hamcrest.core.StringContains.containsString; -import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; /** @@ -241,7 +233,7 @@ public void testRunWithConfigPath() throws Exception { } - @Test + @Test(enabled = false) //todo enable public void testRunAsSysDbaTestConnection() throws Exception { String outputPath = tempOutput.getAbsolutePath(); String dba[] = dbaAsSysdbaUrl.split(" "); @@ -255,7 +247,7 @@ public void testRunAsSysDbaTestConnection() throws Exception { } - @Test + @Test(enabled = false) //todo enable public void testRunAsSysDbaWithTypeFilter() throws Exception { String outputPath = tempOutput.getAbsolutePath(); String dba[] = dbaAsSysdbaUrl.split(" "); @@ -295,7 +287,7 @@ public void testRunWithTestCustomConfig() throws Exception { } - @Test + @Test(enabled = false) //todo enable public void testCustomConfigWithSchemaList() throws Exception { String outputPath = tempOutput.getAbsolutePath(); String[] args = {"-url", url, "-c", "src/test/resources/test_schema_list.config.xml", "-o", outputPath}; @@ -321,7 +313,7 @@ public void testCustomConfigWithSchemaList() throws Exception { )); } - @Test + @Test(enabled = false) //todo enable public void testCustomConfigWithSchemaListAsDba() throws Exception { String outputPath = tempOutput.getAbsolutePath(); String dba[] = dbaAsSysdbaUrl.split(" "); From aaeb9be00f00f8006235d46b0fa0061433d4e95e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Jul 2021 21:39:31 +0300 Subject: [PATCH 38/50] Bump commons-io from 2.5 to 2.7 (#61) Bumps commons-io from 2.5 to 2.7. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ce2d736..7b24be5 100644 --- a/pom.xml +++ b/pom.xml @@ -152,7 +152,7 @@ commons-io commons-io - 2.5 + 2.7 javax.annotation From d7519f3c67b10e56e03653f6c5fb5d995618ac77 Mon Sep 17 00:00:00 2001 From: qwazer Date: Thu, 15 Jul 2021 11:10:37 +0300 Subject: [PATCH 39/50] Move out of bintray to cloudsmith.io (#62) --- pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 7b24be5..a7b2f2e 100644 --- a/pom.xml +++ b/pom.xml @@ -25,9 +25,8 @@ - bintray-qwazer-maven - qwazer-maven - https://api.bintray.com/maven/${bintray.repo}/${bintray.package}/;publish=1 + cloudsmith + https://maven.cloudsmith.io/qwazer/repo From cc045c5478d38c74b6b6148a7cfccf2f1d234c18 Mon Sep 17 00:00:00 2001 From: qwazer Date: Thu, 15 Jul 2021 11:13:52 +0300 Subject: [PATCH 40/50] [maven-release-plugin] prepare release v2.4.3 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a7b2f2e..68506da 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.googlecode scheme2ddl - 2.4.3-SNAPSHOT + 2.4.3 jar @@ -19,7 +19,7 @@ scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git - HEAD + v2.4.3 From aea1f3d8bc5259b7b1d28620ba2ba5f2100c3114 Mon Sep 17 00:00:00 2001 From: qwazer Date: Thu, 15 Jul 2021 11:21:23 +0300 Subject: [PATCH 41/50] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 68506da..780c8ab 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.googlecode scheme2ddl - 2.4.3 + 2.4.4-SNAPSHOT jar From 656231046986d5ab45c9eb41d94fe49667e73ded Mon Sep 17 00:00:00 2001 From: qwazer Date: Thu, 15 Jul 2021 11:25:32 +0300 Subject: [PATCH 42/50] update download link to cloudsmith.io repo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5738de..7bb6aeb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.com/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg?branch=master)](https://coveralls.io/github/qwazer/scheme2ddl?branch=master) +[![Latest version of 'scheme2ddl' @ Cloudsmith](https://api-prd.cloudsmith.io/v1/badges/version/qwazer/repo/maven/scheme2ddl/latest/a=noarch;xg=com.googlecode/?render=true&show_latest=true)](https://cloudsmith.io/~qwazer/repos/repo/packages/detail/maven/scheme2ddl/latest/a=noarch;xg=com.googlecode/)   [![Build Status](https://travis-ci.com/qwazer/scheme2ddl.svg?branch=master)](https://travis-ci.com/qwazer/scheme2ddl)   [![Coverage Status](https://coveralls.io/repos/github/qwazer/scheme2ddl/badge.svg?branch=master)](https://coveralls.io/github/qwazer/scheme2ddl?branch=master) **scheme2ddl** is command line util for export oracle schema to set of ddl scripts. Provide a lot of configurations via basic command line options or advanced XML configuartion. From 1c8a79a5d434b586c2b8fa2012ff985ac17c9bf6 Mon Sep 17 00:00:00 2001 From: qwazer Date: Thu, 15 Jul 2021 11:27:45 +0300 Subject: [PATCH 43/50] add download info --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 7bb6aeb..698c8cd 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,14 @@ ### Benefits **scheme2ddl** give ability to filter undesirable information, separate DDL in different files, pretty format output. +### Download + +Use link above or + +```yaml +wget https://dl.cloudsmith.io/public/qwazer/repo/maven/com/googlecode/scheme2ddl/2.4.3/scheme2ddl-2.4.3.jar +``` + ### How to start with minimal configuration Java must be installed on your computer. From befb43b723e14169bccdf9ae14a72cce52246005 Mon Sep 17 00:00:00 2001 From: qwazer Date: Fri, 23 Jul 2021 12:05:09 +0300 Subject: [PATCH 44/50] Use UTF-8 encoding to save files (#64) * scheme2ddl-63 use UTF-8 encoding to save files --- .../scheme2ddl/UserObjectWriter.java | 4 +-- .../scheme2ddl/UserObjectWriterTest.java | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/googlecode/scheme2ddl/UserObjectWriterTest.java diff --git a/src/main/java/com/googlecode/scheme2ddl/UserObjectWriter.java b/src/main/java/com/googlecode/scheme2ddl/UserObjectWriter.java index 919d2f6..2ec5231 100644 --- a/src/main/java/com/googlecode/scheme2ddl/UserObjectWriter.java +++ b/src/main/java/com/googlecode/scheme2ddl/UserObjectWriter.java @@ -9,6 +9,7 @@ import org.springframework.batch.item.ItemWriter; import java.io.File; +import java.nio.charset.StandardCharsets; import java.util.List; /** @@ -31,7 +32,7 @@ public void writeUserObject(UserObject userObject) throws Exception { String absoluteFileName = outputPath + "/" + userObject.getFileName(); absoluteFileName = FilenameUtils.separatorsToSystem(absoluteFileName); File file = new File(absoluteFileName); - FileUtils.writeStringToFile(file, userObject.getDdl()); + FileUtils.writeStringToFile(file, userObject.getDdl(), StandardCharsets.UTF_8); log.info(String.format("Saved %s %s.%s to file %s", userObject.getType().toLowerCase(), userObject.getSchema().toLowerCase(), @@ -40,7 +41,6 @@ public void writeUserObject(UserObject userObject) throws Exception { } - public void setOutputPath(String outputPath) { this.outputPath = outputPath; } diff --git a/src/test/java/com/googlecode/scheme2ddl/UserObjectWriterTest.java b/src/test/java/com/googlecode/scheme2ddl/UserObjectWriterTest.java new file mode 100644 index 0000000..052ab48 --- /dev/null +++ b/src/test/java/com/googlecode/scheme2ddl/UserObjectWriterTest.java @@ -0,0 +1,33 @@ +package com.googlecode.scheme2ddl; + +import com.googlecode.scheme2ddl.domain.UserObject; +import org.assertj.core.api.Assertions; +import org.testng.annotations.Test; + +import java.io.File; + +public class UserObjectWriterTest { + + private UserObjectWriter userObjectWriter = new UserObjectWriter(); + + @Test + public void testWriteUserObjectWithUtf8() throws Exception { + + String content = "--你好 Немного текста в UTF-8"; + String outputPath = "output"; + userObjectWriter.setOutputPath(outputPath); + UserObject userObject = new UserObject(); + userObject.setType("tmp_test"); + userObject.setSchema("tmp_test"); + userObject.setName("content_utf8"); + userObject.setFileName("tmp_test.sql"); + userObject.setDdl(content); + userObjectWriter.writeUserObject(userObject); + + String fileName = outputPath + "/" + userObject.getFileName(); + File f = new File(fileName); + f.deleteOnExit(); //to delete temp file after test over + Assertions.assertThat(f).hasContent(content); + + } +} \ No newline at end of file From d6d95547524794d4d1d63a676ef6d6c4f7d6dd00 Mon Sep 17 00:00:00 2001 From: qwazer Date: Fri, 23 Jul 2021 12:30:12 +0300 Subject: [PATCH 45/50] [maven-release-plugin] prepare release v2.4.4 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 780c8ab..663040f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.googlecode scheme2ddl - 2.4.4-SNAPSHOT + 2.4.4 jar @@ -19,7 +19,7 @@ scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git scm:git:git@github.com:qwazer/scheme2ddl.git - v2.4.3 + v2.4.4 From eafb66c4194edad45585e802e891ced74b7c8a30 Mon Sep 17 00:00:00 2001 From: qwazer Date: Fri, 23 Jul 2021 12:41:12 +0300 Subject: [PATCH 46/50] [maven-release-plugin] prepare for next development iteration & update download link --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 698c8cd..42c9503 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Use link above or ```yaml -wget https://dl.cloudsmith.io/public/qwazer/repo/maven/com/googlecode/scheme2ddl/2.4.3/scheme2ddl-2.4.3.jar +wget https://dl.cloudsmith.io/public/qwazer/repo/maven/com/googlecode/scheme2ddl/2.4.4/scheme2ddl-2.4.4.jar ``` ### How to start with minimal configuration diff --git a/pom.xml b/pom.xml index 663040f..3e8695e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.googlecode scheme2ddl - 2.4.4 + 2.4.5-SNAPSHOT jar From f69af063231c3abd5d4cb9b0548a2b4ea3a52464 Mon Sep 17 00:00:00 2001 From: YunLemon <340355960@qq.com> Date: Tue, 17 Aug 2021 21:37:07 +0800 Subject: [PATCH 47/50] Improve Travis CI build Performance (#65) --- .travis.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 90f75c7..b701a49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,17 +13,17 @@ before_install: # - docker inspect oracle # - docker ps -a - echo "Wait to allow Oracle to be initialized" - - travis_wait sleep 10 + - sleep 10 - docker top oracle - - travis_wait sleep 10 + - sleep 10 - docker top oracle - - travis_wait sleep 10 + - sleep 10 - docker top oracle - - travis_wait sleep 10 + - sleep 10 - docker top oracle - - travis_wait sleep 10 + - sleep 10 - docker top oracle - - travis_wait sleep 10 + - sleep 10 - docker top oracle script: @@ -31,3 +31,7 @@ script: after_success: - mvn coveralls:report -Dcoveralls.repoToken=$COVERALLS_REPO_TOKEN + +cache: + directories: + - $HOME/.m2 From fce24f70aa5ec6af5c15f1e3917e5ca3d3e9c384 Mon Sep 17 00:00:00 2001 From: Gilles QUERRET Date: Wed, 6 Oct 2021 21:06:31 +0200 Subject: [PATCH 48/50] Compatibility of unit tests with Windows (#67) --- .../com/googlecode/scheme2ddl/MainIT.java | 65 +++++++++---------- .../scheme2ddl/UserObjectWriterTest.java | 3 +- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/test/java/com/googlecode/scheme2ddl/MainIT.java b/src/test/java/com/googlecode/scheme2ddl/MainIT.java index 3b72371..fbfc056 100644 --- a/src/test/java/com/googlecode/scheme2ddl/MainIT.java +++ b/src/test/java/com/googlecode/scheme2ddl/MainIT.java @@ -1,5 +1,13 @@ package com.googlecode.scheme2ddl; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.core.StringContains.containsString; +import static org.testng.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + import org.apache.commons.io.FileUtils; import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.testng.Assert; @@ -8,14 +16,6 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import java.io.File; -import java.io.IOException; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.core.StringContains.containsString; -import static org.testng.Assert.assertTrue; - /** * @author A_Reshetnikov * @since Date: 17.09.2016 @@ -56,7 +56,7 @@ public void testJustTestConnectionPositive(String urlParamName, String testConnP Main.main(args); Assert.assertEquals( outContent.toString(), - "OK success connection to jdbc:oracle:thin:" + url + "\n" + String.format("OK success connection to jdbc:oracle:thin:%1$s%n", url) ); } @@ -82,22 +82,21 @@ private static void assertHRSchemaDefault(String dirPath, String out) throws IOE assertThat(out, containsString("Start getting of user object list in schema HR for processing")); assertThat(out, containsString("WARNING: processing of 'PUBLIC DATABASE LINK' will be skipped because HR no access to view it")); assertThat(out, containsString("Found 34 items for processing in schema HR")); - assertThat(out, containsString(String.format("Saved sequence hr.locations_seq to file %s/sequences/locations_seq.sql", dirPath))); - assertThat(out, containsString(String.format("Saved sequence hr.employees_seq to file %s/sequences/employees_seq.sql", dirPath))); - assertThat(out, containsString(String.format("Saved trigger hr.update_job_history to file %s/triggers/update_job_history.sql", dirPath))); - assertThat(out, containsString(String.format("Saved procedure hr.add_job_history to file %s/procedures/add_job_history.sql", dirPath))); - assertThat(out, containsString(String.format("Saved table hr.locations to file %s/tables/locations.sql", dirPath))); - assertThat(out, containsString(String.format("Saved procedure hr.secure_dml to file %s/procedures/secure_dml.sql", dirPath))); - assertThat(out, containsString(String.format("Saved view hr.emp_details_view to file %s/views/emp_details_view.sql", dirPath))); - - - assertThat(out, containsString( - "-------------------------------------------------------\n" + - " R E P O R T S K I P P E D O B J E C T S \n" + - "-------------------------------------------------------\n" + - "| skip rule | object type | count |\n" + - "-------------------------------------------------------\n" + - "| config | INDEX | 19 |")); + assertThat(out, containsString(String.format("Saved sequence hr.locations_seq to file %1$s%2$1ssequences%2$1slocations_seq.sql", dirPath, File.separator))); + assertThat(out, containsString(String.format("Saved sequence hr.employees_seq to file %1$s%2$1ssequences%2$1semployees_seq.sql", dirPath, File.separator))); + assertThat(out, containsString(String.format("Saved trigger hr.update_job_history to file %1$s%2$1striggers%2$1supdate_job_history.sql", dirPath, File.separator))); + assertThat(out, containsString(String.format("Saved procedure hr.add_job_history to file %1$s%2$1sprocedures%2$1sadd_job_history.sql", dirPath, File.separator))); + assertThat(out, containsString(String.format("Saved table hr.locations to file %1$s%2$1stables%2$1slocations.sql", dirPath, File.separator))); + assertThat(out, containsString(String.format("Saved procedure hr.secure_dml to file %1$s%2$1sprocedures%2$1ssecure_dml.sql", dirPath, File.separator))); + assertThat(out, containsString(String.format("Saved view hr.emp_details_view to file %1$s%2$1sviews%2$1semp_details_view.sql", dirPath, File.separator))); + + assertThat(out, containsString(String.format( + "-------------------------------------------------------%n" + + " R E P O R T S K I P P E D O B J E C T S %n" + + "-------------------------------------------------------%n" + + "| skip rule | object type | count |%n" + + "-------------------------------------------------------%n" + + "| config | INDEX | 19 |"))); assertThat(out, containsString("Written 15 ddls with user objects from total 34 in schema HR")); @@ -275,15 +274,15 @@ public void testRunWithTestCustomConfig() throws Exception { " ORA-31603: object \"SYS_C004102\" of type CONSTRAINT not found in schema \"HR\"\n")); - assertThat(out, containsString( - "-------------------------------------------------------\n" + - " R E P O R T S K I P P E D O B J E C T S \n" + - "-------------------------------------------------------\n" + - "| skip rule | object type | count |\n" + - "-------------------------------------------------------\n" + - "| config | INDEX | 19 |\n" + + assertThat(out, containsString(String.format( + "-------------------------------------------------------%n" + + " R E P O R T S K I P P E D O B J E C T S %n" + + "-------------------------------------------------------%n" + + "| skip rule | object type | count |%n" + + "-------------------------------------------------------%n" + + "| config | INDEX | 19 |%n" + "| sql error | CONSTRAINT | 1 |" - )); + ))); } diff --git a/src/test/java/com/googlecode/scheme2ddl/UserObjectWriterTest.java b/src/test/java/com/googlecode/scheme2ddl/UserObjectWriterTest.java index 052ab48..b8df549 100644 --- a/src/test/java/com/googlecode/scheme2ddl/UserObjectWriterTest.java +++ b/src/test/java/com/googlecode/scheme2ddl/UserObjectWriterTest.java @@ -5,6 +5,7 @@ import org.testng.annotations.Test; import java.io.File; +import java.nio.charset.StandardCharsets; public class UserObjectWriterTest { @@ -27,7 +28,7 @@ public void testWriteUserObjectWithUtf8() throws Exception { String fileName = outputPath + "/" + userObject.getFileName(); File f = new File(fileName); f.deleteOnExit(); //to delete temp file after test over - Assertions.assertThat(f).hasContent(content); + Assertions.assertThat(f).usingCharset(StandardCharsets.UTF_8).hasContent(content); } } \ No newline at end of file From 44041ef857b445ea18a4f94fba67a78227b90202 Mon Sep 17 00:00:00 2001 From: Gilles QUERRET Date: Sat, 16 Oct 2021 18:22:56 +0200 Subject: [PATCH 49/50] AlternateNameConstructor (#69) * Alternate file name constructor * Encoding attribute --- .gitignore | 4 +- .settings/org.eclipse.jdt.core.prefs | 295 ++++++++++++++++++ .../AlternateFileNameConstructor.java | 136 ++++++++ .../scheme2ddl/FileNameConstructor.java | 99 +++--- .../scheme2ddl/IFileNameConstructor.java | 10 + .../java/com/googlecode/scheme2ddl/Main.java | 24 +- .../scheme2ddl/UserObjectProcessor.java | 4 +- .../scheme2ddl/UserObjectWriter.java | 9 +- src/main/resources/scheme2ddl.config.xml | 90 ++++-- .../scheme2ddl/FileNameConstructorTest.java | 12 +- 10 files changed, 583 insertions(+), 100 deletions(-) create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 src/main/java/com/googlecode/scheme2ddl/AlternateFileNameConstructor.java create mode 100644 src/main/java/com/googlecode/scheme2ddl/IFileNameConstructor.java diff --git a/.gitignore b/.gitignore index 222ee23..d80e483 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ - .idea +.classpath +.project +.settings/ target/ pom.xml.tag pom.xml.releaseBackup diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..d1dbfc3 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,295 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.methodParameters=generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=48 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=32 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=4 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=0 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=0 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=0 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=true +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true +org.eclipse.jdt.core.formatter.comment.format_source_code=false +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert +org.eclipse.jdt.core.formatter.comment.line_length=120 +org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true +org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true +org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true +org.eclipse.jdt.core.formatter.indentation.size=2 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.join_lines_in_comments=true +org.eclipse.jdt.core.formatter.join_wrapped_lines=true +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=120 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=false +org.eclipse.jdt.core.formatter.tabulation.char=space +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.use_on_off_tags=false +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true +org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter diff --git a/src/main/java/com/googlecode/scheme2ddl/AlternateFileNameConstructor.java b/src/main/java/com/googlecode/scheme2ddl/AlternateFileNameConstructor.java new file mode 100644 index 0000000..a91a530 --- /dev/null +++ b/src/main/java/com/googlecode/scheme2ddl/AlternateFileNameConstructor.java @@ -0,0 +1,136 @@ +package com.googlecode.scheme2ddl; + +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Resource; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; + +import com.googlecode.scheme2ddl.domain.UserObject; + +public class AlternateFileNameConstructor implements IFileNameConstructor, InitializingBean { + public static final String KW_SCHEMA_LOWER = "%s"; + public static final String KW_SCHEMA_UPPER = "%S"; + public static final String KW_TYPE_LOWER = "%a"; + public static final String KW_TYPE_UPPER = "%A"; + public static final String KW_TYPES_PLURAL_LOWER = "%t"; + public static final String KW_TYPES_PLURAL_UPPER = "%T"; + public static final String KW_OBJECTNAME_LOWER = "%o"; + public static final String KW_OBJECTNAME_UPPER = "%O"; + public static final String KW_EXTENSION_LOWER = "%e"; + public static final String KW_EXTENSION_UPPER = "%E"; + + public static final String TEMPLATEDEFAULT = "%t/%o.%e"; + + private String template; + private String templateForSysDBA = "%S/%t/%o.%e"; + private Map extensionMap; + private boolean combinePackage; + private boolean needToReplaceWindowsReservedFileNames = false; + + private boolean sysDbaTmpl = false; + + @Resource + private Map windowsReservedNamesReplacements; + + @Override + public void useSysDBATemplate() { + this.sysDbaTmpl = true; + } + + @Override + public String map2FileName(UserObject userObject) { + String filename = sysDbaTmpl ? templateForSysDBA : template; + + filename = filename.replace(KW_SCHEMA_LOWER, userObject.getSchema().toLowerCase()); + filename = filename.replace(KW_SCHEMA_UPPER, userObject.getSchema().toUpperCase()); + + String typeName = abbreviate(userObject.getType()).replace(" ", "_"); + String typeNameBackup = typeName; + if (combinePackage && typeName.equals("PACKAGE_BODY")) { + typeName = "PACKAGE"; + } + + filename = filename.replace(KW_TYPES_PLURAL_LOWER, pluralize(typeName).toLowerCase()); + filename = filename.replace(KW_TYPES_PLURAL_UPPER, pluralize(typeName).toUpperCase()); + filename = filename.replace(KW_TYPE_LOWER, typeName.toLowerCase()); + filename = filename.replace(KW_TYPE_UPPER, typeName.toUpperCase()); + + if (combinePackage) { + typeName = typeNameBackup; + } + + String userObjectName = userObject.getName(); + if (needToReplaceWindowsReservedFileNames && (windowsReservedNamesReplacements.get(userObjectName) != null)) { + userObjectName = windowsReservedNamesReplacements.get(userObjectName); + } + + filename = filename.replace(KW_OBJECTNAME_LOWER, userObjectName.toLowerCase()); + filename = filename.replace(KW_OBJECTNAME_UPPER, userObjectName.toUpperCase()); + + String extension = extensionMap.get(typeName.toUpperCase()); + if (extension == null) { + extension = extensionMap.get("DEFAULT"); + Assert.state(extension != null, + String.format("No file extension rule for type %s and no DEFAULT rule", typeName.toUpperCase())); + } + filename = filename.replace(KW_EXTENSION_LOWER, extension.toLowerCase()); + filename = filename.replace(KW_EXTENSION_UPPER, extension.toUpperCase()); + + return filename; + } + + @Override + public void afterPropertiesSet() { + if ((this.template == null) || this.template.isBlank()) { + this.template = TEMPLATEDEFAULT; + } + if (extensionMap == null) { + extensionMap = new HashMap<>(); + extensionMap.put("DEFAULT", "sql"); + } + if (windowsReservedNamesReplacements == null) { + needToReplaceWindowsReservedFileNames = false; + } + } + + public void setTemplate(String template) { + this.template = template; + } + + public void setTemplateForSysDBA(String templateForSysDBA) { + this.templateForSysDBA = templateForSysDBA; + } + + public void setExtensionMap(Map extensionMap) { + this.extensionMap = extensionMap; + } + + public void setCombinePackage(boolean combinePackage) { + this.combinePackage = combinePackage; + } + + public void setNeedToReplaceWindowsReservedFileNames(boolean needToReplaceWindowsReservedFileNames) { + this.needToReplaceWindowsReservedFileNames = needToReplaceWindowsReservedFileNames; + } + + private String abbreviate(String type) { + type = type.replace("DATABASE", "DB"); + type = type.replace("database", "db"); + return type; + } + + private String pluralize(String type) { + type = type.toLowerCase(); + if (type.endsWith("x") || type.endsWith("s")) { + return type + "es"; + } else if (type.endsWith("y")) { + return type.substring(0, type.length() - 1) + "ies"; + } else { + return type + "s"; + } + } + +} diff --git a/src/main/java/com/googlecode/scheme2ddl/FileNameConstructor.java b/src/main/java/com/googlecode/scheme2ddl/FileNameConstructor.java index b4cf369..3806bcd 100644 --- a/src/main/java/com/googlecode/scheme2ddl/FileNameConstructor.java +++ b/src/main/java/com/googlecode/scheme2ddl/FileNameConstructor.java @@ -1,42 +1,38 @@ package com.googlecode.scheme2ddl; -import com.googlecode.scheme2ddl.domain.UserObject; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Resource; + import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import org.springframework.util.Assert; -import javax.annotation.Resource; -import java.util.HashMap; -import java.util.Map; +import com.googlecode.scheme2ddl.domain.UserObject; /** * @author A_Reshetnikov * @since Date: 01.05.2013 */ -public class FileNameConstructor implements InitializingBean { - - private static final Log log = LogFactory.getLog(FileNameConstructor.class); - public static String kw_schema_lower = "schema"; - public static String kw_type_lower = "type"; - public static String kw_types_plural_lower = "types_plural"; - public static String kw_objectname_lower = "object_name"; - public static String kw_extension_lower = "ext"; - public static String kw_schema_UPPER = "SCHEMA"; - public static String kw_type_UPPER = "TYPE"; - public static String kw_types_plural_UPPER = "TYPES_PLURAL"; - public static String kw_objectname_UPPER = "OBJECT_NAME"; - public static String kw_extension_UPPER = "EXT"; - public static String nonOracleChar = "%"; //char not used in Oracle names - public static String templateDefault = "types_plural/object_name.ext"; +public class FileNameConstructor implements IFileNameConstructor, InitializingBean { + public static final String KW_SCHEMA_LOWER = "schema"; + public static final String KW_TYPE_LOWER = "type"; + public static final String KW_TYPES_PLURAL_LOWER = "types_plural"; + public static final String KW_OBJECTNAME_LOWER = "object_name"; + public static final String KW_EXTENSION_LOWER = "ext"; + public static final String KW_SCHEMA_UPPER = "SCHEMA"; + public static final String KW_TYPE_UPPER = "TYPE"; + public static final String KW_TYPES_PLURAL_UPPER = "TYPES_PLURAL"; + public static final String KW_OBJECTNAME_UPPER = "OBJECT_NAME"; + public static final String KW_EXTENSION_UPPER = "EXT"; + public static final String NONORACLECHAR = "%"; //char not used in Oracle names + public static final String TEMPLATEDEFAULT = "types_plural/object_name.ext"; + private String template; private String templateForSysDBA = "SCHEMA/types_plural/object_name.ext"; private String preparedTemplate; private Map extensionMap; - private boolean combinePackage; - + private boolean combinePackage; private boolean needToReplaceWindowsReservedFileNames = false; @@ -51,22 +47,28 @@ public class FileNameConstructor implements InitializingBean { * @return */ private static String prepareTemplate(String template) { - String[] keywords = new String[]{ - kw_schema_lower, kw_schema_UPPER, - kw_types_plural_lower, kw_types_plural_UPPER, - kw_objectname_lower, kw_objectname_UPPER, - kw_extension_lower, kw_extension_UPPER}; + var keywords = new String[]{ + KW_SCHEMA_LOWER, KW_SCHEMA_UPPER, + KW_TYPES_PLURAL_LOWER, KW_TYPES_PLURAL_UPPER, + KW_OBJECTNAME_LOWER, KW_OBJECTNAME_UPPER, + KW_EXTENSION_LOWER, KW_EXTENSION_UPPER}; for (int i = 0; i < keywords.length; i++) { - template = template.replace(keywords[i], nonOracleChar + keywords[i]); + template = template.replace(keywords[i], NONORACLECHAR + keywords[i]); } // keyword kw_type_lower is substring of kw_types_plural_lower so we need additional preparing - String typesPluralTail = kw_types_plural_lower.replace(kw_type_lower, ""); - template = template.replaceAll(kw_type_lower + "(?!" + typesPluralTail + ")", nonOracleChar + kw_type_lower); - typesPluralTail = kw_types_plural_UPPER.replace(kw_type_UPPER, ""); - template = template.replaceAll(kw_type_UPPER + "(?!S_PLURAL)", nonOracleChar + kw_type_UPPER); + String typesPluralTail = KW_TYPES_PLURAL_LOWER.replace(KW_TYPE_LOWER, ""); + template = template.replaceAll(KW_TYPE_LOWER + "(?!" + typesPluralTail + ")", NONORACLECHAR + KW_TYPE_LOWER); + typesPluralTail = KW_TYPES_PLURAL_UPPER.replace(KW_TYPE_UPPER, ""); + template = template.replaceAll(KW_TYPE_UPPER + "(?!S_PLURAL)", NONORACLECHAR + KW_TYPE_UPPER); return template; } + @Override + public void useSysDBATemplate() { + template = templateForSysDBA; + afterPropertiesSet(); + } + public static String abbreviate(String type) { type = type.replace("DATABASE", "DB"); type = type.replace("database", "db"); @@ -87,8 +89,8 @@ public static String pluralaze(String type) { public String map2FileName(UserObject userObject) { String filename = preparedTemplate; - filename = filename.replace(nonOracleChar + kw_schema_lower, userObject.getSchema().toLowerCase()); - filename = filename.replace(nonOracleChar + kw_schema_UPPER, userObject.getSchema().toUpperCase()); + filename = filename.replace(NONORACLECHAR + KW_SCHEMA_LOWER, userObject.getSchema().toLowerCase()); + filename = filename.replace(NONORACLECHAR + KW_SCHEMA_UPPER, userObject.getSchema().toUpperCase()); String typeName = abbreviate(userObject.getType()).replace(" ", "_"); @@ -98,11 +100,11 @@ public String map2FileName(UserObject userObject) { } //process kw_types_plural before kw_type - filename = filename.replace(nonOracleChar + kw_types_plural_lower, pluralaze(typeName).toLowerCase()); - filename = filename.replace(nonOracleChar + kw_types_plural_UPPER, pluralaze(typeName).toUpperCase()); + filename = filename.replace(NONORACLECHAR + KW_TYPES_PLURAL_LOWER, pluralaze(typeName).toLowerCase()); + filename = filename.replace(NONORACLECHAR + KW_TYPES_PLURAL_UPPER, pluralaze(typeName).toUpperCase()); - filename = filename.replace(nonOracleChar + kw_type_lower, typeName.toLowerCase()); - filename = filename.replace(nonOracleChar + kw_type_UPPER, typeName.toUpperCase()); + filename = filename.replace(NONORACLECHAR + KW_TYPE_LOWER, typeName.toLowerCase()); + filename = filename.replace(NONORACLECHAR + KW_TYPE_UPPER, typeName.toUpperCase()); if (combinePackage) { typeName = typeName_backup; @@ -116,16 +118,16 @@ public String map2FileName(UserObject userObject) { } } - filename = filename.replace(nonOracleChar + kw_objectname_lower, userObjectName.toLowerCase()); - filename = filename.replace(nonOracleChar + kw_objectname_UPPER, userObjectName.toUpperCase()); + filename = filename.replace(NONORACLECHAR + KW_OBJECTNAME_LOWER, userObjectName.toLowerCase()); + filename = filename.replace(NONORACLECHAR + KW_OBJECTNAME_UPPER, userObjectName.toUpperCase()); String extension = extensionMap.get(typeName.toUpperCase()); if (extension == null) { extension = extensionMap.get("DEFAULT"); Assert.state(extension != null, String.format("No file extension rule for type %s and no DEFAULT rule", typeName.toUpperCase())); } - filename = filename.replace(nonOracleChar + kw_extension_lower, extension.toLowerCase()); - filename = filename.replace(nonOracleChar + kw_extension_UPPER, extension.toUpperCase()); + filename = filename.replace(NONORACLECHAR + KW_EXTENSION_LOWER, extension.toLowerCase()); + filename = filename.replace(NONORACLECHAR + KW_EXTENSION_UPPER, extension.toUpperCase()); return filename; } @@ -144,13 +146,10 @@ public void setTemplateForSysDBA(String templateForSysDBA) { //for compability with old configs public void afterPropertiesSet() { - String s; - if (this.template == null) s = templateDefault; - else s = template; - preparedTemplate = prepareTemplate(s); + preparedTemplate = prepareTemplate(this.template == null ? TEMPLATEDEFAULT : template); if (extensionMap == null) { - extensionMap = new HashMap(); + extensionMap = new HashMap<>(); extensionMap.put("DEFAULT", "sql"); } diff --git a/src/main/java/com/googlecode/scheme2ddl/IFileNameConstructor.java b/src/main/java/com/googlecode/scheme2ddl/IFileNameConstructor.java new file mode 100644 index 0000000..01312ec --- /dev/null +++ b/src/main/java/com/googlecode/scheme2ddl/IFileNameConstructor.java @@ -0,0 +1,10 @@ +package com.googlecode.scheme2ddl; + +import com.googlecode.scheme2ddl.domain.UserObject; + +public interface IFileNameConstructor { + /** Switch to SYSDBA naming scheme */ + void useSysDBATemplate(); + /** Returns filename based on UserObject */ + String map2FileName(UserObject userObject); +} diff --git a/src/main/java/com/googlecode/scheme2ddl/Main.java b/src/main/java/com/googlecode/scheme2ddl/Main.java index 1cf89e6..05c133d 100644 --- a/src/main/java/com/googlecode/scheme2ddl/Main.java +++ b/src/main/java/com/googlecode/scheme2ddl/Main.java @@ -6,6 +6,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -39,9 +40,9 @@ public class Main { private static String schemas; private static boolean isLaunchedByDBA; private static List schemaList; - private static String objectFilter = "%"; - private static String typeFilter = ""; - private static String typeFilterMode = "include"; + private static String objectFilter = "%"; + private static String typeFilter = ""; + private static String typeFilterMode = "include"; public static void main(String[] args) throws Exception { typeFilterMode = "include"; //default is to include any type filter @@ -111,10 +112,9 @@ private static void modifyContext(ConfigurableApplicationContext context) { //process schemas processSchemas(context); - FileNameConstructor fileNameConstructor = retrieveFileNameConstructor(context); //will create new one if not exist + IFileNameConstructor fileNameConstructor = retrieveFileNameConstructor(context); //will create new one if not exist if (isLaunchedByDBA) { - fileNameConstructor.setTemplate(fileNameConstructor.getTemplateForSysDBA()); - fileNameConstructor.afterPropertiesSet(); + fileNameConstructor.useSysDBATemplate(); } if (stopOnWarning){ @@ -191,16 +191,14 @@ private static List retrieveSchemaListFromContext(ConfigurableApplicatio * @param context * @return existing bean 'fileNameConstructor', if this exists, or create and register new bean */ - private static FileNameConstructor retrieveFileNameConstructor(ConfigurableApplicationContext context) { - FileNameConstructor fileNameConstructor; + private static IFileNameConstructor retrieveFileNameConstructor(ConfigurableApplicationContext context) { + IFileNameConstructor fileNameConstructor; try { - fileNameConstructor = (FileNameConstructor) context.getBean("fileNameConstructor"); + fileNameConstructor = (IFileNameConstructor) context.getBean("fileNameConstructor"); } catch (NoSuchBeanDefinitionException e) { - DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) context.getBeanFactory(); + BeanDefinitionRegistry beanFactory = (BeanDefinitionRegistry) context.getBeanFactory(); beanFactory.registerBeanDefinition("fileNameConstructor", BeanDefinitionBuilder.rootBeanDefinition(FileNameConstructor.class).getBeanDefinition()); - fileNameConstructor = (FileNameConstructor) context.getBean("fileNameConstructor"); - fileNameConstructor.afterPropertiesSet(); - //for compatability with old config without fileNameConstructor bean + fileNameConstructor = (IFileNameConstructor) context.getBean("fileNameConstructor"); UserObjectProcessor userObjectProcessor = (UserObjectProcessor) context.getBean("processor"); userObjectProcessor.setFileNameConstructor(fileNameConstructor); } diff --git a/src/main/java/com/googlecode/scheme2ddl/UserObjectProcessor.java b/src/main/java/com/googlecode/scheme2ddl/UserObjectProcessor.java index 09d7c68..418b346 100644 --- a/src/main/java/com/googlecode/scheme2ddl/UserObjectProcessor.java +++ b/src/main/java/com/googlecode/scheme2ddl/UserObjectProcessor.java @@ -22,7 +22,7 @@ public class UserObjectProcessor implements ItemProcessor> excludes; private Map> dependencies; private boolean stopOnWarning; @@ -116,7 +116,7 @@ public void setDdlFormatter(DDLFormatter ddlFormatter) { this.ddlFormatter = ddlFormatter; } - public void setFileNameConstructor(FileNameConstructor fileNameConstructor) { + public void setFileNameConstructor(IFileNameConstructor fileNameConstructor) { this.fileNameConstructor = fileNameConstructor; } diff --git a/src/main/java/com/googlecode/scheme2ddl/UserObjectWriter.java b/src/main/java/com/googlecode/scheme2ddl/UserObjectWriter.java index 2ec5231..c95907c 100644 --- a/src/main/java/com/googlecode/scheme2ddl/UserObjectWriter.java +++ b/src/main/java/com/googlecode/scheme2ddl/UserObjectWriter.java @@ -9,7 +9,7 @@ import org.springframework.batch.item.ItemWriter; import java.io.File; -import java.nio.charset.StandardCharsets; +import java.nio.charset.Charset; import java.util.List; /** @@ -20,7 +20,7 @@ public class UserObjectWriter implements ItemWriter { private static final Log log = LogFactory.getLog(UserObjectWriter.class); private String outputPath; - + private String encoding = "utf-8"; public void write(List data) throws Exception { if (data.size() > 0) { @@ -32,7 +32,7 @@ public void writeUserObject(UserObject userObject) throws Exception { String absoluteFileName = outputPath + "/" + userObject.getFileName(); absoluteFileName = FilenameUtils.separatorsToSystem(absoluteFileName); File file = new File(absoluteFileName); - FileUtils.writeStringToFile(file, userObject.getDdl(), StandardCharsets.UTF_8); + FileUtils.writeStringToFile(file, userObject.getDdl(), Charset.forName(encoding)); log.info(String.format("Saved %s %s.%s to file %s", userObject.getType().toLowerCase(), userObject.getSchema().toLowerCase(), @@ -40,6 +40,9 @@ public void writeUserObject(UserObject userObject) throws Exception { file.getAbsolutePath())); } + public void setEncoding(String encoding) { + this.encoding = encoding; + } public void setOutputPath(String outputPath) { this.outputPath = outputPath; diff --git a/src/main/resources/scheme2ddl.config.xml b/src/main/resources/scheme2ddl.config.xml index ba261b6..b1b4689 100644 --- a/src/main/resources/scheme2ddl.config.xml +++ b/src/main/resources/scheme2ddl.config.xml @@ -31,6 +31,7 @@ + @@ -55,35 +56,48 @@ - - - + + + + + + + + + + + + + + + - - - + + --> @@ -91,6 +105,32 @@ + + + + .sql + + + .prc + + + .fnc + + + .trg + + + .vw + + + .pks + + + -body.pkb + + + + diff --git a/src/test/java/com/googlecode/scheme2ddl/FileNameConstructorTest.java b/src/test/java/com/googlecode/scheme2ddl/FileNameConstructorTest.java index d01e0a2..7106a18 100644 --- a/src/test/java/com/googlecode/scheme2ddl/FileNameConstructorTest.java +++ b/src/test/java/com/googlecode/scheme2ddl/FileNameConstructorTest.java @@ -86,7 +86,7 @@ public void testDefaultTemplate() throws Exception { @Test public void testKeywordSchema() throws Exception { - String template = FileNameConstructor.kw_schema_lower + "/" + FileNameConstructor.kw_schema_UPPER; + String template = FileNameConstructor.KW_SCHEMA_LOWER + "/" + FileNameConstructor.KW_SCHEMA_UPPER; fileNameConstructor.setTemplate(template); fileNameConstructor.afterPropertiesSet(); for (UserObject userObject : list) { @@ -97,7 +97,7 @@ public void testKeywordSchema() throws Exception { @Test public void testKeywordObjectName() throws Exception { - String template = FileNameConstructor.kw_objectname_lower + "/" + FileNameConstructor.kw_objectname_UPPER; + String template = FileNameConstructor.KW_OBJECTNAME_LOWER + "/" + FileNameConstructor.KW_OBJECTNAME_UPPER; fileNameConstructor.setTemplate(template); fileNameConstructor.afterPropertiesSet(); for (UserObject userObject : list) { @@ -108,7 +108,7 @@ public void testKeywordObjectName() throws Exception { @Test public void testKeywordExtension() throws Exception { - String template = FileNameConstructor.kw_extension_lower + "/" + FileNameConstructor.kw_extension_UPPER; + String template = FileNameConstructor.KW_EXTENSION_LOWER + "/" + FileNameConstructor.KW_EXTENSION_UPPER; fileNameConstructor.setTemplate(template); fileNameConstructor.afterPropertiesSet(); for (UserObject userObject : list) { @@ -119,9 +119,9 @@ public void testKeywordExtension() throws Exception { @Test public void testTemplateWithTypeMix() throws Exception { - String template = FileNameConstructor.kw_type_lower + "/" + FileNameConstructor.kw_type_lower + - FileNameConstructor.kw_type_UPPER + "/" + FileNameConstructor.kw_types_plural_lower + "//" + - FileNameConstructor.kw_types_plural_UPPER + "/" + FileNameConstructor.kw_types_plural_UPPER + ".TyPEs_PLURAL"; + String template = FileNameConstructor.KW_TYPE_LOWER + "/" + FileNameConstructor.KW_TYPE_LOWER + + FileNameConstructor.KW_TYPE_UPPER + "/" + FileNameConstructor.KW_TYPES_PLURAL_LOWER + "//" + + FileNameConstructor.KW_TYPES_PLURAL_UPPER + "/" + FileNameConstructor.KW_TYPES_PLURAL_UPPER + ".TyPEs_PLURAL"; fileNameConstructor.setTemplate(template); fileNameConstructor.afterPropertiesSet(); for (UserObject userObject : list) { From 6d7cca4642ae106eec6a08ed5f9597d03526ac0f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:24:36 +0300 Subject: [PATCH 50/50] Bump commons-io:commons-io from 2.7 to 2.14.0 (#70) Bumps commons-io:commons-io from 2.7 to 2.14.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3e8695e..73fe7cf 100644 --- a/pom.xml +++ b/pom.xml @@ -151,7 +151,7 @@ commons-io commons-io - 2.7 + 2.14.0 javax.annotation