|
|
|
@ -22,6 +22,7 @@ import com.fr.file.ConnectionConfig;
|
|
|
|
|
import com.fr.file.ConnectionOperator; |
|
|
|
|
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.stable.ArrayUtils; |
|
|
|
@ -34,6 +35,7 @@ import com.fr.workspace.WorkContext;
|
|
|
|
|
import com.fr.workspace.server.database.DataBaseTypeOperator; |
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
|
|
|
|
|
|
import javax.swing.SwingWorker; |
|
|
|
|
import java.awt.Window; |
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
@ -45,6 +47,7 @@ import java.util.List;
|
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.UUID; |
|
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Connection List Pane. |
|
|
|
@ -54,6 +57,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
|
|
|
|
|
private boolean isNamePermitted = true; |
|
|
|
|
private final HashMap<String, String> renameMap = new HashMap<>(); |
|
|
|
|
private final Map<String, Connection> populatedConnectionsSnapshot = new LinkedHashMap<>(); |
|
|
|
|
private static List<String> supportedDatabaseTypes = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
public ConnectionListPane() { |
|
|
|
|
renameMap.clear(); |
|
|
|
@ -67,6 +71,30 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
|
|
|
|
|
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 |
|
|
|
@ -250,19 +278,40 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
|
|
|
|
|
for (ConnectionBean bean : addedOrUpdatedConnections) { |
|
|
|
|
Connection connection = bean.getConnection(); |
|
|
|
|
// 仅校验jdbc连接,其他插件数据连接不进行校验
|
|
|
|
|
boolean connectionIsNotSupported = connection instanceof JDBCDatabaseConnection && !WorkContext.getCurrent().get(DataBaseTypeOperator.class).supportDatabaseType(connection.getDriver(), connection.feature()); |
|
|
|
|
if (connectionIsNotSupported) { |
|
|
|
|
if (connection instanceof JDBCDatabaseConnection) { |
|
|
|
|
BaseDataBaseTypePoint dataBaseTypePoint = BaseDataBaseTypePoint.getDataBaseTypePoint(connection.getDriver(), connection.feature()); |
|
|
|
|
if (dataBaseTypePoint != null && dataBaseTypePoint.getDataBaseType() != null) { |
|
|
|
|
|
|
|
|
|
if (connectionIsNotSupported(connection, dataBaseTypePoint)) { |
|
|
|
|
notSupportedConnections.addAll(dataBaseTypePoint.getDataBaseType()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!notSupportedConnections.isEmpty()) { |
|
|
|
|
throw new DataBaseNotSupportedException(notSupportedConnections, BaseDataBaseTypePoint.getSupportedDatabaseType()); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|