|
|
@ -21,6 +21,9 @@ import com.fr.event.EventDispatcher; |
|
|
|
import com.fr.file.ConnectionConfig; |
|
|
|
import com.fr.file.ConnectionConfig; |
|
|
|
import com.fr.file.ConnectionOperator; |
|
|
|
import com.fr.file.ConnectionOperator; |
|
|
|
import com.fr.general.NameObject; |
|
|
|
import com.fr.general.NameObject; |
|
|
|
|
|
|
|
import com.fr.license.database.BaseDataBaseTypePoint; |
|
|
|
|
|
|
|
import com.fr.license.database.DBTypes; |
|
|
|
|
|
|
|
import com.fr.license.exception.DataBaseNotSupportedException; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
import com.fr.stable.Nameable; |
|
|
|
import com.fr.stable.Nameable; |
|
|
@ -30,17 +33,21 @@ import com.fr.transaction.Configurations; |
|
|
|
import com.fr.transaction.WorkerFacade; |
|
|
|
import com.fr.transaction.WorkerFacade; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
import com.fr.workspace.server.database.DataBaseTypeOperator; |
|
|
|
import com.fr.workspace.server.database.DataBaseTypeOperator; |
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.SwingWorker; |
|
|
|
import java.awt.Window; |
|
|
|
import java.awt.Window; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Connection List Pane. |
|
|
|
* Connection List Pane. |
|
|
@ -50,6 +57,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
private boolean isNamePermitted = true; |
|
|
|
private boolean isNamePermitted = true; |
|
|
|
private final HashMap<String, String> renameMap = new HashMap<>(); |
|
|
|
private final HashMap<String, String> renameMap = new HashMap<>(); |
|
|
|
private final Map<String, Connection> populatedConnectionsSnapshot = new LinkedHashMap<>(); |
|
|
|
private final Map<String, Connection> populatedConnectionsSnapshot = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
private static List<String> supportedDatabaseTypes = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
public ConnectionListPane() { |
|
|
|
public ConnectionListPane() { |
|
|
|
renameMap.clear(); |
|
|
|
renameMap.clear(); |
|
|
@ -63,6 +71,30 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
rename(selectedName, getEditingName()); |
|
|
|
rename(selectedName, getEditingName()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getSupportedTypes(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取本地、远程环境lic中未受限制的数据库类型信息 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static void getSupportedTypes() { |
|
|
|
|
|
|
|
SwingWorker<List<String>, Void> getSupportedTypesWorker = new SwingWorker<List<String>, Void>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected List<String> doInBackground() { |
|
|
|
|
|
|
|
return WorkContext.getCurrent().get(DataBaseTypeOperator.class).getSupportedDatabaseTypes(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void done() { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
supportedDatabaseTypes = get(); |
|
|
|
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
getSupportedTypesWorker.execute(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -232,10 +264,56 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.validateDatabaseType(addedOrUpdatedConnections); |
|
|
|
this.validateConnections(addedOrUpdatedConnections); |
|
|
|
this.validateConnections(addedOrUpdatedConnections); |
|
|
|
this.alterConnections(removedConnNames, addedOrUpdatedConnections); |
|
|
|
this.alterConnections(removedConnNames, addedOrUpdatedConnections); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 校验是否支持所有新增和修改数据连接的数据库类型 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void validateDatabaseType(@NotNull List<ConnectionBean> addedOrUpdatedConnections) { |
|
|
|
|
|
|
|
Set<String> notSupportedConnections = new HashSet<>(); |
|
|
|
|
|
|
|
if (!addedOrUpdatedConnections.isEmpty()) { |
|
|
|
|
|
|
|
for (ConnectionBean bean : addedOrUpdatedConnections) { |
|
|
|
|
|
|
|
Connection connection = bean.getConnection(); |
|
|
|
|
|
|
|
// 仅校验jdbc连接,其他插件数据连接不进行校验
|
|
|
|
|
|
|
|
if (connection instanceof JDBCDatabaseConnection) { |
|
|
|
|
|
|
|
BaseDataBaseTypePoint dataBaseTypePoint = BaseDataBaseTypePoint.getDataBaseTypePoint(connection.getDriver(), connection.feature()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (connectionIsNotSupported(connection, dataBaseTypePoint)) { |
|
|
|
|
|
|
|
notSupportedConnections.addAll(dataBaseTypePoint.getDataBaseType()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!notSupportedConnections.isEmpty()) { |
|
|
|
|
|
|
|
throw new DataBaseNotSupportedException(notSupportedConnections, supportedDatabaseTypes); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 校验当前数据连接是否被限制 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static boolean connectionIsNotSupported(Connection connection, BaseDataBaseTypePoint dataBaseTypePoint) { |
|
|
|
|
|
|
|
return !validateFRDemo(connection.getDriver(), connection.feature()) && |
|
|
|
|
|
|
|
(dataBaseTypePoint != null && !supportedDatabaseTypes.containsAll(dataBaseTypePoint.getDatabaseType())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 校验当前是否为FRDemo,不对其进行限制 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static boolean validateFRDemo(String driver, String url) { |
|
|
|
|
|
|
|
if (DBTypes.Sqlite.getDriver().equals(driver) && url.contains(DBTypes.Sqlite.getUrlKey())) { |
|
|
|
|
|
|
|
// 产品:对sqlite类型只允许示例连接FRDemo
|
|
|
|
|
|
|
|
String databaseName = url.substring(url.lastIndexOf("/") + 1); |
|
|
|
|
|
|
|
return StringUtils.equals("FRDemo.db", databaseName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void validateConnections(List<ConnectionBean> addedOrUpdatedConnections) throws Exception { |
|
|
|
private void validateConnections(List<ConnectionBean> addedOrUpdatedConnections) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|