use of org.talend.core.model.metadata.builder.connection.util.ConnectionSwitch in project tdq-studio-se by Talend.
the class ReadItemConnectionFile method test.
@Test
public void test() {
EMFUtil emfUtil = new EMFUtil();
File file = new File("data/my_0.1.item");
System.out.println("Loading file " + file.getAbsolutePath());
ResourceSet rs = emfUtil.getResourceSet();
Resource r = rs.getResource(URI.createFileURI(file.getAbsolutePath()), true);
// TreeIterator<EObject> allContents = r.getAllContents();
// while (allContents.hasNext()) {
// EObject metadata = allContents.next();
// System.out.println(metadata);
// }
// should contain the connection, then catalog/schema, then tables, then columns
EList<EObject> contents = r.getContents();
// switch class that returns a connection when it finds one.
ConnectionSwitch<Connection> connectionFinder = new ConnectionSwitch<Connection>() {
/*
* (non-Javadoc)
*
* @see
* org.talend.core.model.metadata.builder.connection.util.ConnectionSwitch#caseConnection(org.talend.core
* .model.metadata.builder.connection.Connection)
*/
@Override
public Connection caseConnection(Connection object) {
return object;
}
};
// loop on all the content of the resource
for (EObject eObject : contents) {
Connection connection = connectionFinder.doSwitch(eObject);
if (connection != null) {
Set<Catalog> allCatalogs = ConnectionHelper.getAllCatalogs(connection);
for (Catalog catalog : allCatalogs) {
System.out.println("## Catalog: " + catalog.getName());
System.out.println("\t## Tables");
List<TdTable> tables = CatalogHelper.getTables(catalog);
for (TdTable tdTable : tables) {
System.out.println("\t\t" + tdTable.getName());
List<TdColumn> columns = TableHelper.getColumns(tdTable);
if (!columns.isEmpty()) {
System.out.println("\t\t\t## Columns");
}
for (TdColumn tdColumn : columns) {
System.out.println("\t\t\t\t" + tdColumn.getName());
}
}
System.out.println("\t## Views");
List<TdView> views = CatalogHelper.getViews(catalog);
for (TdView tdView : views) {
System.out.println("\t\t" + tdView.getName());
List<TdColumn> columns = ViewHelper.getColumns(tdView);
if (!columns.isEmpty()) {
System.out.println("\t\t\t## Columns");
}
for (TdColumn tdColumn : columns) {
System.out.println("\t\t\t\t" + tdColumn.getName());
}
}
}
}
}
}
Aggregations