Search in sources :

Example 16 with MetadataTable

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

the class MetadataColumnComparator method saveEMFMetadataColumn.

@SuppressWarnings("unchecked")
private static void saveEMFMetadataColumn(String id, List<MetadataColumn> columnNodes) {
    DatabaseConnectionItem item = getEMFItem(id);
    final DatabaseConnection connection = (DatabaseConnection) item.getConnection();
    IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
    Set<MetadataTable> tableset = ConnectionHelper.getTables(connection);
    List<MetadataTable> tables = new ArrayList<MetadataTable>();
    tables.addAll(tableset);
    List<MetadataColumn> emfCols = new ArrayList<MetadataColumn>();
    List<MetadataColumn> dbCols = new ArrayList<MetadataColumn>();
    for (MetadataColumn col : columnNodes) {
        for (MetadataTable table : tables) {
            if (table.getLabel().equals(col.getTable().getLabel())) {
                List<TdColumn> returnCols = ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, table.getSourceName());
                for (MetadataColumn emfcolumn : table.getColumns()) {
                    for (MetadataColumn column : returnCols) {
                        if (emfcolumn.getLabel().equals(col.getLabel()) && column.getLabel().equals(col.getOriginalField())) {
                            emfCols.add(emfcolumn);
                            dbCols.add(column);
                        }
                    }
                }
            }
        }
    }
    saveOneMetadataColumn(emfCols, columnNodes, dbCols);
    saveMetaData(item);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdColumn(org.talend.cwm.relational.TdColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 17 with MetadataTable

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

the class MetadataColumnComparator method isChangeElementColor.

/**
     * dev Comment method "isChangeElementColor".
     * 
     * @param node
     * @return
     */
public boolean isChangeElementColor(RepositoryNode node) {
    boolean flag = false;
    Object type = node.getProperties(EProperties.CONTENT_TYPE);
    if (type.equals(RepositoryNodeType.DATABASE)) {
        return getItem(node).getConnection().isDivergency();
    }
    if (type.equals(RepositoryNodeType.TABLE)) {
        MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
        MetadataTable table = object.getTable();
        flag = table.getSourceName().equals(table.getLabel());
        flag = flag && table.isDivergency();
    }
    return flag;
}
Also used : MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) SqlBuilderRepositoryObject(org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) MetadataColumnRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataColumnRepositoryObject) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject)

Example 18 with MetadataTable

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

the class MetadataColumnComparator method restoreConnection.

/**
     * dev Comment method "restoreConnection".
     * 
     * @param connection
     * @param tablesFromEMF
     */
