Search in sources :

Example 11 with Connection

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

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

the class ESBService method copyJobForService.

private Item copyJobForService(final Item item, final IPath path, final String newName) {
    try {
        final Item newItem = ProxyRepositoryFactory.getInstance().copy(item, path, newName);
        if (newItem instanceof ConnectionItem) {
            Connection connection = ((ConnectionItem) newItem).getConnection();
            if (connection != null) {
                connection.setLabel(newName);
                connection.setName(newName);
                connection.getSupplierDependency().clear();
            }
        }
        ProxyRepositoryFactory.getInstance().save(newItem);
        return newItem;
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    } catch (BusinessException e) {
        ExceptionHandler.process(e);
    }
    return null;
}
Also used : Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ProcessItem(org.talend.core.model.properties.ProcessItem) BusinessException(org.talend.commons.exception.BusinessException) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 13 with Connection

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

the class JSONConnectionContextHelper method setPropertiesForContextMode.

public static void setPropertiesForContextMode(ConnectionItem connectionItem, ContextItem contextItem, Set<IConnParamName> paramSet, Map<String, String> map) {
    if (connectionItem == null || contextItem == null) {
        return;
    }
    final String label = contextItem.getProperty().getLabel();
    Connection conn = connectionItem.getConnection();
    if (conn instanceof JSONFileConnection) {
        setJSONFilePropertiesForContextMode(label, (JSONFileConnection) conn);
    }
    // set connection for context mode
    connectionItem.getConnection().setContextMode(true);
    connectionItem.getConnection().setContextId(contextItem.getProperty().getId());
    connectionItem.getConnection().setContextName(contextItem.getDefaultContext());
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection)

Example 14 with Connection

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

the class JSONConnectionContextHelper method revertPropertiesForContextMode.

public static void revertPropertiesForContextMode(ConnectionItem connItem, ContextType contextType) {
    if (connItem == null || contextType == null) {
        return;
    }
    Connection conn = connItem.getConnection();
    if (conn instanceof JSONFileConnection) {
        revertJSONFilePropertiesForContextMode((JSONFileConnection) conn, contextType);
    }
    // set connection for context mode
    conn.setContextMode(false);
    conn.setContextId(EMPTY);
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection)

Example 15 with Connection

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

the class FillParametersForDatabaseConnectionMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof DatabaseConnectionItem) {
        DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
        Connection connection = dbItem.getConnection();
        DatabaseConnection dbconn = (DatabaseConnection) connection;
        EList<orgomg.cwm.objectmodel.core.Package> pkgs = dbconn.getDataPackage();
        // get all tdtables and set sqldatatype
        fillParametersForColumns(pkgs);
        dbconn.setName(dbItem.getProperty().getLabel());
        try {
            factory.save(dbItem, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

Connection (org.talend.core.model.metadata.builder.connection.Connection)74 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)42 ConnectionItem (org.talend.core.model.properties.ConnectionItem)39 PersistenceException (org.talend.commons.exception.PersistenceException)28 IElementParameter (org.talend.core.model.process.IElementParameter)27 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)26 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)20 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)19 Item (org.talend.core.model.properties.Item)19 ArrayList (java.util.ArrayList)14 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)14 Property (org.talend.core.model.properties.Property)14 ChangeValuesFromRepository (org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository)13 QueriesConnection (org.talend.core.model.metadata.builder.connection.QueriesConnection)12 XmlFileConnection (org.talend.core.model.metadata.builder.connection.XmlFileConnection)9 IConnection (org.talend.core.model.process.IConnection)9 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)8 IDynamicProperty (org.talend.core.ui.properties.tab.IDynamicProperty)8 List (java.util.List)7 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)7