Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
planetf1 authored Nov 3, 2022
2 parents 348bde3 + 3f1b9e0 commit ca16ab7
Show file tree
Hide file tree
Showing 42 changed files with 258 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
import java.sql.SQLException;
import java.util.List;

import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.*;
import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.EXCEPTION_ON_CONTEXT_RETRIEVAL;
import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.EXCEPTION_READING_JDBC;
import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.EXITING_ON_COMPLETE;
import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.EXITING_ON_CONNECTION_FAIL;
import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.EXITING_ON_INTEGRATION_CONTEXT_FAIL;
import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.EXITING_ON_TRANSFER_FAIL;

public class JdbcIntegrationConnector extends DatabaseIntegratorConnector{

Expand All @@ -39,14 +44,14 @@ public void refresh() {
DatabaseMetaData databaseMetaData = getDatabaseMetadata(connection);
if(databaseMetaData == null){
auditLog.logMessage(exitAction, EXITING_ON_CONNECTION_FAIL.getMessageDefinition(methodName));
disconnect(connection);
close(connection);
return;
}

JdbcMetadataTransfer jdbcMetadataTransfer = createJdbcMetadataTransfer(databaseMetaData);
if(jdbcMetadataTransfer == null){
auditLog.logMessage(exitAction, EXITING_ON_INTEGRATION_CONTEXT_FAIL.getMessageDefinition(methodName));
disconnect(connection);
close(connection);
return;
}

Expand All @@ -57,35 +62,39 @@ public void refresh() {
}else{
auditLog.logMessage(exitAction, EXITING_ON_TRANSFER_FAIL.getMessageDefinition(methodName));
}
disconnect(connection);
close(connection);
}

private Connection connect(){
String methodName = "connect";
try {
return jdbcConnector.asDataSource().getConnection();
} catch (SQLException e) {
} catch (SQLException sqlException) {
auditLog.logException("Connecting to target database server",
EXITING_ON_CONNECTION_FAIL.getMessageDefinition(methodName), e);
EXCEPTION_READING_JDBC.getMessageDefinition(methodName), sqlException);
}
return null;
}

