use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class ColumnAnalysisExecutor method checkAnalyzedElements.
/**
* DOC scorreia Comment method "checkAnalyzedElements".
*
* @param analysis
* @param context
*/
protected boolean checkAnalyzedElements(final Analysis analysis, AnalysisContext context) {
ModelElementAnalysisHandler analysisHandler = new ModelElementAnalysisHandler();
analysisHandler.setAnalysis(analysis);
for (ModelElement node : context.getAnalysedElements()) {
TdColumn column = SwitchHelpers.COLUMN_SWITCH.doSwitch(node);
// --- Check that each analyzed element has at least one indicator
if (analysisHandler.getIndicators(column).size() == 0) {
// $NON-NLS-1$
setError(Messages.getString("ColumnAnalysisExecutor.EachColumnHaveOneIndicator"));
return false;
}
// --- get the data provider
Connection dp = ConnectionHelper.getTdDataProvider(column);
if (!isAccessWith(dp)) {
setError(// $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"ColumnAnalysisExecutor.AllColumnsBelongSameConnection", column.getName(), dataprovider.getName()));
return false;
}
}
return true;
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class ColumnAnalysisExecutor method evaluate.
@Override
protected ReturnCode evaluate(Analysis analysis, java.sql.Connection connection, String sqlStatement) {
IndicatorEvaluator eval = CreateIndicatorEvaluator(analysis);
// MOD xqliu 2009-02-09 bug 6237
eval.setMonitor(getMonitor());
// set it into the evaluator
eval.setConnection(connection);
// use pooled connection
eval.setPooledConnection(POOLED_CONNECTION);
// --- add indicators
EList<Indicator> indicators = analysis.getResults().getIndicators();
RowCountIndicatorsAdapter.getInstance().clear();
for (Indicator indicator : indicators) {
assert indicator != null;
TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(indicator.getAnalyzedElement());
if (tdColumn == null) {
continue;
}
// --- get the schema owner
if (!belongToSameSchemata(tdColumn)) {
// $NON-NLS-1$
setError(Messages.getString("ColumnAnalysisExecutor.GivenColumn", tdColumn.getName()));
return new ReturnCode(getErrorMessage(), Boolean.FALSE);
}
String columnName = ColumnHelper.getFullName(tdColumn);
eval.storeIndicator(columnName, indicator);
}
// when to close connection
boolean closeAtTheEnd = true;
Package catalog = schemata.values().iterator().next();
if (!eval.selectCatalog(catalog.getName())) {
// $NON-NLS-1$
log.warn(Messages.getString("ColumnAnalysisExecutor.FAILEDTOSELECTCATALOG", catalog.getName()));
}
return eval.evaluateIndicators(sqlStatement, closeAtTheEnd);
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class ColumnAnalysisSqlExecutor method duplicateForCrossJoin.
/**
* Method "duplicateForCrossJoin". For some SQL queries, auto-joins are used in subqueries. This means that the
* table has two differents aliases and the columns must be prefixed with the alias of the table. Each where clause
* must be duplicated. For example, the clause "AGE > 10" must be duplicated to give "a.AGE > 10" and "b.AGE" when
* table aliases are "a" and "b".
*
* @param completedSqlString the SQL query
*
* @param whereExpression some where clauses
* @param tdColumn the analyzed column
* @return a list of new where clauses (or the one given as argument)
*/
private List<String> duplicateForCrossJoin(String completedSqlString, List<String> whereExpression, TdColumn tdColumn) {
if (whereExpression.isEmpty()) {
return whereExpression;
}
String quotedColName = getQuotedColumnName(tdColumn);
String[] tableAliases = getTableTableAliasA(completedSqlString, quotedColName);
if (tableAliases == null) {
return whereExpression;
}
List<String> duplicatedWhereExpressions = new ArrayList<String>();
// get the table
ColumnSet columnSetOwner = ColumnHelper.getColumnOwnerAsColumnSet(tdColumn);
List<TdColumn> columns = ColumnHelper.getColumns(columnSetOwner.getFeature());
for (String where : whereExpression) {
// we expect only 2 table aliases, hence two distinct where clauses.
String whereA = where;
String whereB = where;
for (TdColumn col : columns) {
String colNameToReplace = where.contains(quotedColName) ? quotedColName : col.getName();
if (where.contains(colNameToReplace)) {
whereA = whereA.replace(colNameToReplace, tableAliases[0] + PluginConstant.DOT_STRING + colNameToReplace);
whereB = whereB.replace(colNameToReplace, tableAliases[1] + PluginConstant.DOT_STRING + colNameToReplace);
}
}
duplicatedWhereExpressions.add(whereA);
duplicatedWhereExpressions.add(whereB);
}
return duplicatedWhereExpressions;
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class ColumnSetAnalysisHandler method addIndicator.
/**
* The resources that are connected to this analysis and that are potentially modified.
*/
// private Collection<Resource> modifiedResources = new HashSet<Resource>();
/**
* Method "addColumnToAnalyze".
*
* @param column
* @return
*/
public boolean addIndicator(List<ModelElement> columns, Indicator indicator) {
for (ModelElement tdColumn : columns) {
if (!analysis.getContext().getAnalysedElements().contains(tdColumn)) {
analysis.getContext().getAnalysedElements().add(tdColumn);
}
}
// store first level of indicators in result.
analysis.getResults().getIndicators().add(indicator);
initializeIndicator(indicator);
DataManager connection = analysis.getContext().getConnection();
if (connection == null) {
// try to get one
for (ModelElement element : columns) {
TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(element);
// $NON-NLS-1$
log.error(Messages.getString("ColumnCorrelationAnalysisHandler.CONNNOTBEENSETINANALYSIS"));
connection = ConnectionHelper.getTdDataProvider(tdColumn);
if (connection != null) {
analysis.getContext().setConnection(connection);
break;
}
}
}
TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(analysis, connection);
return rc.isOk();
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class AddTdRelationalSwitch method caseForeignKey.
@Override
public Boolean caseForeignKey(ForeignKey object) {
ColumnSet columnSet = null;
TdColumn tdColumn = null;
if (leftElement instanceof TdColumn) {
tdColumn = (TdColumn) leftElement;
columnSet = ColumnHelper.getColumnOwnerAsColumnSet(tdColumn);
}
if (columnSet == null) {
return Boolean.FALSE;
}
String fkName = object.getName();
ForeignKey foreignKey = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createForeignKey();
foreignKey.setName(fkName);
if (columnSet instanceof Table) {
foreignKey = TableHelper.addForeignKey((TdTable) columnSet, foreignKey);
if (tdColumn != null) {
tdColumn.getKeyRelationship().add(foreignKey);
}
}
return Boolean.TRUE;
}
Aggregations