Search in sources :

Example 6 with Connection

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

the class DynamicComposite method getRepositoryAliasName.

// /**
// * ftang Comment method "updateContextList".
// */
// public void updateContextList(IElementParameter jobParam) {
// if (jobParam == null || jobParam.getField() != EParameterFieldType.PROCESS_TYPE) {
// return;
// }
// // for context type
// List<String> contextNameList = new ArrayList<String>();
// List<String> contextValueList = new ArrayList<String>();
//
// IElementParameter jobNameParam =
// jobParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
//
// Item item = jobNameParam.getLinkedRepositoryItem();
// final String jobValue = (String) jobNameParam.getValue();
// if (jobValue != null) {
// if (item == null || (item != null && !item.getProperty().getId().equals(jobValue))) {
// item = ProcessorUtilities.getProcessItemById(jobValue);
// }
// } else {
// item = null;
// }
// if (item != null) {
// if (item instanceof ProcessItem) {
// for (Object o : ((ProcessItem) item).getProcess().getContext()) {
// if (o instanceof ContextType) {
// ContextType context = (ContextType) o;
// contextNameList.add(context.getName());
// contextValueList.add(context.getName());
// }
// }
// }
// jobNameParam.setLabelFromRepository(item.getProperty().getLabel());
// }
// jobNameParam.setLinkedRepositoryItem(item);
// // set default context
// String defalutValue = null;
// if (item != null && item instanceof ProcessItem) {
// defalutValue = ((ProcessItem) item).getProcess().getDefaultContext();
// }
// setProcessTypeRelatedValues(jobParam, contextNameList, contextValueList,
// EParameterName.PROCESS_TYPE_CONTEXT.getName(),
// defalutValue);
//
// // for version type
// List<String> versionNameList = new ArrayList<String>();
// List<String> versionValueList = new ArrayList<String>();
//
// if (item != null) { // existed item
// List<IRepositoryObject> allVersion = ProcessorUtilities.getAllRepositoryObjectById(item.getProperty().getId());
// for (IRepositoryObject obj : allVersion) {
// String version = obj.getVersion();
// versionNameList.add(version);
// versionValueList.add(version);
// }
// }
// setProcessTypeRelatedValues(jobParam, versionNameList, versionValueList,
// EParameterName.PROCESS_TYPE_VERSION.getName(),
// null);
//
// }
//
// /**
// *
// * ggu Comment method "setProcessTypeRelatedValues".
// *
// *
// */
// private void setProcessTypeRelatedValues(IElementParameter parentParam, List<String> nameList, List<String>
// valueList,
// final String childName, final String defaultValue) {
// if (parentParam == null || childName == null) {
// return;
// }
// final String fullChildName = parentParam.getName() + ":" + childName;
// IElementParameter childParam = parentParam.getChildParameters().get(childName);
// if (nameList == null) {
// childParam.setListItemsDisplayName(new String[0]);
// } else {
// childParam.setListItemsDisplayName(nameList.toArray(new String[0]));
// }
// if (valueList == null) {
// childParam.setListItemsValue(new String[0]);
// } else {
// childParam.setListItemsValue(valueList.toArray(new String[0]));
// }
// // set default value
// if (defaultValue != null) {
// childParam.setValue(defaultValue);
// }
// if (elem != null) {
// if (valueList != null && !valueList.contains(childParam.getValue())) {
// if (nameList != null && nameList.size() > 0) {
// elem.setPropertyValue(fullChildName, valueList.get(valueList.size() - 1));
// }
// } else {
// // force to store the value again to activate the code
// // generation in Node.setPropertyValue
// elem.setPropertyValue(fullChildName, childParam.getValue());
// }
// }
// }
public String getRepositoryAliasName(ConnectionItem connectionItem) {
    ERepositoryObjectType repositoryObjectType = ERepositoryObjectType.getItemType(connectionItem);
    String aliasName = repositoryObjectType.getAlias();
    Connection connection = connectionItem.getConnection();
    if (connection instanceof DatabaseConnection) {
        //$NON-NLS-1$
        String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
        //$NON-NLS-1$ //$NON-NLS-2$
        aliasName += " (" + currentDbType + ")";
    }
    return aliasName;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) WSDLSchemaConnection(org.talend.core.model.metadata.builder.connection.WSDLSchemaConnection) GenericSchemaConnection(org.talend.core.model.metadata.builder.connection.GenericSchemaConnection) PositionalFileConnection(org.talend.core.model.metadata.builder.connection.PositionalFileConnection) RegexpFileConnection(org.talend.core.model.metadata.builder.connection.RegexpFileConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) LDAPSchemaConnection(org.talend.core.model.metadata.builder.connection.LDAPSchemaConnection) FileExcelConnection(org.talend.core.model.metadata.builder.connection.FileExcelConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 7 with Connection

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

the class MultipleThreadDynamicComposite method updateRepositoryList.

public void updateRepositoryList() {
    ProgressDialog progressDialog = new ProgressDialog(this.getShell(), 1000) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitorWrap = new EventLoopProgressMonitor(monitor);
            IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
            List<IRepositoryViewObject> repositoryObjects = getAllRepositoryMetadata();
            // + elem.getElementParameters().size();
            int total = repositoryObjects.size();
            //$NON-NLS-1$
            monitorWrap.beginTask(Messages.getString("MultipleThreadDynamicComposite.gatherInformation"), total);
            IElementParameter propertyParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, section);
            String repositoryValue = null;
            if (propertyParam != null) {
                repositoryValue = propertyParam.getRepositoryValue();
            }
            if (repositoryObjects != null && (repositoryObjects.size() != 0)) {
                tableIdAndDbTypeMap.clear();
                tableIdAndDbSchemaMap.clear();
                for (IRepositoryViewObject curObject : repositoryObjects) {
                    Item item = curObject.getProperty().getItem();
                    if (item instanceof ConnectionItem) {
                        ConnectionItem connectionItem = (ConnectionItem) item;
                        Connection connection = connectionItem.getConnection();
                        if (connection == null || connection.isReadOnly()) {
                            continue;
                        }
                        for (Object tableObj : ConnectionHelper.getTables(connection)) {
                            org.talend.core.model.metadata.builder.connection.MetadataTable table;
                            table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
                            if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
                                if (!factory.isDeleted(table)) {
                                    IMetadataTable newTable = ConvertionHelper.convert(table);
                                    // newTable);
                                    if (connection instanceof DatabaseConnection) {
                                        String dbType = ((DatabaseConnection) connection).getDatabaseType();
                                        String schema = ((DatabaseConnection) connection).getUiSchema();
                                        tableIdAndDbTypeMap.put(newTable.getId(), dbType);
                                        if (schema != null && !schema.equals("")) {
                                            //$NON-NLS-1$
                                            tableIdAndDbSchemaMap.put(newTable.getId(), schema);
                                        }
                                    }
                                }
                            }
                        }
                        monitorWrap.worked(1);
                    }
                    // hywang add for feature 6484
                    if (item instanceof FileItem) {
                        FileItem FileItem = (FileItem) item;
                        if (repositoryValue != null) {
                            if (repositoryValue.equals("RULE")) {
                                //$NON-NLS-1$
                                repositoryFileItemMap.put(FileItem.getProperty().getId(), FileItem);
                            }
                        }
                        monitorWrap.worked(1);
                    }
                    if (item instanceof LinkRulesItem) {
                        LinkRulesItem linkItem = (LinkRulesItem) item;
                        if (repositoryValue != null) {
                            if (repositoryValue.equals("RULE")) {
                                //$NON-NLS-1$
                                repositoryLinkRulesItemMap.put(linkItem.getProperty().getId(), linkItem);
                            }
                        }
                        monitorWrap.worked(1);
                    }
                }
            }
            monitorWrap.done();
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
        return;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return;
    }
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) FileItem(org.talend.core.model.properties.FileItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 8 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 9 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 10 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