Search in sources :

Example 6 with ConnectionItem

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

the class AbstractJobSettingsPage method save.

protected void save() {
    List<String> checkedObjects = new ArrayList<String>();
    List<IRepositoryViewObject> allProcess = null;
    try {
        allProcess = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.PROCESS);
    } catch (PersistenceException e1) {
        ExceptionHandler.process(e1);
    }
    for (IRepositoryViewObject object : allProcess) {
        if (isStatUseProjectSetting(object)) {
            if (!checkedObjects.contains(object.getProperty().getId())) {
                checkedObjects.add(object.getProperty().getId());
                if (!checkedNodeObject.contains(object)) {
                    checkedNodeObject.add(object);
                }
            }
        }
    }
    List<IProcess2> allOpenedProcessList = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(getEditors());
    if (allOpenedProcessList != null) {
        for (int i = 0; i < allOpenedProcessList.size(); i++) {
            if (checkedObjects.contains(allOpenedProcessList.get(i).getProperty().getId())) {
                openedProcessList.add(allOpenedProcessList.get(i));
            }
        }
    }
    //
    final IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(getTaskMessages(), (checkedNodeObject.size()) * 100);
            final Map<String, Set<String>> contextVars = DetectContextVarsUtils.detectByPropertyType(elem, true);
            // must init this
            addContextModel = false;
            if (!contextVars.isEmpty()) {
                // boolean showDialog = false;
                Set<String> contextSet = new HashSet<String>();
                for (String key : contextVars.keySet()) {
                    contextSet = contextVars.get(key);
                    break;
                }
                Connection connection = null;
                IElementParameter ptParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
                if (ptParam != null) {
                    IElementParameter propertyElem = ptParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
                    Object proValue = propertyElem.getValue();
                    if (proValue instanceof String && ((String) proValue).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
                        IElementParameter repositoryElem = ptParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                        String value = (String) repositoryElem.getValue();
                        ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(value);
                        connection = connectionItem.getConnection();
                        if (connection != null && connection.isContextMode()) {
                            addContextModel = true;
                        // ContextItem contextItem =
                        // ContextUtils.getContextItemById(connection.getContextId());
                        // for (IProcess process : openedProcessList) {
                        // Set<String> addedContext =
                        // ConnectionContextHelper.checkAndAddContextVariables(contextItem,
                        // contextSet, process.getContextManager(), false);
                        // if (addedContext != null && !addedContext.isEmpty()) {
                        // showDialog = true;
                        // break;
                        // }
                        // }
                        }
                    }
                }
                if (addContextModel) {
                    // if the context is not existed in job, will add or not.
                    Display disp = Display.getCurrent();
                    if (disp == null) {
                        disp = Display.getDefault();
                    }
                    if (disp != null) {
                        disp.syncExec(new Runnable() {

                            @Override
                            public void run() {
                                showContextAndCheck(contextVars);
                            }
                        });
                    } else {
                        showContextAndCheck(contextVars);
                    }
                }
            }
            monitor.worked(10);
            IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {

                @Override
                public void run(IProgressMonitor monitor) throws CoreException {
                    for (IRepositoryViewObject object : checkedNodeObject) {
                        saveProcess(object, addContextModel, contextVars, monitor);
                    }
                }
            };
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                workspace.run(workspaceRunnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
            monitor.done();
        }
    };
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ArrayList(java.util.ArrayList) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IElementParameter(org.talend.core.model.process.IElementParameter) HashSet(java.util.HashSet) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Display(org.eclipse.swt.widgets.Display)

Example 7 with ConnectionItem

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

the class DynamicComposite method getConnectionItems.

/**
     * DOC qzhang Comment method "getConnectionItems".
     * 
     * @return
     * @throws PersistenceException
     */
