use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class AnalysisExecutorSelector method executeAnalysis.
/**
* DOC xqliu Comment method "executeAnalysis".
*
* @param analysis
* @param monitor
* @return
* @deprecated use {@link #executeAnalysis(TDQAnalysisItem, IProgressMonitor)} instead.
*/
@Deprecated
public static ReturnCode executeAnalysis(final Analysis analysis, IProgressMonitor monitor) {
IAnalysisExecutor analysisExecutor = getAnalysisExecutor(analysis);
if (analysisExecutor != null) {
// MOD xqliu 2009-02-09 bug 6237
analysisExecutor.setMonitor(monitor);
ReturnCode execute = analysisExecutor.execute(analysis);
// save analysis.
if (Platform.isRunning()) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
AnaResourceFileHelper.getInstance().save(analysis);
}
});
}
return execute;
}
// $NON-NLS-1$
return new ReturnCode(Messages.getString("AnalysisExecutorSelector.NotFindHowExecute", analysis.getName()), false);
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class DatabaseSQLExecutor method executeQuery.
/*
* (non-Javadoc)
*
* @see org.talend.cwm.db.connection.ISQLExecutor#executeQuery(orgomg.cwm.foundation.softwaredeployment.DataManager,
* java.util.List, java.lang.String, org.talend.dataquality.analysis.SampleDataShowWay)
*/
public List<Object[]> executeQuery(DataManager connection, List<ModelElement> analysedElements, String where) throws SQLException {
getDataFromTable().clear();
try {
beginQuery();
} catch (Exception e1) {
log.error(e1.getMessage(), e1);
return getDataFromTable();
}
int columnListSize = analysedElements.size();
TypedReturnCode<java.sql.Connection> sqlconnection = getSQLConnection(connection);
Statement statement = null;
ResultSet resultSet = null;
try {
statement = sqlconnection.getObject().createStatement();
statement.execute(createSqlStatement(connection, analysedElements, where));
resultSet = statement.getResultSet();
while (resultSet.next()) {
Object[] oneRow = new Object[columnListSize];
// --- for each column
for (int i = 0; i < columnListSize; i++) {
// --- get content of column
oneRow[i] = ResultSetUtils.getBigObject(resultSet, i + 1);
}
handleRow(oneRow);
}
} catch (Exception e) {
log.error(e, e);
if (SQLException.class.isInstance(e)) {
throw (SQLException) e;
}
} finally {
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
ReturnCode closed = ConnectionUtils.closeConnection(sqlconnection.getObject());
if (!closed.isOk()) {
log.error(closed.getMessage());
}
}
try {
endQuery();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return getDataFromTable();
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class AbstractWizard method checkMetadata.
public ReturnCode checkMetadata() {
String elementName = getParameter().getName();
IFolder folderResource = getParameter().getFolderProvider().getFolderResource();
if (elementName == null || folderResource == null) {
// $NON-NLS-1$
return new ReturnCode("", false);
} else {
Collection<ModelElement> modelElements = new ArrayList<ModelElement>();
switch(getParameter().getParamType()) {
case ANALYSIS:
modelElements.addAll(AnaResourceFileHelper.getInstance().getAllElement(folderResource));
break;
case REPORT:
modelElements.addAll(RepResourceFileHelper.getInstance().getAllElement(folderResource));
break;
case PATTERN:
modelElements.addAll(PatternResourceFileHelper.getInstance().getAllElement(folderResource));
break;
case CONNECTION:
List<Connection> conns = new ArrayList<Connection>();
try {
for (ConnectionItem connItem : ProxyRepositoryFactory.getInstance().getMetadataConnectionsItem()) {
conns.add(connItem.getConnection());
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
modelElements.addAll(conns);
break;
case DQRULE:
modelElements.addAll(DQRuleResourceFileHelper.getInstance().getAllElement(folderResource));
break;
case UDINDICATOR:
modelElements.addAll(IndicatorResourceFileHelper.getInstance().getAllElement(folderResource));
break;
default:
break;
}
if (!modelElements.isEmpty()) {
for (ModelElement element : modelElements) {
String theElementName = element.getName();
if (theElementName == null) {
if (element instanceof Connection) {
// MOD klliu 2011-04-18 get repository Object label
// theElementName =RepositoryNodeHelper.recursiveFind(element).getObject().getLabel();
}
}
if (elementName.equals(theElementName)) {
// MOD xqliu 2010-09-21 bug 15762
return new ReturnCode(UIMessages.MSG_ANALYSIS_SAME_NAME, false);
// if (!MessageUI.openConfirm(UIMessages.MSG_ANALYSIS_SAME_NAME)) {
// getParameter().setName(elementName + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss")); //$NON-NLS-1$
// }
// break;
// ~ 15762
}
}
}
}
return new ReturnCode(true);
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class FolderWizard method performFinish.
/**
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
@Override
public boolean performFinish() {
final ReturnCode returncode = new ReturnCode(true);
RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>(// $NON-NLS-1$
DefaultMessagesImpl.getString("FolderWizard.newFolder")) {
@Override
protected void run() throws LoginException, PersistenceException {
String folderName = mainPage.getName();
if (defaultLabel == null) {
IRepositoryNode currentSelectionNode = CorePlugin.getDefault().getCurrentSelectionNode();
IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
IFolder newFolder = folder.getFolder(folderName);
try {
if (ResourceManager.getConnectionFolder().getFullPath().isPrefixOf(folder.getFullPath())) {
// when create folder under dbconnections
ProxyRepositoryFactory.getInstance().createFolder(ERepositoryObjectType.METADATA_CONNECTIONS, path.makeRelativeTo(ResourceManager.getConnectionFolder().getFullPath()), folderName);
} else {
// when create folder under other nodes
newFolder.create(false, true, null);
}
// do refresh
folder.refreshLocal(IResource.DEPTH_INFINITE, null);
DQRespositoryView findView = CorePlugin.getDefault().getRepositoryView();
if (findView != null) {
findView.getCommonViewer().setExpandedState(newFolder, true);
findView.getCommonViewer().refresh(currentSelectionNode);
}
// list .
if (DQRepositoryNode.isOnFilterring()) {
RepositoryNodeHelper.fillTreeList(null);
RepositoryNodeHelper.setFilteredNode(RepositoryNodeHelper.getRootNode(ERepositoryObjectType.TDQ_DATA_PROFILING, true));
}
} catch (CoreException e) {
// $NON-NLS-1$
MessageDialog.openError(// $NON-NLS-1$
getShell(), // $NON-NLS-1$
DefaultMessagesImpl.getString("FolderWizard.error"), // $NON-NLS-1$
DefaultMessagesImpl.getString("FolderWizard.folderCreatedError"));
ExceptionHandler.process(e);
returncode.setOk(false);
return;
}
}
}
};
workUnit.setAvoidUnloadResources(true);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(workUnit);
return returncode.isOk();
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class AElementPersistance method saveWithDependencies.
/**
* Save item with dependencies.
*
* @param element
* @throws PersistenceException
*/
protected ReturnCode saveWithDependencies(Item item, ModelElement element) throws PersistenceException {
ReturnCode rc = new ReturnCode();
removeDependencies(item);
addDependencies(element);
addResourceContent(element.eResource(), element);
Map<EObject, Collection<Setting>> find = EcoreUtil.ExternalCrossReferencer.find(element.eResource());
Set<EObject> needSaves = new HashSet<EObject>();
for (EObject object : find.keySet()) {
Resource re = object.eResource();
if (re == null) {
continue;
}
// only do save when the dependency is not reference project node, and do not do resolve
if (!re.getURI().segment(1).equals(ProjectManager.getInstance().getCurrentProject().getTechnicalLabel())) {
continue;
}
// MOD sizhaoliu TDQ-6296 the resource should be resolved before saving the item to make sure the references
// are updated.
EcoreUtil.resolveAll(re);
needSaves.add(object);
}
// Set the TDQ item file name.
if (item instanceof TDQItem) {
setTDQItemFileName(element, item);
}
ProxyRepositoryFactory.getInstance().save(item);
AbstractResourceChangesService resChangeService = TDQServiceRegister.getInstance().getResourceChangeService(AbstractResourceChangesService.class);
if (resChangeService != null) {
for (EObject toSave : needSaves) {
// only do save when the dependency is not reference project node
toSave = EObjectHelper.resolveObject(toSave);
if (!toSave.eResource().getURI().segment(1).equals(ProjectManager.getInstance().getCurrentProject().getTechnicalLabel())) {
continue;
}
resChangeService.saveResourceByEMFShared(toSave.eResource());
}
}
return rc;
}
Aggregations