use of org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException in project egeria-database-connectors by odpi.
the class PostgresDatabaseConnector method updateTableColumns.
/**
* @param postgresTable the Postgres table which contains the columns to be updates
* @param egeriaTable the column data from Egeria
* @throws AlreadyHandledException this exception has already been logged
*/
private void updateTableColumns(PostgresTable postgresTable, DatabaseTableElement egeriaTable) throws AlreadyHandledException {
final String methodName = "updateTableColumns";
PostgresSourceDatabase source = new PostgresSourceDatabase(this.connectionProperties);
String tableGuid = egeriaTable.getElementHeader().getGUID();
try {
List<PostgresColumn> postgresColumns = source.getColumns(postgresTable.getTable_name());
List<DatabaseColumnElement> egeriaColumns = getContext().getColumnsForDatabaseTable(tableGuid, startFrom, pageSize);
List<String> primarykeys = source.getPrimaryKeyColumnNamesForTable(postgresTable.getTable_name());
if (egeriaColumns != null && postgresColumns.size() > 0) {
egeriaColumns = deleteTableColumns(postgresColumns, egeriaColumns);
}
for (PostgresColumn postgresColumn : postgresColumns) {
boolean found = false;
/*
we have no columns in Egeria
so all columns are new
*/
if (egeriaColumns == null) {
if (postgresColumns.size() > 0) {
addColumn(postgresColumn, tableGuid);
}
} else {
/*
check if the database table is known to Egeria
and needs to be updated
*/
for (DatabaseColumnElement egeriaColumn : egeriaColumns) {
if (egeriaColumn.getDatabaseColumnProperties().getQualifiedName().equals(postgresColumn.getQualifiedName())) {
/*
we have found an exact instance to update
*/
found = true;
// updateColumn(postgresColumn, egeriaColumn);
break;
}
if (primarykeys.contains(egeriaColumn.getDatabaseColumnProperties().getDisplayName())) {
DatabasePrimaryKeyProperties props = new DatabasePrimaryKeyProperties();
getContext().setPrimaryKeyOnColumn(egeriaColumn.getElementHeader().getGUID(), props);
} else {
// was this a primary key previously.
if (egeriaColumn.getPrimaryKeyProperties() != null) {
getContext().removePrimaryKeyFromColumn(egeriaColumn.getElementHeader().getGUID());
}
}
}
/*
this is a new database so add it
*/
if (!found) {
addColumn(postgresColumn, tableGuid);
}
}
}
} catch (SQLException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.ERROR_READING_POSTGRES.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.ERROR_READING_FROM_POSTGRES.getMessageDefinition(methodName));
} catch (InvalidParameterException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName));
} catch (UserNotAuthorizedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName));
} catch (PropertyServerException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName));
} catch (ConnectorCheckedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName));
} catch (Exception error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.UNEXPECTED_ERROR.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.UNEXPECTED_ERROR.getMessageDefinition(methodName));
}
}
use of org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException in project egeria-database-connectors by odpi.
the class PostgresDatabaseConnector method deleteTableColumns.
/**
* Checks if any columns need to be removed from Egeria
*
* @param postgresColumns a list of the bean properties of a Postgres cols
* @param egeriaColumns a list of the cols already known to Egeria
* @throws AlreadyHandledException this exception has already been logged
*/
private List<DatabaseColumnElement> deleteTableColumns(List<PostgresColumn> postgresColumns, List<DatabaseColumnElement> egeriaColumns) throws AlreadyHandledException {
String methodName = "deleteTableColumns";
try {
if (egeriaColumns != null) {
/*
for each column already known to Egeria
*/
for (Iterator<DatabaseColumnElement> itr = egeriaColumns.iterator(); itr.hasNext(); ) {
boolean found = false;
DatabaseColumnElement egeriaColumn = itr.next();
String knownName = egeriaColumn.getDatabaseColumnProperties().getQualifiedName();
/*
check that the database is still present in Postgres
*/
for (PostgresColumn postgresColumn : postgresColumns) {
String sourceName = postgresColumn.getQualifiedName();
if (sourceName.equals(knownName)) {
/*
if found then check the next column
*/
found = true;
break;
}
}
/*
not found in Postgres , so delete the table from Egeria
*/
if (!found) {
getContext().removeDatabaseView(egeriaColumn.getElementHeader().getGUID(), knownName);
itr.remove();
}
}
}
} catch (InvalidParameterException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName));
} catch (PropertyServerException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName));
} catch (UserNotAuthorizedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName));
} catch (ConnectorCheckedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName));
} catch (Exception error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.UNEXPECTED_ERROR.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.UNEXPECTED_ERROR.getMessageDefinition(methodName));
}
return egeriaColumns;
}
use of org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException in project egeria-database-connectors by odpi.
the class PostgresDatabaseConnector method refresh.
@Override
public void refresh() throws ConnectorCheckedException {
String methodName = "PostgresConnector.refresh";
PostgresSourceDatabase source = new PostgresSourceDatabase(connectionProperties);
try {
/*
get a list of databases currently hosted in Postgres
and a list of databases already known by Egeria
*/
List<PostgresDatabase> postgresDatabases = source.getDabases();
List<DatabaseElement> egeriaDatabases = getContext().getMyDatabases(startFrom, pageSize);
/*
first we remove any Egeria databases that are no longer present in Postgres
*/
egeriaDatabases = deleteDatabases(postgresDatabases, egeriaDatabases);
for (PostgresDatabase postgresDatabase : postgresDatabases) {
boolean found = false;
if (egeriaDatabases == null) {
if (postgresDatabases.size() > 0) {
/*
we have no databases in Egeria
so all databases are new
*/
addDatabase(postgresDatabase);
}
} else {
/*
check if the database is known to Egeria
and needs to be updated
*/
for (DatabaseElement egeriaDatabase : egeriaDatabases) {
String egeriaQN = egeriaDatabase.getDatabaseProperties().getQualifiedName();
String postgresQN = postgresDatabase.getQualifiedName();
if (egeriaQN.equals(postgresQN)) {
/*
we have found an exact instance to update
*/
found = true;
updateDatabase(postgresDatabase, egeriaDatabase);
break;
}
}
/*
this is a new database so add it
*/
if (!found) {
addDatabase(postgresDatabase);
}
}
}
} catch (SQLException error) {
if (this.auditLog != null) {
auditLog.logException(methodName, PostgresConnectorAuditCode.ERROR_READING_POSTGRES.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), error);
}
throw new ConnectorCheckedException(PostgresConnectorErrorCode.ERROR_READING_FROM_POSTGRES.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), this.getClass().getName(), methodName, error);
} catch (InvalidParameterException error) {
if (this.auditLog != null) {
auditLog.logException(methodName, PostgresConnectorAuditCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), error);
}
throw new ConnectorCheckedException(PostgresConnectorErrorCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName), this.getClass().getName(), methodName, error);
} catch (UserNotAuthorizedException error) {
if (this.auditLog != null) {
auditLog.logException(methodName, PostgresConnectorAuditCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), error);
}
throw new ConnectorCheckedException(PostgresConnectorErrorCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName), this.getClass().getName(), methodName, error);
} catch (ConnectorCheckedException error) {
if (this.auditLog != null) {
auditLog.logException(methodName, PostgresConnectorAuditCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), error);
}
throw error;
} catch (AlreadyHandledException error) {
throw new ConnectorCheckedException(PostgresConnectorErrorCode.ALREADY_HANDLED_EXCEPTION.getMessageDefinition(error.getClass().getName(), error.getMessage()), this.getClass().getName(), methodName, error);
} catch (Exception error) {
if (this.auditLog != null) {
auditLog.logException(methodName, PostgresConnectorAuditCode.UNEXPECTED_ERROR.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), error);
}
throw new ConnectorCheckedException(PostgresConnectorErrorCode.ERROR_READING_FROM_POSTGRES.getMessageDefinition(methodName), this.getClass().getName(), methodName, error);
}
}
use of org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException in project egeria-database-connectors by odpi.
the class PostgresDatabaseConnector method updateViewColumns.
/**
* @param postgresTable the Postgres table which contains the columns to be updates
* @param egeriaTable the column data from Egeria
* @throws AlreadyHandledException this exception has already been logged
*/
private void updateViewColumns(PostgresTable postgresTable, DatabaseViewElement egeriaTable) throws AlreadyHandledException {
final String methodName = "updateViewColumns";
PostgresSourceDatabase source = new PostgresSourceDatabase(this.connectionProperties);
String guid = egeriaTable.getElementHeader().getGUID();
try {
List<PostgresColumn> postgresColumns = source.getColumns(postgresTable.getTable_name());
List<DatabaseColumnElement> egeriaColumns = getContext().getColumnsForDatabaseTable(egeriaTable.getElementHeader().getGUID(), startFrom, pageSize);
if (egeriaColumns != null) {
egeriaColumns = deleteViewColumns(postgresColumns, egeriaColumns);
}
for (PostgresColumn postgresColumn : postgresColumns) {
boolean found = false;
/*
we have no tables in Egeria
so all tables are new
*/
if (egeriaColumns == null) {
if (postgresColumns.size() > 0) {
addColumn(postgresColumn, guid);
}
} else {
/*
check if the database table is known to Egeria
and needs to be updated
*/
for (DatabaseColumnElement egeriaColumn : egeriaColumns) {
if (egeriaColumn.getDatabaseColumnProperties().getQualifiedName().equals(postgresColumn.getQualifiedName())) {
/*
we have found an exact instance to update
*/
found = true;
updateColumn(postgresColumn, egeriaColumn);
break;
}
}
/*
this is a new column so add it
*/
if (!found) {
addColumn(postgresColumn, guid);
}
}
}
} catch (SQLException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.ERROR_READING_POSTGRES.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.ERROR_READING_FROM_POSTGRES.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()));
} catch (InvalidParameterException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName));
} catch (UserNotAuthorizedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName));
} catch (PropertyServerException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName));
} catch (ConnectorCheckedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName));
} catch (Exception error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.UNEXPECTED_ERROR.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.UNEXPECTED_ERROR.getMessageDefinition(methodName));
}
}
use of org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException in project egeria-database-connectors by odpi.
the class PostgresDatabaseConnector method updateViews.
/**
* @param postgresSchema the Postgres schema bean
* @param egeriaSchema the Egeria schema bean
* @throws AlreadyHandledException this exception has already been logged
*/
private void updateViews(PostgresSchema postgresSchema, DatabaseSchemaElement egeriaSchema) throws AlreadyHandledException {
final String methodName = "updateViews";
String schemaGuid = egeriaSchema.getElementHeader().getGUID();
PostgresSourceDatabase source = new PostgresSourceDatabase(this.connectionProperties);
try {
/*
get a list of databases views currently hosted in Postgres
and remove any tables that have been dropped since the last refresh
*/
List<PostgresTable> postgresViews = source.getViews(postgresSchema.getSchema_name());
List<DatabaseViewElement> egeriaViews = getContext().getViewsForDatabaseSchema(schemaGuid, startFrom, pageSize);
egeriaViews = deleteViews(postgresViews, egeriaViews);
for (PostgresTable postgresView : postgresViews) {
boolean found = false;
/*
we have no views in Egeria
so all views are new
*/
if (egeriaViews == null) {
if (postgresViews.size() > 0) {
addView(postgresView, schemaGuid);
}
} else {
/*
check if the database table is known to Egeria
and needs to be updated
*/
for (DatabaseViewElement egeriaView : egeriaViews) {
if (egeriaView.getDatabaseViewProperties().getQualifiedName().equals(postgresView.getQualifiedName())) {
/*
we have found an exact instance to update
*/
found = true;
updateView(postgresView, egeriaView);
break;
}
}
/*
this is a new database view so add it
*/
if (!found) {
addView(postgresView, schemaGuid);
}
}
}
} catch (SQLException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.ERROR_READING_POSTGRES.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.ERROR_READING_FROM_POSTGRES.getMessageDefinition(methodName));
} catch (InvalidParameterException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName));
} catch (UserNotAuthorizedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName));
} catch (PropertyServerException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName));
} catch (ConnectorCheckedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName));
} catch (Exception error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.UNEXPECTED_ERROR.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.UNEXPECTED_ERROR.getMessageDefinition(methodName));
}
}
Aggregations