use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class RedundancyAnalysisDetailsPage method saveAnalysis.
@Override
protected void saveAnalysis() throws DataprofilerCoreException {
for (Domain domain : getCurrentModelElement().getParameters().getDataFilter()) {
domain.setName(getCurrentModelElement().getName());
}
IRepositoryViewObject reposObject = null;
getAnalysisHandler().clearAnalysis();
List<ModelElement> analysedElements = new ArrayList<ModelElement>();
anaColumnCompareViewer.setColumnABForMatchingIndicator(rowMatchingIndicatorA, anaColumnCompareViewer.getColumnListA(), anaColumnCompareViewer.getColumnListB());
anaColumnCompareViewer.setColumnABForMatchingIndicator(rowMatchingIndicatorB, anaColumnCompareViewer.getColumnListB(), anaColumnCompareViewer.getColumnListA());
Connection tdDataProvider = null;
for (int i = 0; i < anaColumnCompareViewer.getColumnListA().size(); i++) {
reposObject = anaColumnCompareViewer.getColumnListA().get(i).getObject();
analysedElements.add(((MetadataColumnRepositoryObject) reposObject).getTdColumn());
}
for (int i = 0; i < anaColumnCompareViewer.getColumnListB().size(); i++) {
reposObject = anaColumnCompareViewer.getColumnListB().get(i).getObject();
analysedElements.add(((MetadataColumnRepositoryObject) reposObject).getTdColumn());
}
if (analysedElements.size() > 0) {
tdDataProvider = ConnectionHelper.getTdDataProvider((TdColumn) analysedElements.get(0));
// MOD qiongli bug 14437:Add dependency
getCurrentModelElement().getContext().setConnection(tdDataProvider);
TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(getCurrentModelElement(), tdDataProvider);
if (!rc.isOk()) {
// $NON-NLS-1$
log.info("fail to save dependency analysis:" + getCurrentModelElement().getFileName());
}
} else {
getCurrentModelElement().getContext().setConnection(null);
}
AnalysisBuilder anaBuilder = new AnalysisBuilder();
anaBuilder.setAnalysis(getCurrentModelElement());
if (anaColumnCompareViewer.getCheckComputeButton().getSelection()) {
getCurrentModelElement().getParameters().getDeactivatedIndicators().add(rowMatchingIndicatorB);
} else {
getCurrentModelElement().getParameters().getDeactivatedIndicators().clear();
}
anaBuilder.addElementsToAnalyze(analysedElements.toArray(new ModelElement[analysedElements.size()]), new Indicator[] { rowMatchingIndicatorA, rowMatchingIndicatorB });
// save the number of connections per analysis
this.saveNumberOfConnectionsPerAnalysis();
// 2011.1.12 MOD by zhsne to unify anlysis and connection id when saving.
this.nameText.setText(getCurrentModelElement().getName());
// MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
ReturnCode saved = ElementWriterFactory.getInstance().createAnalysisWrite().save(getCurrentRepNode().getObject().getProperty().getItem(), true);
// MOD yyi 2012-02-03 TDQ-3602:Avoid to rewriting all analyzes after saving, no reason to update all analyzes
// which is depended in the referred connection.
// Extract saving log function.
// @see org.talend.dataprofiler.core.ui.editor.analysis.AbstractAnalysisMetadataPage#logSaved(ReturnCode)
logSaved(saved);
// ADD xqliu 2012-04-19 TDQ-5005
anaColumnCompareViewer.setDirty(false);
dataFilterCompA.setDirty(false);
dataFilterCompB.setDirty(false);
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class ColumnAnalysisSqlExecutor method getTdColumn.
/**
* DOC talend Comment method getTdColumn.
*
* @param indicator
*/
private TypedReturnCode<TdColumn> getTdColumn(Indicator indicator) {
TypedReturnCode<TdColumn> rt = new TypedReturnCode<TdColumn>(true);
ModelElement analyzedElement = indicator.getAnalyzedElement();
if (analyzedElement == null) {
traceError(Messages.getString("ColumnAnalysisSqlExecutor.ANALYSISELEMENTISNULL", // $NON-NLS-1$
AnalysisExecutorHelper.getIndicatorName(indicator)));
rt.setOk(false);
return rt;
}
TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(analyzedElement);
rt.setObject(tdColumn);
if (tdColumn == null) {
traceError(Messages.getString("ColumnAnalysisSqlExecutor.ANALYZEDISNOTCOLUMNINDICATOR", // $NON-NLS-1$
AnalysisExecutorHelper.getIndicatorName(indicator)));
rt.setOk(false);
}
return rt;
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class MultiColumnAnalysisExecutor method runAnalysis.
/**
* DOC scorreia Comment method "getTableName".
*
* @param analyzedColumns
* @return the quoted table name
*/
/*
* tableName = columnSetOwner.getName(); Package pack = PackageHelper.getCatalogOrSchema(columnSetOwner); if (pack
* == null) { log.error("No Catalog or Schema found for column set owner: " + tableName); continue; // do not break
* until we find the owner } this.catalogOrSchema = pack.getName(); break; // all columns should belong to the same
* table
*/
/*
* (non-Javadoc)
*
* @see org.talend.dq.analysis.AnalysisExecutor#runAnalysis(org.talend.dataquality.analysis.Analysis,
* java.lang.String)
*/
@Override
protected boolean runAnalysis(Analysis analysis, String sqlStatement) {
boolean isSuccess = 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();
for (Indicator indicator : indicators) {
indicator.prepare();
// set the connection's catalog
if (this.catalogOrSchema != null && needChangeCatalog(connection)) {
// check whether null argument can be given
changeCatalog(this.catalogOrSchema, connection);
}
Expression query = dbms().getInstantiatedExpression(indicator);
if (query == null) {
traceError(// $NON-NLS-1$//$NON-NLS-2$
"Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + // $NON-NLS-1$
"query is null");
isSuccess = Boolean.FALSE;
continue;
}
try {
Boolean isExeSuccess = executeQuery(indicator, connection, query);
if (!isExeSuccess) {
traceError(// $NON-NLS-1$//$NON-NLS-2$
"Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + // $NON-NLS-1$//$NON-NLS-2$
((query == null) ? "query is null" : "SQL query: " + query.getBody()));
isSuccess = Boolean.FALSE;
continue;
}
} catch (Exception e) {
traceError(e.getMessage());
isSuccess = Boolean.FALSE;
continue;
}
indicator.setComputed(true);
}
} finally {
ReturnCode rc = closeConnection(analysis, connection);
if (!rc.isOk()) {
isSuccess = Boolean.FALSE;
}
}
return isSuccess;
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutor method runAnalysis.
@Override
protected boolean runAnalysis(Analysis analysis, String sqlStatement) {
boolean isSuccess = true;
TypedReturnCode<java.sql.Connection> trc = this.getConnectionBeforeRun(analysis);
if (!trc.isOk()) {
log.error(trc.getMessage());
traceError(Messages.getString("FunctionalDependencyExecutor.CANNOTEXECUTEANALYSIS", analysis.getName(), // $NON-NLS-1$
trc.getMessage()));
return Boolean.FALSE;
}
Connection connection = trc.getObject();
try {
Long rowCount = 0L;
List<Indicator> indicatorList = IndicatorHelper.getIndicatorLeavesBySingleNode(analysis.getResults());
// execute the row count
Indicator rowIndicator = indicatorList.get(0);
isSuccess = executeIndicator(rowIndicator, connection);
publishDynamicEvent(rowIndicator);
// remember the row count
rowCount = rowIndicator.getCount();
// execute the sql statement for each group of aide and rule
for (int i = 1; i < indicatorList.size(); i++) {
final Indicator rule = indicatorList.get(i);
isSuccess = executeRule((WhereRuleIndicator) rule, connection);
// if there's no joins, should use the row count as the count.
if (isJoinConditionEmpty(rule)) {
rule.setCount(rowCount);
}
publishDynamicEvent(rule);
}
} finally {
ReturnCode rc = closeConnection(analysis, connection);
if (!rc.isOk()) {
appendError(rc.getMessage());
isSuccess = Boolean.FALSE;
}
}
return isSuccess;
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class DependenciesHandler method createUsageDependencyOn.
/**
* Method "createUsageDependencyOn".
*
* @param clientElement the analysis that depends on the data provider.
* @param dataManager the data provider
* @return a true return code if the dependency has been correctly added to the resource of the supplier element.
* Return false otherwise. In any case, the dependency is created and the getObject() method returns it.
*/
TypedReturnCode<Dependency> createUsageDependencyOn(ModelElement clientElement, ModelElement dataManager) {
assert dataManager != null;
Dependency dependency = createDependencyOn(USAGE, clientElement, dataManager);
TypedReturnCode<Dependency> rc = new TypedReturnCode<Dependency>();
rc.setObject(dependency);
return rc;
}
Aggregations