use of com.developmentontheedge.dbms.DbmsConnector in project be5 by DevelopmentOnTheEdge.
the class MySqlSchemaReader method readIndices.
@Override
public Map<String, List<IndexInfo>> readIndices(SqlExecutor sql, String defSchema, ProcessController controller) throws SQLException, ProcessInterruptedException {
DbmsConnector connector = sql.getConnector();
Map<String, List<IndexInfo>> result = new HashMap<>();
ResultSet rs = connector.executeQuery("SELECT table_name,index_name,column_name,non_unique FROM information_schema.statistics " + "WHERE table_schema='" + defSchema + "' ORDER BY table_name,index_name,seq_in_index");
try {
IndexInfo curIndex = null;
String lastTable = null;
while (rs.next()) {
String tableName = rs.getString(1).toLowerCase();
String indexName = rs.getString(2);
if (!tableName.equals(lastTable) || curIndex == null || !curIndex.getName().equals(indexName)) {
List<IndexInfo> list = result.get(tableName);
if (list == null) {
list = new ArrayList<>();
result.put(tableName, list);
}
curIndex = new IndexInfo();
lastTable = tableName;
list.add(curIndex);
curIndex.setName(indexName);
int nonUnique = rs.getInt(4);
curIndex.setUnique(nonUnique == 0);
}
String column = rs.getString(3);
curIndex.addColumn(column);
}
} finally {
connector.close(rs);
}
return result;
}
use of com.developmentontheedge.dbms.DbmsConnector in project be5 by DevelopmentOnTheEdge.
the class OracleSchemaReader method readTableNames.
@Override
public Map<String, String> readTableNames(SqlExecutor sql, String defSchema, ProcessController controller) throws SQLException {
DbmsConnector connector = sql.getConnector();
Map<String, String> result = new HashMap<>();
ResultSet rs = connector.executeQuery("SELECT " + "t.table_name FROM user_tables t JOIN entities e ON (UPPER(e.name)=t.table_name)");
try {
while (rs.next()) {
String tableName = rs.getString(1);
result.put(tableName.toLowerCase(), "TABLE");
}
} finally {
connector.close(rs);
}
rs = connector.executeQuery("SELECT " + "view_name FROM user_views v JOIN entities e ON (UPPER(e.name)=v.view_name)");
try {
while (rs.next()) {
String viewName = rs.getString(1);
result.put(viewName.toLowerCase(), "VIEW");
}
} finally {
connector.close(rs);
}
return result;
}
use of com.developmentontheedge.dbms.DbmsConnector in project be5 by DevelopmentOnTheEdge.
the class PostgresSchemaReader method getDefaultSchema.
@Override
public String getDefaultSchema(SqlExecutor sqlExecutor) {
DbmsConnector connector = null;
ResultSet rs = null;
try {
connector = sqlExecutor.getConnector();
rs = sqlExecutor.getConnector().executeQuery("SHOW search_path");
rs.next();
String search_path = rs.getString("search_path");
// for different settings: default and after setup
if (search_path.contains(","))
return search_path.split(",")[1].trim();
else
return search_path.trim();
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
if (connector != null)
connector.close(rs);
}
}
use of com.developmentontheedge.dbms.DbmsConnector in project be5 by DevelopmentOnTheEdge.
the class PostgresSchemaReader method readTableNames.
@Override
public Map<String, String> readTableNames(SqlExecutor sql, String defSchema, ProcessController controller) throws SQLException {
DbmsConnector connector = sql.getConnector();
Map<String, String> result = new HashMap<>();
ResultSet rs = connector.executeQuery("SELECT table_name,table_type FROM information_schema.tables t WHERE table_schema='" + defSchema + "' AND table_type IN ('BASE TABLE','VIEW')");
try {
while (rs.next()) {
String tableName = rs.getString(1);
if (!tableName.equals(tableName.toLowerCase()))
continue;
String type = rs.getString(2);
if ("BASE TABLE".equals(type)) {
type = "TABLE";
}
result.put(tableName, type);
}
} finally {
connector.close(rs);
}
return result;
}
Aggregations