Skip to content

Commit 10ea71b

Browse files
committed
Merge branch 'DBTOOLS-1632-loader-javadocs' into 'master'
DBTOOLS-1632 added loader javadocs See merge request codekeeper/pgcodekeeper-core!35
2 parents 457cbcb + 5151cb4 commit 10ea71b

23 files changed

+808
-322
lines changed

src/main/java/org/pgcodekeeper/core/loader/AbstractJdbcConnector.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@
1515
*******************************************************************************/
1616
package org.pgcodekeeper.core.loader;
1717

18+
import org.pgcodekeeper.core.DatabaseType;
19+
import org.pgcodekeeper.core.Utils;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
1823
import java.io.IOException;
1924
import java.sql.Connection;
2025
import java.sql.DriverManager;
2126
import java.sql.SQLException;
2227
import java.util.Properties;
2328

24-
import org.pgcodekeeper.core.DatabaseType;
25-
import org.pgcodekeeper.core.Utils;
26-
import org.pgcodekeeper.core.localizations.Messages;
27-
import org.slf4j.Logger;
28-
import org.slf4j.LoggerFactory;
29-
29+
/**
30+
* Abstract base class for JDBC database connectors.
31+
* Provides common functionality for establishing database connections across different database types
32+
* including PostgreSQL, Microsoft SQL Server, and ClickHouse.
33+
*/
3034
public abstract class AbstractJdbcConnector {
3135

3236
private static final Logger LOG = LoggerFactory.getLogger(AbstractJdbcConnector.class);
@@ -47,12 +51,11 @@ protected AbstractJdbcConnector(DatabaseType dbType) {
4751
}
4852

4953
/**
50-
* Creates new connection instance with params specified in constructor.<br>
51-
* It is the caller responsibility to close connection.
54+
* Creates a new database connection using the parameters specified in the constructor.
55+
* The caller is responsible for closing the connection.
5256
*
53-
* @return new connection
54-
* @throws IOException
55-
* If driver not found or a database access error occurs
57+
* @return new database connection
58+
* @throws IOException if the driver is not found or a database access error occurs
5659
*/
5760
public Connection getConnection() throws IOException {
5861
try {
@@ -74,10 +77,9 @@ protected Properties makeProperties() {
7477

7578
protected String getDriverName() {
7679
return switch (dbType) {
77-
case PG -> PG_DRIVER_NAME;
78-
case MS -> MS_DRIVER_NAME;
79-
case CH -> CH_DRIVER_NAME;
80-
default -> throw new IllegalArgumentException(Messages.DatabaseType_unsupported_type + dbType);
80+
case PG -> PG_DRIVER_NAME;
81+
case MS -> MS_DRIVER_NAME;
82+
case CH -> CH_DRIVER_NAME;
8183
};
8284
}
8385

src/main/java/org/pgcodekeeper/core/loader/DatabaseLoader.java

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
*******************************************************************************/
1616
package org.pgcodekeeper.core.loader;
1717

18-
import java.io.IOException;
19-
import java.util.ArrayDeque;
20-
import java.util.ArrayList;
21-
import java.util.List;
22-
import java.util.Queue;
23-
24-
import org.pgcodekeeper.core.localizations.Messages;
2518
import org.pgcodekeeper.core.parsers.antlr.AntlrTask;
2619
import org.pgcodekeeper.core.parsers.antlr.AntlrTaskManager;
2720
import org.pgcodekeeper.core.schema.AbstractDatabase;
@@ -30,6 +23,17 @@
3023
import org.pgcodekeeper.core.schema.pg.PgDatabase;
3124
import org.pgcodekeeper.core.settings.ISettings;
3225

26+
import java.io.IOException;
27+
import java.util.ArrayDeque;
28+
import java.util.ArrayList;
29+
import java.util.List;
30+
import java.util.Queue;
31+
32+
/**
33+
* Abstract base class for database schema loaders.
34+
* Provides common functionality for loading database schemas with ANTLR task management
35+
* and error collection. Supports loading with or without full analysis.
36+
*/
3337
public abstract class DatabaseLoader {
3438

3539
protected final List<Object> errors;
@@ -38,29 +42,38 @@ public abstract class DatabaseLoader {
3842
protected final Queue<DatabaseLoader> launchedLoaders = new ArrayDeque<>();
3943

4044
/**
41-
* Loads database schema with analyze.
45+
* Loads database schema and performs full analysis.
4246
*
43-
* @return database schema
47+
* @return the loaded and analyzed database schema
48+
* @throws IOException if database loading fails
49+
* @throws InterruptedException if the loading process is interrupted
4450
*/
4551
public AbstractDatabase loadAndAnalyze() throws IOException, InterruptedException {
4652
AbstractDatabase d = load();
4753
FullAnalyze.fullAnalyze(d, errors);
4854
return d;
4955
}
5056

57+
/**
58+
* Creates a new database instance based on the database type specified in settings.
59+
*
60+
* @param settings configuration settings containing the database type
61+
* @return new database instance of the appropriate type
62+
*/
5163
public static AbstractDatabase createDb(ISettings settings) {
5264
return switch (settings.getDbType()) {
53-
case CH -> new ChDatabase();
54-
case MS -> new MsDatabase();
55-
case PG -> new PgDatabase();
56-
default -> throw new IllegalArgumentException(Messages.DatabaseType_unsupported_type + settings.getDbType());
65+
case CH -> new ChDatabase();
66+
case MS -> new MsDatabase();
67+
case PG -> new PgDatabase();
5768
};
5869
}
5970

6071
/**
61-
* Loads database schema without analyze.
72+
* Loads database schema without performing full analysis.
6273
*
63-
* @return database schema
74+
* @return the loaded database schema
75+
* @throws IOException if database loading fails
76+
* @throws InterruptedException if the loading process is interrupted
6477
*/
6578
public abstract AbstractDatabase load() throws IOException, InterruptedException;
6679

src/main/java/org/pgcodekeeper/core/loader/FullAnalyze.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
*******************************************************************************/
1616
package org.pgcodekeeper.core.loader;
1717

18-
import java.io.IOException;
19-
import java.util.ArrayDeque;
20-
import java.util.ArrayList;
21-
import java.util.List;
22-
import java.util.Queue;
23-
2418
import org.pgcodekeeper.core.parsers.antlr.AntlrTask;
2519
import org.pgcodekeeper.core.parsers.antlr.AntlrTaskManager;
2620
import org.pgcodekeeper.core.parsers.antlr.expr.launcher.AbstractAnalysisLauncher;
@@ -33,6 +27,16 @@
3327
import org.pgcodekeeper.core.schema.meta.MetaContainer;
3428
import org.pgcodekeeper.core.schema.meta.MetaUtils;
3529

30+
import java.io.IOException;
31+
import java.util.ArrayDeque;
32+
import java.util.ArrayList;
33+
import java.util.List;
34+
import java.util.Queue;
35+
36+
/**
37+
* Performs full analysis of database objects including operators, aggregates, views, and other database elements.
38+
* Manages ANTLR tasks for concurrent analysis and collects references and dependencies.
39+
*/
3640
public final class FullAnalyze {
3741

3842
private final List<Object> errors;
@@ -47,11 +51,28 @@ private FullAnalyze(AbstractDatabase db, MetaContainer meta, List<Object> errors
4751
this.errors = errors;
4852
}
4953

54+
/**
55+
* Performs full analysis of the database using metadata created from the database.
56+
*
57+
* @param db the database to analyze
58+
* @param errors list to collect analysis errors
59+
* @throws InterruptedException if analysis is interrupted
60+
* @throws IOException if analysis fails
61+
*/
5062
public static void fullAnalyze(AbstractDatabase db, List<Object> errors)
5163
throws InterruptedException, IOException {
5264
fullAnalyze(db, MetaUtils.createTreeFromDb(db), errors);
5365
}
5466

67+
/**
68+
* Performs full analysis of the database using the provided metadata container.
69+
*
70+
* @param db the database to analyze
71+
* @param metaDb metadata container for analysis context
72+
* @param errors list to collect analysis errors
73+
* @throws InterruptedException if analysis is interrupted
74+
* @throws IOException if analysis fails
75+
*/
5576
public static void fullAnalyze(AbstractDatabase db, MetaContainer metaDb, List<Object> errors)
5677
throws InterruptedException, IOException {
5778
new FullAnalyze(db, metaDb, errors).fullAnalyze();
@@ -80,14 +101,19 @@ private void fullAnalyze() throws InterruptedException, IOException {
80101
}
81102
}
82103

104+
/**
105+
* Analyzes views in the database, optionally focusing on a specific relation.
106+
*
107+
* @param rel the specific relation to analyze, or null to analyze all views
108+
*/
83109
public void analyzeView(IRelation rel) {
84110
List<AbstractAnalysisLauncher> launchers = db.getAnalysisLaunchers();
85111
for (int i = 0; i < launchers.size(); ++i) {
86112
AbstractAnalysisLauncher l = launchers.get(i);
87113
if (l instanceof ViewAnalysisLauncher v
88114
&& (rel == null
89115
|| (rel.getSchemaName().equals(l.getSchemaName())
90-
&& rel.getName().equals(l.getStmt().getName())))) {
116+
&& rel.getName().equals(l.getStmt().getName())))) {
91117
// allow GC to reclaim context memory immediately
92118
// and protects from infinite recursion
93119
launchers.set(i, null);

src/main/java/org/pgcodekeeper/core/loader/JdbcQueries.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*******************************************************************************/
1616
package org.pgcodekeeper.core.loader;
1717

18+
/**
19+
* Utility class containing pre-built SQL queries for JDBC database operations.
20+
* Provides queries for PostgreSQL metadata extraction, version checking, privilege validation,
21+
* and system object enumeration.
22+
*/
1823
public class JdbcQueries {
1924

2025
private static final String NSPNAME = "n.nspname";
@@ -30,7 +35,7 @@ public class JdbcQueries {
3035
public static final String QUERY_CHECK_MS_VERSION = getCheckMsVersionQuery();
3136
public static final String QUERY_SCHEMAS_ACCESS = getSchemasAccessQuery();
3237
public static final String QUERY_SEQUENCES_ACCESS = getSequencesAccessQuery();
33-
public static final String QUERY_SEQUENCES_DATA = getSequencesDataQuery();
38+
public static final String QUERY_SEQUENCES_DATA = getSequencesDataQuery();
3439
public static final String QUERY_SYSTEM_FUNCTIONS = getSystemFunctionsQuery();
3540
public static final String QUERY_SYSTEM_RELATIONS = getSystemRelationsQuery();
3641
public static final String QUERY_SYSTEM_OPERATORS = getSystemOperatorsQuery();
@@ -193,5 +198,6 @@ private static String getSequencesDataQuery() {
193198
.build();
194199
}
195200

196-
private JdbcQueries() {}
201+
private JdbcQueries() {
202+
}
197203
}

0 commit comments

Comments
 (0)