Search in sources :

Example 71 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable 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 72 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable 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 73 with MetadataTable

use of org.talend.core.model.metadata.builder.connection.MetadataTable 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)

Example 74 with MetadataTable

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

the class MetadataColumnComparator method fixedTables.

/**
     * fixed Table .
     * 
     * @param metaFromDB MetadataTable from Database
     * @param metaFromEMF MetadataTable from Emf
     * @param iMetadataConnection contain Connection.
     */
@SuppressWarnings("unchecked")
private void fixedTables(List<MetadataTable> metaFromDB, List<MetadataTable> metaFromEMF, IMetadataConnection iMetadataConnection, RepositoryNode oldNode) {
    List<MetadataTable> removeEmfDB = new ArrayList<MetadataTable>();
    for (MetadataTable emf : metaFromEMF) {
        boolean flag = modifyOldOneTableFromDB(metaFromDB, emf);
        if (flag) {
            removeEmfDB.add(emf);
        }
    }
    for (MetadataTable metadataTable : removeEmfDB) {
        if (metadataTable.getLabel() == null || "".equals(metadataTable.getLabel())) {
            //$NON-NLS-1$
            metaFromEMF.remove(metadataTable);
        }
    }
    // }
    int nbTables = 0;
    while (!metaFromDB.isEmpty() && nbTables < 500) {
        MetadataTable db = metaFromDB.remove(0);
        modifyOldOneTableFromEMF(metaFromEMF, iMetadataConnection, db);
        nbTables++;
    }
}
Also used : ArrayList(java.util.ArrayList) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable)

Example 75 with MetadataTable

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

the class CreateJSONSchemaAction method doRun.

@Override
protected void doRun() {
    if (repositoryNode == null) {
        repositoryNode = getCurrentRepositoryNode();
    }
    JSONFileConnection connection = null;
    MetadataTable metadataTable = null;
    boolean creation = false;
    if (repositoryNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
        ERepositoryObjectType nodeType = (ERepositoryObjectType) repositoryNode.getProperties(EProperties.CONTENT_TYPE);
        String metadataTableLabel = (String) repositoryNode.getProperties(EProperties.LABEL);
        JSONFileConnectionItem item = null;
        if (nodeType == ERepositoryObjectType.METADATA_CON_TABLE) {
            item = (JSONFileConnectionItem) repositoryNode.getObject().getProperty().getItem();
            connection = (JSONFileConnection) item.getConnection();
            metadataTable = TableHelper.findByLabel(connection, metadataTableLabel);
            creation = false;
        } else if (nodeType == JSONRepositoryNodeType.JSON) {
            item = (JSONFileConnectionItem) repositoryNode.getObject().getProperty().getItem();
            connection = (JSONFileConnection) item.getConnection();
            metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
            String nextId = ProxyRepositoryFactory.getInstance().getNextId();
            metadataTable.setId(nextId);
            metadataTable.setLabel(getStringIndexed(metadataTable.getLabel()));
            RecordFile record = (RecordFile) ConnectionHelper.getPackage(connection.getName(), connection, RecordFile.class);
            if (record != null) {
                // hywang
                PackageHelper.addMetadataTable(metadataTable, record);
            } else {
                RecordFile newrecord = RecordFactory.eINSTANCE.createRecordFile();
                ConnectionHelper.addPackage(newrecord, connection);
                PackageHelper.addMetadataTable(metadataTable, newrecord);
            }
            creation = true;
        } else {
            return;
        }
        initContextMode(item);
        openJSONSchemaWizard(item, metadataTable, false, creation);
    }
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) RecordFile(orgomg.cwm.resource.record.RecordFile) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) JSONFileConnectionItem(org.talend.repository.model.json.JSONFileConnectionItem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Aggregations

MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)76 ArrayList (java.util.ArrayList)26 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)24 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)22 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)18 List (java.util.List)14 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)13 PersistenceException (org.talend.commons.exception.PersistenceException)11 ConnectionItem (org.talend.core.model.properties.ConnectionItem)10 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)10 RepositoryNode (org.talend.repository.model.RepositoryNode)10 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)9 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)9 HashMap (java.util.HashMap)8 Schema (org.apache.avro.Schema)7 ComponentProperties (org.talend.components.api.properties.ComponentProperties)7 SAPFunctionUnit (org.talend.core.model.metadata.builder.connection.SAPFunctionUnit)7 IElementParameter (org.talend.core.model.process.IElementParameter)7 Map (java.util.Map)6 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)6