Search in sources :

Example 11 with EDatabaseTypeName

use of org.talend.core.database.EDatabaseTypeName in project tdi-studio-se by Talend.

the class PropertyTypeController method updateDBType.

// see bug 0004305
private void updateDBType(CompoundCommand compoundCommand, Connection repositoryConnection) {
    if (repositoryConnection == null) {
        return;
    }
    if (!(repositoryConnection instanceof DatabaseConnection)) {
        return;
    }
    //$NON-NLS-1$
    final String property = "DBTYPE";
    if (elem.getElementParameter(property) == null) {
        return;
    }
    String currentDbType = ((DatabaseConnection) repositoryConnection).getDatabaseType();
    EDatabaseTypeName typeName = EDatabaseTypeName.getTypeFromDbType(currentDbType);
    Command command = new PropertyChangeCommand(elem, property, typeName.getXMLType());
    compoundCommand.add(command);
}
Also used : PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName)

Example 12 with EDatabaseTypeName

use of org.talend.core.database.EDatabaseTypeName in project tdi-studio-se by Talend.

the class JobSettingsManager method createExtraContextLoadNodes.

public static List<DataNode> createExtraContextLoadNodes(IProcess process) {
    List<DataNode> nodeList = new ArrayList<DataNode>();
    String paramName = EParameterName.IMPLICIT_TCONTEXTLOAD.getName();
    boolean useContextLoad = ((Boolean) process.getElementParameter(paramName).getValue()) && process.getElementParameter(paramName).isShow(process.getElementParameters());
    if (!useContextLoad) {
        // not used
        return Collections.emptyList();
    }
    // file
    paramName = JobSettingsConstants.getExtraParameterName(EParameterName.FROM_FILE_FLAG.getName());
    boolean fileFlag = ((Boolean) process.getElementParameter(paramName).getValue()) && process.getElementParameter(paramName).isShow(process.getElementParameters());
    // db
    String dbInput = null;
    paramName = JobSettingsConstants.getExtraParameterName(EParameterName.FROM_DATABASE_FLAG.getName());
    boolean dbFlag = ((Boolean) process.getElementParameter(paramName).getValue()) && process.getElementParameter(paramName).isShow(process.getElementParameters());
    if (!dbFlag) {
        dbInput = null;
    } else {
        dbInput = (String) process.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName())).getValue();
        dbInput = OracleComponentHelper.filterOracleComponentName(dbInput);
        if (dbInput == null || dbInput.equals("")) {
            //$NON-NLS-1$
            dbInput = null;
            dbFlag = false;
        }
    }
    if (!fileFlag && !dbFlag) {
        // not used
        return Collections.emptyList();
    }
    IComponent tContextLoadComponent = new JobContextLoadComponent(fileFlag, dbInput);
    //$NON-NLS-1$
    final String uniqueName = "Implicit_Context";
    DataNode tContextLoadNode = new DataNode(tContextLoadComponent, uniqueName);
    tContextLoadNode.setStart(true);
    tContextLoadNode.setSubProcessStart(true);
    tContextLoadNode.setActivate(true);
    IMetadataTable table = getSchemaTablefromComponent(JobContextLoadComponent.CONTEXTLOAD_COMPONENT, uniqueName);
    if (table != null) {
        tContextLoadNode.getMetadataList().clear();
        tContextLoadNode.getMetadataList().add(table);
    }
    // set parameters
    IElementParameter param = null;
    if (fileFlag) {
        // is file
        String inputFile = (String) process.getElementParameter(EParameterName.IMPLICIT_TCONTEXTLOAD_FILE.getName()).getValue();
        String fileSparator = (String) process.getElementParameter(EParameterName.FIELDSEPARATOR.getName()).getValue();
        tContextLoadNode.getElementParameter(EParameterName.IMPLICIT_TCONTEXTLOAD_FILE.getName()).setValue(inputFile);
        String regex = FileSeparator.getSeparatorsRegexp(TalendQuoteUtils.removeQuotes(fileSparator));
        tContextLoadNode.getElementParameter(JobSettingsConstants.IMPLICIT_TCONTEXTLOAD_REGEX).setValue(regex);
    } else {
        // is db
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.URL.getName());
        param = process.getElementParameter(paramName);
        if (param != null) {
            tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
        }
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.DRIVER_JAR.getName());
        param = process.getElementParameter(paramName);
        if (param != null) {
            tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
        }
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.DRIVER_CLASS.getName());
        param = process.getElementParameter(paramName);
        if (param != null) {
            tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
        }
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.HOST.getName());
        tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.PORT.getName());
        tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.DBNAME.getName());
        tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.DB_VERSION.getName());
        tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTIES.getName());
        param = process.getElementParameter(paramName);
        if (param != null) {
            tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
        }
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.SCHEMA_DB.getName());
        param = process.getElementParameter(paramName);
        if (param != null) {
            tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
        }
        String schema = (String) process.getElementParameter(paramName).getValue();
        if (schema != null) {
            schema = TalendTextUtils.removeQuotes(schema);
        }
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.USER.getName());
        tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.PASS.getName());
        tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.CONNECTION_TYPE.getName());
        tContextLoadNode.getElementParameter(paramName).setValue(OracleComponentHelper.filterOracleConnectionType((String) process.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName())).getValue()));
        paramName = JobSettingsConstants.getExtraParameterName(EParameterName.DBTABLE.getName());
        tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
        // query
        String dbTableName = (String) process.getElementParameter(paramName).getValue();
        String realTableName = getCurrentTableName(dbTableName);
        if (realTableName == null) {
            realTableName = QueryUtil.DEFAULT_TABLE_NAME;
        }
        String dbType = getDatabaseTypeFromParameter(process);
        if (dbType != null) {
            // TDI-18161:the SQL script's syntax is not right because of the implicit context of General JDBC.
            if (dbType.equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
                dbType = findRealDbTypeForJDBC(process, dbType);
            }
            EDatabaseTypeName dbTypeName = EDatabaseTypeName.getTypeFromDbType(dbType);
            if (EDatabaseTypeName.ORACLE_OCI.equals(dbTypeName) || EDatabaseTypeName.ORACLEFORSID.equals(dbTypeName) || EDatabaseTypeName.ORACLESN.equals(dbTypeName)) {
                for (IMetadataColumn column : table.getListColumns()) {
                    column.setOriginalDbColumnName(column.getOriginalDbColumnName().toUpperCase());
                }
            }
            if (realTableName.startsWith(TalendTextUtils.QUOTATION_MARK) && realTableName.endsWith(TalendTextUtils.QUOTATION_MARK) && realTableName.length() > 2) {
                realTableName = realTableName.substring(1, realTableName.length() - 1);
            }
            String query = TalendTextUtils.addSQLQuotes(QueryUtil.generateNewQuery(null, table, dbType, schema, realTableName));
            paramName = JobSettingsConstants.getExtraParameterName(EParameterName.QUERY_CONDITION.getName());
            String conditionStatement = (String) process.getElementParameter(paramName).getValue();
            if (conditionStatement != null) {
                String tmp = TalendTextUtils.removeQuotes(conditionStatement);
                if (!"".equals(tmp)) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    query = query + CONNECTOR + QUOTE + " WHERE " + QUOTE + CONNECTOR + conditionStatement;
                }
            }
            final String quoteByDBType = TalendTextUtils.getQuoteByDBType(dbType, false);
            if (dbTypeName == EDatabaseTypeName.MSSQL) {
                query = //$NON-NLS-1$
                query.replaceAll(//$NON-NLS-1$
                "(?i)\bkey\b", //$NON-NLS-1$  //$NON-NLS-2$
                "\\\\" + quoteByDBType + "key\\\\" + quoteByDBType);
            }
            tContextLoadNode.getElementParameter(JobSettingsConstants.QUERY).setValue(query);
        }
    }
    // tContextLoad
    paramName = EParameterName.LOAD_NEW_VARIABLE.getName();
    param = process.getElementParameter(paramName);
    if (param != null) {
        tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
    }
    paramName = EParameterName.NOT_LOAD_OLD_VARIABLE.getName();
    param = process.getElementParameter(paramName);
    if (param != null) {
        tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
    }
    paramName = EParameterName.PRINT_OPERATIONS.getName();
    tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
    paramName = EParameterName.DISABLE_ERROR.getName();
    param = process.getElementParameter(paramName);
    if (param != null) {
        tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
    }
    paramName = EParameterName.DISABLE_INFO.getName();
    param = process.getElementParameter(paramName);
    if (param != null) {
        tContextLoadNode.getElementParameter(paramName).setValue(param.getValue());
    }
    paramName = EParameterName.DISABLE_WARNINGS.getName();
    tContextLoadNode.getElementParameter(paramName).setValue(process.getElementParameter(paramName).getValue());
    tContextLoadNode.setProcess(process);
    nodeList.add(tContextLoadNode);
    return nodeList;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) DataNode(org.talend.designer.core.model.process.DataNode) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 13 with EDatabaseTypeName

