use of org.talend.core.IRepositoryContextService in project tdq-studio-se by Talend.
the class DbmsLanguage method cloneOriginalValueConnection.
/**
* clone the database connection with original value according to the context(the database connection must be
* context mode).
*
* @param dbConn
* @return
*/
private DatabaseConnection cloneOriginalValueConnection(DatabaseConnection dbConn) {
IRepositoryContextService repositoryContextService = CoreRuntimePlugin.getInstance().getRepositoryContextService();
if (repositoryContextService != null) {
String contextName = dbConn.getContextName();
if (contextName == null) {
// $NON-NLS-1$
String msg = Messages.getString("DbmsLanguage.ContextNameIsNull");
RuntimeException exp = new RuntimeException(msg);
log.error(msg, exp);
throw exp;
}
return repositoryContextService.cloneOriginalValueConnection(dbConn, false, contextName);
} else {
// $NON-NLS-1$
String msg = Messages.getString("DbmsLanguage.IRepositoryContextServiceIsNull");
RuntimeException exp = new RuntimeException(msg);
log.error(msg, exp);
throw exp;
}
}
use of org.talend.core.IRepositoryContextService in project tdq-studio-se by Talend.
the class ConnectionUtils method isConnectionAvailable.
/**
* This method is used to check conectiton is avalible for analysis or report ,when analysis or report runs.
*
* @param analysisDataProvider
* @return
*/
public static ReturnCode isConnectionAvailable(Connection analysisDataProvider) {
ReturnCode returnCode = new ReturnCode();
if (analysisDataProvider == null) {
returnCode.setOk(false);
// $NON-NLS-1$
returnCode.setMessage(Messages.getString("ConnectionUtils.checkConnFailTitle"));
return returnCode;
}
// check hive connection
IMetadataConnection metadataConnection = ConvertionHelper.convert(analysisDataProvider);
if (metadataConnection != null) {
if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
try {
// need to do this first when check for hive embed connection.
if (isHiveEmbedded(analysisDataProvider)) {
JavaSqlFactory.doHivePreSetup(analysisDataProvider);
}
HiveConnectionManager.getInstance().checkConnection(metadataConnection);
returnCode.setOk(true);
} catch (ClassNotFoundException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
} catch (InstantiationException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
} catch (IllegalAccessException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
} catch (SQLException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
}
return returnCode;
}
}
// MOD klliu check file connection is available
if (analysisDataProvider instanceof FileConnection) {
FileConnection fileConn = (FileConnection) analysisDataProvider;
// ADD msjian TDQ-4559 2012-2-28: when the fileconnection is context mode, getOriginalFileConnection.
if (fileConn.isContextMode()) {
IRepositoryContextService service = CoreRuntimePlugin.getInstance().getRepositoryContextService();
if (service != null) {
fileConn = service.cloneOriginalValueConnection(fileConn);
}
}
// TDQ-4559 ~
String filePath = fileConn.getFilePath();
try {
BufferedReader filePathAvailable = FilesUtils.isFilePathAvailable(filePath, fileConn);
if (filePathAvailable == null) {
returnCode.setOk(false);
// $NON-NLS-1$ //$NON-NLS-2$
returnCode.setMessage(Messages.getString("ConnectionUtils.checkConnFailTitle") + " " + filePath);
}
} catch (UnsupportedEncodingException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
} catch (FileNotFoundException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
} catch (IOException e) {
returnCode.setOk(false);
returnCode.setMessage(e.toString());
}
return returnCode;
}
// ~
Properties props = new Properties();
props.put(TaggedValueHelper.USER, JavaSqlFactory.getUsername(analysisDataProvider));
props.put(TaggedValueHelper.PASSWORD, JavaSqlFactory.getPassword(analysisDataProvider));
if (analysisDataProvider instanceof DatabaseConnection) {
// MOD qiongli TDQ-11507,for GeneralJdbc,should check connection too after validation jar and jdbc driver .
if (isTcompJdbc(analysisDataProvider) || isGeneralJdbc(analysisDataProvider)) {
ReturnCode rcJdbc = checkJdbcJarFilePathDriverClassName((DatabaseConnection) analysisDataProvider);
if (!rcJdbc.isOk()) {
return rcJdbc;
}
}
// MOD qiongli 2014-5-14 in order to check and connect a dbConnection by a correct driver,replace
// 'ConnectionUtils.checkConnection(...)' with 'managerConn.check(metadataConnection)'.
ManagerConnection managerConn = new ManagerConnection();
returnCode.setOk(managerConn.check(metadataConnection));
returnCode.setMessage(managerConn.getMessageException());
}
return returnCode;
}
use of org.talend.core.IRepositoryContextService in project tdq-studio-se by Talend.
the class DelimitedFileIndicatorEvaluator method executeSqlQuery.
@Override
protected ReturnCode executeSqlQuery(String sqlStatement) {
ReturnCode returnCode = new ReturnCode(true);
if (delimitedFileconnection == null) {
delimitedFileconnection = (DelimitedFileConnection) analysis.getContext().getConnection();
}
if (delimitedFileconnection.isContextMode()) {
IRepositoryContextService service = CoreRuntimePlugin.getInstance().getRepositoryContextService();
delimitedFileconnection = (DelimitedFileConnection) service.cloneOriginalValueConnection(delimitedFileconnection);
}
String path = JavaSqlFactory.getURL(delimitedFileconnection);
IPath iPath = new Path(path);
File file = iPath.toFile();
if (!file.exists()) {
// $NON-NLS-1$
returnCode.setReturnCode(Messages.getString("DelimitedFileIndicatorEvaluator.CanNotFindFile"), false);
return returnCode;
}
List<ModelElement> analysisElementList = this.analysis.getContext().getAnalysedElements();
EMap<Indicator, AnalyzedDataSet> indicToRowMap = analysis.getResults().getIndicToRowMap();
indicToRowMap.clear();
List<MetadataColumn> columnElementList = new ArrayList<MetadataColumn>();
for (int i = 0; i < analysisElementList.size(); i++) {
MetadataColumn mColumn = (MetadataColumn) analysisElementList.get(i);
MetadataTable mTable = ColumnHelper.getColumnOwnerAsMetadataTable(mColumn);
columnElementList = mTable == null ? columnElementList : mTable.getColumns();
if (!columnElementList.isEmpty()) {
break;
}
}
ReturnCode readDataReturnCode = new ReturnCode(true);
// use CsvReader to parse.
if (Escape.CSV.equals(delimitedFileconnection.getEscapeType())) {
readDataReturnCode = useCsvReader(file, analysisElementList, columnElementList, indicToRowMap);
} else {
readDataReturnCode = useDelimitedReader(analysisElementList, columnElementList, indicToRowMap);
}
// handle error message
if (!readDataReturnCode.isOk()) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), // $NON-NLS-1$
Messages.getString("DelimitedFileIndicatorEvaluator.badlyForm.Title"), // $NON-NLS-1$
Messages.getString("DelimitedFileIndicatorEvaluator.badlyForm.Message"));
}
});
}
// Added yyin 20120608 TDQ-3589
for (MetadataColumn col : columnElementList) {
List<Indicator> indicators = getIndicators(col.getLabel());
for (Indicator indicator : indicators) {
if (indicator instanceof DuplicateCountIndicator) {
AnalyzedDataSet analyzedDataSet = indicToRowMap.get(indicator);
if (analyzedDataSet == null) {
analyzedDataSet = AnalysisFactory.eINSTANCE.createAnalyzedDataSet();
indicToRowMap.put(indicator, analyzedDataSet);
analyzedDataSet.setDataCount(analysis.getParameters().getMaxNumberRows());
analyzedDataSet.setRecordSize(0);
}
// indicator.finalizeComputation();
addResultToIndicatorToRowMap(indicator, indicToRowMap);
}
}
}
return returnCode;
}
Aggregations