use of org.talend.metadata.managment.model.MetadataFillFactory in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method getRealOracleDatabase.
/**
* get a real database connection,the connection parameters load from a propery file.
*
* @return
*/
public Connection getRealOracleDatabase() {
Properties connectionParams = DBPropertiesUtils.getDefault().getProperties();
// $NON-NLS-1$
String driverClassName = connectionParams.getProperty("driver_oracle");
// $NON-NLS-1$
String dbUrl = connectionParams.getProperty("url_oracle");
// $NON-NLS-1$
String sqlTypeName = connectionParams.getProperty("sqlTypeName_oracle");
// $NON-NLS-1$
String dbVersion = connectionParams.getProperty("dbVersion_oracle");
// $NON-NLS-1$
String userName = connectionParams.getProperty("user_oracle");
// $NON-NLS-1$
String password = connectionParams.getProperty("password_oracle");
DBConnectionParameter params = new DBConnectionParameter();
// $NON-NLS-1$
params.setName("oracle_Connection");
params.setDriverClassName(driverClassName);
params.setJdbcUrl(dbUrl);
params.setSqlTypeName(sqlTypeName);
Properties properties = new Properties();
properties.setProperty(TaggedValueHelper.USER, userName);
properties.setProperty(TaggedValueHelper.PASSWORD, password);
properties.setProperty(TaggedValueHelper.DB_PRODUCT_VERSION, dbVersion);
params.setParameters(properties);
// create connection
ConnectionUtils.setTimeout(false);
MetadataFillFactory instance = MetadataFillFactory.getDBInstance();
IMetadataConnection metaConnection = instance.fillUIParams(ParameterUtil.toMap(params));
metaConnection.setDbVersionString(dbVersion);
ReturnCode rc = null;
try {
rc = instance.checkConnection(metaConnection);
} catch (java.lang.RuntimeException e) {
// $NON-NLS-1$ //$NON-NLS-2$
Assert.fail("connect to " + dbUrl + "failed," + e.getMessage());
}
Connection dataProvider = null;
if (rc.isOk()) {
dataProvider = instance.fillUIConnParams(metaConnection, null);
dataProvider.setName("oracleDB");
// 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.metadata.managment.model.MetadataFillFactory 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.metadata.managment.model.MetadataFillFactory 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