Commit e258024b authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Supported dbname column, for compatibility with taplib.

parent 06003c06
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>it.inaf.ia2.tap</groupId> <groupId>it.inaf.ia2.tap</groupId>
<artifactId>tasman-core</artifactId> <artifactId>tasman-core</artifactId>
<version>1.3.1</version> <version>1.3.2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>tasman-core</name> <name>tasman-core</name>
<properties> <properties>
......
...@@ -44,6 +44,7 @@ public class Column extends ChildEntity<Table> { ...@@ -44,6 +44,7 @@ public class Column extends ChildEntity<Table> {
public final static String UCD_KEY = "ucd"; public final static String UCD_KEY = "ucd";
public final static String UNIT_KEY = "unit"; public final static String UNIT_KEY = "unit";
public final static String COLUMN_INDEX = "column_index"; // TAP version >= 1.1 public final static String COLUMN_INDEX = "column_index"; // TAP version >= 1.1
public final static String DBNAME = "dbname";
// Original datatype (computed from information_schema data), used for consistency checking // Original datatype (computed from information_schema data), used for consistency checking
public final static String ORIGINAL_DATATYPE_KEY = "original_datatype"; public final static String ORIGINAL_DATATYPE_KEY = "original_datatype";
......
...@@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory; ...@@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory;
public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<Table> { public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<Table> {
public final static String SCHEMA_NAME_KEY = "schema_name"; public final static String SCHEMA_NAME_KEY = "schema_name";
public final static String DBNAME = "dbname";
private static final long serialVersionUID = 8828583158332877855L; private static final long serialVersionUID = 8828583158332877855L;
private static final Logger LOG = LoggerFactory.getLogger(Schema.class); private static final Logger LOG = LoggerFactory.getLogger(Schema.class);
...@@ -61,7 +62,7 @@ public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer< ...@@ -61,7 +62,7 @@ public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<
tables = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); tables = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
tablesTypes = broker.getAllTableTypes(name); tablesTypes = broker.getAllTableTypes(name);
for (String tableName : broker.getAllTablesNames(name)) { for (String tableName : broker.getAllTablesNames(getRealSchemaName())) {
tables.put(tableName, null); tables.put(tableName, null);
} }
LOG.debug("Schema {} contains {} tables", name, tables.size()); LOG.debug("Schema {} contains {} tables", name, tables.size());
...@@ -69,6 +70,13 @@ public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer< ...@@ -69,6 +70,13 @@ public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<
setStatus(Status.LOADED); setStatus(Status.LOADED);
} }
public String getRealSchemaName() {
if (tapSchema.getDBName() != null && this.getName().equals(tapSchema.getName())) {
return tapSchema.getDBName();
}
return getName();
}
/** /**
* {@inheritDoc} The value in the {@code schema_name} column. * {@inheritDoc} The value in the {@code schema_name} column.
*/ */
......
...@@ -42,6 +42,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu ...@@ -42,6 +42,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu
public final static String SCHEMA_NAME_KEY = "schema_name"; public final static String SCHEMA_NAME_KEY = "schema_name";
public final static String TABLE_NAME_KEY = "table_name"; public final static String TABLE_NAME_KEY = "table_name";
public final static String TABLE_TYPE_KEY = "table_type"; public final static String TABLE_TYPE_KEY = "table_type";
public final static String DBNAME = "dbname";
private static final long serialVersionUID = 8265331530960896871L; private static final long serialVersionUID = 8265331530960896871L;
private static final Logger LOG = LoggerFactory.getLogger(Table.class); private static final Logger LOG = LoggerFactory.getLogger(Table.class);
...@@ -98,7 +99,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu ...@@ -98,7 +99,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu
DBBroker broker = tapSchema.getDBBroker(schema.getName()); DBBroker broker = tapSchema.getDBBroker(schema.getName());
tableTableModel = getTableTableModel(); tableTableModel = getTableTableModel();
columnsMetadata = broker.getAllColumnsMetadata(schema.getName(), tableSimpleName, tableTableModel, tapSchema.getDataTypeMode()); columnsMetadata = broker.getAllColumnsMetadata(schema.getRealSchemaName(), tableSimpleName, tableTableModel, tapSchema.getDataTypeMode());
fixIndexedMetadataValues(); fixIndexedMetadataValues();
for (Map.Entry<String, Map<String, Object>> entry : columnsMetadata.entrySet()) { for (Map.Entry<String, Map<String, Object>> entry : columnsMetadata.entrySet()) {
......
...@@ -47,6 +47,8 @@ import org.slf4j.LoggerFactory; ...@@ -47,6 +47,8 @@ import org.slf4j.LoggerFactory;
*/ */
public class TapSchema implements EntitiesContainer<Schema>, Serializable { public class TapSchema implements EntitiesContainer<Schema>, Serializable {
public static final String STANDARD_NAME = "TAP_SCHEMA";
// Mandatory tables constants // Mandatory tables constants
public static final String TABLES_TABLE = "tables"; public static final String TABLES_TABLE = "tables";
public static final String SCHEMAS_TABLE = "schemas"; public static final String SCHEMAS_TABLE = "schemas";
...@@ -65,6 +67,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { ...@@ -65,6 +67,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
private boolean loading; private boolean loading;
private DBWrapper dbWrapper; private DBWrapper dbWrapper;
private String dbName;
private String name;
private boolean exists; private boolean exists;
private TapSchemaSettings settings; private TapSchemaSettings settings;
private DataTypeMode dataTypeMode; private DataTypeMode dataTypeMode;
...@@ -101,12 +105,32 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { ...@@ -101,12 +105,32 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
this.dbWrapper = dbWrapper; this.dbWrapper = dbWrapper;
this.exists = exists; this.exists = exists;
this.settings = settings; this.settings = settings;
// Don't change the instructions order!
loadDBName();
loadName();
dataTypeMode = getTapSchemaModel().getDataTypeMode(); dataTypeMode = getTapSchemaModel().getDataTypeMode();
load(); load();
} }
private void loadDBName() {
// Detect if the TAP_SCHEMA version supports dbmodel
SchemaModel tapSchemaModel = SchemaModels.getTapSchemaModel(settings.getTapSchemaVersion());
boolean hasDBName = tapSchemaModel.getTable(SCHEMAS_TABLE).get("dbname") != null;
if (hasDBName && !STANDARD_NAME.equals(settings.getTapSchemaName())) {
dbName = settings.getTapSchemaName();
}
}
private void loadName() {
if (dbName != null) {
name = STANDARD_NAME;
} else {
name = settings.getTapSchemaName();
}
}
public final void load() throws SQLException { public final void load() throws SQLException {
loading = true; loading = true;
...@@ -115,7 +139,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { ...@@ -115,7 +139,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
for (String schemaName : getSourceDBBroker().getAllSchemaNames()) { for (String schemaName : getSourceDBBroker().getAllSchemaNames()) {
schemas.put(schemaName, null); schemas.put(schemaName, null);
} }
schemas.put(settings.getTapSchemaName(), null); // the TAP_SCHEMA contains itself schemas.put(getName(), null); // the TAP_SCHEMA contains itself
if (exists) { if (exists) {
consistencyChecks = TapSchemaLoader.loadExistingTapSchema((this)); consistencyChecks = TapSchemaLoader.loadExistingTapSchema((this));
...@@ -138,7 +162,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { ...@@ -138,7 +162,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
* The name of the TAP_SCHEMA schema. * The name of the TAP_SCHEMA schema.
*/ */
public final String getName() { public final String getName() {
return settings.getTapSchemaName(); return name;
} }
/** /**
...@@ -153,7 +177,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { ...@@ -153,7 +177,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
} }
private void loadSchemaKeysMetadata(String schemaName) throws SQLException { private void loadSchemaKeysMetadata(String schemaName) throws SQLException {
allKeys.addAll(getDBBroker(schemaName).getKeys(this, schemaName)); allKeys.addAll(getDBBroker(schemaName)
.getKeys(this, schemaName, getRealSchemaName(schemaName)));
} }
public Set<Key> getAllKeys() { public Set<Key> getAllKeys() {
...@@ -307,7 +332,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { ...@@ -307,7 +332,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
if (!exists) { if (!exists) {
SchemaModel tapSchemaModel = getTapSchemaModel(); SchemaModel tapSchemaModel = getTapSchemaModel();
broker.createTapSchemaStructure(getName(), tapSchemaModel); broker.createTapSchemaStructure(getRealName(), tapSchemaModel);
// Adding TAP_SCHEMA into TAP_SCHEMA // Adding TAP_SCHEMA into TAP_SCHEMA
addEntireSchema(getName()); addEntireSchema(getName());
...@@ -525,6 +550,11 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { ...@@ -525,6 +550,11 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
public Map<String, Object> getSchemaMetadata(String schemaName) { public Map<String, Object> getSchemaMetadata(String schemaName) {
Map<String, Object> metadata = new HashMap<>(); Map<String, Object> metadata = new HashMap<>();
metadata.put(Schema.SCHEMA_NAME_KEY, schemaName); metadata.put(Schema.SCHEMA_NAME_KEY, schemaName);
String dbNameMetadata = null;
if (dbName != null && schemaName.equals(STANDARD_NAME)) {
dbNameMetadata = dbName;
}
metadata.put(Schema.DBNAME, dbNameMetadata);
return metadata; return metadata;
} }
...@@ -585,4 +615,25 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable { ...@@ -585,4 +615,25 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
public void fillColumnsProperties(SchemaModel schemaModel) { public void fillColumnsProperties(SchemaModel schemaModel) {
fillColumnProperties(schemaModel, schemaModel.getName()); fillColumnProperties(schemaModel, schemaModel.getName());
} }
/**
* Allows to name the TAP_SCHEMA using the standard name, but referring to a
* differently named schema. This value is null if the TAP_SCHEMA version
* doesn't support the dbname column or if the schema name is already the
* standard value.
*/
public String getDBName() {
return dbName;
}
public String getRealName() {
return getRealSchemaName(getName());
}
public String getRealSchemaName(String schemaName) {
if (dbName != null && STANDARD_NAME.equals(schemaName)) {
return dbName;
}
return schemaName;
}
} }
...@@ -241,7 +241,7 @@ public class TapSchemaLoader { ...@@ -241,7 +241,7 @@ public class TapSchemaLoader {
} }
private void loadAndCheckSchemata() throws SQLException { private void loadAndCheckSchemata() throws SQLException {
for (Map<String, Object> schemaProps : tapSchemaDBBroker.getSavedItems(tapSchema.getName(), tapSchema.getTableModel(SCHEMAS_TABLE))) { for (Map<String, Object> schemaProps : tapSchemaDBBroker.getSavedItems(tapSchema.getRealName(), tapSchema.getTableModel(SCHEMAS_TABLE))) {
String schemaName = (String) schemaProps.get(Schema.SCHEMA_NAME_KEY); String schemaName = (String) schemaProps.get(Schema.SCHEMA_NAME_KEY);
Schema schema = tapSchema.addChild(schemaName); Schema schema = tapSchema.addChild(schemaName);
if (schema == null) { if (schema == null) {
...@@ -254,7 +254,7 @@ public class TapSchemaLoader { ...@@ -254,7 +254,7 @@ public class TapSchemaLoader {
} }
private void loadAndCheckTables() throws SQLException { private void loadAndCheckTables() throws SQLException {
for (Map<String, Object> tableProps : tapSchemaDBBroker.getSavedItems(tapSchema.getName(), tapSchema.getTableModel(TABLES_TABLE))) { for (Map<String, Object> tableProps : tapSchemaDBBroker.getSavedItems(tapSchema.getRealName(), tapSchema.getTableModel(TABLES_TABLE))) {
String tableCompleteName = (String) tableProps.get(Table.TABLE_NAME_KEY); String tableCompleteName = (String) tableProps.get(Table.TABLE_NAME_KEY);
String[] tableNameSplit = tableCompleteName.split(Pattern.quote(".")); String[] tableNameSplit = tableCompleteName.split(Pattern.quote("."));
String schemaName = tableNameSplit[0]; String schemaName = tableNameSplit[0];
...@@ -275,7 +275,7 @@ public class TapSchemaLoader { ...@@ -275,7 +275,7 @@ public class TapSchemaLoader {
} }
private void loadAndCheckColumns() throws SQLException { private void loadAndCheckColumns() throws SQLException {
for (Map<String, Object> columnProps : tapSchemaDBBroker.getSavedItems(tapSchema.getName(), tapSchema.getTableModel(COLUMNS_TABLE))) { for (Map<String, Object> columnProps : tapSchemaDBBroker.getSavedItems(tapSchema.getRealName(), tapSchema.getTableModel(COLUMNS_TABLE))) {
String tableCompleteName = (String) columnProps.get(Column.TABLE_NAME_KEY); String tableCompleteName = (String) columnProps.get(Column.TABLE_NAME_KEY);
String[] tableNameSplit = tableCompleteName.split(Pattern.quote(".")); String[] tableNameSplit = tableCompleteName.split(Pattern.quote("."));
String schemaName = tableNameSplit[0]; String schemaName = tableNameSplit[0];
...@@ -302,8 +302,8 @@ public class TapSchemaLoader { ...@@ -302,8 +302,8 @@ public class TapSchemaLoader {
} }
private void loadAndCheckKeys() throws SQLException { private void loadAndCheckKeys() throws SQLException {
List<Map<String, Object>> keysProps = tapSchemaDBBroker.getSavedItems(tapSchema.getName(), tapSchema.getTableModel(KEYS_TABLE)); List<Map<String, Object>> keysProps = tapSchemaDBBroker.getSavedItems(tapSchema.getRealName(), tapSchema.getTableModel(KEYS_TABLE));
List<Map<String, Object>> keysColumnsProps = tapSchemaDBBroker.getSavedItems(tapSchema.getName(), tapSchema.getTableModel(KEY_COLUMNS_TABLE)); List<Map<String, Object>> keysColumnsProps = tapSchemaDBBroker.getSavedItems(tapSchema.getRealName(), tapSchema.getTableModel(KEY_COLUMNS_TABLE));
for (Map<String, Object> keyProp : keysProps) { for (Map<String, Object> keyProp : keysProps) {
String fromTable = (String) keyProp.get(Key.FROM_TABLE_KEY); String fromTable = (String) keyProp.get(Key.FROM_TABLE_KEY);
......
...@@ -152,7 +152,7 @@ public class TapSchemaMender { ...@@ -152,7 +152,7 @@ public class TapSchemaMender {
private void fixInconsistentValues() throws SQLException { private void fixInconsistentValues() throws SQLException {
for (InconsistentColumnProperty inconsistency : consistencyChecks.getInconsistencies()) { for (InconsistentColumnProperty inconsistency : consistencyChecks.getInconsistencies()) {
tapSchema.getTapSchemaDBBroker().updateTapSchemaColumnValue(tapSchema.getName(), tapSchema.getTapSchemaDBBroker().updateTapSchemaColumnValue(tapSchema.getRealName(),
inconsistency.getTableCompleteName(), inconsistency.getColumnName(), inconsistency.getTableCompleteName(), inconsistency.getColumnName(),
inconsistency.getKey(), inconsistency.getCorrectValue()); inconsistency.getKey(), inconsistency.getCorrectValue());
} }
......
...@@ -58,7 +58,7 @@ public interface DBBroker { ...@@ -58,7 +58,7 @@ public interface DBBroker {
Map<String, Map<String, Object>> getAllColumnsMetadata(String schemaName, String tableSimpleName, TableModel tableModel, DataTypeMode dataTypeMode) throws SQLException; Map<String, Map<String, Object>> getAllColumnsMetadata(String schemaName, String tableSimpleName, TableModel tableModel, DataTypeMode dataTypeMode) throws SQLException;
List<Key> getKeys(TapSchema tapSchema, String schemaName) throws SQLException; List<Key> getKeys(TapSchema tapSchema, String schemaName, String realSchemaName) throws SQLException;
List<Map<String, Object>> getSavedItems(String tapSchemaName, TableModel tableModel, String whereCondition, Object[] whereParams) throws SQLException; List<Map<String, Object>> getSavedItems(String tapSchemaName, TableModel tableModel, String whereCondition, Object[] whereParams) throws SQLException;
......
...@@ -210,7 +210,7 @@ public abstract class DBBrokerTemplate implements DBBroker { ...@@ -210,7 +210,7 @@ public abstract class DBBrokerTemplate implements DBBroker {
connection.setAutoCommit(false); // start transaction connection.setAutoCommit(false); // start transaction
transactionStarted = true; transactionStarted = true;
String tapSchemaNameEscaped = escape(tapSchema.getName()); String tapSchemaNameEscaped = escape(tapSchema.getRealName());
// REMOVE ELEMENTS // REMOVE ELEMENTS
if (tapSchema.exists()) { if (tapSchema.exists()) {
...@@ -265,21 +265,21 @@ public abstract class DBBrokerTemplate implements DBBroker { ...@@ -265,21 +265,21 @@ public abstract class DBBrokerTemplate implements DBBroker {
LOG.debug("Inserting {} new schemas", operations.getSchemasToAdd().size()); LOG.debug("Inserting {} new schemas", operations.getSchemasToAdd().size());
} }
for (Schema schema : operations.getSchemasToAdd()) { for (Schema schema : operations.getSchemasToAdd()) {
insertItem(tapSchema.getName(), schema, connection); insertItem(tapSchema.getRealName(), schema, connection);
} }
if (!operations.getTablesToAdd().isEmpty()) { if (!operations.getTablesToAdd().isEmpty()) {
LOG.debug("Inserting {} new tables", operations.getTablesToAdd().size()); LOG.debug("Inserting {} new tables", operations.getTablesToAdd().size());
} }
for (Table table : operations.getTablesToAdd()) { for (Table table : operations.getTablesToAdd()) {
insertItem(tapSchema.getName(), table, connection); insertItem(tapSchema.getRealName(), table, connection);
} }
if (!operations.getColumnsToAdd().isEmpty()) { if (!operations.getColumnsToAdd().isEmpty()) {
LOG.debug("Inserting {} new columns", operations.getColumnsToAdd().size()); LOG.debug("Inserting {} new columns", operations.getColumnsToAdd().size());
} }
for (Column column : operations.getColumnsToAdd()) { for (Column column : operations.getColumnsToAdd()) {
insertItem(tapSchema.getName(), column, connection); insertItem(tapSchema.getRealName(), column, connection);
} }
if (!operations.getKeysToAdd().isEmpty()) { if (!operations.getKeysToAdd().isEmpty()) {
...@@ -287,9 +287,9 @@ public abstract class DBBrokerTemplate implements DBBroker { ...@@ -287,9 +287,9 @@ public abstract class DBBrokerTemplate implements DBBroker {
} }
for (Key key : operations.getKeysToAdd()) { for (Key key : operations.getKeysToAdd()) {
// insert new keys and their key columns // insert new keys and their key columns
insertItem(tapSchema.getName(), key, connection); insertItem(tapSchema.getRealName(), key, connection);
for (KeyColumn keyColumn : key.getKeyColumns()) { for (KeyColumn keyColumn : key.getKeyColumns()) {
insertItem(tapSchema.getName(), keyColumn, connection); insertItem(tapSchema.getRealName(), keyColumn, connection);
} }
} }
...@@ -298,26 +298,26 @@ public abstract class DBBrokerTemplate implements DBBroker { ...@@ -298,26 +298,26 @@ public abstract class DBBrokerTemplate implements DBBroker {
for (Key key : operations.getKeysToUpdate()) { for (Key key : operations.getKeysToUpdate()) {
// update keys and their key columns // update keys and their key columns
String whereCond = String.format("%s = ?", escape(Key.ID_KEY)); String whereCond = String.format("%s = ?", escape(Key.ID_KEY));
updateItem(tapSchema.getName(), key, connection, whereCond, key.getId()); updateItem(tapSchema.getRealName(), key, connection, whereCond, key.getId());
for (KeyColumn keyColumn : key.getKeyColumns()) { for (KeyColumn keyColumn : key.getKeyColumns()) {
whereCond = String.format("%s = ?", escape(KeyColumn.KEY_ID_KEY)); whereCond = String.format("%s = ?", escape(KeyColumn.KEY_ID_KEY));
updateItem(tapSchema.getName(), keyColumn, connection, whereCond, keyColumn.getKeyId()); updateItem(tapSchema.getRealName(), keyColumn, connection, whereCond, keyColumn.getKeyId());
} }
} }
for (Schema schema : operations.getSchemasToUpdate()) { for (Schema schema : operations.getSchemasToUpdate()) {
String whereCond = String.format("%s = ?", escape(Schema.SCHEMA_NAME_KEY)); String whereCond = String.format("%s = ?", escape(Schema.SCHEMA_NAME_KEY));
updateItem(tapSchema.getName(), schema, connection, whereCond, schema.getName()); updateItem(tapSchema.getRealName(), schema, connection, whereCond, schema.getName());
} }
for (Table table : operations.getTablesToUpdate()) { for (Table table : operations.getTablesToUpdate()) {
String whereCond = String.format("%s = ?", escape(Table.TABLE_NAME_KEY)); String whereCond = String.format("%s = ?", escape(Table.TABLE_NAME_KEY));
updateItem(tapSchema.getName(), table, connection, whereCond, table.getCompleteName()); updateItem(tapSchema.getRealName(), table, connection, whereCond, table.getCompleteName());
} }
for (Column column : operations.getColumnsToUpdate()) { for (Column column : operations.getColumnsToUpdate()) {
String whereCond = String.format("%s = ? AND %s = ?", escape(Column.TABLE_NAME_KEY), escape(Column.COLUMN_NAME_KEY)); String whereCond = String.format("%s = ? AND %s = ?", escape(Column.TABLE_NAME_KEY), escape(Column.COLUMN_NAME_KEY));
updateItem(tapSchema.getName(), column, connection, whereCond, column.getTableCompleteName(), column.getName()); updateItem(tapSchema.getRealName(), column, connection, whereCond, column.getTableCompleteName(), column.getName());
} }
} }
...@@ -1050,4 +1050,11 @@ public abstract class DBBrokerTemplate implements DBBroker { ...@@ -1050,4 +1050,11 @@ public abstract class DBBrokerTemplate implements DBBroker {
} }
} }
} }
protected String getExposedSchemaName(String schemaName, String realSchemaName, String keySchemaName) {
if (keySchemaName.equals(realSchemaName)) {
return schemaName;
}
return keySchemaName;
}
} }
...@@ -132,7 +132,7 @@ public class MySQLDBBroker extends DBBrokerTemplate { ...@@ -132,7 +132,7 @@ public class MySQLDBBroker extends DBBrokerTemplate {
cm.put(Column.DATATYPE_KEY, datatype); cm.put(Column.DATATYPE_KEY, datatype);
cm.put(Column.SIZE_KEY, size); cm.put(Column.SIZE_KEY, size);
String arraySize = null; String arraySize = "*";
if (size != null) { if (size != null) {
arraySize = String.valueOf(size); arraySize = String.valueOf(size);
// variable length columns must have a "*" symbol on arraysize // variable length columns must have a "*" symbol on arraysize
...@@ -219,7 +219,7 @@ public class MySQLDBBroker extends DBBrokerTemplate { ...@@ -219,7 +219,7 @@ public class MySQLDBBroker extends DBBrokerTemplate {
} }
@Override @Override
public List<Key> getKeys(TapSchema tapSchema, String schemaName) throws SQLException { public List<Key> getKeys(TapSchema tapSchema, String schemaName, String realSchemaName) throws SQLException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("SELECT\n"); sb.append("SELECT\n");
...@@ -235,9 +235,9 @@ public class MySQLDBBroker extends DBBrokerTemplate { ...@@ -235,9 +235,9 @@ public class MySQLDBBroker extends DBBrokerTemplate {
sb.append("ON c.CONSTRAINT_NAME = k.CONSTRAINT_NAME AND c.TABLE_SCHEMA = k.TABLE_SCHEMA\n"); sb.append("ON c.CONSTRAINT_NAME = k.CONSTRAINT_NAME AND c.TABLE_SCHEMA = k.TABLE_SCHEMA\n");
sb.append("WHERE c.CONSTRAINT_TYPE = 'FOREIGN KEY' \n"); sb.append("WHERE c.CONSTRAINT_TYPE = 'FOREIGN KEY' \n");
sb.append("AND k.TABLE_SCHEMA = '"); sb.append("AND k.TABLE_SCHEMA = '");
sb.append(schemaName); sb.append(realSchemaName);
sb.append("' OR k.REFERENCED_TABLE_SCHEMA = '"); sb.append("' OR k.REFERENCED_TABLE_SCHEMA = '");
sb.append(schemaName); sb.append(realSchemaName);
sb.append("'"); sb.append("'");
String query = sb.toString(); String query = sb.toString();
...@@ -258,8 +258,10 @@ public class MySQLDBBroker extends DBBrokerTemplate { ...@@ -258,8 +258,10 @@ public class MySQLDBBroker extends DBBrokerTemplate {
String targetTableName = resultSet.getString("target_table"); String targetTableName = resultSet.getString("target_table");
Map<String, Object> keyMetadata = new HashMap<>(); Map<String, Object> keyMetadata = new HashMap<>();
keyMetadata.put(Key.FROM_TABLE_KEY, fromSchemaName + "." + fromTableName); String exposedFromSchemaName = getExposedSchemaName(schemaName, realSchemaName, fromSchemaName);
keyMetadata.put(Key.TARGET_TABLE_KEY, targetSchemaName + "." + targetTableName); keyMetadata.put(Key.FROM_TABLE_KEY, String.format("%s.%s", exposedFromSchemaName, fromTableName));
String exposedTargetSchemaName = getExposedSchemaName(schemaName, realSchemaName, targetSchemaName);
keyMetadata.put(Key.TARGET_TABLE_KEY, String.format("%s.%s", exposedTargetSchemaName, targetTableName));
Key key = null; Key key = null;
// Searching for a partial built key // Searching for a partial built key
......
...@@ -131,7 +131,7 @@ public class PostgresDBBroker extends DBBrokerTemplate { ...@@ -131,7 +131,7 @@ public class PostgresDBBroker extends DBBrokerTemplate {
} }
first = false; first = false;
querySb.append(cm.getName()); querySb.append(escape(cm.getName()));
querySb.append(" "); querySb.append(" ");