use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.
the class ColumnAnalysisExecutor method belongToSameSchemata.
/**
* Method "belongToSameSchemata" fills in the map this{@link #schemata}.
*
* @param tdColumn a column
* @return false when the given column has an owner different from the one registered in the map.
*/
protected boolean belongToSameSchemata(final ModelElement tdColumn) {
assert tdColumn != null;
if (schemata.get(tdColumn) != null) {
return true;
}
// get table or view
ColumnSet owner = ColumnHelper.getColumnOwnerAsColumnSet(tdColumn);
if (owner == null) {
// $NON-NLS-1$
setError(Messages.getString("ColumnAnalysisExecutor.NotFoundColumn", tdColumn.getName()));
return false;
}
// get catalog or schema
Package schema = ColumnSetHelper.getParentCatalogOrSchema(owner);
if (schema == null) {
// $NON-NLS-1$
setError(Messages.getString("ColumnAnalysisExecutor.NoSchemaOrCatalogFound", owner.getName(), tdColumn.getName()));
return false;
}
schemata.put(tdColumn, schema);
return true;
}
use of orgomg.cwm.resource.relational.ColumnSet 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 orgomg.cwm.resource.relational.ColumnSet 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;
}
use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.
the class AddTdRelationalSwitch method casePrimaryKey.
@Override
public Boolean casePrimaryKey(PrimaryKey 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 pkName = object.getName();
PrimaryKey primaryKey = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createPrimaryKey();
primaryKey.setName(pkName);
if (columnSet instanceof Table) {
primaryKey = TableHelper.addPrimaryKey((TdTable) columnSet, primaryKey);
if (tdColumn != null) {
tdColumn.getUniqueKey().add(primaryKey);
}
}
return Boolean.TRUE;
}
use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.
the class RowMatchingAnalysisExecutor method getTableName.
/**
* DOC scorreia Comment method "getTableName".
*
* @param columnSetA
* @return
*/
private String getTableName(EList<TdColumn> columnSetA) {
String tableName = null;
for (TdColumn column : columnSetA) {
if (column == null) {
continue;
}
if (column.eIsProxy()) {
column = (TdColumn) EObjectHelper.resolveObject(column);
}
if (belongToSameSchemata(column)) {
ColumnSet columnSetOwner = ColumnHelper.getColumnOwnerAsColumnSet(column);
if (columnSetOwner == null) {
// $NON-NLS-1$
log.error(Messages.getString("FunctionalDependencyExecutor.COLUMNSETOWNERISNULL", column.getName()));
continue;
} else {
tableName = dbms().getQueryColumnSetWithPrefix(column);
// ~11005
this.catalogOrSchema = getCatalogOrSchemaName(column);
// all columns should belong to the same table
break;
}
} else {
log.error(getErrorMessage());
}
}
return quote(tableName);
}
Aggregations