|
|
|
|
@@ -16,8 +16,11 @@ import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
import org.eclipse.jface.dialogs.MessageDialog;
|
|
|
|
|
import org.talend.commons.exception.ExceptionHandler;
|
|
|
|
|
import org.talend.commons.exception.PersistenceException;
|
|
|
|
|
import org.talend.core.GlobalServiceRegister;
|
|
|
|
|
import org.talend.core.ITDQRepositoryService;
|
|
|
|
|
import org.talend.core.database.EDatabaseTypeName;
|
|
|
|
|
import org.talend.core.database.conn.DatabaseConnStrUtil;
|
|
|
|
|
import org.talend.core.hadoop.IHadoopClusterService;
|
|
|
|
|
@@ -100,7 +103,7 @@ public class SwitchContextGroupNameImpl implements ISwitchContext {
|
|
|
|
|
newContextName = newContextType == null ? null : newContextType.getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isContextIsValid(newContextName, oldContextName, con)) {
|
|
|
|
|
if (!isContextIsValidAndInUse(newContextName, oldContextName, connItem)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
con.setContextName(newContextName);
|
|
|
|
|
@@ -129,8 +132,9 @@ public class SwitchContextGroupNameImpl implements ISwitchContext {
|
|
|
|
|
* @param selectedContext
|
|
|
|
|
* @paramconn
|
|
|
|
|
*/
|
|
|
|
|
private boolean isContextIsValid(String selectedContext, String oldContextName, Connection conn) {
|
|
|
|
|
private boolean isContextIsValidAndInUse(String selectedContext, String oldContextName, ConnectionItem connItem) {
|
|
|
|
|
boolean retCode = false;
|
|
|
|
|
Connection conn = connItem.getConnection();
|
|
|
|
|
if (conn instanceof DatabaseConnection) {
|
|
|
|
|
EDatabaseTypeName dbType = EDatabaseTypeName.getTypeFromDbType(((DatabaseConnection) conn).getDatabaseType());
|
|
|
|
|
|
|
|
|
|
@@ -138,33 +142,52 @@ public class SwitchContextGroupNameImpl implements ISwitchContext {
|
|
|
|
|
retCode = true;
|
|
|
|
|
} else if (dbType == EDatabaseTypeName.GENERAL_JDBC) {
|
|
|
|
|
retCode = true;
|
|
|
|
|
} else {
|
|
|
|
|
DatabaseConnection dbConn = (DatabaseConnection) conn;
|
|
|
|
|
boolean hasCatalog = ConnectionHelper.hasCatalog(dbConn);
|
|
|
|
|
boolean hasSchema = ConnectionHelper.hasSchema(dbConn);
|
|
|
|
|
ContextType newContextType = ConnectionContextHelper.getContextTypeForContextMode(dbConn, selectedContext, false);
|
|
|
|
|
ContextType oldContextType = ConnectionContextHelper.getContextTypeForContextMode(dbConn, oldContextName, false);
|
|
|
|
|
String newSidOrDatabase = ConnectionContextHelper.getOriginalValue(newContextType, dbConn.getSID());
|
|
|
|
|
String newUiShema = ConnectionContextHelper.getOriginalValue(newContextType, dbConn.getUiSchema());
|
|
|
|
|
String oldSidOrDatabase = ConnectionContextHelper.getOriginalValue(oldContextType, dbConn.getSID());
|
|
|
|
|
String oldUiShema = ConnectionContextHelper.getOriginalValue(oldContextType, dbConn.getUiSchema());
|
|
|
|
|
if (hasCatalog) {// for example mysql
|
|
|
|
|
retCode = !isEmptyString(oldSidOrDatabase) && !isEmptyString(newSidOrDatabase);
|
|
|
|
|
if (hasSchema) {// for example mssql
|
|
|
|
|
retCode &= !isEmptyString(oldUiShema) && !isEmptyString(newUiShema);
|
|
|
|
|
}
|
|
|
|
|
} else if (hasSchema) {// for example oracle
|
|
|
|
|
retCode = !isEmptyString(oldUiShema) && !isEmptyString(newUiShema);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
DatabaseConnection dbConn = (DatabaseConnection) conn;
|
|
|
|
|
boolean hasCatalog = ConnectionHelper.hasCatalog(dbConn);
|
|
|
|
|
boolean hasSchema = ConnectionHelper.hasSchema(dbConn);
|
|
|
|
|
ContextType newContextType = ConnectionContextHelper.getContextTypeForContextMode(dbConn,
|
|
|
|
|
selectedContext, false);
|
|
|
|
|
ContextType oldContextType = ConnectionContextHelper.getContextTypeForContextMode(dbConn,
|
|
|
|
|
oldContextName, false);
|
|
|
|
|
String newSidOrDatabase = ConnectionContextHelper.getOriginalValue(newContextType, dbConn.getSID());
|
|
|
|
|
String newUiShema = ConnectionContextHelper.getOriginalValue(newContextType, dbConn.getUiSchema());
|
|
|
|
|
String oldSidOrDatabase = ConnectionContextHelper.getOriginalValue(oldContextType, dbConn.getSID());
|
|
|
|
|
String oldUiShema = ConnectionContextHelper.getOriginalValue(oldContextType, dbConn.getUiSchema());
|
|
|
|
|
if (hasCatalog) {// for example mysql
|
|
|
|
|
retCode = checkEmpty(newSidOrDatabase, oldSidOrDatabase);
|
|
|
|
|
if (hasSchema) {// for example mssql
|
|
|
|
|
retCode &= checkEmpty(newUiShema, oldUiShema);
|
|
|
|
|
}
|
|
|
|
|
} else if (hasSchema) {// for example oracle
|
|
|
|
|
retCode = checkEmpty(newUiShema, oldUiShema);
|
|
|
|
|
}else {//some db didnot have catelog and schema
|
|
|
|
|
retCode = true;
|
|
|
|
|
}
|
|
|
|
|
// Added TDQ-18565
|
|
|
|
|
if (!retCode && GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) {
|
|
|
|
|
ITDQRepositoryService tdqRepService = GlobalServiceRegister.getDefault()
|
|
|
|
|
.getService(ITDQRepositoryService.class);
|
|
|
|
|
if (!tdqRepService.hasClientDependences(connItem)) {
|
|
|
|
|
retCode = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (conn instanceof FileConnection) {
|
|
|
|
|
retCode = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return retCode;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean checkEmpty(String newSidOrDatabase, String oldSidOrDatabase) {
|
|
|
|
|
if (isEmptyString(oldSidOrDatabase) && isEmptyString(newSidOrDatabase)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return !isEmptyString(oldSidOrDatabase) && !isEmptyString(newSidOrDatabase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* change context Group need to synchronization name of catalog or schema
|
|
|
|
|
@@ -180,7 +203,7 @@ public class SwitchContextGroupNameImpl implements ISwitchContext {
|
|
|
|
|
String newUiShema = ConnectionContextHelper.getOriginalValue(newContextType, dbConn.getUiSchema());
|
|
|
|
|
String oldSidOrDatabase = ConnectionContextHelper.getOriginalValue(oldContextType, dbConn.getSID());
|
|
|
|
|
String oldUiShema = ConnectionContextHelper.getOriginalValue(oldContextType, dbConn.getUiSchema());
|
|
|
|
|
if (!isEmptyString(newSidOrDatabase) && !isEmptyString(oldSidOrDatabase)) {// for example mysql or mssql
|
|
|
|
|
if (checkEmpty(oldSidOrDatabase, newSidOrDatabase)) {// for example mysql or mssql
|
|
|
|
|
Catalog catalog = CatalogHelper.getCatalog(dbConn, oldSidOrDatabase);
|
|
|
|
|
if (catalog != null) {
|
|
|
|
|
catalog.setName(newSidOrDatabase);
|
|
|
|
|
@@ -193,7 +216,7 @@ public class SwitchContextGroupNameImpl implements ISwitchContext {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isEmptyString(newUiShema) && !isEmptyString(oldUiShema)) {// for example oracle
|
|
|
|
|
if (checkEmpty(oldUiShema, newUiShema)) {// for example oracle
|
|
|
|
|
Schema schema = SchemaHelper.getSchema(dbConn, oldUiShema);
|
|
|
|
|
if (schema != null) {
|
|
|
|
|
schema.setName(newUiShema);
|
|
|
|
|
|