use of org.apache.cayenne.dbsync.reverse.dbimport.Catalog in project cayenne by apache.
the class FiltersConfigBuilderTest method testCompact_02.
@Test
public void testCompact_02() {
ReverseEngineering engineering = new ReverseEngineering();
engineering.addCatalog(new Catalog("catalogName"));
engineering.addSchema(new Schema("schemaName01"));
engineering.addSchema(new Schema("schemaName02"));
engineering.addIncludeTable(new IncludeTable("table1"));
engineering.addExcludeTable(new ExcludeTable("table2"));
engineering.addIncludeColumn(new IncludeColumn("includeColumn"));
FiltersConfigBuilder builder = new FiltersConfigBuilder(engineering);
builder.compact();
assertEquals("ReverseEngineering: \n" + " Catalog: catalogName\n" + " Schema: schemaName01\n" + " IncludeTable: table1\n" + " IncludeColumn: includeColumn\n" + " ExcludeTable: table2\n" + " Schema: schemaName02\n" + " IncludeTable: table1\n" + " IncludeColumn: includeColumn\n" + " ExcludeTable: table2\n\n" + " Use primitives", engineering.toString());
}
use of org.apache.cayenne.dbsync.reverse.dbimport.Catalog in project cayenne by apache.
the class LoadDbSchemaAction method performAction.
public void performAction(ActionEvent e, TreePath tablePath) {
final DbImportView rootParent = ((DbImportView) draggableTreePanel.getParent().getParent());
rootParent.getLoadDbSchemaProgress().setVisible(true);
rootParent.getLoadDbSchemaButton().setEnabled(false);
Thread thread = new Thread(() -> {
LoadDbSchemaAction.this.setEnabled(false);
rootParent.lockToolbarButtons();
draggableTreePanel.getMoveButton().setEnabled(false);
draggableTreePanel.getMoveInvertButton().setEnabled(false);
try {
DBConnectionInfo connectionInfo = getConnectionInfo("Load Db Schema");
if (connectionInfo == null) {
return;
}
if (tablePath != null) {
Object userObject = ((DbImportTreeNode) tablePath.getLastPathComponent()).getUserObject();
if (userObject instanceof Catalog) {
Catalog catalog = (Catalog) userObject;
if (catalog.getSchemas().isEmpty()) {
loadTables(connectionInfo, tablePath, rootParent);
}
} else if (userObject instanceof Schema) {
loadTables(connectionInfo, tablePath, rootParent);
} else if (userObject instanceof IncludeTable) {
loadColumns(connectionInfo, tablePath);
} else {
loadTables(connectionInfo, tablePath, rootParent);
}
} else {
loadDataBase(connectionInfo);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(Application.getFrame(), ex.getMessage(), "Error loading db schema", JOptionPane.ERROR_MESSAGE);
LOGGER.warn("Error loading db schema", ex);
} finally {
rootParent.getLoadDbSchemaButton().setEnabled(true);
rootParent.getLoadDbSchemaProgress().setVisible(false);
rootParent.unlockToolbarButtons();
}
});
thread.start();
}
use of org.apache.cayenne.dbsync.reverse.dbimport.Catalog in project cayenne by apache.
the class FilterContainerTest method fillContainer.
@Test
public void fillContainer() throws Exception {
Catalog catalog = new Catalog();
FilterContainer container = new FilterContainer();
container.setName("name");
container.includeTable("table1");
container.includeTables("table2", "table3");
container.excludeTable("table4");
container.excludeTables("table5", "table6");
container.includeColumn("column1");
container.includeColumns("column2", "column3");
container.excludeColumn("column4");
container.excludeColumns("column5", "collum6");
container.includeProcedure("proc1");
container.includeProcedures("proc2", "proc3");
container.excludeProcedure("proc4");
container.excludeProcedures("proc5", "proc6");
container.fillContainer(catalog);
assertEquals("name", catalog.getName());
assertEquals(3, catalog.getIncludeTables().size());
assertEquals("table1", catalog.getIncludeTables().iterator().next().getPattern());
assertEquals(3, catalog.getExcludeTables().size());
assertEquals("table4", catalog.getExcludeTables().iterator().next().getPattern());
assertEquals(3, catalog.getIncludeColumns().size());
assertEquals("column1", catalog.getIncludeColumns().iterator().next().getPattern());
assertEquals(3, catalog.getExcludeColumns().size());
assertEquals("column4", catalog.getExcludeColumns().iterator().next().getPattern());
assertEquals(3, catalog.getIncludeProcedures().size());
assertEquals("proc1", catalog.getIncludeProcedures().iterator().next().getPattern());
assertEquals(3, catalog.getExcludeProcedures().size());
assertEquals("proc4", catalog.getExcludeProcedures().iterator().next().getPattern());
}
use of org.apache.cayenne.dbsync.reverse.dbimport.Catalog in project cayenne by apache.
the class DatabaseSchemaLoader method packFilterContainer.
private FilterContainer packFilterContainer(String catalogName, String schemaName) {
SchemaContainer parentCatalog;
if (catalogName == null) {
parentCatalog = databaseReverseEngineering;
} else {
parentCatalog = getCatalogByName(databaseReverseEngineering.getCatalogs(), catalogName);
if (parentCatalog == null) {
parentCatalog = new Catalog();
parentCatalog.setName(catalogName);
databaseReverseEngineering.addCatalog((Catalog) parentCatalog);
}
}
Schema parentSchema = null;
if (schemaName != null) {
parentSchema = getSchemaByName(parentCatalog.getSchemas(), schemaName);
if (parentSchema == null) {
parentSchema = new Schema();
parentSchema.setName(schemaName);
parentCatalog.addSchema(parentSchema);
}
}
return parentSchema == null ? parentCatalog : parentSchema;
}
use of org.apache.cayenne.dbsync.reverse.dbimport.Catalog in project cayenne by apache.
the class DatabaseSchemaLoader method loadTables.
public ReverseEngineering loadTables(DBConnectionInfo connectionInfo, ClassLoadingService loadingService, TreePath path, String[] tableTypesFromConfig) throws SQLException {
int pathIndex = 1;
String catalogName = null, schemaName = null;
Object userObject = getUserObjectOrNull(path, pathIndex);
if (userObject != null) {
if (userObject instanceof Catalog) {
Catalog catalog = (Catalog) userObject;
catalogName = catalog.getName();
if (!catalog.getSchemas().isEmpty()) {
userObject = getUserObjectOrNull(path, ++pathIndex);
if (userObject instanceof Schema) {
schemaName = ((Schema) userObject).getName();
}
}
} else if (userObject instanceof Schema) {
schemaName = ((Schema) userObject).getName();
}
}
try (Connection connection = connectionInfo.makeDataSource(loadingService).getConnection()) {
String[] types = tableTypesFromConfig != null && tableTypesFromConfig.length != 0 ? tableTypesFromConfig : new String[] { "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM" };
try (ResultSet resultSet = connection.getMetaData().getTables(catalogName, schemaName, INCLUDE_ALL_PATTERN, types)) {
boolean hasTables = false;
while (resultSet.next()) {
hasTables = true;
String table = resultSet.getString("TABLE_NAME");
String schema = resultSet.getString("TABLE_SCHEM");
String catalog = resultSet.getString("TABLE_CAT");
packTable(table, catalog == null ? catalogName : catalog, schema, null);
}
if (!hasTables && (catalogName != null || schemaName != null)) {
packFilterContainer(catalogName, schemaName);
}
packProcedures(connection);
}
}
return databaseReverseEngineering;
}
Aggregations