1919import org .pgcodekeeper .cli .localizations .Messages ;
2020import org .pgcodekeeper .core .PgCodekeeperException ;
2121import org .pgcodekeeper .core .PgDiff ;
22+ import org .pgcodekeeper .core .api .DatabaseFactory ;
23+ import org .pgcodekeeper .core .api .PgCodeKeeperApi ;
2224import 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 ;
25+ import org .pgcodekeeper .core .loader .FullAnalyze ;
26+ import org .pgcodekeeper .core .loader . LibraryLoader ;
27+ import org .pgcodekeeper .core .loader . ProjectLoader ;
2628import org .pgcodekeeper .core .model .difftree .IgnoreSchemaList ;
27- import org .pgcodekeeper .core .model .difftree .TreeElement ;
28- import org .pgcodekeeper .core .model .exporter .ModelExporter ;
2929import org .pgcodekeeper .core .schema .AbstractDatabase ;
3030import org .pgcodekeeper .core .schema .PgOverride ;
31- import org .pgcodekeeper .core .utils .ProjectUpdater ;
3231import org .pgcodekeeper .core .xmlstore .DependenciesXmlStore ;
3332
3433import java .io .IOException ;
3534import java .nio .file .Paths ;
3635import java .util .Collection ;
3736import java .util .List ;
3837
39-
4038public final class PgDiffCli extends PgDiff {
4139
42-
4340 private final CliArgs arguments ;
4441
4542 public PgDiffCli (CliArgs arguments ) {
@@ -49,51 +46,22 @@ public PgDiffCli(CliArgs arguments) {
4946
5047 public void updateProject ()
5148 throws IOException , InterruptedException , PgCodekeeperException {
52-
5349 AbstractDatabase oldDatabase = loadOldDatabaseWithLibraries ();
5450 AbstractDatabase newDatabase = loadNewDatabaseWithLibraries ();
55- IgnoreList ignoreList = getIgnoreList ();
56- TreeElement root = DiffTree .create (oldDatabase , newDatabase , null );
57- root .setAllChecked ();
5851
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 ();
52+ PgCodeKeeperApi .update (settings , oldDatabase , newDatabase ,
53+ arguments .getOutputTarget (), arguments .getIgnoreLists (), null );
6454 }
6555
6656 public void exportProject () throws IOException , InterruptedException , PgCodekeeperException {
6757 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 ;
58+ PgCodeKeeperApi .export (settings , newDb , arguments .getOutputTarget (), arguments .getIgnoreLists (), null );
8459 }
8560
8661 public String createDiff () throws InterruptedException , IOException , PgCodekeeperException {
8762 AbstractDatabase oldDatabase = loadOldDatabaseWithLibraries ();
8863 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 );
64+ return PgCodeKeeperApi .diff (settings , oldDatabase , newDatabase , arguments .getIgnoreLists ());
9765 }
9866
9967 public AbstractDatabase loadNewDatabaseWithLibraries ()
@@ -176,16 +144,12 @@ private void loadLibraries(AbstractDatabase db, Collection<String> libXmls, Coll
176144
177145 private AbstractDatabase loadNewDatabase ()
178146 throws IOException , InterruptedException , PgCodekeeperException {
179- AbstractDatabase db = loadDatabaseSchema (arguments .getNewSrcFormat (), arguments .getNewSrc ());
180- assertErrors ();
181- return db ;
147+ return loadDatabaseSchema (arguments .getNewSrcFormat (), arguments .getNewSrc ());
182148 }
183149
184150 private AbstractDatabase loadOldDatabase ()
185151 throws IOException , InterruptedException , PgCodekeeperException {
186- AbstractDatabase db = loadDatabaseSchema (arguments .getOldSrcFormat (), arguments .getOldSrc ());
187- assertErrors ();
188- return db ;
152+ return loadDatabaseSchema (arguments .getOldSrcFormat (), arguments .getOldSrc ());
189153 }
190154
191155 /**
@@ -198,24 +162,20 @@ private AbstractDatabase loadOldDatabase()
198162 * @return the loaded database
199163 */
200164 private AbstractDatabase loadDatabaseSchema (SourceFormat format , String srcPath )
201- throws InterruptedException , IOException {
165+ throws InterruptedException , IOException , PgCodekeeperException {
202166 LOG .info (Messages .PgDiffCli_log_load_ignored_schemas );
203167 IgnoreSchemaList ignoreSchemaList = new IgnoreSchemaList ();
204168 IgnoreParser ignoreParser = new IgnoreParser (ignoreSchemaList );
205169 if (arguments .getIgnoreSchemaList () != null ) {
206170 ignoreParser .parse (Paths .get (arguments .getIgnoreSchemaList ()));
207171 }
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 );
212- };
172+ var factory = new DatabaseFactory (settings , arguments .isIgnoreErrors (), false );
213173
214- try {
215- return loader . load ( );
216- } finally {
217- errors . addAll ( loader . getErrors ());
218- }
174+ return switch ( format ) {
175+ case DB -> factory . loadFromJdbc ( srcPath , arguments . getIgnoreSchemaList () );
176+ case DUMP -> factory . loadFromDump ( srcPath );
177+ case PARSED -> factory . loadFromProject ( srcPath , arguments . getIgnoreSchemaList ());
178+ };
219179 }
220180
221181 private void assertErrors () throws PgCodekeeperException {
0 commit comments