use of org.talend.core.model.metadata.IMetadataConnection in project tdq-studio-se by Talend.
the class MultiColAnalysisCreationTest method getDataManager.
/**
* DOC scorreia Comment method "getDataManager".
*
* @return
*/
public Connection getDataManager() {
// $NON-NLS-1$
TypedProperties connectionParams = PropertiesLoader.getProperties(AllDataProfilerCoreTests.class, "db.properties");
// $NON-NLS-1$
String driverClassName = connectionParams.getProperty("driver");
// $NON-NLS-1$
String dbUrl = connectionParams.getProperty("url");
// $NON-NLS-1$
String sqlTypeName = connectionParams.getProperty("sqlTypeName");
DBConnectionParameter params = new DBConnectionParameter();
// $NON-NLS-1$
params.setName("My connection");
params.setDriverClassName(driverClassName);
params.setJdbcUrl(dbUrl);
params.setSqlTypeName(sqlTypeName);
params.setParameters(connectionParams);
params.getParameters();
// create connection
ConnectionUtils.setTimeout(false);
MetadataFillFactory instance = MetadataFillFactory.getDBInstance();
IMetadataConnection metaConnection = instance.fillUIParams(ParameterUtil.toMap(params));
ReturnCode rc = null;
try {
rc = instance.checkConnection(metaConnection);
} catch (java.lang.RuntimeException e) {
Assert.fail("connect to " + dbUrl + "failed," + e.getMessage());
}
Connection dataProvider = null;
if (rc.isOk()) {
dataProvider = instance.fillUIConnParams(metaConnection, null);
dataProvider.setName(DATA_PROVIDER_NAME);
// because the DI side code is changed, modify the following code.
metaConnection.setCurrentConnection(dataProvider);
try {
ProjectNodeHelper.fillCatalogAndSchemas(metaConnection, (DatabaseConnection) dataProvider);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Assert.assertNotNull(dataProvider);
return dataProvider;
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdq-studio-se by Talend.
the class ManagedDriver method registerHiveSQLDriver.
/**
* register hive jdbc driver by DatabaseConnection
*
* @param dbConnection
* @throws ClassNotFoundException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws Exception
*/
public synchronized void registerHiveSQLDriver(DatabaseConnection dbConnection) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
if (dbConnection != null || driverClassName != null || driverClassName.length() != 0) {
String dbType = dbConnection.getDatabaseType();
if (dbType.equalsIgnoreCase(EDatabaseTypeName.HIVE.getXmlName())) {
unregisterSQLDriver();
IMetadataConnection metadataConn = ConvertionHelper.convert(dbConnection);
ClassLoader classLoader = HiveClassLoaderFactory.getInstance().getClassLoader(metadataConn);
Class<?> classDriver = Class.forName(driverClassName, true, classLoader);
jdbcDriver = (Driver) classDriver.newInstance();
} else if (dbType.equalsIgnoreCase(EDatabaseTypeName.IMPALA.getXmlName())) {
unregisterSQLDriver();
IMetadataConnection metadataConn = ConvertionHelper.convert(dbConnection);
ClassLoader classLoader = AliasAndManaDriverHelper.getInstance().getImpalaClassLoader(metadataConn);
Class<?> classDriver = Class.forName(driverClassName, true, classLoader);
jdbcDriver = (Driver) classDriver.newInstance();
}
}
if (jdbcDriver == null) {
log.error("fail to regist Hive jdbc driver in SQLExplorer");
}
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdq-studio-se by Talend.
the class User method createNewConnection.
/**
* Creates a new connection, MOD xqliu 2013-04-03 TDQ-7003
*
* @return
* @throws ExplorerException
* @throws SQLException
*/
protected synchronized SQLConnection createNewConnection() throws SQLException {
SQLConnection connection = null;
// need use DynamicClassLoader to deal with it
if (databaseConnection != null && EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(databaseConnection.getDatabaseType())) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) {
ITDQRepositoryService tdqRepService = (ITDQRepositoryService) GlobalServiceRegister.getDefault().getService(ITDQRepositoryService.class);
if (tdqRepService != null) {
IMetadataConnection mdConn = ConvertionHelper.convert(databaseConnection);
Connection hiveConnection = tdqRepService.createHiveConnection(mdConn);
if (hiveConnection != null) {
connection = new SQLConnection(this, hiveConnection, alias.getDriver(), "HiveConnection");
}
}
}
} else {
connection = alias.getDriver().getConnection(this);
}
return connection;
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdq-studio-se by Talend.
the class TdqAnalysisConnectionPool method newConnection.
/**
* DOC xqliu Comment method "newConnection".
*
* @return
*/
private Connection newConnection() {
Connection conn = null;
if (isFull()) {
return conn;
}
DataManager datamanager = analysis.getContext().getConnection();
if (datamanager == null) {
// $NON-NLS-1$
log.error(Messages.getString("AnalysisExecutor.DataManagerNull", analysis.getName()));
return null;
}
if (datamanager != null && datamanager.eIsProxy()) {
datamanager = (DataManager) EObjectHelper.resolveObject(datamanager);
}
org.talend.core.model.metadata.builder.connection.Connection dataprovider = SwitchHelpers.CONNECTION_SWITCH.doSwitch(datamanager);
TypedReturnCode<Connection> trcConn = null;
IMetadataConnection metadataConnection = ConvertionHelper.convert(dataprovider);
if (metadataConnection != null && EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
trcConn = new TypedReturnCode<Connection>(false);
try {
HiveConnectionHandler hiveConnHandler = HiveConnectionManager.getInstance().createHandler(metadataConnection);
Connection hiveConnection = hiveConnHandler.createHiveConnection();
if (hiveConnection != null) {
trcConn.setOk(true);
trcConn.setObject(hiveConnection);
}
} catch (ClassNotFoundException e) {
trcConn.setOk(false);
log.error(e);
} catch (InstantiationException e) {
trcConn.setOk(false);
log.error(e);
} catch (IllegalAccessException e) {
trcConn.setOk(false);
log.error(e);
} catch (SQLException e) {
trcConn.setOk(false);
log.error(e);
}
} else {
trcConn = JavaSqlFactory.createConnection(dataprovider);
}
if (trcConn != null && trcConn.isOk()) {
conn = trcConn.getObject();
synchronized (this.synchronizedFlag) {
this.getPConnections().add(new PooledTdqAnalysisConnection(conn));
}
}
if (conn != null) {
try {
if (metadataConnection != null && EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
// don't set the max connection number if it is hive connection
} else {
DatabaseMetaData metaData = conn.getMetaData();
int currentDriverMaxConnections = new Float(metaData.getMaxConnections() * DEFAULT_CONNECTION_NUMBER_OFFSET).intValue();
synchronized (this.synchronizedFlag) {
this.setDriverMaxConnections(currentDriverMaxConnections);
}
}
} catch (SQLException e) {
log.debug(e, e);
}
}
return conn;
}
use of org.talend.core.model.metadata.IMetadataConnection in project tdq-studio-se by Talend.
the class ConnectionService method createConnection.
public static TypedReturnCode<Connection> createConnection(DBConnectionParameter parameter) {
TypedReturnCode<Connection> tReturnCode = new TypedReturnCode<Connection>(false);
MetadataFillFactory instance = null;
instance = MetadataFillFactory.getDBInstance();
IMetadataConnection metaConnection = instance.fillUIParams(ParameterUtil.toMap(parameter));
ReturnCode rc = instance.createConnection(metaConnection);
if (rc.isOk()) {
Connection dbConn = instance.fillUIConnParams(metaConnection, null);
DatabaseMetaData dbMetadata = null;
List<String> packageFilter = ConnectionUtils.getPackageFilter(parameter);
java.sql.Connection sqlConn = null;
try {
if (rc instanceof TypedReturnCode) {
@SuppressWarnings("rawtypes") Object sqlConnObject = ((TypedReturnCode) rc).getObject();
if (sqlConnObject instanceof java.sql.Connection) {
sqlConn = (java.sql.Connection) sqlConnObject;
dbMetadata = org.talend.utils.sql.ConnectionUtils.getConnectionMetadata(sqlConn);
}
}
instance.fillCatalogs(dbConn, dbMetadata, packageFilter);
instance.fillSchemas(dbConn, dbMetadata, packageFilter);
tReturnCode.setObject(dbConn);
} catch (SQLException e) {
log.error(e, e);
// Need to add a dialog for report the reson of error
} finally {
if (sqlConn != null) {
ConnectionUtils.closeConnection(sqlConn);
}
}
} else {
tReturnCode.setMessage(rc.getMessage());
tReturnCode.setOk(false);
}
return tReturnCode;
}
Aggregations