Search in sources :

Example 1 with TableNode

use of org.talend.core.model.metadata.builder.database.TableNode in project tbd-studio-se by Talend.

the class HBaseMetadataProvider method createTableChildNode.

/**
 * Create a TableNode that represent a column family element.
 * <p>
 * The TableNode instance is setup with values for a table
 * and added the the list of rootElements.
 *
 * @param rootElements       the parent TableNode in the TableTreeNode GUI
 * @param table              The table representation linked to this node
 * @param metadataConnection the metadataConnection
 * @return TableNode         created node.
 */
private static TableNode createTableChildNode(List<TableNode> rootElements, TdTable table, IMetadataConnection metadataConnection) {
    TableNode tableNode = new TableNode();
    tableNode.setType(TableNode.TABLE);
    tableNode.setValue(table.getLabel());
    tableNode.setItemType(table.getTableType());
    tableNode.setMetadataConn(metadataConnection);
    tableNode.setTable(table);
    rootElements.add(tableNode);
    return tableNode;
}
Also used : TableNode(org.talend.core.model.metadata.builder.database.TableNode)

Example 2 with TableNode

use of org.talend.core.model.metadata.builder.database.TableNode in project tbd-studio-se by Talend.

the class MapRDBMetadataProvider 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) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with TableNode

use of org.talend.core.model.metadata.builder.database.TableNode in project tbd-studio-se by Talend.

the class HBaseMetadataProvider 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)

Example 4 with TableNode

use of org.talend.core.model.metadata.builder.database.TableNode in project tbd-studio-se by Talend.

the class HBaseMetadataProvider method createColumnFamilyChildNode.

/**
 * Create a TableNode that represent a column family element.
 * <p>
 * The TableNode instance is setup with values for a column family
 * and added the the children of the parent.
 *
 * @param parent             the parent TableNode in the TableTreeNode GUI
 * @param columnFamilyName   The name of the column family
 * @param metadataConnection the metadataConnection
 * @return TableNode created node.
 */
private static TableNode createColumnFamilyChildNode(TableNode parent, String columnFamilyName, IMetadataConnection metadataConnection) {
    TableNode columnFamilyNode = new TableNode();
    columnFamilyNode.setParent(parent);
    columnFamilyNode.setType(TableNode.COLUMN_FAMILY);
    columnFamilyNode.setValue(columnFamilyName);
    columnFamilyNode.setItemType(COLUMN_FAMILY);
    columnFamilyNode.setTable(parent.getTable());
    columnFamilyNode.setMetadataConn(metadataConnection);
    parent.getChildren().add(columnFamilyNode);
    return columnFamilyNode;
}
Also used : TableNode(org.talend.core.model.metadata.builder.database.TableNode)

Example 5 with TableNode

use of org.talend.core.model.metadata.builder.database.TableNode in project tbd-studio-se by Talend.

the class HBaseMetadataProvider method executeInRunnable.

/**
 * run method in Runnable will execute this
 */
@Override
public void executeInRunnable(IMetadataConnection metadataConnection, Object currentNode, DatabaseConnection dbconn) {
    Object hConnection = getRealConnection(metadataConnection);
    MetadataTable metadataTable = null;
    TableNode columnNode = null;
    ClassLoader oldClassLoaderLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);
        if (currentNode instanceof TableNode) {
            columnNode = (TableNode) currentNode;
        }
        if (columnNode == null) {
            return;
        }
        TableNode columnFamilyNode = columnNode.getParent();
        TableNode tableNode = null;
        String tableName = null;
        String columnFamilyName = null;
        if (columnFamilyNode != null) {
            columnFamilyName = columnFamilyNode.getValue();
            tableNode = columnFamilyNode.getParent();
            if (tableNode != null) {
                tableName = tableNode.getValue();
                metadataTable = (MetadataTable) tableNode.getTable();
            }
        }
        if (columnNode != null && columnNode.getType() == TableNode.COLUMN) {
            Object scan = createScan();
            Object table = getTable(hConnection, tableName, classLoader);
            addFamily(scan, columnFamilyName.getBytes());
            // Limit
            int count = 0;
            int limit = -1;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
                limit = GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class).getHBaseOrMaprDBScanLimit();
            }
            List<String> existingColumns = new ArrayList<String>();
            List<MetadataTable> tables = ConnectionHelper.getTablesWithOrders(dbconn);
            for (MetadataTable t : tables) {
                if (t.getName().equals(metadataTable.getName())) {
                    List<MetadataColumn> existColumns = t.getColumns();
                    for (MetadataColumn c : existColumns) {
                        existingColumns.add(c.getName());
                    }
                    break;
                }
            }
            Object scanner = getResultScanner(table, scan);
            Object result = nextItem(scanner);
            while (result != null) {
                List<Object> list = listCells(result);
                if (list != null) {
                    for (Object cell : list) {
                        String familyName = getFamily(cell);
                        String columnName = getQualifier(cell);
                        if (familyName.equals(columnFamilyNode.getValue()) && columnName != null && columnName.equals(columnNode.getValue()) && !existingColumns.contains(columnName)) {
                            TdColumn column = createDatabaseColumn(columnName, columnFamilyName);
                            List<MetadataColumn> columns = metadataTable.getColumns();
                            columns.add(column);
                            existingColumns.add(columnName);
                            List<Catalog> catalogs = ConnectionHelper.getCatalogs(dbconn);
                            Catalog catalogToWrite = null;
                            for (Catalog c : catalogs) {
                                if (c.getName() != null && c.getName().equals(getDefaultCatalogName())) {
                                    catalogToWrite = c;
                                    break;
                                }
                            }
                            if (catalogToWrite != null) {
                                boolean findTable = false;
                                List<TdTable> existingTables = CatalogHelper.getTables(catalogToWrite);
                                for (TdTable tb : existingTables) {
                                    if (tableName != null && tb.getLabel().equals(tableName)) {
                                        List<MetadataColumn> columnsExsit = tb.getColumns();
                                        /*
                                             * can add into column list directly because it will delete the same
                                             * name column when deselect
                                             */
                                        columnsExsit.add(column);
                                        findTable = true;
                                    }
                                }
                                if (!findTable) {
                                    if (metadataTable.getId() == null) {
                                        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                                        metadataTable.setId(factory.getNextId());
                                    }
                                    PackageHelper.addMetadataTable(metadataTable, catalogToWrite);
                                }
                            }
                        }
                    }
                }
                count++;
                if (count == limit) {
                    break;
                }
                result = nextItem(scanner);
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoaderLoader);
    }
}
Also used : TdTable(org.talend.cwm.relational.TdTable) ArrayList(java.util.ArrayList) Catalog(orgomg.cwm.resource.relational.Catalog) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdColumn(org.talend.cwm.relational.TdColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) TableNode(org.talend.core.model.metadata.builder.database.TableNode) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

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