use of org.kie.workbench.common.screens.datasource.management.metadata.TableMetadata in project kie-wb-common by kiegroup.
the class DatabaseMetadataUtilTest method includeTable.
private boolean includeTable(TableMetadata tableMetadata, String schema, String tableNamePattern, DatabaseMetadata.TableType... types) {
if (schema != null && !schema.equals(tableMetadata.getSchemaName())) {
return false;
}
if (tableNamePattern != null) {
String regex = tableNamePattern.replace("%", "(.*)");
Pattern pattern = Pattern.compile(regex);
if (!pattern.matcher(tableMetadata.getTableName()).matches()) {
return false;
}
}
return types == null || Arrays.stream(types).anyMatch(tableType -> tableType == DatabaseMetadata.TableType.ALL || tableType.name().equals(tableMetadata.getTableType()));
}
use of org.kie.workbench.common.screens.datasource.management.metadata.TableMetadata in project kie-wb-common by kiegroup.
the class DatabaseMetadataUtil method findTables.
/**
* Gets a list of database objects metadata for a given database.
* @param conn A valid connection to the target database.
* @param schema A schema name for filtering. A null value will query all the available schemas.
* @param tableNamePattern A table name pattern for filtering the database objects by name, e.g. %INVOICE_%. A null
* value will include all tables.
* @param types A list of database object types for filtering. A null value will include all types.
* @return A list of database objects fulfilling the filtering criteria.
*/
public static List<TableMetadata> findTables(Connection conn, String schema, String tableNamePattern, DatabaseMetadata.TableType... types) throws Exception {
try {
List<TableMetadata> result = new ArrayList<>();
DatabaseMetaData sqlMetadata = conn.getMetaData();
ResultSet rs = sqlMetadata.getTables(null, schema, tableNamePattern, toSqlTypes(types));
TableMetadata tableMetadata;
while (rs.next()) {
tableMetadata = new TableMetadata(rs.getString("TABLE_CAT"), rs.getString("TABLE_SCHEM"), rs.getString("TABLE_NAME"), rs.getString("TABLE_TYPE"));
result.add(tableMetadata);
}
rs.close();
return result;
} catch (Exception e) {
throw new Exception("It was not possible to read schema tables due to the following error: " + e.getMessage());
} finally {
try {
conn.close();
} catch (Exception e) {
// we are not interested in raising this error case.
}
}
}
use of org.kie.workbench.common.screens.datasource.management.metadata.TableMetadata in project kie-wb-common by kiegroup.
the class DatabaseObjectExplorerTest method setup.
@Before
public void setup() {
objectExplorer = new DatabaseObjectExplorer(view, new CallerMock<>(metadataService), translationService);
// emulate the @PostConstruct invocation.
objectExplorer.init();
schemas.add(new SchemaMetadata(SCHEMA_NAME));
schemas.add(new SchemaMetadata("schema2"));
schemas.add(new SchemaMetadata("schema3"));
dbObjects.add(new TableMetadata(CATALOG_NAME, SCHEMA_NAME, "table1", DatabaseMetadata.TableType.TABLE.name()));
dbObjects.add(new TableMetadata(CATALOG_NAME, SCHEMA_NAME, "table2", DatabaseMetadata.TableType.TABLE.name()));
}
use of org.kie.workbench.common.screens.datasource.management.metadata.TableMetadata in project kie-wb-common by kiegroup.
the class DatabaseObjectExplorer method loadTables.
private void loadTables(List<TableMetadata> response) {
rows.clear();
for (TableMetadata metadata : response) {
rows.add(new DatabaseObjectRow(metadata.getTableName(), metadata.getTableType()));
}
refreshRows();
}
Aggregations