use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class ConnectionUtils method getHadoopClusterIDOfHive.
/**
* get the hadoop cluster ID .
*
* @param viewObject
* @return
*/
public static String getHadoopClusterIDOfHive(IRepositoryViewObject viewObject) {
DatabaseConnectionItem dbItem = (DatabaseConnectionItem) viewObject.getProperty().getItem();
DatabaseConnection dbConnection = (DatabaseConnection) dbItem.getConnection();
return dbConnection.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HADOOP_CLUSTER_ID);
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class ConnectionUtils method isGeneralJdbc.
/**
* if the Connection's type is General JDBC return true.
*
* @param conn a database connection
* @return
*/
public static boolean isGeneralJdbc(Connection conn) {
boolean jdbc = false;
if (conn instanceof DatabaseConnection) {
DatabaseConnection dbConn = (DatabaseConnection) conn;
EDatabaseTypeName databaseType = EDatabaseTypeName.getTypeFromDbType(dbConn.getDatabaseType());
if (EDatabaseTypeName.GENERAL_JDBC.equals(databaseType)) {
jdbc = true;
}
}
return jdbc;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class ConnectionUtils method setName.
/**
* DOC zshen Comment method "setName".
*
* @param conn
* @param password
*/
public static void setName(Connection conn, String name) {
DatabaseConnection dbConn = SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(conn);
if (dbConn != null) {
dbConn.setName(name);
dbConn.setLabel(name);
}
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection 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.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class ConnectionUtils method getRetrieveAllMetadata.
/**
* if the connection has sid return false, else return true (don't need the TaggedValue any more).
*
* @param element
* @return
*/
public static boolean getRetrieveAllMetadata(ModelElement element) {
if (element != null && element instanceof Connection) {
if (element instanceof DatabaseConnection) {
DatabaseConnection dbConn = (DatabaseConnection) element;
String sid = JavaSqlFactory.getSID(dbConn);
if (sid != null && !"".equals(sid.trim())) {
// $NON-NLS-1$
// MOD klliu bug 22900
TaggedValue taggedValue = TaggedValueHelper.getTaggedValue(TaggedValueHelper.RETRIEVE_ALL, element.getTaggedValue());
// if connection is created by 4.2 or 5.0 ,the tagedValue(RETRIEVE_ALL) has been removed.
if (taggedValue != null) {
String value = taggedValue.getValue();
if (value.equals("true")) {
// $NON-NLS-1$
return true;
}
}
// ~
if (ConnectionHelper.isOracle(dbConn) || isPostgresql(dbConn)) {
String uiSchema = dbConn.getUiSchema();
if (uiSchema != null && !"".equals(uiSchema.trim())) {
// $NON-NLS-1$
return false;
} else {
return true;
}
} else {
return false;
}
} else {
return true;
}
} else if (element instanceof FileConnection) {
// do file connection can filter catalog/schema?
return true;
}
}
return true;
}
Aggregations