use of org.talend.core.database.EDatabaseTypeName in project tdq-studio-se by Talend.

the class DQStructureComparer method getRefreshedDataProvider.

public static TypedReturnCode<Connection> getRefreshedDataProvider(Connection prevDataProvider) {
    // ADD xqliu 2010-03-29 bug 11951
    TypedReturnCode<Connection> returnProvider = new TypedReturnCode<Connection>();
    // ~11951
    // MOD by zshen 2012-07-05 for bug 5074 remove convert about DatabaseParameter instead
    // Connection->DatabaseParameter->ImetadataConnection into Connection->ImetadataConnection
    IMetadataConnection metadataConnection = ConvertionHelper.convert((DatabaseConnection) prevDataProvider, false, prevDataProvider.getContextName());
    Connection copyedConnection = null;
    EDatabaseTypeName currentEDatabaseType = EDatabaseTypeName.getTypeFromDbType(metadataConnection.getDbType());
    if (currentEDatabaseType != null) {
        MetadataFillFactory dbInstance = MetadataFillFactory.getDBInstance(metadataConnection);
        TypedReturnCode<?> trc = (TypedReturnCode<?>) dbInstance.createConnection(metadataConnection);
        Object sqlConnObject = trc.getObject();
        DatabaseMetaData dbJDBCMetadata = null;
        if (trc.isOk() && sqlConnObject instanceof java.sql.Connection) {
            java.sql.Connection sqlConn = (java.sql.Connection) sqlConnObject;
            // MOD sizhaoliu 2012-5-21 TDQ-4884 reload structure issue
            // dbJDBCMetadata = org.talend.utils.sql.ConnectionUtils.getConnectionMetadata(sqlConn);
            dbJDBCMetadata = ExtractMetaDataUtils.getInstance().getDatabaseMetaData(sqlConn, (DatabaseConnection) prevDataProvider);
            copyedConnection = EObjectHelper.deepCopy(prevDataProvider);
            copyedConnection.getDataPackage().clear();
            // MOD zshen the parameter for packageFiler need to differnent isCatalog or not.
            dbInstance.fillCatalogs(copyedConnection, dbJDBCMetadata, metadataConnection, MetadataConnectionUtils.getPackageFilter(copyedConnection, dbJDBCMetadata, true));
            dbInstance.fillSchemas(copyedConnection, dbJDBCMetadata, metadataConnection, MetadataConnectionUtils.getPackageFilter(copyedConnection, dbJDBCMetadata, false));
            ConnectionUtils.closeConnection(sqlConn);
        } else {
            returnProvider.setMessage(trc.getMessage());
        }
    }
    if (copyedConnection == null) {
        returnProvider.setOk(false);
    } else {
        returnProvider.setObject(copyedConnection);
    }
    // ~11951
    return returnProvider;
}
Also used : 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) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DatabaseMetaData(java.sql.DatabaseMetaData) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory) EObject(org.eclipse.emf.ecore.EObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName)

Aggregations

EDatabaseTypeName (org.talend.core.database.EDatabaseTypeName)13 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)9 ArrayList (java.util.ArrayList)4 DatabaseMetaData (java.sql.DatabaseMetaData)2 List (java.util.List)2 EObject (org.eclipse.emf.ecore.EObject)2 IComponent (org.talend.core.model.components.IComponent)2 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 IElementParameter (org.talend.core.model.process.IElementParameter)2 ConnectionItem (org.talend.core.model.properties.ConnectionItem)2 NotReallyNeedSchemaDBS (org.talend.designer.core.sqlbuilder.NotReallyNeedSchemaDBS)2 Schema (orgomg.cwm.resource.relational.Schema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Connection (java.sql.Connection)1 Entry (java.util.Map.Entry)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1