use of org.talend.designer.core.sqlbuilder.NotReallyNeedSchemaDBS 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.designer.core.sqlbuilder.NotReallyNeedSchemaDBS in project tdi-studio-se by Talend.
the class MetadataColumnComparator method createConnection.
/**
* dev Comment method "createConnection".
*
* @param parameters inputed when use Built-In .
* @return DatabaseConnection : connetion .
*/
public DatabaseConnection createConnection(ConnectionParameters parameters) {
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("SQLBuilderRepositoryNodeManager.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 ("".equals(connection.getLabel())) {
//$NON-NLS-1$
connection.setLabel(parameters.getDatasource());
}
final String product = EDatabaseTypeName.getTypeFromDisplayName(connection.getDatabaseType()).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());
String driverClassByDbType = null;
if (parameters.getDriverClass() != null) {
driverClassByDbType = parameters.getDriverClass();
} else {
driverClassByDbType = ExtractMetaDataUtils.getInstance().getDriverClassByDbType(dbType);
}
connection.setDriverClass(driverClassByDbType);
connection.setDriverJarPath(parameters.getDriverJar());
connection.setURL(parameters.getCombineURL());
connection.setDBRootPath(parameters.getDirectory());
connection.setDbVersionString(parameters.getDbVersion());
return connection;
}
Aggregations