Compare commits

...

3 Commits

Author SHA1 Message Date
root
75870cb65d FIx TDQ-18565 change logic 2020-07-16 17:18:11 +08:00
root
c03f1c29f2 FIx TDQ-18565 2020-07-09 15:09:58 +08:00
root
a904bf6af2 Fix TDQ-18565 Cannot save Hive metadata object with context variables
- if the analysis didnot use the current db, can pass
- if any analysis use this db, popup let the user select
2020-07-09 15:04:45 +08:00
3 changed files with 51 additions and 27 deletions

View File

@@ -214,5 +214,5 @@ public interface ITDQRepositoryService extends IService {
/**
* @param chooseContext the context name which want to swtich
*/
void popupSwitchContextFailedMessage(String chooseContext);
boolean popupSwitchContextFailedMessage(String chooseContext);
}

View File

@@ -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);

View File

@@ -27,6 +27,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
@@ -560,8 +561,8 @@ public class DatabaseWizard extends CheckLastVersionRepositoryWizard implements
isSuccess = SwitchContextGroupNameImpl
.getInstance()
.updateContextGroup(connectionItem, contextName, originalSelectedContextType.getName());
if (!isSuccess) {
tdqRepService.popupSwitchContextFailedMessage(contextName);
if (!isSuccess) {
isSuccess = tdqRepService.popupSwitchContextFailedMessage(contextName);
}else {
isSuccess &= handleDatabaseUpdate(metadataConnection, tdqRepService);
}