use of org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException 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.PropertyServerException 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.PropertyServerException 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.PropertyServerException 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));
}
}
use of org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException in project egeria-database-connectors by odpi.
the class PostgresDatabaseConnector method deleteViews.
/**
* Checks if any views need to be removed from Egeria
*
* @param postgresViews a list of the bean properties of a Postgres views
* @param egeriaViews a list of the views already known to Egeria
* @throws AlreadyHandledException this exception has already been logged
*/
private List<DatabaseViewElement> deleteViews(List<PostgresTable> postgresViews, List<DatabaseViewElement> egeriaViews) throws AlreadyHandledException {
String methodName = "deleteViews";
try {
if (egeriaViews != null) {
/*
for each view already known to Egeria
*/
for (Iterator<DatabaseViewElement> itr = egeriaViews.iterator(); itr.hasNext(); ) {
boolean found = false;
DatabaseViewElement egeriaView = itr.next();
String knownName = egeriaView.getDatabaseViewProperties().getQualifiedName();
/*
check that the database is still present in Postgres
*/
for (PostgresTable postgresView : postgresViews) {
String sourceName = postgresView.getQualifiedName();
if (sourceName.equals(knownName)) {
/*
if found then check the next table
*/
found = true;
break;
}
}
/*
not found in Postgres , so delete the table from Egeria
*/
if (!found) {
getContext().removeDatabaseView(egeriaView.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 egeriaViews;
}
Aggregations