2222import org .kohsuke .args4j .CmdLineException ;
2323import org .pgcodekeeper .cli .localizations .Messages ;
2424import org .pgcodekeeper .core .DangerStatement ;
25- import org .pgcodekeeper .core .PgCodekeeperException ;
26- import org .pgcodekeeper .core .database . base . jdbc . IJdbcConnector ;
27- import org .pgcodekeeper .core .loader .JdbcRunner ;
28- import org .pgcodekeeper .core .model . graph . DepcyFinder ;
29- import org .pgcodekeeper .core .model . graph . InsertWriter ;
30- import org .pgcodekeeper .core .parsers . antlr . base . ScriptParser ;
31- import org .pgcodekeeper .core .schema . AbstractDatabase ;
25+ import org .pgcodekeeper .core .api . ApiRegistry ;
26+ import org .pgcodekeeper .core .api . PgCodeKeeperApi ;
27+ import org .pgcodekeeper .core .database . api . loader .ILoader ;
28+ import org .pgcodekeeper .core .database . ch . ChDatabaseProvider ;
29+ import org .pgcodekeeper .core .database . ms . MsDatabaseProvider ;
30+ import org .pgcodekeeper .core .database . pg . PgDatabaseProvider ;
31+ import org .pgcodekeeper .core .settings . DiffSettings ;
3232import org .pgcodekeeper .core .utils .FileUtils ;
3333import org .pgcodekeeper .core .utils .UnixPrintWriter ;
3434import org .slf4j .Logger ;
4141import java .nio .file .Path ;
4242import java .sql .SQLException ;
4343import java .util .List ;
44+ import java .util .Set ;
4445import java .util .function .Consumer ;
4546import java .util .stream .Collectors ;
4647
@@ -65,6 +66,10 @@ public static void main(String[] args) {
6566 * @return success value
6667 */
6768 static boolean process (String [] args ) {
69+ ApiRegistry .register (new PgDatabaseProvider ());
70+ ApiRegistry .register (new MsDatabaseProvider ());
71+ ApiRegistry .register (new ChDatabaseProvider ());
72+
6873 CliArgs arguments = new CliArgs ();
6974 try {
7075 if (!arguments .parse (args )) {
@@ -104,20 +109,20 @@ static boolean process(String[] args) {
104109 private static boolean diff (CliArgs arguments )
105110 throws InterruptedException , IOException , SQLException {
106111 try (PrintWriter encodedWriter = getDiffWriter (arguments )) {
107- var diff = new PgDiffCli (arguments );
112+ var diffSettings = new DiffSettings (arguments );
113+ var diff = new PgDiffCli (arguments , diffSettings );
108114 String text ;
109115 try {
110116 LOG .info (Messages .Main_log_create_script );
111117 text = diff .createDiff ();
112- } catch (PgCodekeeperException ex ) {
118+ } catch (IllegalStateException ex ) {
113119 printError (diff );
114120 return false ;
115121 }
116122
117- ScriptParser parser = new ScriptParser ("CLI" , text , arguments ); //$NON-NLS-1$
118-
119123 if (arguments .isSafeMode ()) {
120- var dangerTypes = parser .getDangerDdl (arguments .getAllowedDangers ());
124+ Set <DangerStatement > dangerTypes = PgCodeKeeperApi .checkDangerousStatements (
125+ arguments .getProvider (), "CLI" , text , diffSettings , arguments .getAllowedDangers ());
121126
122127 if (!dangerTypes .isEmpty ()) {
123128 String dangerStmt = dangerTypes .stream ().map (DangerStatement ::name )
@@ -144,7 +149,7 @@ private static boolean diff(CliArgs arguments)
144149 }
145150
146151 LOG .info (Messages .Main_log_apply_migration_script );
147- new JdbcRunner (). runBatches ( getConnector ( arguments , url ), parser . batch (), null );
152+ PgCodeKeeperApi . runSQL ( arguments . getProvider (), "CLI" , text , url , diffSettings );
148153 } else if (encodedWriter == null ) {
149154 writeToConsole (text );
150155 }
@@ -160,8 +165,8 @@ private static PrintWriter getDiffWriter(CliArgs arguments)
160165 return outFile == null ? null : new UnixPrintWriter (outFile , arguments .getOutCharsetName ());
161166 }
162167
163- private static boolean parse (CliArgs arguments ) throws IOException , InterruptedException , PgCodekeeperException {
164- PgDiffCli diff = new PgDiffCli (arguments );
168+ private static boolean parse (CliArgs arguments ) throws IOException , InterruptedException {
169+ PgDiffCli diff = new PgDiffCli (arguments , new DiffSettings ( arguments ) );
165170 try {
166171 if (arguments .isProjUpdate ()) {
167172 LOG .info (Messages .Main_log_start_update_proj );
@@ -170,7 +175,7 @@ private static boolean parse(CliArgs arguments) throws IOException, InterruptedE
170175 LOG .info (Messages .Main_log_start_export_proj );
171176 diff .exportProject ();
172177 }
173- } catch (PgCodekeeperException ex ) {
178+ } catch (IllegalStateException ex ) {
174179 diff .getErrors ().forEach (Application ::writeError );
175180 return false ;
176181 }
@@ -179,22 +184,20 @@ private static boolean parse(CliArgs arguments) throws IOException, InterruptedE
179184 return true ;
180185 }
181186
182- private static IJdbcConnector getConnector (CliArgs arguments , String url ) {
183- return arguments .getProvider ().getJdbcConnector (url );
184- }
185-
186187 private static boolean graph (CliArgs arguments ) throws IOException , InterruptedException {
187- var diff = new PgDiffCli (arguments );
188- AbstractDatabase d ;
188+ var diff = new PgDiffCli (arguments , new DiffSettings ( arguments ) );
189+ ILoader dbLoader ;
189190 try {
190- d = diff .loadNewDatabaseWithLibraries ();
191- } catch (PgCodekeeperException ex ) {
191+ dbLoader = diff .getDatabaseLoader (arguments .getNewSrc (),
192+ arguments .getTargetLibXmls (), arguments .getTargetLibs (), arguments .getTargetLibsWithoutPriv ());
193+ } catch (IllegalStateException ex ) {
192194 printError (diff );
193195 return false ;
194196 }
195197 LOG .info (Messages .Main_log_build_graph_deps );
196- List <String > dependencies = DepcyFinder .byPatterns (arguments .getGraphDepth (), arguments .isGraphReverse (),
197- arguments .getGraphFilterTypes (), arguments .isGraphInvertFilter (), d , arguments .getGraphNames ());
198+ List <String > dependencies = PgCodeKeeperApi .analyzeDependencies (dbLoader , arguments .getGraphNames (),
199+ arguments .getGraphDepth (), arguments .isGraphReverse (),
200+ arguments .getGraphFilterTypes (), arguments .isGraphInvertFilter ());
198201
199202 try (PrintWriter pw = getDiffWriter (arguments )) {
200203 Consumer <String > consumer = pw != null ? pw ::println : Application ::writeToConsole ;
0 commit comments