Search in sources :

Example 1 with FileConnection

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

the class AddQuoteMarkMigrationTask method addQuote.

/**
     * Add quote marks to the separators.
     * 
     * yzhang Comment method "addQuote".
     * 
     * @throws PersistenceException
     */
private void addQuote(ConnectionItem connItem) throws PersistenceException {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    Connection conn = connItem.getConnection();
    if (conn instanceof FileConnection) {
        FileConnection fileConnection = (FileConnection) conn;
        String old = null;
        old = fileConnection.getFieldSeparatorValue();
        if (!isWithinQuote(old)) {
            fileConnection.setFieldSeparatorValue(surroundDQuote(old));
            modified = true;
        }
        old = fileConnection.getRowSeparatorValue();
        if (!isWithinQuote(old)) {
            fileConnection.setRowSeparatorValue(surroundDQuote(old));
            modified = true;
        }
        old = fileConnection.getEscapeChar();
        if (!isWithinQuote(old)) {
            fileConnection.setEscapeChar(TalendTextUtils.addQuotes(old));
            modified = true;
        }
        old = fileConnection.getTextEnclosure();
        if (!isWithinQuote(old)) {
            fileConnection.setTextEnclosure(TalendTextUtils.addQuotes(old));
            modified = true;
        }
    }
    if (modified) {
        factory.save(connItem);
    }
}
Also used : ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection)

Example 2 with FileConnection

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

the class ConnectionUtils method isConnectionAvailable.

/**
 * This method is used to check conectiton is avalible for analysis or report ,when analysis or report runs.
 *
 * @param analysisDataProvider
 * @return
 */
public static ReturnCode isConnectionAvailable(Connection analysisDataProvider) {
    ReturnCode returnCode = new ReturnCode();
    if (analysisDataProvider == null) {
        returnCode.setOk(false);
        // $NON-NLS-1$
        returnCode.setMessage(Messages.getString("ConnectionUtils.checkConnFailTitle"));
        return returnCode;
    }
    // check hive connection
    IMetadataConnection metadataConnection = ConvertionHelper.convert(analysisDataProvider);
    if (metadataConnection != null) {
        if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
            try {
                // need to do this first when check for hive embed connection.
                if (isHiveEmbedded(analysisDataProvider)) {
                    JavaSqlFactory.doHivePreSetup(analysisDataProvider);
                }
                HiveConnectionManager.getInstance().checkConnection(metadataConnection);
                returnCode.setOk(true);
            } catch (ClassNotFoundException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            } catch (InstantiationException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            } catch (IllegalAccessException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            } catch (SQLException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            }
            return returnCode;
        }
    }
    // MOD klliu check file connection is available
    if (analysisDataProvider instanceof FileConnection) {
        FileConnection fileConn = (FileConnection) analysisDataProvider;
        // ADD msjian TDQ-4559 2012-2-28: when the fileconnection is context mode, getOriginalFileConnection.
        if (fileConn.isContextMode()) {
            IRepositoryContextService service = CoreRuntimePlugin.getInstance().getRepositoryContextService();
            if (service != null) {
                fileConn = service.cloneOriginalValueConnection(fileConn);
            }
        }
        // TDQ-4559 ~
        String filePath = fileConn.getFilePath();
        try {
            BufferedReader filePathAvailable = FilesUtils.isFilePathAvailable(filePath, fileConn);
            if (filePathAvailable == null) {
                returnCode.setOk(false);
                // $NON-NLS-1$ //$NON-NLS-2$
                returnCode.setMessage(Messages.getString("ConnectionUtils.checkConnFailTitle") + " " + filePath);
            }
        } catch (UnsupportedEncodingException e) {
            returnCode.setOk(false);
            returnCode.setMessage(e.toString());
        } catch (FileNotFoundException e) {
            returnCode.setOk(false);
            returnCode.setMessage(e.toString());
        } catch (IOException e) {
            returnCode.setOk(false);
            returnCode.setMessage(e.toString());
        }
        return returnCode;
    }
    // ~
    Properties props = new Properties();
    props.put(TaggedValueHelper.USER, JavaSqlFactory.getUsername(analysisDataProvider));
    props.put(TaggedValueHelper.PASSWORD, JavaSqlFactory.getPassword(analysisDataProvider));
    if (analysisDataProvider instanceof DatabaseConnection) {
        // MOD qiongli TDQ-11507,for GeneralJdbc,should check connection too after validation jar and jdbc driver .
        if (isTcompJdbc(analysisDataProvider) || isGeneralJdbc(analysisDataProvider)) {
            ReturnCode rcJdbc = checkJdbcJarFilePathDriverClassName((DatabaseConnection) analysisDataProvider);
            if (!rcJdbc.isOk()) {
                return rcJdbc;
            }
        }
        // MOD qiongli 2014-5-14 in order to check and connect a dbConnection by a correct driver,replace
        // 'ConnectionUtils.checkConnection(...)' with 'managerConn.check(metadataConnection)'.
        ManagerConnection managerConn = new ManagerConnection();
        returnCode.setOk(managerConn.check(metadataConnection));
        returnCode.setMessage(managerConn.getMessageException());
    }
    return returnCode;
}
Also used : ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) ReturnCode(org.talend.utils.sugars.ReturnCode) SQLException(java.sql.SQLException) FileNotFoundException(java.io.FileNotFoundException) IRepositoryContextService(org.talend.core.IRepositoryContextService) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) IOException(java.io.IOException) Properties(java.util.Properties) BufferedReader(java.io.BufferedReader) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection)