private List<ConnectionItem> getConnectionItems() throws PersistenceException {
    List<ConnectionItem> list = new ArrayList<ConnectionItem>();
    IRepositoryView repositoryView = RepositoryManagerHelper.findRepositoryView();
    if (repositoryView != null) {
        TreeViewer viewer = (TreeViewer) repositoryView.getViewer();
        IContentProvider contentProvider = viewer.getContentProvider();
        if (contentProvider instanceof RepositoryContentProvider) {
            RepositoryContentProvider provider = (RepositoryContentProvider) contentProvider;
            RepositoryNode metadataConNode = provider.getRootRepositoryNode(ERepositoryObjectType.METADATA);
            for (IRepositoryNode connectionItem : metadataConNode.getChildren()) {
                if (viewer.isExpandable(connectionItem)) {
                    provider.getChildren(connectionItem);
                }
                for (IRepositoryNode node : connectionItem.getChildren()) {
                    addConnectionItem(viewer, provider, list, (RepositoryNode) node);
                }
            }
        }
    }
    return list;
}
Also used : IContentProvider(org.eclipse.jface.viewers.IContentProvider) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryContentProvider(org.talend.repository.viewer.ui.provider.RepositoryContentProvider) ConnectionItem(org.talend.core.model.properties.ConnectionItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 8 with ConnectionItem

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

the class DynamicComposite method updateRepositoryListExtra.

/**
     * for job settings extra (feature 2710).
     * 
     */
private void updateRepositoryListExtra(IElementParameter param, List<String> repositoryConnectionNameList, List<String> repositoryConnectionValueList, boolean extra) {
    String repositoryValue = param.getParentParameter().getRepositoryValue();
    if (repositoryValue != null) {
        List<String> connectionNamesList = new ArrayList<String>();
        List<String> connectionValuesList = new ArrayList<String>();
        for (String key : repositoryConnectionItemMap.keySet()) {
            ConnectionItem connectionItem = repositoryConnectionItemMap.get(key);
            Connection connection = connectionItem.getConnection();
            String name = //$NON-NLS-1$
            getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel();
            if ((connection instanceof DelimitedFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.DELIMITED.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof PositionalFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.POSITIONAL.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof RegexpFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.REGEX.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof XmlFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.XML.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof FileExcelConnection) && (repositoryValue.equals(ERepositoryCategoryType.EXCEL.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof GenericSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.GENERIC.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof LDAPSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.LDAP.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof SalesforceSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.SALESFORCE.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof WSDLSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.WSDL.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof DatabaseConnection) && (repositoryValue.startsWith(ERepositoryCategoryType.DATABASE.getName()))) {
                //$NON-NLS-1$
                String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
                if (repositoryValue.contains(":")) {
                    // database //$NON-NLS-1$
                    // is
                    // specified
                    // //$NON-NLS-1$
                    //$NON-NLS-1$
                    String neededDbType = repositoryValue.substring(repositoryValue.indexOf(":") + 1);
                    if (neededDbType.equals(currentDbType)) {
                        addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
                    }
                } else {
                    addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
                }
            }
        }
        repositoryConnectionNameList.addAll(connectionNamesList);
        repositoryConnectionValueList.addAll(connectionValuesList);
    } else {
        List<String> connectionValuesList = new ArrayList<String>();
        List<String> connectionStringList = new ArrayList<String>();
        for (String key : repositoryConnectionItemMap.keySet()) {
            ConnectionItem connectionItem = repositoryConnectionItemMap.get(key);
            String name = connectionItem.getProperty().getLabel();
            addOrderDisplayNames(connectionValuesList, connectionStringList, key, name);
        }
        repositoryConnectionNameList.addAll(connectionStringList);
        repositoryConnectionValueList.addAll(connectionValuesList);
    }
    param.setListItemsDisplayName(repositoryConnectionNameList.toArray(new String[0]));
    param.setListItemsValue(repositoryConnectionValueList.toArray(new String[0]));
    if (!repositoryConnectionItemMap.keySet().contains(param.getValue())) {
        if (repositoryConnectionNameList.size() > 0) {
            param.setValue(repositoryConnectionValueList.get(0));
        }
    }
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) ArrayList(java.util.ArrayList) 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) FileExcelConnection(org.talend.core.model.metadata.builder.connection.FileExcelConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) RegexpFileConnection(org.talend.core.model.metadata.builder.connection.RegexpFileConnection) PositionalFileConnection(org.talend.core.model.metadata.builder.connection.PositionalFileConnection) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) GenericSchemaConnection(org.talend.core.model.metadata.builder.connection.GenericSchemaConnection) LDAPSchemaConnection(org.talend.core.model.metadata.builder.connection.LDAPSchemaConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) WSDLSchemaConnection(org.talend.core.model.metadata.builder.connection.WSDLSchemaConnection)

Example 9 with ConnectionItem

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

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

