Skip to content

Commit ed83f42

Browse files
fix insertion error.
1 parent 348ad42 commit ed83f42

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cosmos/src/main/java/com/microsoft/azure/toolkit/intellij/cosmos/dbtools/DbToolsWorkaround.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package com.microsoft.azure.toolkit.intellij.cosmos.dbtools;
77

8-
import com.intellij.database.dataSource.DatabaseDriver;
98
import com.intellij.database.dataSource.DatabaseDriverImpl;
109
import com.intellij.database.dataSource.DatabaseDriverManager;
1110
import com.intellij.database.dataSource.DatabaseDriverManagerImpl;
@@ -17,6 +16,7 @@
1716
import com.microsoft.azure.toolkit.intellij.common.IntelliJAzureIcons;
1817
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
1918
import lombok.SneakyThrows;
19+
import org.apache.commons.lang3.StringUtils;
2020
import org.apache.commons.lang3.reflect.FieldUtils;
2121
import org.jdom.Element;
2222

@@ -47,24 +47,28 @@ public void preload(@Nonnull ProgressIndicator indicator) {
4747

4848
private static void loadMongoDriver() {
4949
final DatabaseDriverManager manager = DatabaseDriverManager.getInstance();
50-
final DatabaseDriver oldDriver = manager.getDriver(COSMOS_MONGO_DRIVER_ID);
51-
if (Objects.isNull(oldDriver) || !"Azure Cosmos DB API for MongoDB".equals(oldDriver.getName())) { // remove if old driver is not user defined.
50+
final DatabaseDriverImpl oldDriver = (DatabaseDriverImpl) manager.getDriver(COSMOS_MONGO_DRIVER_ID);
51+
final boolean legacy = Optional.ofNullable(oldDriver).map(DatabaseDriverImpl::getUrlTemplates)
52+
.flatMap(ts -> ts.stream().findFirst())
53+
.filter(t -> StringUtils.containsIgnoreCase(t.getTemplate(), "retrywrites"))
54+
.isEmpty();
55+
if (legacy) { // remove if old driver is not user defined.
5256
Optional.ofNullable(oldDriver).ifPresent(manager::removeDriver);
5357
addAsUserDriver(COSMOS_MONGO_DRIVER_CONFIG);
5458
} else {
55-
((DatabaseDriverImpl) oldDriver).setIcon(IntelliJAzureIcons.getIcon(COSMOS_MONGO_ICON));
59+
oldDriver.setIcon(IntelliJAzureIcons.getIcon(COSMOS_MONGO_ICON));
5660
}
5761
}
5862

5963
private static void loadCassandraDriver() {
6064
final DatabaseDriverManager manager = DatabaseDriverManager.getInstance();
61-
final DatabaseDriver oldDriver = manager.getDriver(COSMOS_CASSANDRA_DRIVER_ID);
65+
final DatabaseDriverImpl oldDriver = (DatabaseDriverImpl) manager.getDriver(COSMOS_CASSANDRA_DRIVER_ID);
6266
if (Registry.is("azure.toolkit.cosmos_cassandra.dbtools.enabled")) {
6367
if (Objects.isNull(oldDriver) || !"Azure Cosmos DB API for Cassandra".equals(oldDriver.getName())) { // remove if old driver is not user defined.
6468
Optional.ofNullable(oldDriver).ifPresent(manager::removeDriver);
6569
addAsUserDriver(COSMOS_CASSANDRA_DRIVER_CONFIG);
6670
} else {
67-
((DatabaseDriverImpl) oldDriver).setIcon(IntelliJAzureIcons.getIcon(COSMOS_CASSANDRA_ICON));
71+
oldDriver.setIcon(IntelliJAzureIcons.getIcon(COSMOS_CASSANDRA_ICON));
6872
}
6973
} else {
7074
Optional.ofNullable(oldDriver).ifPresent(manager::removeDriver);

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cosmos/src/main/resources/databaseDrivers/azure-cosmos-mongo-drivers.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<driver id="az_cosmos_mongo" name="Azure Cosmos DB API for MongoDB" forced-dbms="MONGO"
66
dialect="MongoDB" driver-class="com.dbschema.MongoJdbcDriver"
77
icon-path="icons/Microsoft.DocumentDB/databaseAccounts/mongo.svg">
8-
<url-template name="default" template="[jdbc:]mongodb[+srv]://[{user:identifier}[:{password:param}]@]&lt;\,,{host::localhost}?[:{port::27017}]&gt;[/{database}?[/{account:cosmos_account_mongo}?][\?&lt;&amp;,{:identifier}={:param}&gt;]]"/>
8+
<url-template name="default" template="[jdbc:]mongodb[+srv]://[{user:identifier}[:{password:param}]@]&lt;\,,{host::localhost}?[:{port::27017}]&gt;[/{database}?[/{account:cosmos_account_mongo}?]]/\?ssl=true&amp;replicaSet=globaldb&amp;retrywrites=false&amp;maxIdleTimeMS=120000[\?&lt;&amp;,{:identifier}={:param}&gt;]"/>
99
<artifact name="MongoDB" use="true" rolling="true"/>
1010
<option name="auto-sync" value="true"/>
1111
<property name="appName" value="DataGrip"/>

0 commit comments

Comments
 (0)