String selfRefColumnName = getString(resultSet, "SELF_REFERENCING_COL_NAME", false);
// get ref generation
String refGeneration = getString(resultSet, "REF_GENERATION", false);
// create Table object
Table table = factory.createTable();
// ***************************
// *** DatabaseNamedObject ***
// ***************************
// set name
table.setName(tableName);
// set remarks
table.setRemarks(remarks);
// TODO set extra properties
// table.addExtraProperty (String key, Object value);
// ********************
// *** SchemaObject ***
// ********************
// set catalog
if ((tableCatalog != null) && (tableCatalog.trim().length() != 0)) {
// find catalog
Catalog catalog = database.findCatalogByName(tableCatalog);
// set catalog
table.setCatalog(catalog);
// warn if null
if (catalog == null) {
traceLog.debug(String.format("[Database %s] Unable to find catalog '%4$s' for the table %s (schema %s, catalog %s)",
database.getName(),
tableName,
tableSchema,
tableCatalog));
}
// if fail is enabled
if (failOnError) {
throw new DatabaseMetaDataMethodException("Catalog name shall be provided", "populateTable");
}
}
// set schema
if ((tableSchema != null) && (tableSchema.trim().length() != 0)) {
// find schema
Schema schema = database.findSchemaByName(tableCatalog, tableSchema);
// set schema
table.setSchema(schema);
// warn if null
if (schema == null) {
traceLog.debug(String.format("[Database %s] Unable to find schema '%3$s' for the table %s (schema %s, catalog %s)",
database.getName(),
tableName,
tableSchema,
tableCatalog));
}
// if fail is enabled
if (failOnError) {
throw new DatabaseMetaDataMethodException("Table name shall be provided", "populateTable");
}
}
// **************
// *** Table ***
// **************
// set table type
if (tableTypeName != null) {
// create
TableType tableType = factory.createTableType();
// fill
tableType.setName(tableTypeName);
// set type
table.setTableType(tableType);
}
// set catalog
if ((typeCatalogName != null) && (typeCatalogName.trim().length() != 0)) {
// find catalog
Catalog typeCatalog = database.findCatalogByName(typeCatalogName);
// set type catalog
table.setTypeCatalog(typeCatalog);
// warn if null
if (typeCatalog == null) {
traceLog.debug(String.format("[Database %s] Unable to find catalog '%4$s' for the table %s (schema %s, catalog %s)",
database.getName(),
tableName,
tableSchema,
typeCatalogName));
}
}
// set schema
if ((typeSchemaName != null) && (typeSchemaName.trim().length() != 0)) {
// find schema
Schema typeSchema = database.findSchemaByName(typeCatalogName, typeSchemaName);
// set schema
table.setTypeSchema(typeSchema);
// warn if null
if (typeSchema == null) {
traceLog.debug(String.format("[Database %s] Unable to find schema '%3$s' for the table %s (schema %s, catalog %s)",
database.getName(),
tableName,
typeSchemaName,
typeCatalogName));
}
// if fail is enabled
if (failOnError && (typeSchema == null)) {
throw new DatabaseMetaDataMethodException("Schema name shall be provided", "populateTable");
}
}
// set type name
table.setTypeName(typeName);
// set self referencing column name
table.setSelfReferencingColumnName(selfRefColumnName);
// set reference generation
table.setReferenceGeneration(refGeneration);
// add table to the list
database.addTable(table);
// log