use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class TracesConnectionUtils method createConnection.
/**
* DOC hwang Comment method "createConnection".
*/
public static DatabaseConnection createConnection(ConnectionParameters parameters) {
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
String dbType = parameters.getDbType();
boolean isNeedSchema = EDatabaseTypeName.getTypeFromDbType(dbType).isNeedSchema();
String productName = EDatabaseTypeName.getTypeFromDisplayName(dbType).getProduct();
// boolean isOralceWithSid = productName.equals(EDatabaseTypeName.ORACLEFORSID.getProduct());
String schema = parameters.getSchema();
EDatabaseTypeName type = EDatabaseTypeName.getTypeFromDbType(dbType);
if (ManagerConnection.isSchemaFromSidOrDatabase(type)) {
schema = parameters.getDbName();
}
if ("".equals(schema) && EDatabaseTypeName.INFORMIX.getProduct().equals(productName)) {
//$NON-NLS-1$
schema = parameters.getUserName();
}
if (EDatabaseTypeName.EXASOL.getProduct().equals(productName)) {
schema = parameters.getDbName();
}
boolean isSchemaInValid = //$NON-NLS-1$ //$NON-NLS-2$
(schema == null) || (schema.equals("\'\'")) || (schema.equals("\"\"")) || //$NON-NLS-1$
(schema.trim().equals(""));
// from 616 till line 622 modified by hyWang
NotReallyNeedSchemaDBS dbs = new NotReallyNeedSchemaDBS();
dbs.init();
List<String> names = dbs.getNeedSchemaDBNames();
boolean ifNeedSchemaDB = names.contains(productName);
if (isNeedSchema && isSchemaInValid && !ifNeedSchemaDB) {
//$NON-NLS-1$
parameters.setConnectionComment(Messages.getString("TracesConnectionUtils.connectionComment"));
return null;
}
DatabaseConnection connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
connection.setFileFieldName(parameters.getFilename());
connection.setDatabaseType(dbType);
connection.setUsername(parameters.getUserName());
connection.setPort(parameters.getPort());
connection.setRawPassword(parameters.getPassword());
if (dbType != null && dbType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName()) && parameters.getLocalServiceName() != null && !"".equals(parameters.getLocalServiceName())) {
connection.setSID(parameters.getLocalServiceName());
} else {
connection.setSID(parameters.getDbName());
}
connection.setLabel(parameters.getDbName());
connection.setDatasourceName(parameters.getDatasource());
if (parameters.getDbType().equals(EDatabaseTypeName.GODBC.getDisplayName()) && StringUtils.isEmpty(parameters.getDatasource())) {
connection.setDatasourceName(parameters.getDbName());
}
if ("".equals(connection.getLabel())) {
//$NON-NLS-1$
connection.setLabel(parameters.getDatasource());
}
String driverClassByDbType = null;
if (parameters.getDriverClass() != null) {
driverClassByDbType = parameters.getDriverClass();
} else {
driverClassByDbType = extractMeta.getDriverClassByDbType(dbType);
}
String driverJar = parameters.getDriverJar();
connection.setDriverClass(driverClassByDbType);
connection.setDriverJarPath(driverJar);
String databaseType = connection.getDatabaseType();
if (driverClassByDbType != null && !"".equals(driverClassByDbType) && EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(parameters.getDbType())) {
if (driverClassByDbType.startsWith("\"") && driverClassByDbType.endsWith("\"")) {
driverClassByDbType = TalendTextUtils.removeQuotes(driverClassByDbType);
}
String dbTypeByClassName = "";
if (driverJar != null && !"".equals(driverJar)) {
dbTypeByClassName = extractMeta.getDbTypeByClassNameAndDriverJar(driverClassByDbType, driverJar);
} else {
dbTypeByClassName = extractMeta.getDbTypeByClassName(driverClassByDbType);
}
if (dbTypeByClassName != null) {
databaseType = dbTypeByClassName;
}
}
final String product = EDatabaseTypeName.getTypeFromDisplayName(databaseType).getProduct();
;
connection.setProductId(product);
if (MetadataTalendType.getDefaultDbmsFromProduct(product) != null) {
final String mapping = MetadataTalendType.getDefaultDbmsFromProduct(product).getId();
connection.setDbmsId(mapping);
}
if (!isSchemaInValid && isNeedSchema) {
//$NON-NLS-1$ //$NON-NLS-2$
schema = schema.replaceAll("\'", "");
//$NON-NLS-1$ //$NON-NLS-2$
schema = schema.replaceAll("\"", "");
connection.setUiSchema(schema);
}
connection.setServerName(parameters.getHost());
connection.setAdditionalParams(parameters.getJdbcProperties());
connection.setURL(parameters.getCombineURL());
connection.setDBRootPath(parameters.getDirectory());
connection.setDbVersionString(parameters.getDbVersion());
// Added by Marvin Wang to add other parameters.
Map<String, String> params = parameters.getParameters();
if (params != null && params.size() > 0) {
Set<Entry<String, String>> collection = params.entrySet();
for (Entry<String, String> para : collection) {
connection.getParameters().put(para.getKey(), para.getValue());
}
}
return connection;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class TAmazonOracleDndFilter method except.
@Override
public boolean except(Item item, ERepositoryObjectType type, RepositoryNode seletetedNode, IComponent component, String repositoryType) {
if (component != null) {
// for tAmazonOracleInput/Output/Connection/Row
if (component.getName().startsWith("tAmazonOracle")) {
//$NON-NLS-1$
String dbType = null;
if (item != null && item instanceof DatabaseConnectionItem) {
if (((DatabaseConnectionItem) item).getConnection() instanceof DatabaseConnection) {
dbType = ((DatabaseConnection) ((DatabaseConnectionItem) item).getConnection()).getDatabaseType();
}
}
Node node = new Node(component);
if (node != null) {
//$NON-NLS-1$
IElementParameter param = node.getElementParameter("CONNECTION_TYPE");
if (param != null) {
Object[] valuesList = param.getListItemsValue();
for (Object element : valuesList) {
String conType = EDatabaseTypeName.getTypeFromDbType(element.toString()).getDisplayName();
if (conType != null && dbType != null && conType.equals(dbType)) {
return false;
}
}
}
}
return true;
} else if (("tOracleCDCOutput").equals(component.getName())) {
//$NON-NLS-1$
if (item != null && item instanceof DatabaseConnectionItem) {
if (((DatabaseConnectionItem) item).getConnection() instanceof DatabaseConnection) {
DatabaseConnection connection = ((DatabaseConnection) ((DatabaseConnectionItem) item).getConnection());
if (MetadataConnectionUtils.isOracle(connection)) {
String version = connection.getDbVersionString();
if (EDatabaseVersion4Drivers.ORACLE_12.name().equals(version)) {
return false;
}
}
}
}
return true;
}
}
return false;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class MysqlOutputDBVersionForBug13250 method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
public ExecutionResult execute(Item item) {
if (item instanceof DatabaseConnectionItem) {
boolean modify = false;
DatabaseConnectionItem mysqlConnItem = (DatabaseConnectionItem) item;
if (mysqlConnItem.getConnection() instanceof DatabaseConnection) {
DatabaseConnection mysqlConnection = (DatabaseConnection) mysqlConnItem.getConnection();
if ("MySQL".equalsIgnoreCase(mysqlConnection.getDatabaseType())) {
if (mysqlConnection.getDbVersionString() == null || "".equals(mysqlConnection.getDbVersionString())) {
mysqlConnection.setDbVersionString("MYSQL_5");
modify = true;
}
}
}
if (modify) {
try {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
factory.save(item, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class RenameDbProductIdMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
try {
DatabaseConnection connection = (DatabaseConnection) ((DatabaseConnectionItem) item).getConnection();
String id = connection.getProductId();
for (int i = 0; i < CHANGE_SET.length; i++) {
if (id.equals(CHANGE_SET[i][OLD])) {
connection.setProductId(CHANGE_SET[i][NEW]);
return ExecutionResult.SUCCESS_WITH_ALERT;
}
}
return ExecutionResult.NOTHING_TO_DO;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class SchemaTypeProcessor method selectRepositoryNode.
@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
if (super.selectRepositoryNode(viewer, parentNode, node)) {
IRepositoryViewObject object = node.getObject();
if (object != null) {
// query
if (object instanceof Query) {
return false;
}
}
// cdc
ICDCProviderService cdcService = null;
if (PluginChecker.isCDCPluginLoaded()) {
cdcService = (ICDCProviderService) GlobalServiceRegister.getDefault().getService(ICDCProviderService.class);
}
String repositoryType = getRepositoryType();
if (ERepositoryCategoryType.CDC.getName().equals(repositoryType) && (object != null)) {
if (object.getRepositoryObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
DatabaseConnectionItem item = (DatabaseConnectionItem) object.getProperty().getItem();
DatabaseConnection connection = (DatabaseConnection) item.getConnection();
if (cdcService != null && cdcService.canCreateCDCConnection(connection)) {
return true;
}
return false;
}
if (object instanceof MetadataTable) {
return ((MetadataTableRepositoryObject) object).getTable().isActivatedCDC();
}
}
return true;
}
return false;
}
Aggregations