use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class DatabaseSQLExecutor method createSqlStatement.
/**
* createSqlStatement: if has limit, add it, else do not use limit
*
* @param connection
* @param analysedElements
* @return
*/
private String createSqlStatement(DataManager connection, List<ModelElement> analysedElements, String where) {
DbmsLanguage dbms = DbmsLanguageFactory.createDbmsLanguage(connection);
TdColumn col = null;
// $NON-NLS-1$
StringBuilder sql = new StringBuilder("SELECT ");
final Iterator<ModelElement> iterator = analysedElements.iterator();
while (iterator.hasNext()) {
ModelElement modelElement = iterator.next();
col = SwitchHelpers.COLUMN_SWITCH.doSwitch(modelElement);
sql.append(dbms.quote(col.getName()));
// append comma if more columns exist
if (iterator.hasNext()) {
sql.append(',');
}
}
sql.append(dbms.from());
sql.append(dbms.getQueryColumnSetWithPrefix(col));
if (where != null && where.length() > 0) {
sql.append(dbms.where());
sql.append(where);
}
String finalQuery = sql.toString();
if (isShowRandomData()) {
finalQuery = dbms.getRandomQuery(finalQuery);
}
if (getLimit() > 0) {
return dbms.getTopNQuery(finalQuery, getLimit());
} else {
return finalQuery;
}
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class ChartDataEntity method checkRange.
private boolean checkRange(String inString) {
String[] definedRange = getDefinedRange(inString);
if (definedRange != null && definedRange.length >= 2) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
range = "[" + definedRange[0] + "," + definedRange[1] + "]";
ModelElement temp = indicator.getAnalyzedElement();
int sqltype = Types.INTEGER;
if (null != temp) {
int tempType = sqltype;
if (temp instanceof TdColumn) {
// MOD qiongli 2011-11-15,TDQ-3690.it should be set value to 'tempType' not 'sqltype' at here.
tempType = ((TdColumn) temp).getSqlDataType().getJavaDataType();
}
sqltype = temp instanceof TdTable ? Types.INTEGER : tempType;
}
boolean isChildOfRange = IndicatorsPackage.eINSTANCE.getValueIndicator().isSuperTypeOf(indicator.eClass());
if (Java2SqlType.isDateInSQL(sqltype) && isChildOfRange) {
try {
// $NON-NLS-1$
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date dValue = format.parse(value);
if ("".equals(definedRange[0])) {
// $NON-NLS-1$
Date max = format.parse(definedRange[1]);
// $NON-NLS-1$ //$NON-NLS-2$
range = "[*, " + definedRange[1] + "]";
return dValue.after(max);
} else if ("".equals(definedRange[1])) {
// $NON-NLS-1$
Date min = format.parse(definedRange[0]);
// $NON-NLS-1$ //$NON-NLS-2$
range = "[" + definedRange[0] + ", *]";
return dValue.before(min);
} else {
Date min = format.parse(definedRange[0]);
Date max = format.parse(definedRange[1]);
return dValue.after(max) || dValue.before(min);
}
} catch (Exception e) {
log.error(e, e);
return false;
}
} else {
Double min = StringFormatUtil.formatFourDecimalDouble(definedRange[0]);
Double max = StringFormatUtil.formatFourDecimalDouble(definedRange[1]);
// handle min and max
Double dValue = inString != null ? StringFormatUtil.parseDouble(inString) : Double.NaN;
if (min == null || Double.isNaN(min)) {
min = Double.NEGATIVE_INFINITY;
}
if (max == null || Double.isNaN(max)) {
max = Double.POSITIVE_INFINITY;
}
if (isPercent) {
return dValue < min * 100 || dValue > max * 100;
}
return dValue < min || dValue > max;
}
}
return false;
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class DBColumnFolderRepNode method getChildren.
@Override
public List<IRepositoryNode> getChildren() {
if (!this.isReload() && !children.isEmpty()) {
// MOD gdbu 2011-6-29 bug : 22204
return filterResultsIfAny(children);
}
children.clear();
String filterCharater = null;
IRepositoryViewObject meataColumnSetObject = this.getParent().getObject();
EList<MetadataColumn> columns = null;
if (meataColumnSetObject instanceof TdTableRepositoryObject) {
TdTableRepositoryObject tdTableRepositoryObject = (TdTableRepositoryObject) meataColumnSetObject;
// MOD klliu 2011-09-06 bug TDQ-3414
setItem((ConnectionItem) tdTableRepositoryObject.getViewObject().getProperty().getItem());
if (tdTableRepositoryObject.getTdTable().eIsProxy()) {
// reload the connection to make sure the connection(and all it's owned elements) is not proxy
reloadConnectionViewObject();
}
tdTable = tdTableRepositoryObject.getTdTable();
columns = tdTable.getColumns();
filterCharater = ColumnHelper.getColumnFilter(tdTable);
} else if (meataColumnSetObject instanceof TdViewRepositoryObject) {
TdViewRepositoryObject tdViewRepositoryObject = (TdViewRepositoryObject) meataColumnSetObject;
// MOD klliu 2011-09-06 bug TDQ-3414
setItem((ConnectionItem) tdViewRepositoryObject.getViewObject().getProperty().getItem());
if (tdViewRepositoryObject.getTdView().eIsProxy()) {
// reload the connection to make sure the connection(and all it's owned elements) is not proxy
reloadConnectionViewObject();
}
tdView = tdViewRepositoryObject.getTdView();
columns = tdView.getColumns();
filterCharater = ColumnHelper.getColumnFilter(tdView);
}
setConnection(getItem().getConnection());
// MOD TDQ-8718 20140430 the repository view cares about if use the filter or not, the column select dialog
// cares about if connect to DB or not.
List<TdColumn> tdcolumns = null;
if (columns.size() <= 0) {
if (isCallingFromColumnDialog()) {
tdcolumns = loadColumns(isLoadDBFromDialog());
} else if (!isOnFilterring()) {
// MOD gdbu 2011-6-28 bug : 22204
tdcolumns = loadColumns(true);
}
} else {
tdcolumns = new ArrayList<TdColumn>();
for (MetadataColumn mec : columns) {
tdcolumns.add((TdColumn) mec);
}
}
if (tdcolumns != null && filterCharater != null && !filterCharater.equals("")) {
// $NON-NLS-1$
tdcolumns = RepositoryNodeHelper.filterColumns(tdcolumns, filterCharater);
}
createTdcolumnsNode(tdcolumns, children);
this.setReload(false);
// MOD gdbu 2011-6-28 bug : 22204
return filterResultsIfAny(children);
// return children;
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class ChangeConnectionAction method reloadByColumnSetFolderLevel.
private void reloadByColumnSetFolderLevel(List<SynTreeModel> treeModelLs, AnalyzedElementSynDialog anaEleSynDialog, Connection newDataProv) throws ReloadCompareException {
ModelElement oldDataProviderModel = treeModelLs.get(0).getOldDataProvElement();
// Reload columnSet folder
ColumnSet columnset = null;
if (oldDataProviderModel instanceof ColumnSet) {
columnset = (ColumnSet) oldDataProviderModel;
} else if (oldDataProviderModel instanceof TdColumn) {
columnset = ColumnHelper.getColumnOwnerAsColumnSet(oldDataProviderModel);
} else {
return;
}
// MOD mzhao bug 8567 2010-03-29
IFolderNode reloadFolder = FolderNodeHelper.getFolderNode((Package) treeModelLs.get(0).getNewDataProvElement(), columnset);
if (reloadFolder != null) {
IComparisonLevel creatComparisonLevel = ComparisonLevelFactory.creatComparisonLevel(reloadFolder);
if (creatComparisonLevel != null) {
// FIXME newDataProv is never used in the following codes.
newDataProv = creatComparisonLevel.reloadCurrentLevelElement();
}
// Recompute after reload
// FIXME treeModelLs is never used in the following codes.
treeModelLs = anaEleSynDialog.getSynInputModel();
}
}
use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.
the class ChangeConnectionAction method reloadByColumnFolderLevel.
private void reloadByColumnFolderLevel(List<SynTreeModel> treeModelLs, AnalyzedElementSynDialog anaEleSynDialog, Connection newDataProv) throws ReloadCompareException {
ModelElement newDataProviderModel = treeModelLs.get(0).getNewDataProvElement();
// If schema or catalog changed, we did not load anymore.
// Reload column folder
ColumnSet columnset = null;
if (newDataProviderModel instanceof ColumnSet) {
columnset = (ColumnSet) newDataProviderModel;
} else if (newDataProviderModel instanceof TdColumn) {
columnset = ColumnHelper.getColumnOwnerAsColumnSet(newDataProviderModel);
} else {
return;
}
// MOD mzhao bug 8567 2010-03-29
IFolderNode reloadFolder = FolderNodeHelper.getFolderNodes(columnset)[0];
if (reloadFolder != null) {
IComparisonLevel creatComparisonLevel = ComparisonLevelFactory.creatComparisonLevel(reloadFolder);
if (creatComparisonLevel != null) {
// FIXME newDataProv is never used in the following codes.
newDataProv = creatComparisonLevel.reloadCurrentLevelElement();
}
// Recompute after reload
// FIXME treeModelLs is never used in the following codes.
treeModelLs = anaEleSynDialog.getSynInputModel();
}
}
Aggregations