Example 3 with FileConnection

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

the class ConnectionUtils method getRetrieveAllMetadata.

/**
 * if the connection has sid return false, else return true (don't need the TaggedValue any more).
 *
 * @param element
 * @return
 */
public static boolean getRetrieveAllMetadata(ModelElement element) {
    if (element != null && element instanceof Connection) {
        if (element instanceof DatabaseConnection) {
            DatabaseConnection dbConn = (DatabaseConnection) element;
            String sid = JavaSqlFactory.getSID(dbConn);
            if (sid != null && !"".equals(sid.trim())) {
                // $NON-NLS-1$
                // MOD klliu bug 22900
                TaggedValue taggedValue = TaggedValueHelper.getTaggedValue(TaggedValueHelper.RETRIEVE_ALL, element.getTaggedValue());
                // if connection is created by 4.2 or 5.0 ,the tagedValue(RETRIEVE_ALL) has been removed.
                if (taggedValue != null) {
                    String value = taggedValue.getValue();
                    if (value.equals("true")) {
                        // $NON-NLS-1$
                        return true;
                    }
                }
                // ~
                if (ConnectionHelper.isOracle(dbConn) || isPostgresql(dbConn)) {
                    String uiSchema = dbConn.getUiSchema();
                    if (uiSchema != null && !"".equals(uiSchema.trim())) {
                        // $NON-NLS-1$
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    return false;
                }
            } else {
                return true;
            }
        } else if (element instanceof FileConnection) {
            // do file connection can filter catalog/schema?
            return true;
        }
    }
    return true;
}
Also used : TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection)

Example 4 with FileConnection

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

the class RespositoryDetailView method createDataProviderDetail.

private void createDataProviderDetail(ConnectionItem connectionItem) {
    Connection dataProvider = connectionItem.getConnection();
    Property dbProperty = connectionItem.getProperty();
    boolean isDelimitedFile = ConnectionUtils.isDelimitedFileConnection(dataProvider);
    // MOD qiongli 2011-9-21 TDQ-3317
    Connection origValueConn = null;
    if (dataProvider.isContextMode()) {
        if (dataProvider instanceof DatabaseConnection) {
            origValueConn = ConnectionUtils.getOriginalDatabaseConnection((DatabaseConnection) dataProvider);
        } else if (dataProvider instanceof FileConnection) {
            origValueConn = ConnectionUtils.getOriginalFileConnection((FileConnection) dataProvider);
        }
    }
    if (!isDelimitedFile) {
        createName(origValueConn == null ? dataProvider : origValueConn);
    }
    if (origValueConn != null) {
        createContextDetail(dataProvider);
    }
    if (dbProperty != null) {
        createPurpose(dbProperty);
        createDescription(dbProperty);
    } else {
        createPurpose(origValueConn == null ? dataProvider : origValueConn);
        createDescription(origValueConn == null ? dataProvider : origValueConn);
    }
    // MOD mzhao xmldb have no actual connection.
    if (dataProvider != null) {
        String connectionString = JavaSqlFactory.getURL(dataProvider);
        // $NON-NLS-1$
        newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.URL"), connectionString);
    }
    // MOD gdbu 2011-9-16 TDQ-3337
    String subtype = PluginConstant.EMPTY_STRING;
    String version = PluginConstant.EMPTY_STRING;
    if (dataProvider instanceof DatabaseConnection) {
        subtype = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_NAME, dataProvider);
        if (PluginConstant.EMPTY_STRING.equals(subtype)) {
            // tagged values not present in local connection file.
            ConnectionUtils.updataTaggedValueForConnectionItem(dataProvider);
            subtype = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_NAME, dataProvider);
            if (!PluginConstant.EMPTY_STRING.equals(subtype)) {
                version = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_VERSION, dataProvider);
            }
        } else {
            version = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_VERSION, dataProvider);
        }
    } else {
        subtype = isDelimitedFile ? SupportDBUrlType.DELIMITEDFILE.getLanguage() : PluginConstant.EMPTY_STRING;
        if (!DQRepositoryNode.isOnFilterring()) {
            version = PluginConstant.EMPTY_STRING;
        }
    }
    // ~TDQ-3337
    // $NON-NLS-1$
    newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.type2"), subtype);
    // $NON-NLS-1$
    newLabelAndText(gContainer, "Version: ", version);
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Property(org.talend.core.model.properties.Property) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection)

Aggregations

FileConnection (org.talend.core.model.metadata.builder.connection.FileConnection)4 Connection (org.talend.core.model.metadata.builder.connection.Connection)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)3 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)2 ManagerConnection (org.talend.metadata.managment.repository.ManagerConnection)2 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 IRepositoryContextService (org.talend.core.IRepositoryContextService)1 Property (org.talend.core.model.properties.Property)1 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)1 ReturnCode (org.talend.utils.sugars.ReturnCode)1 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)1