Search in sources :

Example 41 with MetadataColumn

use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.

the class MetadataColumnComparator method fixedColumns.

/**
     * fixed Column from EMF use Column From DataBase .
     * 
     * @param columnsFromDB MetadataColumn from Database
     * @param cloumnsFromEMF MetadataColumn from Emf
     */
private void fixedColumns(List<MetadataColumn> columnsFromDB, List<MetadataColumn> cloumnsFromEMF) {
    for (MetadataColumn emf : cloumnsFromEMF) {
        modifyOldOneColumnFromDB(columnsFromDB, emf);
    }
    while (!columnsFromDB.isEmpty()) {
        MetadataColumn db = columnsFromDB.remove(0);
        modifyOldOneColumnFromEMF(cloumnsFromEMF, db);
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn)

Example 42 with MetadataColumn

use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.

the class MetadataColumnComparator method getAllNamesByRepositoryNode.

/**
     * method "getTableNamesByRepositoryNode" get All Table Names in current RepositoryNode's DatabaseConnectionItem.
     * 
     * @param node current RepositoryNode
     * @return List :all Table Names.
     */
@SuppressWarnings("unchecked")
public static Map<String, List<String>> getAllNamesByRepositoryNode(RepositoryNode node) {
    Map<String, List<String>> allNames = new HashMap<String, List<String>>();
    DatabaseConnectionItem item = getItem(getRoot(node));
    DatabaseConnection connection = (DatabaseConnection) item.getConnection();
    Set<MetadataTable> tablesFromEMF = ConnectionHelper.getTables(connection);
    boolean isOdbc = connection.getSID() == null || connection.getSID().length() == 0;
    String sid = isOdbc ? connection.getDatasourceName() : connection.getSID();
    for (MetadataTable table : tablesFromEMF) {
        String tableName = table.getSourceName();
        if (tableName != null && !"".equals(tableName)) {
            //$NON-NLS-1$
            List<String> columnNames = new ArrayList<String>();
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            tableName = "\"" + sid + "\".\"" + tableName + "\"";
            List<MetadataColumn> columns = table.getColumns();
            for (MetadataColumn column : columns) {
                String columnName = column.getOriginalField();
                if (columnName != null && !"".equals(columnName)) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$
                    columnName = tableName + ".\"" + columnName + "\"";
                    columnNames.add(columnName);
                }
            }
            allNames.put(tableName, columnNames);
        }
    }
    return allNames;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 43 with MetadataColumn

use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.

the class MetadataColumnComparator method modifyOldRepositoryNode.

/**
     * dev Comment method "modifyOldRepositoryNode".
     * 
     * @param connection
     * @param iMetadataConnection
     */
@SuppressWarnings("unchecked")
public void modifyOldRepositoryNode(DatabaseConnection connection, IMetadataConnection iMetadataConnection, RepositoryNode oldNode) throws Exception {
    boolean status = new ManagerConnection().check(iMetadataConnection);
    connection.setDivergency(!status);
    if (status) {
        // /Get MetadataTable From DB
        List<MetadataTable> tablesFromDB = ExtractMetaDataFromDataBase.returnMetaTablesFormConnection(iMetadataConnection);
        ExtractMetaDataUtils.getInstance().setReconnect(false);
        // Get MetadataTable From EMF(Old RepositoryNode)
        Set<MetadataTable> tablesetFromEMF = ConnectionHelper.getTables(connection);
        List<MetadataTable> tablesFromEMF = new ArrayList<MetadataTable>();
        tablesFromEMF.addAll(tablesetFromEMF);
        if (oldNode.getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.DATABASE) {
            if (tablesFromEMF.size() < tablesFromDB.size()) {
                modifyOldConnection(tablesFromEMF, iMetadataConnection, tablesFromDB, oldNode);
            }
            restoreConnection(connection, tablesFromEMF);
        } else if (oldNode.getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.TABLE) {
            MetadataTable metadataTable = ((MetadataTableRepositoryObject) oldNode.getObject()).getTable();
            modifyOldOneTableFromDB(tablesFromDB, metadataTable);
            MetadataTable tableFromDB = null;
            for (MetadataTable table : tablesFromDB) {
                if (table.getSourceName().equals(metadataTable.getSourceName())) {
                    tableFromDB = table;
                }
            }
            if (tableFromDB != null) {
                List<MetadataColumn> columnsFromDB = new ArrayList<MetadataColumn>();
                columnsFromDB.addAll(ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, tableFromDB.getSourceName()));
                fixedColumns(columnsFromDB, metadataTable.getColumns());
            }
            // for (MetadataColumn metadataColumn : (List<MetadataColumn>) metadataTable.getColumns()) {
            // modifyOneColumnFromDB(iMetadataConnection, tablesFromDB, metadataColumn);
            // }
            restoreConnection(connection, tablesFromEMF);
        } else if (oldNode.getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.COLUMN) {
            MetadataColumn metadataColumn = ((MetadataColumnRepositoryObject) oldNode.getObject()).getColumn();
            modifyOneColumnFromDB(iMetadataConnection, tablesFromDB, metadataColumn);
        }
    } else {
        Set<MetadataTable> tableset = ConnectionHelper.getTables(connection);
        List<MetadataTable> tablesFromEMF = new ArrayList<MetadataTable>();
        tablesFromEMF.addAll(tableset);
        for (MetadataTable tableFromEMF : tablesFromEMF) {
            List<MetadataColumn> columnsFromEMF = tableFromEMF.getColumns();
            for (MetadataColumn column : columnsFromEMF) {
                //$NON-NLS-1$
                column.setOriginalField(" ");
                column.setDivergency(true);
                column.setSynchronised(false);
            }
            //$NON-NLS-1$
            tableFromEMF.setSourceName(" ");
            tableFromEMF.setDivergency(true);
        }
    }
    ExtractMetaDataUtils.getInstance().setReconnect(true);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) MetadataColumnRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataColumnRepositoryObject)

