use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.
the class PreviewProvider method fillContextMenu.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
*/
@Override
public void fillContextMenu(IMenuManager menu) {
// MOD mzhao user readonly role on svn repository mode.
if (!isShowMenu()) {
return;
}
TreeSelection treeSelection = ((TreeSelection) this.getContext().getSelection());
Object firstElement = treeSelection.getFirstElement();
NamedColumnSet set = null;
if (firstElement instanceof DBTableRepNode) {
set = ((DBTableRepNode) firstElement).getTdTable();
} else if (firstElement instanceof DBViewRepNode) {
set = ((DBViewRepNode) firstElement).getTdView();
}
if (set != null) {
PreviewAction action = new PreviewAction(set);
menu.add(action);
}
}
use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.
the class TableViewerDND method installDND.
/**
* DOC xqliu Comment method "installDND".
*
* @param targetControl
*/
public static void installDND(final Tree targetControl) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
final CommonViewer commonViewer = findView.getCommonViewer();
final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
int operations = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { transfer };
DropTarget dropTarget = new DropTarget(targetControl, operations);
dropTarget.setTransfer(transfers);
DropTargetListener dndListener = new TreeDropTargetEffect(targetControl) {
ISelectionReceiver receiver = null;
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
Object object = selection.getFirstElement();
if (object instanceof RuleRepNode) {
receiver = new DQRuleReceiver();
}
if (object instanceof NamedColumnSet) {
receiver = new TableReceiver();
}
if (object instanceof DBTableRepNode) {
receiver = new TableReceiver();
}
if (object instanceof DBViewRepNode) {
receiver = new TableReceiver();
}
if (receiver == null) {
event.detail = DND.DROP_NONE;
} else {
event.feedback = DND.FEEDBACK_EXPAND;
receiver.doDropValidation(event, commonViewer);
}
}
@Override
public void dragOver(DropTargetEvent event) {
super.dragOver(event);
if (receiver != null) {
receiver.doDropValidation(event, commonViewer);
}
}
@Override
public void drop(DropTargetEvent event) {
int index = targetControl.getItemCount();
super.drop(event);
if (event.item == null) {
// TreeItem item = new TreeItem(targetControl, SWT.NONE);
// item.setText(texts);
// item.setText(text);
} else {
TreeItem item = (TreeItem) event.item;
TreeItem[] items = targetControl.getItems();
for (int i = 0; i < items.length; i++) {
if (items[i] == item) {
index = i;
break;
}
}
}
if (receiver != null) {
receiver.drop(event, commonViewer, index);
}
}
};
dropTarget.addDropListener(dndListener);
}
use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutor method createSqlQuery.
private boolean createSqlQuery(String dataFilterAsString, Indicator indicator, boolean withWhereOfRule) throws AnalysisExecutionException {
if (!isAnalyzedElementValid(indicator)) {
return Boolean.FALSE;
}
IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
return Boolean.FALSE;
}
Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
if (!isExpressionValid(sqlGenericExpression, indicator)) {
return Boolean.FALSE;
}
// --- get indicator parameters and convert them into sql expression
List<String> whereExpressionDQRule = new ArrayList<String>();
final EList<JoinElement> joinConditions = indicator.getJoinConditions();
if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
WhereRule wr = (WhereRule) indicatorDefinition;
if (withWhereOfRule) {
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);
}
}
}
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;
}
// --- default case
// allow join
String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
String completedSqlString = dbms().fillGenericQueryWithJoin(sqlGenericExpression.getBody(), setName, joinclause);
// ~
List<String> whereExpressionAnalysis = new ArrayList<String>();
if (StringUtils.isNotBlank(dataFilterAsString)) {
whereExpressionAnalysis.add(dataFilterAsString);
}
completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, true);
// completedSqlString is the final query
String finalQuery = completedSqlString;
TdExpression instantiateSqlExpression = BooleanExpressionHelper.createTdExpression(dbms().getDbmsName(), finalQuery);
indicator.setInstantiatedExpression(instantiateSqlExpression);
return true;
}
use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutor method evaluate.
@Override
protected ReturnCode evaluate(Analysis analysis, java.sql.Connection connection, String sqlStatement) {
IndicatorEvaluator eval = new IndicatorEvaluator(analysis);
eval.setMonitor(getMonitor());
// --- add indicators
EList<Indicator> indicators = analysis.getResults().getIndicators();
for (Indicator indicator : indicators) {
assert indicator != null;
NamedColumnSet set = SwitchHelpers.NAMED_COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement());
if (set == null) {
continue;
}
// --- get the schema owner
if (!belongToSameSchemata(set)) {
// $NON-NLS-1$
setError(Messages.getString("TableAnalysisExecutor.GivenTable", set.getName()));
return new ReturnCode(getErrorMessage(), Boolean.FALSE);
}
String setName = dbms().getQueryColumnSetWithPrefix(set);
eval.storeIndicator(setName, indicator);
}
// set it into the evaluator
eval.setConnection(connection);
// use pooled connection
eval.setPooledConnection(POOLED_CONNECTION);
// when to close connection
boolean closeAtTheEnd = true;
Package catalog = schemata.values().iterator().next();
if (!eval.selectCatalog(catalog.getName())) {
// $NON-NLS-1$//$NON-NLS-2$
log.warn("Failed to select catalog " + catalog.getName() + " for connection.");
}
ReturnCode retCode = eval.evaluateIndicators(sqlStatement, closeAtTheEnd);
if (getMonitor() != null) {
getMonitor().worked(compIndicatorsWorked);
}
return retCode;
}
use of orgomg.cwm.resource.relational.NamedColumnSet in project tdq-studio-se by Talend.
the class AnalysisTableTreeViewer method setInput.
/**
* DOC xqliu Comment method "setInput".
*
* @param objs
*/
@Override
public void setInput(Object[] objs) {
List<DBTableRepNode> tableNodeList = RepositoryNodeHelper.getTableNodeList(objs);
List<TableIndicator> tableIndicatorList = new ArrayList<TableIndicator>();
// MOD by zshen for 2011.06.13 add the support for the view.
List<DBViewRepNode> viewNodeList = RepositoryNodeHelper.getViewNodeList(objs);
if (tableNodeList.size() == 0 && viewNodeList.size() == 0) {
// feature 22206 : fixed another bug, when deselect all, the view is not changed
this.tableIndicators = tableIndicatorList.toArray(new TableIndicator[tableIndicatorList.size()]);
this.setElements(tableIndicators);
return;
}
List<RepositoryNode> setList = new ArrayList<RepositoryNode>();
Connection tdProvider = null;
for (DBTableRepNode tableNode : tableNodeList) {
if (tdProvider == null) {
tdProvider = ConnectionHelper.getTdDataProvider(TableHelper.getParentCatalogOrSchema(tableNode.getTdTable()));
}
if (tdProvider == null) {
MessageUI.openError(DefaultMessagesImpl.getString("AnalysisTableTreeViewer.TableProviderIsNull", // $NON-NLS-1$
tableNode.getLabel()));
} else if (this.getAnalysis().getContext().getConnection() != null && !tdProvider.equals(this.getAnalysis().getContext().getConnection())) {
MessageUI.openError(DefaultMessagesImpl.getString("AnalysisTableTreeViewer.TableDataProviderIsInvalid", // $NON-NLS-1$
tableNode.getLabel()));
} else {
setList.add(tableNode);
}
}
for (DBViewRepNode tableNode : viewNodeList) {
if (tdProvider == null) {
tdProvider = ConnectionHelper.getTdDataProvider(TableHelper.getParentCatalogOrSchema(tableNode.getTdView()));
}
if (tdProvider == null) {
MessageUI.openError(DefaultMessagesImpl.getString("AnalysisTableTreeViewer.TableProviderIsNull", // $NON-NLS-1$
tableNode.getLabel()));
} else if (this.getAnalysis().getContext().getConnection() != null && !tdProvider.equals(this.getAnalysis().getContext().getConnection())) {
MessageUI.openError(DefaultMessagesImpl.getString("AnalysisTableTreeViewer.TableDataProviderIsInvalid", // $NON-NLS-1$
tableNode.getLabel()));
} else {
setList.add(tableNode);
}
}
for (TableIndicator tableIndicator : tableIndicators) {
// ADDED yyin 20120606 TDQ-5343
NamedColumnSet selectedTable = tableIndicator.getColumnSet();
DQRepositoryNode tableNode = null;
if (selectedTable instanceof TdTable) {
tableNode = RepositoryNodeHelper.recursiveFindTdTable(((TdTable) selectedTable));
} else if (selectedTable instanceof TdView) {
tableNode = RepositoryNodeHelper.recursiveFindTdView(((TdView) selectedTable));
}
// ~
if (setList.contains(tableNode)) {
tableIndicatorList.add(tableIndicator);
setList.remove(tableNode);
}
}
for (RepositoryNode set : setList) {
TableIndicator tableIndicator = null;
if (set instanceof DBViewRepNode) {
tableIndicator = TableIndicator.createTableIndicatorWithRowCountIndicator(((DBViewRepNode) set).getTdView());
} else if (set instanceof DBTableRepNode) {
tableIndicator = TableIndicator.createTableIndicatorWithRowCountIndicator(((DBTableRepNode) set).getTdTable());
} else {
continue;
}
tableIndicatorList.add(tableIndicator);
}
this.tableIndicators = tableIndicatorList.toArray(new TableIndicator[tableIndicatorList.size()]);
this.setElements(tableIndicators);
}
Aggregations