use of org.talend.core.model.metadata.builder.connection.DatabaseConnection 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;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class MetadataColumnComparator method isDiff.
/**
* dev Comment method "isDiff".
*
* @param node
* @return
*/
@SuppressWarnings("unchecked")
public boolean[] isDiff(RepositoryNode node) {
boolean isDiffDivergency = false;
boolean isDiffSyschronize = false;
boolean isDiffGray = false;
Object type = node.getProperties(EProperties.CONTENT_TYPE);
if (type.equals(RepositoryNodeType.DATABASE)) {
DatabaseConnection connection = (DatabaseConnection) getItem(node).getConnection();
Set<MetadataTable> tables = ConnectionHelper.getTables(connection);
for (MetadataTable table : tables) {
List<MetadataColumn> columns = table.getColumns();
for (MetadataColumn column : columns) {
if (column.isDivergency()) {
isDiffDivergency = true;
}
if (column.isSynchronised()) {
isDiffSyschronize = true;
}
if (column.getLabel() == null || "".equals(column.getLabel())) {
//$NON-NLS-1$
isDiffGray = true;
}
}
if (table.isDivergency()) {
isDiffDivergency = true;
}
if (table.getLabel() == null || "".equals(table.getLabel())) {
//$NON-NLS-1$
isDiffGray = true;
}
}
} else if (type.equals(RepositoryNodeType.TABLE)) {
MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
MetadataTable table = object.getTable();
List<MetadataColumn> columns = table.getColumns();
for (MetadataColumn column : columns) {
if (column.isDivergency()) {
isDiffDivergency = true;
}
if (column.isSynchronised()) {
isDiffSyschronize = true;
}
if (column.getLabel() == null || "".equals(column.getLabel())) {
//$NON-NLS-1$
isDiffGray = true;
}
}
if (table.isDivergency()) {
isDiffDivergency = true;
}
}
return new boolean[] { isDiffGray, isDiffDivergency, isDiffSyschronize };
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class MetadataColumnComparator method getRepositoryNodeFromDB.
/**
* method "getRepositoryNodeFromDB".
*
* @param oldNode
* @return
*/
@SuppressWarnings("unchecked")
public RepositoryNode getRepositoryNodeFromDB(RepositoryNode oldNode, String selectedContext) {
DatabaseConnectionItem item = getItem(getRoot(oldNode));
DatabaseConnection connection = (DatabaseConnection) item.getConnection();
IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection, false, selectedContext);
try {
modifyOldRepositoryNode(connection, iMetadataConnection, oldNode);
} catch (Exception e) {
ExceptionHandler.process(e);
}
return oldNode;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class MetadataColumnComparator method deleteNouseTables.
public void deleteNouseTables(Connection connection) {
if (!(connection instanceof DatabaseConnection)) {
return;
}
if (tList == null) {
return;
}
List<MetadataTable> tableList = new ArrayList<MetadataTable>(ConnectionHelper.getTables(connection));
tableList.removeAll(tList);
Catalog catalog = (Catalog) ConnectionHelper.getPackage(((DatabaseConnection) connection).getSID(), connection, Catalog.class);
Schema schema = (Schema) ConnectionHelper.getPackage(((DatabaseConnection) connection).getUiSchema(), connection, Schema.class);
String c = "";
String s = "";
if (catalog != null) {
c = catalog.getName();
}
if (schema != null) {
s = schema.getName();
}
ProjectNodeHelper.removeTablesFromCurrentCatalogOrSchema(c, s, (DatabaseConnection) connection, tableList);
tList = null;
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdi-studio-se by Talend.
the class FillParametersForDatabaseConnectionMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
if (item instanceof DatabaseConnectionItem) {
DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
Connection connection = dbItem.getConnection();
DatabaseConnection dbconn = (DatabaseConnection) connection;
EList<orgomg.cwm.objectmodel.core.Package> pkgs = dbconn.getDataPackage();
// get all tdtables and set sqldatatype
fillParametersForColumns(pkgs);
dbconn.setName(dbItem.getProperty().getLabel());
try {
factory.save(dbItem, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
Aggregations