1919import org .pgcodekeeper .cli .localizations .Messages ;
2020import org .pgcodekeeper .core .PgCodekeeperException ;
2121import org .pgcodekeeper .core .PgDiff ;
22- import org .pgcodekeeper .core .ignoreparser .IgnoreParser ;
23- import org .pgcodekeeper .core .loader .*;
24- import org .pgcodekeeper .core .model .difftree .DiffTree ;
25- import org .pgcodekeeper .core .model .difftree .IgnoreList ;
26- import org .pgcodekeeper .core .model .difftree .IgnoreSchemaList ;
27- import org .pgcodekeeper .core .model .difftree .TreeElement ;
28- import org .pgcodekeeper .core .model .exporter .ModelExporter ;
22+ import org .pgcodekeeper .core .api .DatabaseFactory ;
23+ import org .pgcodekeeper .core .api .PgCodeKeeperApi ;
24+ import org .pgcodekeeper .core .loader .FullAnalyze ;
25+ import org .pgcodekeeper .core .loader .LibraryLoader ;
26+ import org .pgcodekeeper .core .loader .ProjectLoader ;
2927import org .pgcodekeeper .core .schema .AbstractDatabase ;
3028import org .pgcodekeeper .core .schema .PgOverride ;
31- import org .pgcodekeeper .core .utils .ProjectUpdater ;
3229import org .pgcodekeeper .core .xmlstore .DependenciesXmlStore ;
3330
3431import java .io .IOException ;
3532import java .nio .file .Paths ;
3633import java .util .Collection ;
3734import java .util .List ;
3835
39-
4036public final class PgDiffCli extends PgDiff {
4137
42-
4338 private final CliArgs arguments ;
4439
4540 public PgDiffCli (CliArgs arguments ) {
@@ -49,51 +44,22 @@ public PgDiffCli(CliArgs arguments) {
4944
5045 public void updateProject ()
5146 throws IOException , InterruptedException , PgCodekeeperException {
52-
5347 AbstractDatabase oldDatabase = loadOldDatabaseWithLibraries ();
5448 AbstractDatabase newDatabase = loadNewDatabaseWithLibraries ();
55- IgnoreList ignoreList = getIgnoreList ();
56- TreeElement root = DiffTree .create (oldDatabase , newDatabase , null );
57- root .setAllChecked ();
5849
59- List <TreeElement > selected = getSelectedElements (root , ignoreList );
60-
61- new ProjectUpdater (newDatabase , oldDatabase , selected , arguments .getDbType (),
62- arguments .getOutCharsetName (), Paths .get (arguments .getOutputTarget ()),
63- false , settings ).updatePartial ();
50+ PgCodeKeeperApi .update (settings , oldDatabase , newDatabase ,
51+ arguments .getOutputTarget (), arguments .getIgnoreLists (), null );
6452 }
6553
6654 public void exportProject () throws IOException , InterruptedException , PgCodekeeperException {
6755 AbstractDatabase newDb = loadNewDatabase ();
68- TreeElement root = DiffTree .create (newDb , null , null );
69- root .setAllChecked ();
70-
71- IgnoreList ignoreList = getIgnoreList ();
72- List <TreeElement > selected = getSelectedElements (root , ignoreList );
73- new ModelExporter (Paths .get (arguments .getOutputTarget ()), newDb , null ,
74- arguments .getDbType (), selected , arguments .getOutCharsetName (), settings ).exportProject ();
75- }
76-
77- private IgnoreList getIgnoreList () throws IOException {
78- IgnoreList ignoreList = new IgnoreList ();
79- IgnoreParser ignoreParser = new IgnoreParser (ignoreList );
80- for (String listFilename : arguments .getIgnoreLists ()) {
81- ignoreParser .parse (Paths .get (listFilename ));
82- }
83- return ignoreList ;
56+ PgCodeKeeperApi .export (settings , newDb , arguments .getOutputTarget (), arguments .getIgnoreLists (), null );
8457 }
8558
8659 public String createDiff () throws InterruptedException , IOException , PgCodekeeperException {
8760 AbstractDatabase oldDatabase = loadOldDatabaseWithLibraries ();
8861 AbstractDatabase newDatabase = loadNewDatabaseWithLibraries ();
89- IgnoreList ignoreList = new IgnoreList ();
90- IgnoreParser ignoreParser = new IgnoreParser (ignoreList );
91-
92- for (String listFilename : arguments .getIgnoreLists ()) {
93- ignoreParser .parse (Paths .get (listFilename ));
94- }
95-
96- return diff (oldDatabase , newDatabase , ignoreList );
62+ return PgCodeKeeperApi .diff (settings , oldDatabase , newDatabase , arguments .getIgnoreLists ());
9763 }
9864
9965 public AbstractDatabase loadNewDatabaseWithLibraries ()
@@ -176,16 +142,12 @@ private void loadLibraries(AbstractDatabase db, Collection<String> libXmls, Coll
176142
177143 private AbstractDatabase loadNewDatabase ()
178144 throws IOException , InterruptedException , PgCodekeeperException {
179- AbstractDatabase db = loadDatabaseSchema (arguments .getNewSrcFormat (), arguments .getNewSrc ());
180- assertErrors ();
181- return db ;
145+ return loadDatabaseSchema (arguments .getNewSrcFormat (), arguments .getNewSrc ());
182146 }
183147
184148 private AbstractDatabase loadOldDatabase ()
185149 throws IOException , InterruptedException , PgCodekeeperException {
186- AbstractDatabase db = loadDatabaseSchema (arguments .getOldSrcFormat (), arguments .getOldSrc ());
187- assertErrors ();
188- return db ;
150+ return loadDatabaseSchema (arguments .getOldSrcFormat (), arguments .getOldSrc ());
189151 }
190152
191153 /**
@@ -198,24 +160,13 @@ private AbstractDatabase loadOldDatabase()
198160 * @return the loaded database
199161 */
200162 private AbstractDatabase loadDatabaseSchema (SourceFormat format , String srcPath )
201- throws InterruptedException , IOException {
202- LOG .info (Messages .PgDiffCli_log_load_ignored_schemas );
203- IgnoreSchemaList ignoreSchemaList = new IgnoreSchemaList ();
204- IgnoreParser ignoreParser = new IgnoreParser (ignoreSchemaList );
205- if (arguments .getIgnoreSchemaList () != null ) {
206- ignoreParser .parse (Paths .get (arguments .getIgnoreSchemaList ()));
207- }
208- DatabaseLoader loader = switch (format ) {
209- case DB -> LoaderFactory .createJdbcLoader (settings , srcPath , ignoreSchemaList );
210- case DUMP -> new PgDumpLoader (Paths .get (srcPath ), settings );
211- case PARSED -> new ProjectLoader (srcPath , settings , null , errors , ignoreSchemaList );
163+ throws InterruptedException , IOException , PgCodekeeperException {
164+ var factory = new DatabaseFactory (settings , arguments .isIgnoreErrors (), false );
165+ return switch (format ) {
166+ case DB -> factory .loadFromJdbc (srcPath , arguments .getIgnoreSchemaList ());
167+ case DUMP -> factory .loadFromDump (srcPath );
168+ case PARSED -> factory .loadFromProject (srcPath , arguments .getIgnoreSchemaList ());
212169 };
213-
214- try {
215- return loader .load ();
216- } finally {
217- errors .addAll (loader .getErrors ());
218- }
219170 }
220171
221172 private void assertErrors () throws PgCodekeeperException {
0 commit comments