use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.
the class RepositoryNodeHelper method filterMatchingColumnSets.
private static <T extends NamedColumnSet> List<NamedColumnSet> filterMatchingColumnSets(List<T> columnSets, String[] patterns) {
List<NamedColumnSet> retColumnSets = new ArrayList<NamedColumnSet>();
int size = 0;
for (NamedColumnSet t : columnSets) {
for (String pattern : patterns) {
// $NON-NLS-1$ //$NON-NLS-2$
String regex = pattern.replaceAll("%", ".*").toLowerCase();
String name = t.getName().toLowerCase();
if (isMatch(regex, name)) {
// if (name.matches(regex)) {
retColumnSets.add(t);
size++;
if (size > 2000) {
return retColumnSets;
}
break;
}
}
}
return retColumnSets;
}
use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.
the class RepositoryNodeHelper method filterViews.
/**
* DOC klliu Comment method "filterViews".
*
* @param views
* @param columnSetPattern
* @return
*/
public static List<TdView> filterViews(List<TdView> views, String columnSetPattern) {
// $NON-NLS-1$
String[] patterns = cleanPatterns(columnSetPattern.split(","));
List<NamedColumnSet> filterMatchingColumnSets = filterMatchingColumnSets(views, patterns);
List<TdView> filterViews = new ArrayList<TdView>();
for (NamedColumnSet columnSet : filterMatchingColumnSets) {
TdView view = (TdView) columnSet;
filterViews.add(view);
}
return filterViews;
}
use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.
the class AbstractSchemaEvaluator method evalSchemaIndicLow.
protected void evalSchemaIndicLow(final CatalogIndicator catalogIndic, final SchemaIndicator schemaIndic, final Catalog tdCatalog, final Schema tdSchema, ReturnCode ok) throws SQLException {
// MOD klliu 2011-02-17 bug 18961
boolean hasSchema = tdSchema != null;
boolean hasCatalog = false;
String schemaName = hasSchema ? tdSchema.getName() : null;
String catName = null;
if (tdCatalog == null) {
if (tdSchema.eContainer() instanceof Catalog) {
hasCatalog = true;
catName = ((Catalog) tdSchema.eContainer()).getName();
}
} else {
hasCatalog = true;
catName = hasCatalog ? tdCatalog.getName() : null;
}
schemaIndic.setAnalyzedElement(hasSchema ? tdSchema : tdCatalog);
// profile tables
int tableCount = 0;
final String[] tablePatterns = tablePattern != null && tablePattern.contains(String.valueOf(FILTER_SEP)) ? StringUtils.split(this.tablePattern, FILTER_SEP) : new String[] { this.tablePattern };
for (String pat : tablePatterns) {
// MOD zshen bug 12041: the variable trimPat must be null(not a "") if it isn't a table name.
String trimPat = pat != null && !PluginConstant.EMPTY_STRING.equals(pat) ? pat.trim() : null;
try {
Package pacage = tdSchema == null ? tdCatalog : tdSchema;
// MOD gdbu 2011-9-22 TDQ-3607
checkConnectionBeforeGetTableView();
List<? extends NamedColumnSet> tables = DqRepositoryViewService.getTables(getConnection(), getDataManager(), pacage, trimPat, true, false);
// ~TDQ-3607
for (NamedColumnSet t : tables) {
if (this.getMonitor() != null) {
StringBuilder taskName = new StringBuilder();
if (catName != null) {
// $NON-NLS-1$
taskName.append(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementCatalog", catName)).append(// $NON-NLS-1$
", ");
}
if (schemaName != null) {
// $NON-NLS-1$
taskName.append(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementSchema", schemaName)).append(// $NON-NLS-1$
", ");
}
// $NON-NLS-1$
taskName.append(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementTable", t.getName()));
this.getMonitor().setTaskName(// $NON-NLS-1$
Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", taskName.toString()));
}
tableCount++;
evalAllCounts(catName, schemaName, t, schemaIndic, true, ok);
}
} catch (Exception e) {
log.error(e, e);
}
}
schemaIndic.setTableCount(tableCount);
// do the same for views
int viewCount = 0;
final String[] viewPatterns = viewPattern != null && viewPattern.contains(String.valueOf(FILTER_SEP)) ? StringUtils.split(this.viewPattern, FILTER_SEP) : new String[] { this.viewPattern };
for (String pat : viewPatterns) {
// MOD zshen bug 12041: the variable trimPat must be null(not a "") if it isn't a view name.
String trimPat = pat != null && !PluginConstant.EMPTY_STRING.equals(pat) ? pat.trim() : null;
try {
Package pacage = tdSchema == null ? tdCatalog : tdSchema;
// MOD gdbu 2011-9-22 TDQ-3607
checkConnectionBeforeGetTableView();
List<? extends NamedColumnSet> views = DqRepositoryViewService.getViews(getConnection(), getDataManager(), pacage, trimPat, true, false);
// ~TDQ-3607
for (NamedColumnSet t : views) {
viewCount++;
evalAllCounts(catName, schemaName, t, schemaIndic, false, ok);
}
} catch (Exception e) {
log.error(e, e);
}
}
schemaIndic.setViewCount(viewCount);
if (hasCatalog && hasSchema && catalogIndic != null) {
// add it to list of indicators
this.addToConnectionIndicator(catalogIndic, schemaIndic);
// add it to list of indicators
catalogIndic.addSchemaIndicator(schemaIndic);
// --- increment values of catalog indicator
catalogIndic.setTableCount(catalogIndic.getTableCount() + tableCount);
catalogIndic.setTableRowCount(catalogIndic.getTableRowCount() + schemaIndic.getTableRowCount());
catalogIndic.setViewRowCount(catalogIndic.getViewRowCount() + schemaIndic.getViewRowCount());
// Added 20130221 TDQ-6546: add the missed the view count
catalogIndic.setViewCount(catalogIndic.getViewCount() + schemaIndic.getViewCount());
// Added 20130401 TDQ-6823: add the missed key and index count for the catelog(which contains schemas)
catalogIndic.setKeyCount(catalogIndic.getKeyCount() + schemaIndic.getKeyCount());
catalogIndic.setIndexCount(catalogIndic.getIndexCount() + schemaIndic.getIndexCount());
} else if (!hasCatalog) {
// has schema only
// add it to list of indicators
this.addToConnectionIndicator(schemaIndic);
} else if (!hasSchema) {
// has catalog only
if (SchemaPackage.eINSTANCE.getCatalogIndicator().equals(schemaIndic.eClass())) {
this.addToConnectionIndicator(schemaIndic);
} else {
// $NON-NLS-1$
log.error(Messages.getString("AbstractSchemaEvaluator.NoCatalogSchema"));
}
}
}
use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutor method getValidStatement.
/**
* DOC xqliu Comment method "getValidStatement". 2009-10-29 bug 9702
*
* @param dataFilterAsString
* @param indicator
* @param valid
* @return
*/
public String getValidStatement(String dataFilterAsString, Indicator indicator, boolean valid) {
if (!isAnalyzedElementValid(indicator)) {
return PluginConstant.EMPTY_STRING;
}
IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
return PluginConstant.EMPTY_STRING;
}
Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
if (!isExpressionValid(sqlGenericExpression, indicator)) {
return PluginConstant.EMPTY_STRING;
}
// --- get indicator parameters and convert them into sql expression
List<String> whereExpressionAnalysis = new ArrayList<String>();
if (StringUtils.isNotBlank(dataFilterAsString)) {
whereExpressionAnalysis.add(dataFilterAsString);
}
List<String> whereExpressionDQRule = new ArrayList<String>();
String setAliasA = PluginConstant.EMPTY_STRING;
final EList<JoinElement> joinConditions = indicator.getJoinConditions();
if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
WhereRule wr = (WhereRule) indicatorDefinition;
whereExpressionDQRule.add(wr.getWhereExpression());
// MOD scorreia 2009-03-13 copy joins conditions into the indicator
joinConditions.clear();
if (!isJoinConditionEmpty(indicator)) {
for (JoinElement joinelt : wr.getJoins()) {
JoinElement joinCopy = EcoreUtil.copy(joinelt);
joinConditions.add(joinCopy);
setAliasA = PluginConstant.EMPTY_STRING.equals(setAliasA) ? joinCopy.getTableAliasA() : setAliasA;
}
}
}
NamedColumnSet set = SwitchHelpers.NAMED_COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement());
String schemaName = getQuotedSchemaName(set);
// --- normalize table name
String catalogName = getQuotedCatalogName(set);
if (catalogName == null && schemaName != null) {
// try to get catalog above schema
final Schema parentSchema = SchemaHelper.getParentSchema(set);
final Catalog parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
catalogName = parentCatalog != null ? parentCatalog.getName() : null;
}
String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
// ### evaluate SQL Statement depending on indicators ###
String completedSqlString = null;
// --- default case
// allow join
String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
String genericSql = sqlGenericExpression.getBody();
// $NON-NLS-1$//$NON-NLS-2$
setAliasA = PluginConstant.EMPTY_STRING.equals(setAliasA) ? "*" : setAliasA + ".*";
// $NON-NLS-1$
genericSql = genericSql.replace("COUNT(*)", setAliasA);
completedSqlString = dbms().fillGenericQueryWithJoin(genericSql, setName, joinclause);
// ~
completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, valid);
return completedSqlString;
}
use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutor method isAnalyzedElementValid.
private boolean isAnalyzedElementValid(Indicator indicator) {
if (indicator.getAnalyzedElement() == null) {
traceError(Messages.getString("ColumnAnalysisSqlExecutor.ANALYSISELEMENTISNULL", // $NON-NLS-1$
AnalysisExecutorHelper.getIndicatorName(indicator)));
return false;
}
// check the AnalyzedElement as set
NamedColumnSet set = SwitchHelpers.NAMED_COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement());
if (set == null) {
traceError(Messages.getString("TableAnalysisSqlExecutor.ANALYZEDELEMENTISNOTATABLE", // $NON-NLS-1$
AnalysisExecutorHelper.getIndicatorName(indicator)));
return false;
}
// --- get the schema owner
if (!belongToSameSchemata(set)) {
StringBuffer buf = new StringBuffer();
for (orgomg.cwm.objectmodel.core.Package schema : schemata.values()) {
// $NON-NLS-1$
buf.append(schema.getName() + " ");
}
log.error(Messages.getString("TableAnalysisSqlExecutor.TABLENOTBELONGTOEXISSCHEMA", quote(set.getName()), // $NON-NLS-1$
buf.toString().trim()));
return false;
}
return true;
}
Aggregations