Search in sources :

Example 6 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class SQLBuilderDialog method deleteNoUseTable.

private void deleteNoUseTable() {
    // add for bug TDI-17097
    connection = (DatabaseConnection) SQLBuilderRepositoryNodeManager.getItem(SQLBuilderRepositoryNodeManager.getRoot(nodeInEditor)).getConnection();
    if (SQLBuilderRepositoryNodeManager.tList instanceof List) {
        if (SQLBuilderRepositoryNodeManager.tList.size() == 0) {
            SQLBuilderRepositoryNodeManager.tList.addAll(ConnectionHelper.getTables(connection));
        }
    } else {
        SQLBuilderRepositoryNodeManager.tList = new ArrayList<MetadataTable>();
        SQLBuilderRepositoryNodeManager.tList.addAll(ConnectionHelper.getTables(connection));
    }
    if (SQLBuilderRepositoryNodeManager.tList == null || SQLBuilderRepositoryNodeManager.tList.size() == 0) {
        return;
    }
    // changed for bug TDI-19892
    if (node == null) {
        SQLBuilderRepositoryNodeManager.tList = null;
        return;
    }
    IRepositoryViewObject repositoryObject = node.getObject();
    Item item = repositoryObject.getProperty().getItem();
    if (item instanceof DatabaseConnectionItem) {
        manager.deleteNouseTables(((DatabaseConnectionItem) item).getConnection());
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) CTabItem(org.eclipse.swt.custom.CTabItem) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 7 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem 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 8 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class MetadataColumnComparator method getItem.

/**
     * method "getItem" get DatabaseConnectionItem by current RepositoryNode .
     * 
     * @param newNode current RepositoryNode
     * @return DatabaseConnectionItem : item current node.
     */
public static DatabaseConnectionItem getItem(RepositoryNode newNode) {
    IRepositoryViewObject repositoryObject = newNode.getObject();
    DatabaseConnectionItem item = (DatabaseConnectionItem) repositoryObject.getProperty().getItem();
    return item;
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 9 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class MetadataColumnComparator method saveEMFQuery.

/**
     * method "saveQuery" use save inputed Query to EMF's xml File.
     * 
     * @param repositoryNode current RepositoryNode
     * @param query need to save Query
     */
private void saveEMFQuery(String id, Query query, String oldQuery) {
    DatabaseConnectionItem item = getEMFItem(id);
    if (query != null) {
        Connection connection = item.getConnection();
        QueriesConnection queriesConnection = connection.getQueries();
        if (queriesConnection == null) {
            queriesConnection = ConnectionFactory.eINSTANCE.createQueriesConnection();
            queriesConnection.setConnection(connection);
            connection.setQueries(queriesConnection);
        }
        boolean isModify = false;
        List<Query> queries = queriesConnection.getQuery();
        for (Query query2 : queries) {
            if (oldQuery != null && (query2.getLabel().equals(oldQuery)) || query2.getLabel().equals(query.getLabel())) {
                // reset new label, if changed
                query2.setLabel(query.getLabel());
                query2.setComment(query.getComment());
                query2.setValue(query.getValue());
                // add by hywang
                query2.setContextMode(query.isContextMode());
                // assign id to old query without id
                assignQueryId(query2, queriesConnection);
                isModify = true;
            }
        }
        if (!isModify) {
            // assign id to new query
            assignQueryId(query, queriesConnection);
            queriesConnection.getQuery().add(query);
        }
    }
    deleteNouseTables(item.getConnection());
    saveMetaData(item);
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) Query(org.talend.core.model.metadata.builder.connection.Query) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 10 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class MetadataColumnComparator method deleteQueries.

/**
     * method "deleteQueries" use delete Queries.
     * 
     * @param repositoryNode databaseConnection's RepositoryNode
     * @param queries need to deleted Queries
     */
public void deleteQueries(RepositoryNode repositoryNode, List<Query> queries) {
    DatabaseConnectionItem item = getEMFItem(repositoryNode.getObject().getId());
    for (Query query : queries) {
        ProxyRepositoryFactory.getInstance().setSubItemDeleted(item, query, true);
    }
    saveMetaData(item);
}
Also used : Query(org.talend.core.model.metadata.builder.connection.Query) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)50 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)40 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)23 PersistenceException (org.talend.commons.exception.PersistenceException)16 Connection (org.talend.core.model.metadata.builder.connection.Connection)13 Item (org.talend.core.model.properties.Item)13 ConnectionItem (org.talend.core.model.properties.ConnectionItem)12 ArrayList (java.util.ArrayList)11 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)11 IElementParameter (org.talend.core.model.process.IElementParameter)10 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)9 Query (org.talend.core.model.metadata.builder.connection.Query)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 INode (org.talend.core.model.process.INode)7 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)6 ContextItem (org.talend.core.model.properties.ContextItem)6 QueryRepositoryObject (org.talend.core.repository.model.repositoryObject.QueryRepositoryObject)6 Node (org.talend.designer.core.ui.editor.nodes.Node)6 List (java.util.List)5 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)5