the class MergeTosMetadataMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof ConnectionItem) {
        try {
            URI itemURI = getItemURI(item);
            if (itemURI != null) {
                URI itemResourceURI = getItemResourceURI(itemURI);
                if (metadata400to410 == null) {
                    metadata400to410 = new TosMetadataMigrationFrom400to410();
                }
                Resource migratedResource = metadata400to410.migrate(itemResourceURI.toString(), new NullProgressMonitor());
                HashMap<String, Object> xmlSaveOtions = XML_SAVE_OTIONS_1_0;
                if (migratedResource != null) {
                    // check for DB connection caus we need to setup Schema and Catalog properly
                    EObject content = migratedResource.getContents().get(0);
                    if (content != null && "DatabaseConnection".equals(content.eClass().getName())) {
                        // resource is dynamic EMF so convert it to static model by serialising it and reloading it
                        ByteArrayOutputStream tempStream = new ByteArrayOutputStream();
                        try {
                            // serialize into memory
                            try {
                                migratedResource.save(tempStream, XML_SAVE_OTIONS_1_0);
                            } catch (Exception e) {
                                // try with version 1.1
                                tempStream = new ByteArrayOutputStream();
                                xmlSaveOtions = XML_SAVE_OTIONS_1_1;
                                migratedResource.save(tempStream, xmlSaveOtions);
                            } finally {
                                tempStream.close();
                            }
                            // create a resource to laod the inmemory resource that should be a static EMF model
                            migratedResource = resourceSet.createResource(URI.createURI(//$NON-NLS-1$
                            "http://talend/dummy_static.metadata"));
                            migratedResource.load(new ByteArrayInputStream(tempStream.toByteArray()), xmlSaveOtions);
                            // check that DBConnection is firdt element
                            DatabaseConnection databaseConnection = SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(migratedResource.getContents().get(0));
                            // do not check for null caus DB connection is already check above
                            String databaseType = databaseConnection.getDatabaseType();
                            databaseConnection.setDriverClass(ExtractMetaDataUtils.getInstance().getDriverClassByDbType(databaseType));
                            EDatabaseTypeName currentType = EDatabaseTypeName.getTypeFromDbType(databaseType);
                            EDatabaseSchemaOrCatalogMapping curCatalog = currentType.getCatalogMappingField();
                            EDatabaseSchemaOrCatalogMapping curSchema = currentType.getSchemaMappingField();
                            // all the DB connection are migrated with a Schema by default
                            if (!curCatalog.equals(EDatabaseSchemaOrCatalogMapping.None)) {
                                List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
                                if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
                                    // we need to place the current schemas into a catalogs
                                    ConnectionHelper.removeSchemas(schemas, databaseConnection);
                                    for (Schema schema : schemas) {
                                        // compute the name of the schema and the catalogs
                                        String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
                                        String catalogName = computeCatalogName(databaseConnection, curCatalog);
                                        schema.setName(schemaName);
                                        Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
                                        // catalogs are not in a contained reference
                                        migratedResource.getContents().add(catalog);
                                        catalog.setName(catalogName);
                                        // add the schema to the catalog and the the catalog to the connection
                                        CatalogHelper.addSchemas(Collections.singleton(schema), catalog);
                                        ConnectionHelper.addCatalog(catalog, databaseConnection);
                                    }
                                } else {
                                    // we need to replace the Schemas with a Catalogs
                                    for (Schema schema : schemas) {
                                        // compute the name the catalog
                                        String catalogName = computeCatalogName(databaseConnection, curCatalog);
                                        // use owned elements to get everything regardless of tables or views or
                                        // else
                                        Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
                                        // catalogs are not in a contained reference
                                        migratedResource.getContents().add(catalog);
                                        catalog.setName(catalogName);
                                        catalog.getOwnedElement().addAll(schema.getOwnedElement());
                                        ConnectionHelper.addCatalog(catalog, databaseConnection);
                                        ConnectionHelper.removeSchemas(Collections.singleton(schema), databaseConnection);
                                    }
                                }
                            } else if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
                                List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
                                for (Schema schema : schemas) {
                                    String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
                                    schema.setName(schemaName);
                                }
                            }
                        // else no catalog so we keep the schema as is
                        } catch (Exception e) {
                            // we have an exception finalising the migration but we trap it caus we still try to
                            // save it
                            log.error("Cannot complete merge metadata migration on file:" + itemResourceURI.toString(), e);
                            ExceptionHandler.process(e);
                        } finally {
                            tempStream.close();
                        }
                    }
                    // else not a DB connection so persist
                    OutputStream outputStream = item.eResource().getResourceSet().getURIConverter().createOutputStream(itemResourceURI, null);
                    try {
                        migratedResource.save(outputStream, xmlSaveOtions);
                    } finally {
                        outputStream.close();
                    }
                }
                return ExecutionResult.SUCCESS_WITH_ALERT;
            }
        } catch (ATLCoreException e) {
            log.error(e);
            ExceptionHandler.process(e);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (IOException e) {
            log.error(e);
            ExceptionHandler.process(e);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } finally {
            resourceSet.getResources().clear();
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ConnectionItem(org.talend.core.model.properties.ConnectionItem) EDatabaseSchemaOrCatalogMapping(org.talend.core.model.metadata.builder.database.EDatabaseSchemaOrCatalogMapping) Schema(orgomg.cwm.resource.relational.Schema) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) ATLCoreException(org.eclipse.m2m.atl.core.ATLCoreException) IOException(java.io.IOException) Catalog(orgomg.cwm.resource.relational.Catalog) ATLCoreException(org.eclipse.m2m.atl.core.ATLCoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) TosMetadataMigrationFrom400to410(org.talend.model.migration.TosMetadataMigrationFrom400to410) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName)

Aggregations

ConnectionItem (org.talend.core.model.properties.ConnectionItem)79 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)44 PersistenceException (org.talend.commons.exception.PersistenceException)38 Connection (org.talend.core.model.metadata.builder.connection.Connection)38 IElementParameter (org.talend.core.model.process.IElementParameter)38 Item (org.talend.core.model.properties.Item)34 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)31 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)27 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)20 ArrayList (java.util.ArrayList)19 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)19 Property (org.talend.core.model.properties.Property)17 ChangeValuesFromRepository (org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository)17 RepositoryNode (org.talend.repository.model.RepositoryNode)17 INode (org.talend.core.model.process.INode)15 Node (org.talend.designer.core.ui.editor.nodes.Node)15 List (java.util.List)14 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)14 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)13 ProcessItem (org.talend.core.model.properties.ProcessItem)12