Search in sources :

Example 6 with TableNode

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;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdTable(org.talend.cwm.relational.TdTable) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) TableNode(org.talend.core.model.metadata.builder.database.TableNode) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with TableNode

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;
}
Also used : TdTable(org.talend.cwm.relational.TdTable) TableNode(org.talend.core.model.metadata.builder.database.TableNode) ArrayList(java.util.ArrayList)

Example 8 with TableNode

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;
}
Also used : TableNode(org.talend.core.model.metadata.builder.database.TableNode)

Example 9 with TableNode

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;
}
Also used : TdTable(org.talend.cwm.relational.TdTable) TableNode(org.talend.core.model.metadata.builder.database.TableNode) ArrayList(java.util.ArrayList)

Example 10 with TableNode

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;
                    }
                }
            }
        }
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdTable(org.talend.cwm.relational.TdTable) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) TableNode(org.talend.core.model.metadata.builder.database.TableNode) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable)

Aggregations

TableNode (org.talend.core.model.metadata.builder.database.TableNode)11 TdTable (org.talend.cwm.relational.TdTable)8 ArrayList (java.util.ArrayList)6 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)6 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)6 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)5 List (java.util.List)3 TdColumn (org.talend.cwm.relational.TdColumn)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2 Catalog (orgomg.cwm.resource.relational.Catalog)2 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)1