Search in sources :

Example 1 with IRepositoryContextService

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

the class DbmsLanguage method cloneOriginalValueConnection.

/**
 * clone the database connection with original value according to the context(the database connection must be
 * context mode).
 *
 * @param dbConn
 * @return
 */
private DatabaseConnection cloneOriginalValueConnection(DatabaseConnection dbConn) {
    IRepositoryContextService repositoryContextService = CoreRuntimePlugin.getInstance().getRepositoryContextService();
    if (repositoryContextService != null) {
        String contextName = dbConn.getContextName();
        if (contextName == null) {
            // $NON-NLS-1$
            String msg = Messages.getString("DbmsLanguage.ContextNameIsNull");
            RuntimeException exp = new RuntimeException(msg);
            log.error(msg, exp);
            throw exp;
        }
        return repositoryContextService.cloneOriginalValueConnection(dbConn, false, contextName);
    } else {
        // $NON-NLS-1$
        String msg = Messages.getString("DbmsLanguage.IRepositoryContextServiceIsNull");
        RuntimeException exp = new RuntimeException(msg);
        log.error(msg, exp);
        throw exp;
    }
}
Also used : IRepositoryContextService(org.talend.core.IRepositoryContextService)

Example 2 with IRepositoryContextService

use of org.talend.core.IRepositoryContextService 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 IRepositoryContextService

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

the class DelimitedFileIndicatorEvaluator method executeSqlQuery.

@Override
protected ReturnCode executeSqlQuery(String sqlStatement) {
    ReturnCode returnCode = new ReturnCode(true);
    if (delimitedFileconnection == null) {
        delimitedFileconnection = (DelimitedFileConnection) analysis.getContext().getConnection();
    }
    if (delimitedFileconnection.isContextMode()) {
        IRepositoryContextService service = CoreRuntimePlugin.getInstance().getRepositoryContextService();
        delimitedFileconnection = (DelimitedFileConnection) service.cloneOriginalValueConnection(delimitedFileconnection);
    }
    String path = JavaSqlFactory.getURL(delimitedFileconnection);
    IPath iPath = new Path(path);
    File file = iPath.toFile();
    if (!file.exists()) {
        // $NON-NLS-1$
        returnCode.setReturnCode(Messages.getString("DelimitedFileIndicatorEvaluator.CanNotFindFile"), false);
        return returnCode;
    }
    List<ModelElement> analysisElementList = this.analysis.getContext().getAnalysedElements();
    EMap<Indicator, AnalyzedDataSet> indicToRowMap = analysis.getResults().getIndicToRowMap();
    indicToRowMap.clear();
    List<MetadataColumn> columnElementList = new ArrayList<MetadataColumn>();
    for (int i = 0; i < analysisElementList.size(); i++) {
        MetadataColumn mColumn = (MetadataColumn) analysisElementList.get(i);
        MetadataTable mTable = ColumnHelper.getColumnOwnerAsMetadataTable(mColumn);
        columnElementList = mTable == null ? columnElementList : mTable.getColumns();
        if (!columnElementList.isEmpty()) {
            break;
        }
    }
    ReturnCode readDataReturnCode = new ReturnCode(true);
    // use CsvReader to parse.
    if (Escape.CSV.equals(delimitedFileconnection.getEscapeType())) {
        readDataReturnCode = useCsvReader(file, analysisElementList, columnElementList, indicToRowMap);
    } else {
        readDataReturnCode = useDelimitedReader(analysisElementList, columnElementList, indicToRowMap);
    }
    // handle error message
    if (!readDataReturnCode.isOk()) {
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), // $NON-NLS-1$
                Messages.getString("DelimitedFileIndicatorEvaluator.badlyForm.Title"), // $NON-NLS-1$
                Messages.getString("DelimitedFileIndicatorEvaluator.badlyForm.Message"));
            }
        });
    }
    // Added yyin 20120608 TDQ-3589
    for (MetadataColumn col : columnElementList) {
        List<Indicator> indicators = getIndicators(col.getLabel());
        for (Indicator indicator : indicators) {
            if (indicator instanceof DuplicateCountIndicator) {
                AnalyzedDataSet analyzedDataSet = indicToRowMap.get(indicator);
                if (analyzedDataSet == null) {
                    analyzedDataSet = AnalysisFactory.eINSTANCE.createAnalyzedDataSet();
                    indicToRowMap.put(indicator, analyzedDataSet);
                    analyzedDataSet.setDataCount(analysis.getParameters().getMaxNumberRows());
                    analyzedDataSet.setRecordSize(0);
                }
                // indicator.finalizeComputation();
                addResultToIndicatorToRowMap(indicator, indicToRowMap);
            }
        }
    }
    return returnCode;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) ReturnCode(org.talend.utils.sugars.ReturnCode) IPath(org.eclipse.core.runtime.IPath) AnalyzedDataSet(org.talend.dataquality.analysis.AnalyzedDataSet) ArrayList(java.util.ArrayList) IRepositoryContextService(org.talend.core.IRepositoryContextService) UniqueCountIndicator(org.talend.dataquality.indicators.UniqueCountIndicator) Indicator(org.talend.dataquality.indicators.Indicator) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) File(java.io.File)

Aggregations

IRepositoryContextService (org.talend.core.IRepositoryContextService)3 ReturnCode (org.talend.utils.sugars.ReturnCode)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)1 FileConnection (org.talend.core.model.metadata.builder.connection.FileConnection)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 AnalyzedDataSet (org.talend.dataquality.analysis.AnalyzedDataSet)1 DuplicateCountIndicator (org.talend.dataquality.indicators.DuplicateCountIndicator)1