Commit 7d576599 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added support for Postgres foreign tables

parent 6444c2be
Pipeline #112 passed with stage
in 11 seconds
......@@ -39,6 +39,12 @@ To do this: download the jar files listed in the following
credits section and run a couple of `mvn install:install-file`
commands based upond the dependencies description in the _TASMAN-webapp_ _pom.xml_ file.
## Developers info
For debugging TASMAN-embedded:
java -jar -Xdebug -agentlib:jdwp=transport=dt_socket,address=9999,server=y,suspend=n /opt/tasman/tasman-embedded.jar 2000
## Credits
TAP_SCHEMA Manager web application uses the following VO libraries:
......
......@@ -794,14 +794,12 @@ public abstract class DBBrokerTemplate implements DBBroker {
return allSchemas;
}
protected abstract String getAllTablesNamesQuery(String schemaName);
/**
* {@inheritDoc}
*/
@Override
public List<String> getAllTablesNames(String schemaName) throws SQLException {
String query = getAllTablesNamesQuery(schemaName);
String query = getSchemaTablesQuery(schemaName);
LOG.debug("Executing query: {}", query);
List<String> allTables = getAllItemsNames(query);
LOG.debug("{} tables found", allTables.size());
......
......@@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
/**
* MySQL implementation of a {@link it.inaf.ia2.tsm.datalayer.DBBroker}.
*
*
* @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
*/
public class MySQLDBBroker extends DBBrokerTemplate {
......@@ -67,11 +67,6 @@ public class MySQLDBBroker extends DBBrokerTemplate {
return "SHOW DATABASES";
}
@Override
protected String getAllTablesNamesQuery(String schemaName) {
return "SHOW TABLES FROM " + escape(schemaName);
}
@Override
protected String getColumnNamesQuery(String schemaName, String tableName) {
return String.format("SHOW COLUMNS FROM %s.%s", escape(schemaName), escape(tableName));
......
......@@ -191,7 +191,16 @@ public class PostgresDBBroker extends DBBrokerTemplate {
@Override
protected String getSchemaTablesQuery(String schemaName) {
return String.format("SELECT tablename FROM pg_catalog.pg_tables where schemaname = '%s'", schemaName);
StringBuilder sb = new StringBuilder();
sb.append("SELECT tablename FROM pg_catalog.pg_tables where schemaname = '%s'\n");
// Select also foreign tables:
sb.append("UNION SELECT c.relname FROM\n");
sb.append("pg_catalog.pg_foreign_table f\n");
sb.append("JOIN pg_catalog.pg_class c ON f.ftrelid = c.relfilenode\n");
sb.append("JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid\n");
sb.append("WHERE n.nspname = '%s'\n");
return String.format(sb.toString(), schemaName, schemaName);
}
/**
......@@ -219,19 +228,18 @@ public class PostgresDBBroker extends DBBrokerTemplate {
StringBuilder querySb = new StringBuilder();
String tableNameOid = "('\"' || t.schemaname || '\".\"' || t.tablename || '\"')::regclass::oid";
String tableNameOid = String.format("('\"%s\".\"%s\"')::regclass::oid", schemaName, tableSimpleName);
querySb.append("SELECT c.column_name, c.data_type, pg_catalog.format_type(a.atttypid, a.atttypmod), r.contype AS column_type, c.character_maximum_length, c.numeric_precision, a.attndims AS arraydim\n");
querySb.append("FROM information_schema.columns c\n");
querySb.append("JOIN pg_catalog.pg_tables t ON c.table_schema = t.schemaname AND c.table_name = t.tablename\n");
querySb.append("LEFT JOIN pg_catalog.pg_constraint r ON c.ordinal_position = ANY(r.conkey) AND r.conrelid = ");
querySb.append(tableNameOid);
querySb.append("\nLEFT JOIN pg_catalog.pg_attribute a ON a.attrelid = ");
querySb.append(tableNameOid);
querySb.append(" and a.attname = c.column_name\n");
querySb.append("WHERE t.schemaname = '");
querySb.append("WHERE c.table_schema = '");
querySb.append(schemaName);
querySb.append("' AND t.tablename = '");
querySb.append("' AND c.table_name = '");
querySb.append(tableSimpleName);
querySb.append("'");
......@@ -467,11 +475,6 @@ public class PostgresDBBroker extends DBBrokerTemplate {
return "SELECT schema_name FROM information_schema.schemata";
}
@Override
protected String getAllTablesNamesQuery(String schemaName) {
return String.format("SELECT tablename FROM pg_catalog.pg_tables where schemaname = '%s'", schemaName);
}
/**
* {@inheritDoc}
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment