use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.
the class EObjectHelper method getTdDataProvider.
/**
* @deprecated it's probably better to use {@link ConnectionHelper#getTdDataProvider(TdColumn)}
*/
@Deprecated
public static Connection getTdDataProvider(TdColumn column) {
ColumnSet columnSetOwner = ColumnHelper.getColumnSetOwner(column);
Package parentCatalogOrSchema = ColumnSetHelper.getParentCatalogOrSchema(columnSetOwner);
return ConnectionHelper.getTdDataProvider(parentCatalogOrSchema);
}
use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.
the class DbmsLanguage method getCatalogOrSchemaName.
/**
* get the catalog or schema name according to the analyzed column.
*
* @param analyzedColumn
* @return if the catalog is not null, return catalog's name, else if schema is not null, return schema's name, else
* return null
*/
public String getCatalogOrSchemaName(TdColumn tdColumn) {
String name = null;
// get the catalog/schema name from the context
DatabaseConnection dbConn = ConnectionHelper.getTdDataProvider(tdColumn);
if (dbConn != null && dbConn.isContextMode()) {
name = getCatalogNameFromContext(dbConn);
if (!StringUtils.isEmpty(name)) {
return name;
}
name = getSchemaNameFromContext(dbConn);
if (!StringUtils.isEmpty(name)) {
return name;
}
}
// if the catalog/schema name from the context is empty, get it by the column
if (StringUtils.isEmpty(name)) {
ColumnSet columnSet = ColumnHelper.getColumnOwnerAsColumnSet(tdColumn);
// Get catalog
Catalog catalog = getCatalog(columnSet);
if (catalog != null) {
return catalog.getName();
}
// Get schema
Schema schema = getSchema(columnSet);
if (schema != null) {
return schema.getName();
}
// no catalog and schema
// $NON-NLS-1$
log.error(Messages.getString("DbmsLanguage.NoCatalogOrSchema", columnSet.getName()));
}
return name;
}
use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.
the class DbmsLanguage method getQueryColumnsWithPrefix.
/**
* Get query string with prefix (catalog/schema.table.column) given column array.
*
* @param columns
* @return
*/
public String getQueryColumnsWithPrefix(TdColumn[] columns) {
String columnClause = PluginConstant.EMPTY_STRING;
if (columns.length == 0) {
return columnClause;
}
ColumnSet columnSet = ColumnHelper.getColumnOwnerAsColumnSet(columns[0]);
String tableName = getQueryColumnSetWithPrefix(columnSet);
for (TdColumn column : columns) {
columnClause += tableName + DOT + quote(column.getName()) + getSeparatedCharacter();
}
columnClause = columnClause.substring(0, columnClause.length() - 1);
return columnClause;
}
use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.
the class AnalysisExecutorHelper method getTableName.
/**
* get full name as: db.catalog.table, if has catalog/schema
*
* @param analyzedElement only for TdColumn and ColumnSet.
* @param dbmsLanguage
* @return
* @deprecated instead of it by {@link DbmsLanguage#getQueryColumnSetWithPrefix(ColumnSet) or
* DbmsLanguage#getQueryColumnSetWithPrefix(TdColumn)}
*/
@Deprecated
public static String getTableName(ModelElement analyzedElement, DbmsLanguage dbmsLanguage) {
TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(analyzedElement);
if (tdColumn != null) {
return dbmsLanguage.getQueryColumnSetWithPrefix(tdColumn);
}
ColumnSet columnSet = SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(analyzedElement);
if (columnSet != null) {
return dbmsLanguage.getQueryColumnSetWithPrefix(columnSet);
}
// $NON-NLS-1$
log.error(Messages.getString("AnalysisExecutorHelper.TableEmpty"));
return PluginConstant.EMPTY_STRING;
}
use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.
the class ColumnAnalysisExecutor method createSqlStatement.
/*
* (non-Javadoc)
*
* @see org.talend.dq.analysis.AnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)
*/
@Override
public String createSqlStatement(Analysis analysis) {
this.cachedAnalysis = analysis;
// CwmZQuery query = new CwmZQuery();
// $NON-NLS-1$
StringBuilder sql = new StringBuilder("SELECT ");
EList<ModelElement> analysedElements = analysis.getContext().getAnalysedElements();
// so if you modify the code here, please also modify the same part.
if (analysedElements.isEmpty()) {
setError(// $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"ColumnAnalysisExecutor.CannotCreateSQLStatement", analysis.getName()));
return null;
}
Set<ColumnSet> fromPart = new HashSet<ColumnSet>();
final Iterator<ModelElement> iterator = analysedElements.iterator();
while (iterator.hasNext()) {
// for (ModelElement modelElement : analysedElements) {
ModelElement modelElement = iterator.next();
// --- preconditions
TdColumn col = SwitchHelpers.COLUMN_SWITCH.doSwitch(modelElement);
if (col == null) {
// $NON-NLS-1$
setError(Messages.getString("ColumnAnalysisExecutor.GivenElementIsNotColumn", modelElement));
return null;
}
Classifier owner = col.getOwner();
if (owner == null) {
// $NON-NLS-1$
setError(Messages.getString("ColumnAnalysisExecutor.NoOwnerFound", col.getName()));
}
ColumnSet colSet = SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(owner);
if (colSet == null) {
// $NON-NLS-1$
setError(Messages.getString("ColumnAnalysisExecutor.NoContainerFound", col.getName()));
return null;
}
// MOD zshen feature 12919 select all the column to be prepare for drill down when user need.
if (!analysis.getParameters().isStoreData()) {
sql.append(this.quote(col.getName()));
// append comma if more columns exist
if (iterator.hasNext()) {
sql.append(',');
}
}
// add from
fromPart.add(colSet);
}
if (fromPart.size() != 1) {
// $NON-NLS-1$
log.error(Messages.getString("ColumnAnalysisExecutor.ANALYSISMUSTRUNONONETABLE") + fromPart.size() + PluginConstant.DOT_STRING);
// $NON-NLS-1$
setError(Messages.getString("ColumnAnalysisExecutor.ANALYSISMUSTRUNONONETABLEERRORMESSAGE"));
return null;
}
TdColumn firstColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(analysedElements.get(0));
// MOD zshen feature 12919 select all the column to be prepare for drill down.
if (analysis.getParameters().isStoreData()) {
// MOD klliu 2011-06-30 bug 22523 whichever is Table or View,that finds columns should ues columnset
EObject eContainer = firstColumn.eContainer();
List<TdColumn> columnList = ColumnSetHelper.getColumns(SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(eContainer));
// ~
Iterator<TdColumn> iter = columnList.iterator();
while (iter.hasNext()) {
TdColumn column = iter.next();
sql.append(this.quote(column.getName()));
// append comma if more columns exist
if (iter.hasNext()) {
sql.append(',');
}
}
}
// add from clause
sql.append(dbms().from());
sql.append(dbms().getQueryColumnSetWithPrefix(firstColumn));
// add where clause
// --- get data filter
ModelElementAnalysisHandler handler = new ModelElementAnalysisHandler();
handler.setAnalysis(analysis);
String stringDataFilter = handler.getStringDataFilter();
if (!(stringDataFilter == null || "".equals(stringDataFilter))) {
// $NON-NLS-1$
sql.append(GenericSQLHandler.WHERE_CLAUSE);
}
String sqlStatement = sql.toString();
sqlStatement = dbms().addWhereToStatement(sqlStatement, stringDataFilter);
return sqlStatement;
}
Aggregations