Search in sources :

Example 1 with DatabaseSQLExecutor

use of org.talend.cwm.db.connection.DatabaseSQLExecutor in project tdq-studio-se by Talend.

the class MatchAnalysisExecutor method getSQLExectutor.

/**
 * getSQLExectutor .
 *
 * @param modelElement
 * @return
 */
private ISQLExecutor getSQLExectutor(Analysis analysis, RecordMatchingIndicator recordMatchingIndicator, Map<MetadataColumn, String> columnMap) {
    ModelElement modelElement = analysis.getContext().getAnalysedElements().get(0);
    ISQLExecutor sqlExecutor = null;
    if (modelElement instanceof TdColumn) {
        sqlExecutor = new DatabaseSQLExecutor();
    } else if (modelElement instanceof MetadataColumn) {
        sqlExecutor = new DelimitedFileSQLExecutor();
    }
    // Tune on store on disk option when needed.
    Boolean isStoreOnDisk = PluginChecker.isTDQLoaded() ? TaggedValueHelper.getValueBoolean(SQLExecutor.STORE_ON_DISK_KEY, analysis) : Boolean.FALSE;
    if (sqlExecutor != null && isStoreOnDisk) {
        sqlExecutor.setStoreOnDisk(Boolean.TRUE);
        sqlExecutor.initStoreOnDiskHandler(analysis, recordMatchingIndicator, columnMap);
    }
    return sqlExecutor;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) DatabaseSQLExecutor(org.talend.cwm.db.connection.DatabaseSQLExecutor) DelimitedFileSQLExecutor(org.talend.cwm.db.connection.DelimitedFileSQLExecutor) TdColumn(org.talend.cwm.relational.TdColumn) ISQLExecutor(org.talend.cwm.db.connection.ISQLExecutor)

Example 2 with DatabaseSQLExecutor

use of org.talend.cwm.db.connection.DatabaseSQLExecutor in project tdq-studio-se by Talend.

the class DataPreviewHandler method createPreviewData.

public List<Object[]> createPreviewData(ModelElement[] columns, int limit, boolean isRandomData) throws SQLException {
    // no columns be selected so that no data can be read
    if (columns == null || columns.length == 0) {
        return new ArrayList<Object[]>();
    }
    // use ModelElement instead of node to get the data source type directly.
    // get connection from column[0]
    boolean isDelimitedFile = false;
    ModelElement modelElement = columns[0];
    if (modelElement instanceof MetadataColumn && !(modelElement instanceof TdColumn)) {
        isDelimitedFile = true;
        connection = ConnectionHelper.getTdDataProvider((MetadataColumn) modelElement);
    } else if (modelElement instanceof TdColumn) {
        connection = ConnectionHelper.getTdDataProvider((TdColumn) modelElement);
    } else {
        // other case it is not support by now
        // $NON-NLS-1$
        log.warning(DefaultMessagesImpl.getString("DataPreviewHandler.UnSupportType"));
        return new ArrayList<Object[]>();
    }
    ISQLExecutor sqlExecutor = null;
    if (isDelimitedFile) {
        sqlExecutor = new DelimitedFileSQLExecutor();
    } else {
        // is database
        sqlExecutor = new DatabaseSQLExecutor();
    }
    // set limit
    sqlExecutor.setLimit(limit);
    sqlExecutor.setShowRandomData(isRandomData);
    return sqlExecutor.executeQuery(connection, Arrays.asList(columns), dataFilter);
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) DelimitedFileSQLExecutor(org.talend.cwm.db.connection.DelimitedFileSQLExecutor) DatabaseSQLExecutor(org.talend.cwm.db.connection.DatabaseSQLExecutor) TdColumn(org.talend.cwm.relational.TdColumn) ISQLExecutor(org.talend.cwm.db.connection.ISQLExecutor) ArrayList(java.util.ArrayList)

Aggregations

MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)2 DatabaseSQLExecutor (org.talend.cwm.db.connection.DatabaseSQLExecutor)2 DelimitedFileSQLExecutor (org.talend.cwm.db.connection.DelimitedFileSQLExecutor)2 ISQLExecutor (org.talend.cwm.db.connection.ISQLExecutor)2 TdColumn (org.talend.cwm.relational.TdColumn)2 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)2 ArrayList (java.util.ArrayList)1