Example 44 with MetadataColumn

use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.

the class MetadataColumnComparator method modifyOneColumnFromDB.

/**
     * dev Comment method "modifyOneColumnFromDB".
     * 
     * @param iMetadataConnection
     * @param tablesFromDB
     * @param metadataColumn
     */
private void modifyOneColumnFromDB(IMetadataConnection iMetadataConnection, List<MetadataTable> tablesFromDB, MetadataColumn metadataColumn) {
    MetadataTable tableFromDB = null;
    for (MetadataTable table : tablesFromDB) {
        if (table.getSourceName().equals(metadataColumn.getTable().getSourceName())) {
            tableFromDB = table;
        }
    }
    if (tableFromDB != null) {
        List<MetadataColumn> columnsFromDB = new ArrayList<MetadataColumn>();
        columnsFromDB.addAll(ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, tableFromDB.getSourceName()));
        modifyOldOneColumnFromDB(columnsFromDB, metadataColumn);
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ArrayList(java.util.ArrayList)

Example 45 with MetadataColumn

use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.

the class MetadataColumnComparator method modifyOldConnection.

/**
     * dev Comment method "ModifyOldConnection".
     * 
     * @param tablesFromEMF
     * @param iMetadataConnection
     * @param tablesFromDB
     */
@SuppressWarnings("unchecked")
private void modifyOldConnection(List<MetadataTable> tablesFromEMF, IMetadataConnection iMetadataConnection, List<MetadataTable> tablesFromDB, RepositoryNode oldNode) {
    for (MetadataTable tableFromDB : tablesFromDB) {
        MetadataTable tableFromModel = null;
        for (MetadataTable tableFromEMF : tablesFromEMF) {
            // /Get MetadataColumn From EMF
            if (tableFromDB.getSourceName().equals(tableFromEMF.getSourceName())) {
                tableFromModel = tableFromEMF;
                break;
            }
        }
        if (tableFromModel != null) {
            // /Get MetadataColumn from DB
            List<MetadataColumn> columnsFromDB = new ArrayList<MetadataColumn>();
            columnsFromDB.addAll(ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, tableFromDB.getSourceName()));
            List<MetadataColumn> columnsFromEMF = tableFromModel.getColumns();
            fixedColumns(columnsFromDB, columnsFromEMF);
        }
    }
    fixedTables(tablesFromDB, tablesFromEMF, iMetadataConnection, oldNode);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ArrayList(java.util.ArrayList)

Aggregations

MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)59 ArrayList (java.util.ArrayList)27 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)22 List (java.util.List)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 MetadataEmfTableEditor (org.talend.core.ui.metadata.editor.MetadataEmfTableEditor)10 IModel (org.talend.designer.hl7.model.IModel)9 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8 Command (org.eclipse.gef.commands.Command)7 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 ExtendedTableResetDBTypesCommand (org.talend.core.ui.metadata.extended.command.ExtendedTableResetDBTypesCommand)5 MetadataEmfExportXmlCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfExportXmlCommand)5 MetadataEmfImportXmlCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfImportXmlCommand)5 MetadataEmfPasteCommand (org.talend.core.ui.metadata.extended.command.MetadataEmfPasteCommand)5 HL7MultiSchemaUI (org.talend.designer.hl7.ui.HL7MultiSchemaUI)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4