Search in sources :

Example 46 with IMetadataTable

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

the class ConnTextEditPolicy method getDirectEditCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.gef.editpolicies.DirectEditPolicy#getDirectEditCommand(org.eclipse.gef.requests.DirectEditRequest)
     */
protected Command getDirectEditCommand(DirectEditRequest edit) {
    String labelText = (String) edit.getCellEditor().getValue();
    ConnLabelEditPart labelPart = (ConnLabelEditPart) getHost();
    Connection connec = (Connection) getHost().getParent().getModel();
    // if the user enter the same name as the current connection, we just ignore it.
    if (!connec.getName().equalsIgnoreCase(labelText)) {
        if (!ConnectionManager.canRename(connec.getSource(), connec.getTarget(), connec.getLineStyle(), labelText)) {
            //$NON-NLS-1$
            String message = Messages.getString("ConnectionCreateAction.errorCreateConnectionName", labelText);
            MessageDialog.openError(getHost().getViewer().getControl().getShell(), Messages.getString("ConnTextEditPolicy.ErrorTitle"), //$NON-NLS-1$
            message);
            return null;
        } else {
            final IMetadataTable metadataTable = connec.getMetadataTable();
            if (connec.getSource() != null && connec.getSource().getComponent() != null && metadataTable != null) {
                IComponent comp = connec.getSource().getComponent();
                if ("tMap".equals(comp.getName()) && metadataTable.getTableName().endsWith("ErrorReject")) {
                    //$NON-NLS-1$//$NON-NLS-1$
                    MessageDialog.openInformation(getHost().getViewer().getControl().getShell(), "Infor", "Can't rename tMap ErrorReject");
                    return null;
                }
            }
        }
    }
    ChangeConnTextCommand command = new ChangeConnTextCommand((Connection) labelPart.getParent().getModel(), labelText);
    return command;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ChangeConnTextCommand(org.talend.designer.core.ui.editor.cmd.ChangeConnTextCommand) IComponent(org.talend.core.model.components.IComponent)

Example 47 with IMetadataTable

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

the class Connection method orderConnectionsByMetadata.

private void orderConnectionsByMetadata() {
    List<IMetadataTable> tableList = source.getMetadataList();
    List<IConnection> connectionList = (List<IConnection>) source.getOutgoingConnections();
    List<IConnection> tmpList = new ArrayList<IConnection>(connectionList);
    connectionList.clear();
    for (IMetadataTable table : tableList) {
        String tableName = table.getTableName();
        for (IConnection connection : tmpList) {
            if (connection.isActivate() && connection.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA) && connection.getMetadataTable() != null && connection.getMetadataTable().getTableName() != null && connection.getMetadataTable().getTableName().equals(tableName) && connection.getConnectorName().equals(table.getAttachedConnector())) {
                connectionList.add(connection);
            }
        }
    }
    // add connections without metadata
    for (IConnection connection : tmpList) {
        if (!connectionList.contains(connection)) {
            connectionList.add(connection);
        }
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IConnection(org.talend.core.model.process.IConnection)

Example 48 with IMetadataTable

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

the class Connection method initTraceFilterParameters.

/**
     * just keep this method in case we need it again in some day, or we can delete it dirrectly, since it is never
     * used.
     */
private void initTraceFilterParameters() {
    List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
    IMetadataTable metadataTable = this.getMetadataTable();
    if (metadataTable != null) {
        for (IMetadataColumn metaColumn : metadataTable.getListColumns()) {
            Map<String, Object> line = new HashMap<String, Object>();
            line.put(IConnection.TRACE_SCHEMA_COLUMN, metaColumn.getLabel());
            line.put(IConnection.TRACE_SCHEMA_COLUMN_CHECKED, true);
            line.put(IConnection.TRACE_SCHEMA_COLUMN_CONDITION, null);
            values.add(line);
        }
    }
    if (getElementParameter(EParameterName.TRACES_CONNECTION_FILTER.getName()) != null && values != null) {
        getElementParameter(EParameterName.TRACES_CONNECTION_FILTER.getName()).setValue(values);
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) HashMap(java.util.HashMap) Map(java.util.Map)

Example 49 with IMetadataTable

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

the class AbstractElementPropertySectionController method setAllConnectionParameters.

private void setAllConnectionParameters(String typ, IElement element) {
    IElementParameter basePropertyParameter = null;
    for (IElementParameter param : elem.getElementParameters()) {
        if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
            if (param.getRepositoryValue().startsWith("DATABASE")) {
                basePropertyParameter = param;
                break;
            }
        }
    }
    // jobsetting view load the db info from current selected category
    IElementParameter updateBasePropertyParameter = updateBasePropertyParameter();
    if (updateBasePropertyParameter != null && !updateBasePropertyParameter.equals(basePropertyParameter)) {
        basePropertyParameter = updateBasePropertyParameter;
    }
    String type = null;
    ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
    if (typ != null && !typ.equals("")) {
        //$NON-NLS-1$
        type = typ;
    } else {
        //$NON-NLS-1$
        type = getValueFromRepositoryName(element, "TYPE", basePropertyParameter);
    }
    if (type.equals("Oracle") || type.contains("OCLE")) {
        IElementParameter ele = element.getElementParameter("CONNECTION_TYPE");
        if (ele != null) {
            type = (String) ele.getValue();
        } else {
            //$NON-NLS-1$
            type = "ORACLE_SID";
        }
    }
    // Get real hsqldb type
    if (type.equals(EDatabaseTypeName.HSQLDB.name()) && getValueFromRepositoryName(element, "RUNNING_MODE", basePropertyParameter).equals("HSQLDB_INPROGRESS_PERSISTENT")) {
        //$NON-NLS-1$
        type = EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName();
    }
    // If the dbtype has been setted don't reset it again unless the dbtype of connParameters is null.
    if (StringUtils.trimToNull(type) == null && StringUtils.trimToNull(connParameters.getDbType()) == null) {
        type = EDatabaseTypeName.GENERAL_JDBC.getXmlName();
    }
    if (StringUtils.trimToNull(type) != null) {
        connParameters.setDbType(type);
    }
    //$NON-NLS-1$
    String frameWorkKey = getValueFromRepositoryName(element, "FRAMEWORK_TYPE", basePropertyParameter);
    connParameters.setFrameworkType(frameWorkKey);
    String schema = getValueFromRepositoryName(element, EConnectionParameterName.SCHEMA.getName(), basePropertyParameter);
    connParameters.setSchema(schema);
    String userName = getValueFromRepositoryName(element, EConnectionParameterName.USERNAME.getName(), basePropertyParameter);
    connParameters.setUserName(userName);
    String password = getValueFromRepositoryName(element, EConnectionParameterName.PASSWORD.getName(), basePropertyParameter);
    connParameters.setPassword(password);
    String host = getValueFromRepositoryName(element, EConnectionParameterName.SERVER_NAME.getName(), basePropertyParameter);
    connParameters.setHost(host);
    String port = getValueFromRepositoryName(element, EConnectionParameterName.PORT.getName(), basePropertyParameter);
    connParameters.setPort(port);
    boolean https = Boolean.parseBoolean(getValueFromRepositoryName(element, EConnectionParameterName.HTTPS.getName(), basePropertyParameter));
    connParameters.setHttps(https);
    boolean isOracleOCI = type.equals(EDatabaseTypeName.ORACLE_OCI.getXmlName()) || type.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName());
    if (isOracleOCI) {
        String localServiceName = getValueFromRepositoryNameAndParameterName(element, EConnectionParameterName.SID.getName(), EParameterName.LOCAL_SERVICE_NAME.getName());
        // sid is the repository value both for DBName and Local_service_name
        connParameters.setLocalServiceName(localServiceName);
    }
    String datasource = getValueFromRepositoryName(element, EConnectionParameterName.DATASOURCE.getName(), basePropertyParameter);
    connParameters.setDatasource(datasource);
    // qli modified to fix the bug "7364".
    String dbName = getValueFromRepositoryName(element, EConnectionParameterName.SID.getName(), basePropertyParameter);
    if (EDatabaseTypeName.EXASOL.getDisplayName().equals(connParameters.getDbType())) {
        if (dbName.contains("\\\"")) {
            dbName = dbName.replace("\\\"", "");
        }
        dbName = TextUtil.removeQuots(dbName);
    } else if (EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(connParameters.getDbType())) {
        //$NON-NLS-1$
        dbName = "";
    }
    connParameters.setDbName(dbName);
    if (connParameters.getDbType().equals(EDatabaseTypeName.SQLITE.getXmlName()) || connParameters.getDbType().equals(EDatabaseTypeName.ACCESS.getXmlName()) || connParameters.getDbType().equals(EDatabaseTypeName.FIREBIRD.getXmlName())) {
        String file = getValueFromRepositoryName(element, EConnectionParameterName.FILE.getName(), basePropertyParameter);
        connParameters.setFilename(file);
    }
    String dir = getValueFromRepositoryName(element, EConnectionParameterName.DIRECTORY.getName(), basePropertyParameter);
    if (type.equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName())) {
        dir = getValueFromRepositoryName(elem, EConnectionParameterName.DBPATH.getName(), basePropertyParameter);
    }
    connParameters.setDirectory(dir);
    // General jdbc
    String url = getValueFromRepositoryName(element, EConnectionParameterName.URL.getName(), basePropertyParameter);
    if (StringUtils.isEmpty(url)) {
        // to get the Oracle RAC url.
        if (EDatabaseTypeName.ORACLE_CUSTOM.getXmlName().equals(type)) {
            url = getValueFromRepositoryName(element, "RAC_" + EConnectionParameterName.URL.getName(), basePropertyParameter);
        }
    }
    connParameters.setUrl(TalendTextUtils.removeQuotes(url));
    String driverJar = getValueFromRepositoryName(element, EConnectionParameterName.DRIVER_JAR.getName(), basePropertyParameter);
    connParameters.setDriverJar(TalendTextUtils.removeQuotes(driverJar));
    String driverClass = getValueFromRepositoryName(element, EConnectionParameterName.DRIVER_CLASS.getName(), basePropertyParameter);
    String dbVersion = getValueFromRepositoryName(element, "DB_VERSION", basePropertyParameter);
    connParameters.setDbVersion(dbVersion);
    if (EDatabaseVersion4Drivers.VERTICA_5_1.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_6.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_6_1_X.getVersionValue().equals(dbVersion) || EDatabaseVersion4Drivers.VERTICA_7.getVersionValue().equals(dbVersion)) {
        driverClass = EDatabase4DriverClassName.VERTICA2.getDriverClass();
    }
    connParameters.setDriverClass(TalendTextUtils.removeQuotes(driverClass));
    if (driverClass != null && !"".equals(driverClass) && !EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(connParameters.getDbType())) {
        if (driverClass.startsWith("\"") && driverClass.endsWith("\"")) {
            driverClass = TalendTextUtils.removeQuotes(driverClass);
        }
        String dbTypeByClassName = "";
        if (driverJar != null && !"".equals(driverJar)) {
            dbTypeByClassName = extractMeta.getDbTypeByClassNameAndDriverJar(driverClass, driverJar);
        } else {
            dbTypeByClassName = extractMeta.getDbTypeByClassName(driverClass);
        }
        if (dbTypeByClassName != null) {
            connParameters.setDbType(dbTypeByClassName);
        }
    }
    String jdbcProps = getValueFromRepositoryName(element, EConnectionParameterName.PROPERTIES_STRING.getName(), basePropertyParameter);
    connParameters.setJdbcProperties(jdbcProps);
    String realTableName = null;
    if (EmfComponent.REPOSITORY.equals(elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()))) {
        final Object propertyValue = elem.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
        IMetadataTable metadataTable = null;
        String connectionId = propertyValue.toString().split(" - ")[0];
        String tableLabel = propertyValue.toString().split(" - ")[1];
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        Item item = null;
        try {
            IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
            if (repobj != null) {
                Property property = repobj.getProperty();
                if (property != null) {
                    item = property.getItem();
                }
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
        if (item != null && item instanceof ConnectionItem) {
            Connection connection = ((ConnectionItem) item).getConnection();
            for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                if (table.getLabel().equals(tableLabel)) {
                    metadataTable = ConvertionHelper.convert(table);
                    break;
                }
            }
        }
        if (metadataTable != null) {
            realTableName = metadataTable.getTableName();
        }
    }
    connParameters.setSchemaName(QueryUtil.getTableName(elem, connParameters.getMetadataTable(), TalendTextUtils.removeQuotes(schema), type, realTableName));
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ExtractMetaDataUtils(org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 50 with IMetadataTable

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

the class NodeQueryCheckUtil method compareNodeTableColumnsNoFunc.

/**
     * 
     * DOC wzhang Comment method "compareNodeTableColumnsNoFunc".
     * 
     * @param node
     * @param columns
     * @return
     */
private static boolean compareNodeTableColumnsNoFunc(Node node, String columns) {
    if (node.getMetadataList().size() == 0) {
        return true;
    }
    IMetadataTable metaTable = node.getMetadataList().get(0);
    if (metaTable == null || metaTable.getListColumns() == null) {
        return true;
    }
    int originColumnSize = metaTable.getListColumns().size();
    //$NON-NLS-1$
    String[] columnArray = columns.split(",");
    // columns not match
    if (columnArray.length != originColumnSize) {
        return false;
    }
    return true;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable)

Aggregations

IMetadataTable (org.talend.core.model.metadata.IMetadataTable)212 ArrayList (java.util.ArrayList)102 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)81 IElementParameter (org.talend.core.model.process.IElementParameter)67 IConnection (org.talend.core.model.process.IConnection)66 List (java.util.List)56 INode (org.talend.core.model.process.INode)54 Node (org.talend.designer.core.ui.editor.nodes.Node)50 HashMap (java.util.HashMap)48 Map (java.util.Map)39 MetadataTable (org.talend.core.model.metadata.MetadataTable)34 INodeConnector (org.talend.core.model.process.INodeConnector)32 Connection (org.talend.designer.core.ui.editor.connections.Connection)28 Process (org.talend.designer.core.ui.editor.process.Process)25 IComponent (org.talend.core.model.components.IComponent)22 ConnectionItem (org.talend.core.model.properties.ConnectionItem)20 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)18 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)17 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 Point (org.eclipse.swt.graphics.Point)15