@SuppressWarnings("unchecked")
private void restoreConnection(DatabaseConnection connection, List<MetadataTable> tablesFromEMF) {
    tablesFromEMF = sortTableColumn(tablesFromEMF);
    // bug when do refresh twice it will add all tables
    if (tList == null) {
        tList = new ArrayList<MetadataTable>();
        tList.addAll(ConnectionHelper.getTables(connection));
    }
    Catalog c = (Catalog) ConnectionHelper.getPackage(connection.getSID(), connection, Catalog.class);
    Schema s = (Schema) ConnectionHelper.getPackage(connection.getSID(), connection, Schema.class);
    Schema schema = (Schema) ConnectionHelper.getPackage(connection.getUiSchema(), connection, Schema.class);
    if (c != null) {
        PackageHelper.addMetadataTable(tablesFromEMF, c);
    } else if (s != null) {
        PackageHelper.addMetadataTable(tablesFromEMF, s);
    } else if (schema != null) {
        PackageHelper.addMetadataTable(tablesFromEMF, schema);
    } else {
        Schema defaultSchema = null;
        List<Schema> schemas = ConnectionHelper.getSchema(connection);
        if (schemas.size() > 0) {
            for (Schema sch : schemas) {
                if (" ".equals(sch.getName())) {
                    //$NON-NLS-1$
                    defaultSchema = sch;
                    break;
                }
            }
        }
        if (defaultSchema == null) {
            //$NON-NLS-1$
            defaultSchema = SchemaHelper.createSchema(" ");
            ConnectionHelper.addSchema(defaultSchema, connection);
        }
        PackageHelper.addMetadataTable(tablesFromEMF, defaultSchema);
    }
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 19 with MetadataTable

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

the class MetadataColumnComparator method isDiff.

/**
     * dev Comment method "isDiff".
     * 
     * @param node
     * @return
     */
@SuppressWarnings("unchecked")
public boolean[] isDiff(RepositoryNode node) {
    boolean isDiffDivergency = false;
    boolean isDiffSyschronize = false;
    boolean isDiffGray = false;
    Object type = node.getProperties(EProperties.CONTENT_TYPE);
    if (type.equals(RepositoryNodeType.DATABASE)) {
        DatabaseConnection connection = (DatabaseConnection) getItem(node).getConnection();
        Set<MetadataTable> tables = ConnectionHelper.getTables(connection);
        for (MetadataTable table : tables) {
            List<MetadataColumn> columns = table.getColumns();
            for (MetadataColumn column : columns) {
                if (column.isDivergency()) {
                    isDiffDivergency = true;
                }
                if (column.isSynchronised()) {
                    isDiffSyschronize = true;
                }
                if (column.getLabel() == null || "".equals(column.getLabel())) {
                    //$NON-NLS-1$
                    isDiffGray = true;
                }
            }
            if (table.isDivergency()) {
                isDiffDivergency = true;
            }
            if (table.getLabel() == null || "".equals(table.getLabel())) {
                //$NON-NLS-1$
                isDiffGray = true;
            }
        }
    } else if (type.equals(RepositoryNodeType.TABLE)) {
        MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
        MetadataTable table = object.getTable();
        List<MetadataColumn> columns = table.getColumns();
        for (MetadataColumn column : columns) {
            if (column.isDivergency()) {
                isDiffDivergency = true;
            }
            if (column.isSynchronised()) {
                isDiffSyschronize = true;
            }
            if (column.getLabel() == null || "".equals(column.getLabel())) {
                //$NON-NLS-1$
                isDiffGray = true;
            }
        }
        if (table.isDivergency()) {
            isDiffDivergency = true;
        }
    }
    return new boolean[] { isDiffGray, isDiffDivergency, isDiffSyschronize };
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) SqlBuilderRepositoryObject(org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) MetadataColumnRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataColumnRepositoryObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject)

Example 20 with MetadataTable

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

the class MetadataColumnComparator method deleteNouseTables.

public void deleteNouseTables(Connection connection) {
    if (!(connection instanceof DatabaseConnection)) {
        return;
    }
    if (tList == null) {
        return;
    }
    List<MetadataTable> tableList = new ArrayList<MetadataTable>(ConnectionHelper.getTables(connection));
    tableList.removeAll(tList);
    Catalog catalog = (Catalog) ConnectionHelper.getPackage(((DatabaseConnection) connection).getSID(), connection, Catalog.class);
    Schema schema = (Schema) ConnectionHelper.getPackage(((DatabaseConnection) connection).getUiSchema(), connection, Schema.class);
    String c = "";
    String s = "";
    if (catalog != null) {
        c = catalog.getName();
    }
    if (schema != null) {
        s = schema.getName();
    }
    ProjectNodeHelper.removeTablesFromCurrentCatalogOrSchema(c, s, (DatabaseConnection) connection, tableList);
    tList = null;
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) ArrayList(java.util.ArrayList) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Catalog(orgomg.cwm.resource.relational.Catalog)

Aggregations

MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)153 ArrayList (java.util.ArrayList)53 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)51 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)25 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)23 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)22 List (java.util.List)18 Test (org.junit.Test)17 PersistenceException (org.talend.commons.exception.PersistenceException)17 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)15 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)14 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)14 Connection (org.talend.core.model.metadata.builder.connection.Connection)12 RepositoryNode (org.talend.repository.model.RepositoryNode)12 ConnectionItem (org.talend.core.model.properties.ConnectionItem)10 TdColumn (org.talend.cwm.relational.TdColumn)9 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 IRepositoryNode (org.talend.repository.model.IRepositoryNode)9 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)8 HashMap (java.util.HashMap)7