Search in sources :

Example 41 with DatabaseConnection

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

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

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

the class TOPRepositoryServiceTest method testRemoveAliasInSQLExplorer.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.service.TOPRepositoryService#removeAliasInSQLExplorer(org.talend.repository.model.IRepositoryNode)}
 * .
 */
public void testRemoveAliasInSQLExplorer() {
    IRepositoryNode child = mock(IRepositoryNode.class);
    IRepositoryViewObject obj = mock(IRepositoryViewObject.class);
    when(child.getObject()).thenReturn(obj);
    Property pro = mock(Property.class);
    when(obj.getProperty()).thenReturn(pro);
    ConnectionItem item = mock(ConnectionItem.class);
    when(pro.getItem()).thenReturn(item);
    MDMConnection mdm = mock(MDMConnection.class);
    DelimitedFileConnection dfile = mock(DelimitedFileConnection.class);
    DatabaseConnection dbc = mock(DatabaseConnection.class);
    when(item.getConnection()).thenReturn(dbc).thenReturn(dfile).thenReturn(mdm);
    List<ModelElement> dependencyClients = new ArrayList<ModelElement>();
    ModelElement m1 = mock(ModelElement.class);
    dependencyClients.add(m1);
    PowerMockito.mockStatic(EObjectHelper.class);
    when(EObjectHelper.getDependencyClients(dbc)).thenReturn(dependencyClients);
    when(EObjectHelper.getDependencyClients(mdm)).thenReturn(dependencyClients);
    when(EObjectHelper.getDependencyClients(dfile)).thenReturn(dependencyClients);
    Assert.assertFalse(tdqRepService.removeAliasInSQLExplorer(child));
    Assert.assertFalse(tdqRepService.removeAliasInSQLExplorer(child));
    Assert.assertFalse(tdqRepService.removeAliasInSQLExplorer(child));
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Property(org.talend.core.model.properties.Property) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection)

Example 44 with DatabaseConnection

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

the class ExportConnectionToTOSActionRealTest method createConnectionItem.

private static DatabaseConnectionItem createConnectionItem(String name, IFolder folder, Boolean isDelete, boolean isSave) {
    IPath createPath = Path.EMPTY;
    if (folder != null) {
        createPath = new Path(folder.getFullPath().lastSegment());
    }
    // connection
    DatabaseConnection createConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    createConnection.setName(name);
    createConnection.setLabel(name);
    // $NON-NLS-1$
    createConnection.setUsername("UserName");
    // $NON-NLS-1$
    createConnection.setRawPassword("Password");
    // $NON-NLS-1$
    createConnection.setURL("URL");
    createConnection.setDatabaseType(EDatabaseTypeName.MYSQL.getXmlName());
    createConnection.setContextMode(true);
    // ~connection
    DatabaseConnectionItem createDatabaseConnectionItem = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
    org.talend.core.model.properties.Property createDatabaseConnectionProperty = PropertiesFactory.eINSTANCE.createProperty();
    createDatabaseConnectionProperty.setId(EcoreUtil.generateUUID());
    createDatabaseConnectionProperty.setItem(createDatabaseConnectionItem);
    createDatabaseConnectionProperty.setLabel(createConnection.getName());
    createDatabaseConnectionItem.setProperty(createDatabaseConnectionProperty);
    createDatabaseConnectionItem.setConnection(createConnection);
    try {
        if (isSave) {
            factory.create(createDatabaseConnectionItem, createPath, false);
        }
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    return createDatabaseConnectionItem;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 45 with DatabaseConnection

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

the class ExportConnectionToTOSActionRealTest method testRuncase3.

/**
 * Test method for {@link org.talend.dataprofiler.core.ui.action.actions.ExportConnectionToTOSAction#run()}.
 *
 * @throws PersistenceException
 *
 * case3: create new connection from only schema case
 */
@Test
public void testRuncase3() throws PersistenceException {
    // connectionNode
    DatabaseConnectionItem createOldConnectionItem = createConnectionItem("ExportConnectionToTOSActionRealTest3", null, false, // $NON-NLS-1$
    true);
    DatabaseConnection oldConnection = ((DatabaseConnection) createOldConnectionItem.getConnection());
    // $NON-NLS-1$
    oldConnection.setSID("orcl");
    initSchemaList(createOldConnectionItem);
    IRepositoryViewObject createdByUs = factory.getLastVersion(createOldConnectionItem.getProperty().getId());
    Assert.assertTrue(createdByUs != null);
    // $NON-NLS-1$
    Assert.assertTrue("ExportConnectionToTOSActionRealTest3".equals(createdByUs.getLabel()));
    // ~connectionNode
    List<Package> packageList = new ArrayList<Package>();
    packageList.add(schema1);
    createAction = PowerMockito.spy(new ExportConnectionToTOSAction(packageList));
    PowerMockito.doNothing().when(createAction).openSuccessInformation();
    PowerMockito.doNothing().when(createAction).refreshViewerAndNode();
    createAction.run();
    IRepositoryViewObject createByAction = getNewCreatedConnectionByName(createOldConnectionItem.getConnection().getLabel() + "_" + // $NON-NLS-1$
    schema1.getName());
    DatabaseConnectionItem item = (DatabaseConnectionItem) createByAction.getProperty().getItem();
    DatabaseConnection newConnection = (DatabaseConnection) item.getConnection();
    Assert.assertTrue(newConnection.getSID().equalsIgnoreCase(oldConnection.getSID()));
    Assert.assertTrue(newConnection.getUiSchema().equalsIgnoreCase(schema1.getName()));
    Schema exportedSchema = SchemaHelper.getSchema(newConnection, schema1.getName());
    Assert.assertTrue(exportedSchema != null);
    Assert.assertTrue(newConnection.getLabel().equals(// $NON-NLS-1$
    createOldConnectionItem.getConnection().getLabel() + "_" + schema1.getName()));
    Assert.assertTrue(exportedSchema != schema1);
    factory.deleteObjectPhysical(createByAction);
    factory.deleteObjectPhysical(createdByUs);
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Package(orgomg.cwm.objectmodel.core.Package) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Test(org.junit.Test)

Aggregations

DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)211 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)66 Connection (org.talend.core.model.metadata.builder.connection.Connection)53 ConnectionItem (org.talend.core.model.properties.ConnectionItem)42 ArrayList (java.util.ArrayList)41 PersistenceException (org.talend.commons.exception.PersistenceException)41 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)39 Test (org.junit.Test)33 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)30 Property (org.talend.core.model.properties.Property)30 Item (org.talend.core.model.properties.Item)26 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)20 IElementParameter (org.talend.core.model.process.IElementParameter)19 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)18 RepositoryNode (org.talend.repository.model.RepositoryNode)18 SQLException (java.sql.SQLException)17 TdTable (org.talend.cwm.relational.TdTable)17 Catalog (orgomg.cwm.resource.relational.Catalog)17 List (java.util.List)15 ReturnCode (org.talend.utils.sugars.ReturnCode)14