Skip to content

Commit

Permalink
fix insertion error.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangmingliang-ms committed Sep 14, 2022
1 parent 348ad42 commit ed83f42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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

import com.intellij.database.dataSource.DatabaseDriver;
import com.intellij.database.dataSource.DatabaseDriverImpl;
import com.intellij.database.dataSource.DatabaseDriverManager;
import com.intellij.database.dataSource.DatabaseDriverManagerImpl;
Expand All @@ -17,6 +16,7 @@
import com.microsoft.azure.toolkit.intellij.common.IntelliJAzureIcons;
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.jdom.Element;

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

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

private static void loadCassandraDriver() {
final DatabaseDriverManager manager = DatabaseDriverManager.getInstance();
final DatabaseDriver oldDriver = manager.getDriver(COSMOS_CASSANDRA_DRIVER_ID);
final DatabaseDriverImpl oldDriver = (DatabaseDriverImpl) manager.getDriver(COSMOS_CASSANDRA_DRIVER_ID);
if (Registry.is("azure.toolkit.cosmos_cassandra.dbtools.enabled")) {
if (Objects.isNull(oldDriver) || !"Azure Cosmos DB API for Cassandra".equals(oldDriver.getName())) { // remove if old driver is not user defined.
Optional.ofNullable(oldDriver).ifPresent(manager::removeDriver);
addAsUserDriver(COSMOS_CASSANDRA_DRIVER_CONFIG);
} else {
((DatabaseDriverImpl) oldDriver).setIcon(IntelliJAzureIcons.getIcon(COSMOS_CASSANDRA_ICON));
oldDriver.setIcon(IntelliJAzureIcons.getIcon(COSMOS_CASSANDRA_ICON));
}
} else {
Optional.ofNullable(oldDriver).ifPresent(manager::removeDriver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<driver id="az_cosmos_mongo" name="Azure Cosmos DB API for MongoDB" forced-dbms="MONGO"
dialect="MongoDB" driver-class="com.dbschema.MongoJdbcDriver"
icon-path="icons/Microsoft.DocumentDB/databaseAccounts/mongo.svg">
<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;]]"/>
<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;]"/>
<artifact name="MongoDB" use="true" rolling="true"/>
<option name="auto-sync" value="true"/>
<property name="appName" value="DataGrip"/>
Expand Down

0 comments on commit ed83f42

Please sign in to comment.