use of org.talend.core.model.metadata.builder.database.TableNode in project tbd-studio-se by Talend.
the class HBaseMetadataProvider method isMetadataExsit.
@Override
public boolean isMetadataExsit(Object node, DatabaseConnection connection) {
TableNode columnNode = null;
if (node == null) {
return false;
}
if (node instanceof TableNode) {
columnNode = (TableNode) node;
}
if (columnNode.getType() == TableNode.COLUMN) {
TableNode columnFamilyNode = columnNode.getParent();
TableNode tableNode = null;
String tableName = null;
String columnFamilyName = null;
String columnName = columnNode.getValue();
if (columnFamilyNode != null) {
columnFamilyName = columnFamilyNode.getValue();
tableNode = columnFamilyNode.getParent();
if (tableNode != null) {
tableName = tableNode.getValue();
}
}
List<MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
for (MetadataTable table : tables) {
if (table instanceof TdTable) {
TdTable tdTable = (TdTable) table;
if (tdTable.getLabel().equals(tableName)) {
List<MetadataColumn> columns = tdTable.getColumns();
for (MetadataColumn column : columns) {
if (column.getLabel().equals(columnName)) {
List<TaggedValue> tagValues = column.getTaggedValue();
for (TaggedValue tv : tagValues) {
String tag = tv.getTag();
String value = tv.getValue();
if (tag != null && tag.equals(COLUMN_FAMILY)) {
if (value != null && value.equals(columnFamilyName)) {
// columns.remove(column);
return true;
}
}
}
}
}
}
}
}
} else if (columnNode.getType() == TableNode.COLUMN_FAMILY) {
String columnFamilyName = columnNode.getValue();
String tableName = null;
TableNode tableNode = columnNode.getParent();
if (tableNode != null) {
tableName = tableNode.getValue();
}
List<MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
for (MetadataTable table : tables) {
if (table instanceof TdTable) {
TdTable tdTable = (TdTable) table;
if (tdTable.getLabel().equals(tableName)) {
List<MetadataColumn> columns = tdTable.getColumns();
for (MetadataColumn column : columns) {
List<TaggedValue> tagValues = column.getTaggedValue();
for (TaggedValue tv : tagValues) {
String tag = tv.getTag();
String value = tv.getValue();
if (tag != null && tag.equals(COLUMN_FAMILY)) {
if (value != null && value.equals(columnFamilyName)) {
return true;
}
}
}
}
}
}
}
}
return false;
}
use of org.talend.core.model.metadata.builder.database.TableNode in project tbd-studio-se by Talend.
the class HBaseMetadataProvider method getTableNodeInfo.
@Override
public List getTableNodeInfo(IMetadataConnection metadataConnection) {
List<TableNode> rootElements = new ArrayList<TableNode>();
ClassLoader oldClassLoaderLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(classLoader);
Object hConnection = getRealConnection(metadataConnection);
Object hAdmin = getAdmin(hConnection);
List<Object> tableDescriptors = getTableDescriptors(hAdmin);
for (Object tableDescriptor : tableDescriptors) {
String htabName = getTableName(tableDescriptor);
TdTable tb = getTableFromConnection(metadataConnection, htabName);
if (tb == null) {
tb = createDatabaseTable(htabName);
}
TableNode tableNode = createTableChildNode(rootElements, tb, metadataConnection);
}
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoaderLoader);
}
return rootElements;
}
use of org.talend.core.model.metadata.builder.database.TableNode in project tbd-studio-se by Talend.
the class HBaseMetadataProvider method createColumnChildNode.
/**
* Create a TableNode that represent a column element.
* <p>
* The TableNode instance is setup with values for a column
* and added the the children of the parent.
*
* @param parent the parent TableNode in the TableTreeNode GUI
* @param columnName The name of the column
* @return TableNode created node.
*/
private static TableNode createColumnChildNode(TableNode parent, String columnName) {
TableNode columnNode = new TableNode();
columnNode.setParent(parent);
columnNode.setType(TableNode.COLUMN);
columnNode.setValue(columnName);
// $NON-NLS-1$
columnNode.setItemType("COLUMN");
columnNode.setTable(parent.getTable());
parent.getChildren().add(columnNode);
return columnNode;
}
use of org.talend.core.model.metadata.builder.database.TableNode in project tbd-studio-se by Talend.
the class MapRDBMetadataProvider method getTableNodeInfo.
@Override
public List getTableNodeInfo(IMetadataConnection metadataConnection) {
List<TableNode> tableNodes = new ArrayList<TableNode>();
ClassLoader oldClassLoaderLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(classLoader);
Object hAdmin = getAdmin(metadataConnection);
// $NON-NLS-1$
Object[] allTables = (Object[]) ReflectionUtils.invokeMethod(hAdmin, "listTables", new Object[0]);
for (Object td : allTables) {
// $NON-NLS-1$
String htabName = (String) ReflectionUtils.invokeMethod(td, "getNameAsString", new Object[0]);
TdTable tb = getTableFromConnection(metadataConnection, htabName);
if (tb == null) {
tb = RelationalFactory.eINSTANCE.createTdTable();
tb.setLabel(htabName);
tb.setName(htabName);
tb.setTableType(ETableTypes.TABLETYPE_TABLE.getName());
}
TableNode tableNode = new TableNode();
tableNode.setType(TableNode.TABLE);
tableNode.setValue(tb.getLabel());
tableNode.setItemType(tb.getTableType());
tableNode.setMetadataConn(metadataConnection);
tableNode.setTable(tb);
tableNodes.add(tableNode);
}
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoaderLoader);
}
return tableNodes;
}
use of org.talend.core.model.metadata.builder.database.TableNode in project tbd-studio-se by Talend.
the class MapRDBMetadataProvider method deleteMetadataFromConnection.
@Override
public void deleteMetadataFromConnection(Object node, DatabaseConnection connection) {
TableNode columnNode = null;
if (node == null) {
return;
}
if (node instanceof TableNode) {
columnNode = (TableNode) node;
}
List<MetadataTable> tables = ConnectionHelper.getTablesWithOrders(connection);
TableNode columeFamilyNode = columnNode.getParent();
TableNode tableNode = columeFamilyNode.getParent();
String tableName = tableNode.getValue();
String columnFamilyName = columeFamilyNode.getValue();
String columnName = columnNode.getValue();
boolean columnRemoved = false;
for (MetadataTable table : tables) {
if (columnRemoved) {
break;
}
if (table instanceof TdTable) {
TdTable tdTable = (TdTable) table;
if (tdTable.getLabel().equals(tableName)) {
List<MetadataColumn> columns = tdTable.getColumns();
for (MetadataColumn column : columns) {
if (column.getLabel().equals(columnName)) {
List<TaggedValue> tagValues = column.getTaggedValue();
for (TaggedValue tv : tagValues) {
String tag = tv.getTag();
String value = tv.getValue();
if (tag != null && tag.equals(COLUMN_FAMILY)) {
if (value != null && value.equals(columnFamilyName)) {
columns.remove(column);
columnRemoved = true;
break;
}
}
}
}
if (columnRemoved) {
break;
}
}
}
}
}
}
Aggregations