use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutor method belongToSameSchemata.
protected TypedReturnCode<Boolean> belongToSameSchemata(final TdTable tdTable) {
TypedReturnCode<Boolean> returnCode = new TypedReturnCode<Boolean>(Boolean.TRUE);
assert tdTable != null;
if (schemata.get(tdTable) != null) {
return returnCode;
}
// get catalog or schema
Package schema = ColumnSetHelper.getParentCatalogOrSchema(tdTable);
if (schema == null) {
// $NON-NLS-1$
String errorMessage = Messages.getString("TableAnalysisSqlExecutor.NoSchemaOrCatalogFound", tdTable.getName());
returnCode.setMessage(errorMessage);
returnCode.setOk(Boolean.FALSE);
return returnCode;
}
schemata.put(tdTable, schema);
return returnCode;
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class AnalysisExecutor method getConnection.
/**
* DOC scorreia Comment method "getConnection".
*
* @param analysis
* @param schema
* @return
*/
protected TypedReturnCode<java.sql.Connection> getConnection(Analysis analysis) {
// MODSCA 2008-03-25 scorreia schema is not used. removed (was used before to select the catalog of the db)
// now it is done elsewhere
TypedReturnCode<java.sql.Connection> rc = new TypedReturnCode<java.sql.Connection>();
DataManager datamanager = analysis.getContext().getConnection();
if (datamanager == null) {
// $NON-NLS-1$
rc.setReturnCode(Messages.getString("AnalysisExecutor.DataManagerNull", analysis.getName()), false);
return rc;
}
if (datamanager != null && datamanager.eIsProxy()) {
datamanager = (DataManager) EObjectHelper.resolveObject(datamanager);
}
Connection dataprovider = SwitchHelpers.CONNECTION_SWITCH.doSwitch(datamanager);
if (dataprovider == null) {
rc.setReturnCode(// $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"AnalysisExecutor.DataProviderNull", // $NON-NLS-1$
datamanager.getName(), analysis.getName()), false);
return rc;
}
// create hive connection
IMetadataConnection metadataConnection = ConvertionHelper.convert(dataprovider);
if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
try {
HiveConnectionHandler hiveConnHandler = HiveConnectionManager.getInstance().createHandler(metadataConnection);
java.sql.Connection createConnection = hiveConnHandler.createHiveConnection();
rc.setOk(true);
rc.setObject(createConnection);
} catch (ClassNotFoundException e) {
log.error(e);
rc.setOk(false);
} catch (InstantiationException e) {
log.error(e);
rc.setOk(false);
} catch (IllegalAccessException e) {
log.error(e);
rc.setOk(false);
} catch (SQLException e) {
log.error(e);
rc.setOk(false);
}
return rc;
} else {
// create other type connection
TypedReturnCode<java.sql.Connection> connection = JavaSqlFactory.createConnection(dataprovider);
if (!connection.isOk()) {
rc.setReturnCode(connection.getMessage(), false);
return rc;
}
rc.setObject(connection.getObject());
return rc;
}
}
use of org.talend.utils.sugars.TypedReturnCode in project tdq-studio-se by Talend.
the class DependenciesHandler method setUsageDependencyOn.
/**
* Method "setUsageDependencyOn".
*
* @param client the element which depends on the supplier
* @param supplier the element needed by the client element
* @return the dependency object between the two given elements
*/
public TypedReturnCode<Dependency> setUsageDependencyOn(ModelElement client, ModelElement supplier) {
// get the supplier's usage dependencies
EList<Dependency> supplierDependencies = supplier.getSupplierDependency();
// search for clients into them
for (Dependency dependency : supplierDependencies) {
if (dependency.getKind() != null && USAGE.compareTo(dependency.getKind()) == 0) {
// if exist return true with the dependency
EObject resolvedObject = ResourceHelper.resolveObject(dependency.getClient(), client);
// check whether the client contains relation dependency, if yes remove the dependency firstly
if (resolvedObject == null) {
if (checkClientDependencyExist(client, supplier)) {
// normal case the code should not come here, except import same project with the second time
removeClientDependency(client, supplier);
}
// if not add analysis to the dependency
dependency.getClient().add(client);
}
TypedReturnCode<Dependency> rc = new TypedReturnCode<Dependency>();
rc.setObject(dependency);
return rc;
}
}
// if not exist create a usage dependency
return createUsageDependencyOn(client, supplier);
}
use of org.talend.utils.sugars.TypedReturnCode 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.TypedReturnCode in project tdq-studio-se by Talend.
the class AElementPersistance method create.
/**
* Persist an element in the specified folder, the file name is created logically by the name of this element.
*
* @param element
* @param folder
* @return
*/
public TypedReturnCode<Object> create(ModelElement element, IFolder folder, boolean... isImportItem) {
TypedReturnCode<Object> trc = new TypedReturnCode<Object>();
if (getFileExtension() == null) {
// $NON-NLS-1$
trc.setMessage("File extension is null.");
// $NON-NLS-1$
log.error(Messages.getString("Get file extension error"));
} else {
IPath itemPath = folder.getFullPath();
Property property = initProperty(element);
Item item = property.getItem();
try {
ProxyRepositoryFactory.getInstance().create(item, getPath(element, itemPath), isImportItem);
trc.setObject(item);
trc.setOk(Boolean.TRUE);
} catch (Exception e) {
trc.setMessage(e.getMessage());
trc.setOk(Boolean.FALSE);
log.warn("Create item failed, try to create it by a logical name. ", e);
}
}
return trc;
}
Aggregations