public void disconnect(Connection connection) {
public void close(Connection connection) {
String methodName = "close";
try{
if(!connection.isClosed()){
connection.close();
}
} catch (SQLException sqlException) {
auditLog.logMessage("Error when closing connection to database server", null);
auditLog.logException("Closing connection to database server",
EXCEPTION_READING_JDBC.getMessageDefinition(methodName), sqlException);
}
}

private DatabaseMetaData getDatabaseMetadata(Connection connection){
String methodName = "getDatabaseMetadata";
try{
return connection.getMetaData();
}catch (SQLException sqlException){
auditLog.logMessage("Extracting database metadata", null);
auditLog.logException("Extracting database metadata",
EXCEPTION_READING_JDBC.getMessageDefinition(methodName), sqlException);
}
return null;
}
Expand All @@ -98,7 +107,7 @@ private JdbcMetadataTransfer createJdbcMetadataTransfer(DatabaseMetaData databas
connectorTypeQualifiedName, auditLog);
}catch (ConnectorCheckedException e) {
auditLog.logException("Extracting integration context",
EXITING_ON_INTEGRATION_CONTEXT_FAIL.getMessageDefinition(methodName), e);
EXCEPTION_ON_CONTEXT_RETRIEVAL.getMessageDefinition(methodName), e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum JdbcConnectorAuditCode implements AuditLogMessageSet {
OMRSAuditLogRecordSeverity.INFO,
"Exiting from method {0} as a result of a failed connection",
"Stopping execution",
"Investigate database server availability. If the database server is available then contact the Egeria team for support"),
"Investigate log for additional details"),
EXITING_ON_COMPLETE("JDBC-INTEGRATION-CONNECTOR-0002",
OMRSAuditLogRecordSeverity.INFO,
"Execution of method {0} is complete",
Expand All @@ -40,12 +40,12 @@ public enum JdbcConnectorAuditCode implements AuditLogMessageSet {
"Retrieving integration context failed in method {0}",
"Stopping execution",
"Consult logs for further details"),
ERROR_READING_JDBC("JDBC-INTEGRATION-CONNECTOR-0005",
EXCEPTION_READING_JDBC("JDBC-INTEGRATION-CONNECTOR-0005",
OMRSAuditLogRecordSeverity.EXCEPTION,
"An SQL exception was received by method {0}. Exception message is: {1}",
"Reading JDBC",
"Investigate database server availability. If the database server is available then contact the Egeria team for support"),
ERROR_UPSERTING_INTO_OMAS("JDBC-INTEGRATION-CONNECTOR-0006",
"Take appropriate action to remedy the issue described in the exception message"),
EXCEPTION_WRITING_OMAS("JDBC-INTEGRATION-CONNECTOR-0006",
OMRSAuditLogRecordSeverity.EXCEPTION,
"An exception was received by method {0}. Exception message is: {1}",
"Upserting an entity into omas failed.",
Expand All @@ -55,7 +55,7 @@ public enum JdbcConnectorAuditCode implements AuditLogMessageSet {
"Transferring metadata failed in method {0}",
"Stopping execution",
"Consult logs for further details"),
ERROR_READING_OMAS("JDBC-INTEGRATION-CONNECTOR-0008",
EXCEPTION_READING_OMAS("JDBC-INTEGRATION-CONNECTOR-0008",
OMRSAuditLogRecordSeverity.EXCEPTION,
"Error reading data from omas in method {0}. Possible message is {1}",
"Reading omas information",
Expand All @@ -70,11 +70,11 @@ public enum JdbcConnectorAuditCode implements AuditLogMessageSet {
"Unknown error when removing element in omas with guid {0} and qualified name {1}.",
"Removing element in omas",
"Consult logs for further details"),
ERROR_WHEN_SETTING_ASSET_CONNECTION("JDBC-INTEGRATION-CONNECTOR-0011",
OMRSAuditLogRecordSeverity.INFO,
"Unknown error when setting up asset connection in method {0}.",
"Setting up asset connection",
"Consult logs for further details");
EXCEPTION_ON_CONTEXT_RETRIEVAL("JDBC-INTEGRATION-CONNECTOR-0011",
OMRSAuditLogRecordSeverity.EXCEPTION,
"Retrieving integration context failed in method {0}",
"Stopping execution",
"Take appropriate action to remedy the issue described in the exception message"),;


private final AuditLogMessageDefinition messageDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ private String extractDataType(int jdbcDataType){
*/
private void setPrimaryKey(List<JdbcPrimaryKey> jdbcPrimaryKeys, JdbcColumn jdbcColumn, String columnGuid){
Optional<JdbcPrimaryKey> jdbcPrimaryKey = jdbcPrimaryKeys.stream().filter(
key -> key.getTableSchem().equals(jdbcColumn.getTableSchem())
key -> key.getTableCat() == null ? jdbcColumn.getTableCat() == null : key.getTableCat().equals(jdbcColumn.getTableCat())
&& key.getTableSchem() == null ? jdbcColumn.getTableSchem() == null : key.getTableSchem().equals(jdbcColumn.getTableSchem())
&& key.getTableName().equals(jdbcColumn.getTableName())
&& key.getColumnName().equals(jdbcColumn.getColumnName())
).findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,26 @@ public DatabaseElement execute() {
* @return properties
*/
private DatabaseProperties buildDatabaseProperties() {
String user = jdbc.getUserName();
String driverName = jdbc.getDriverName();
String databaseProductVersion = jdbc.getDatabaseProductVersion();
String databaseProductName = jdbc.getDatabaseProductName();
String url = jdbc.getUrl();
String urlWithNoParams = url.contains("?") ? url.substring(0, url.indexOf("?")) : url;
String catalogFromUrl = urlWithNoParams.substring(url.lastIndexOf("/") + 1);

DatabaseProperties databaseProperties = new DatabaseProperties();
databaseProperties.setQualifiedName(url);
databaseProperties.setDisplayName(user);
databaseProperties.setQualifiedName(urlWithNoParams);
databaseProperties.setDisplayName(catalogFromUrl);
databaseProperties.setDatabaseInstance(driverName);
databaseProperties.setDatabaseVersion(databaseProductVersion);
databaseProperties.setDatabaseType(databaseProductName);
databaseProperties.setDatabaseImportedFrom(url);

// Map<String, String> origin = new HashMap<>();
// Optional<JdbcCatalog> catalog = jdbc.getCatalogs().stream().filter(c -> c.getTableCat().equals(catalogFromUrl)).findFirst();
// origin.put("jdbcCatalog", catalog.isPresent() ? catalog.get().getTableCat() : "unavailable");
// databaseProperties.setAdditionalProperties(origin);

return databaseProperties;
}

Expand Down
Loading

0 comments on commit ca16ab7

Please sign in to comment.