use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class FunctionalDependencyExecutor method runAnalysis.
@Override
protected boolean runAnalysis(Analysis analysis, String sqlStatement) {
Boolean runStatus = Boolean.TRUE;
TypedReturnCode<java.sql.Connection> trc = this.getConnectionBeforeRun(analysis);
if (!trc.isOk()) {
log.error(trc.getMessage());
setError(trc.getMessage());
traceError(Messages.getString("FunctionalDependencyExecutor.CANNOTEXECUTEANALYSIS", analysis.getName(), // $NON-NLS-1$
trc.getMessage()));
return Boolean.FALSE;
}
Connection connection = trc.getObject();
try {
// execute the sql statement for each indicator
EList<Indicator> indicators = analysis.getResults().getIndicators();
EList<Indicator> deactivatedIndicators = analysis.getParameters().getDeactivatedIndicators();
for (Indicator indicator : indicators) {
if (deactivatedIndicators.contains(indicator)) {
// do not evaluate this indicator
continue;
}
Expression query = dbms().getInstantiatedExpression(indicator);
if (query == null) {
// TODO internationalize the string.
traceError(// $NON-NLS-1$//$NON-NLS-2$
"Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + // $NON-NLS-1$
"query is null");
runStatus = Boolean.FALSE;
continue;
}
try {
boolean exeStatus = executeQuery(indicator, connection, query);
if (!exeStatus) {
// TODO internationalize the string.
traceError(// $NON-NLS-1$//$NON-NLS-2$
"Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + "SQL query: " + // $NON-NLS-1$
query.getBody());
runStatus = Boolean.FALSE;
continue;
}
} catch (AnalysisExecutionException e) {
traceError(e.getMessage());
runStatus = Boolean.FALSE;
continue;
}
indicator.setComputed(true);
}
} finally {
ReturnCode rc = closeConnection(analysis, connection);
if (!rc.isOk()) {
runStatus = Boolean.FALSE;
}
}
return runStatus;
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class FunctionalDependencyExecutor method createInstantiatedSqlExpression.
/**
* DOC jet Comment method "createInstantiatedSqlExpression".
*
* @param sqlGenericExpression
* @param columnA
* @param columnB
* @param dbmsLanguage
* @param useNulls
* @return
*/
private Expression createInstantiatedSqlExpression(Expression sqlGenericExpression, TdColumn columnA, TdColumn columnB, DbmsLanguage dbmsLanguage) {
assert columnA != null;
assert columnB != null;
String genericSQL = sqlGenericExpression.getBody();
// MOD zshen 11005: SQL syntax error for all analysis on Informix databases in Talend Open Profiler
String table = getTableNameFromColumn(columnA);
String instantiatedSQL = dbms().fillGenericQueryWithColumnsABAndTable(genericSQL, dbmsLanguage.quote(columnA.getName()), dbmsLanguage.quote(columnB.getName()), table);
// ~11005
List<String> whereClauses = new ArrayList<String>();
String dataFilter = ContextHelper.getDataFilterWithoutContext(cachedAnalysis);
if (!StringUtils.isEmpty(dataFilter)) {
whereClauses.add(dataFilter);
}
instantiatedSQL = dbms().addWhereToSqlStringStatement(instantiatedSQL, whereClauses);
Expression instantiatedExpression = CoreFactory.eINSTANCE.createExpression();
instantiatedExpression.setLanguage(sqlGenericExpression.getLanguage());
instantiatedExpression.setBody(instantiatedSQL);
return instantiatedExpression;
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class RowMatchingAnalysisExecutor method instantiateQuery.
/**
* DOC scorreia Comment method "instantiateQuery".
*
* @param indicator
*/
private boolean instantiateQuery(Indicator indicator) {
// (but is not need, hence we keep it commented)
if (ColumnsetPackage.eINSTANCE.getRowMatchingIndicator().equals(indicator.eClass())) {
RowMatchingIndicator rowMatchingIndicator = (RowMatchingIndicator) indicator;
EList<TdColumn> columnSetA = rowMatchingIndicator.getColumnSetA();
EList<TdColumn> columnSetB = rowMatchingIndicator.getColumnSetB();
if (columnSetA.size() != columnSetB.size()) {
// $NON-NLS-1$
traceError("Cannot compare two column sets with different size");
return Boolean.FALSE;
// break;
}
IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
// TODO scorreia create an indicator for each option
boolean useNulls = false;
Expression instantiatedSqlExpression = createInstantiatedSqlExpression(sqlGenericExpression, columnSetA, columnSetB, useNulls, indicator);
indicator.setInstantiatedExpression(instantiatedSqlExpression);
return true;
}
// $NON-NLS-1$
traceError("Unhandled given indicator: " + AnalysisExecutorHelper.getIndicatorName(indicator));
return Boolean.FALSE;
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class AnalysisTableTreeViewer method isExpressionNull.
private String isExpressionNull(TreeItem item) {
String expressContent = null;
TableIndicatorUnit indicatorUnit = (TableIndicatorUnit) item.getData(INDICATOR_UNIT_KEY);
TableIndicator tableIndicator = (TableIndicator) item.getData(TABLE_INDICATOR_KEY);
NamedColumnSet set = tableIndicator.getColumnSet();
Connection dataprovider = ConnectionHelper.getTdDataProvider(ColumnSetHelper.getParentCatalogOrSchema(set));
DbmsLanguage dbmsLang = DbmsLanguageFactory.createDbmsLanguage(dataprovider);
Expression expression = dbmsLang.getInstantiatedExpression(indicatorUnit.getIndicator());
if (expression != null) {
expressContent = expression.getBody();
}
return expressContent;
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class ModelElementTreeMenuProvider method viewQueryForSelectedElement.
/**
* DOC mzhao Comment method "viewQueryForSelectedElement".
*
* @param newTree
*/
private void viewQueryForSelectedElement(Tree newTree) {
TreeItem[] selection = newTree.getSelection();
for (TreeItem item : selection) {
ModelElementIndicator meIndicator = (ModelElementIndicator) item.getData(AbstractColumnDropTree.MODELELEMENT_INDICATOR_KEY);
ConnectionItem connItem = (ConnectionItem) meIndicator.getModelElementRepositoryNode().getObject().getProperty().getItem();
Connection dataprovider = connItem.getConnection();
IndicatorUnit indicatorUnit = (IndicatorUnit) item.getData(AbstractColumnDropTree.INDICATOR_UNIT_KEY);
DbmsLanguage dbmsLang = DbmsLanguageFactory.createDbmsLanguage(dataprovider);
Expression expression = dbmsLang.getInstantiatedExpression(indicatorUnit.getIndicator());
if (expression == null) {
MessageDialogWithToggle.openWarning(null, DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.Warn"), // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.NoQueryDefined"));
return;
}
SqlExplorerUtils.getDefault().runInDQViewer(dataprovider, expression.getBody(), meIndicator.getModelElementRepositoryNode().getObject().getProperty().getLabel());
}
}
Aggregations