DBSchemaParser support Kerberos connection
@@ -62,12 +62,14 @@ public class DBSchemaParser {
public List<String> listSchemas() {
Vector<String> schemas = new Vector<>();
- try (Connection conn = ds.getConnection(); ResultSet rs = conn.getMetaData().getSchemas()) {
+ try (final Connection conn = KerberosUtil.getConnectionWithOrWithoutKerberos(ds, kerberosTicketConfiguration)) {
+ try (ResultSet rs = conn.getMetaData().getSchemas()) {
while (rs.next()) {
String schema = rs.getString("TABLE_SCHEM");
schemas.add(schema);
}
return schemas;
+ }
} catch (SQLException e) {
throw new RuntimeException("Unable to list schemas", e);
}
@@ -75,12 +77,14 @@ public class DBSchemaParser {
private List<String> listCatalogs() {
Vector<String> catalogs = new Vector<>();
- try (Connection conn = ds.getConnection(); ResultSet rs = conn.getMetaData().getCatalogs()) {
+ try (final Connection conn = KerberosUtil.getConnectionWithOrWithoutKerberos(ds, kerberosTicketConfiguration)) {
+ try ( ResultSet rs = conn.getMetaData().getCatalogs()) {
while (rs.next()) {
String cat = rs.getString("TABLE_CAT");
catalogs.add(cat);
}
return catalogs;
+ }
} catch (SQLException e) {
throw new RuntimeException("Unable to list catalogs", e);
}
@@ -147,7 +151,7 @@ public class DBSchemaParser {
if (StringUtils.isNotBlank(schema) || StringUtils.isNotBlank(tableName)) {
//try using the catalog
- try (final Connection conn = ds.getConnection()) {
+ try (final Connection conn = KerberosUtil.getConnectionWithOrWithoutKerberos(ds, kerberosTicketConfiguration)) {
if (hasCatalogs) {
for (final String catalog : catalogs) {
try (final ResultSet result = getTables(conn, catalog, schemaPattern, tableNamePattern)) {
@@ -171,8 +175,10 @@ public class DBSchemaParser {
} else {
- try (final Connection conn = ds.getConnection()) {
+
+ try {
if (hasCatalogs) {
+ try (final Connection conn = KerberosUtil.getConnectionWithOrWithoutKerberos(ds, kerberosTicketConfiguration)) {
for (final String catalog : catalogs) {
try (final ResultSet result = getTables(conn, catalog, "%", tableNamePattern)) {
while (result != null && result.next()) {
@@ -180,8 +186,11 @@ public class DBSchemaParser {
}
}
}
+ }
} else {
- for (final String dbSchema : listSchemas()) {
+ List<String> schemas =listSchemas();
+ try (final Connection conn = KerberosUtil.getConnectionWithOrWithoutKerberos(ds, kerberosTicketConfiguration)) {
+ for (final String dbSchema : schemas) {
try (final ResultSet result = getTables(conn, null, dbSchema, tableNamePattern)) {
while (result != null && result.next()) {
addTableToList(result, tables);
@@ -189,6 +198,7 @@ public class DBSchemaParser {
}
}
}
+ }
} catch (final SQLException e) {
throw new RuntimeException("Unable to obtain table list", e);
}
@@ -213,7 +223,7 @@ public class DBSchemaParser {
final String catalog = StringUtils.isNotBlank(schema) ? listCatalogs().stream().filter(schema::equalsIgnoreCase).findFirst().orElse(null) : null;
- try (final Connection conn = kerberosTicketConfiguration.isKerberosEnabled() ? KerberosUtil.getConnectionWithOrWithoutKerberos(ds, kerberosTicketConfiguration) : ds.getConnection()) {
+ try (final Connection conn = KerberosUtil.getConnectionWithOrWithoutKerberos(ds, kerberosTicketConfiguration)) {
try (final ResultSet result = getTables(conn, catalog, (catalog == null) ? schema : "%", table)) {
while (result != null && result.next()) {
final String cat = result.getString(1);
@@ -295,4 +305,6 @@ public class DBSchemaParser {
}
+
+
}
