Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Mongo driver upgraded to 3.0.4 #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.ipr
*.iws
target/
.idea/
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.codinjutsu.tools.nosql.commons.logic.DatabaseClient;
import org.codinjutsu.tools.nosql.commons.model.DatabaseServer;
import org.codinjutsu.tools.nosql.couchbase.logic.CouchbaseClient;
import org.codinjutsu.tools.nosql.mongo.logic.MongoClient;
import org.codinjutsu.tools.nosql.mongo.logic.SingleMongoClient;
import org.codinjutsu.tools.nosql.redis.logic.RedisClient;

import java.util.HashMap;
Expand All @@ -32,7 +32,7 @@ public class DatabaseVendorClientManager {
private static final Map<DatabaseVendor, Class<? extends DatabaseClient>> dataClientByVendor = new HashMap<>();

static {
dataClientByVendor.put(DatabaseVendor.MONGO, MongoClient.class);
dataClientByVendor.put(DatabaseVendor.MONGO, SingleMongoClient.class);
dataClientByVendor.put(DatabaseVendor.REDIS, RedisClient.class);
dataClientByVendor.put(DatabaseVendor.COUCHBASE, CouchbaseClient.class);
}
Expand Down
35 changes: 17 additions & 18 deletions src/main/java/org/codinjutsu/tools/nosql/NoSqlExplorerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.ui.tree.TreeUtil;
import org.codinjutsu.tools.nosql.commons.logic.ConfigurationException;
import org.codinjutsu.tools.nosql.commons.logic.DatabaseClient;
import org.codinjutsu.tools.nosql.commons.model.Database;
import org.codinjutsu.tools.nosql.commons.model.DatabaseServer;
import org.codinjutsu.tools.nosql.commons.utils.GuiUtils;
Expand All @@ -44,9 +43,9 @@
import org.codinjutsu.tools.nosql.commons.view.editor.NoSqlDatabaseObjectFile;
import org.codinjutsu.tools.nosql.couchbase.model.CouchbaseDatabase;
import org.codinjutsu.tools.nosql.couchbase.view.editor.CouchbaseObjectFile;
import org.codinjutsu.tools.nosql.mongo.logic.MongoClient;
import org.codinjutsu.tools.nosql.mongo.model.MongoCollection;
import org.codinjutsu.tools.nosql.mongo.model.MongoDatabase;
import org.codinjutsu.tools.nosql.mongo.logic.SingleMongoClient;
import org.codinjutsu.tools.nosql.mongo.model.SingleMongoCollection;
import org.codinjutsu.tools.nosql.mongo.model.SingleMongoDatabase;
import org.codinjutsu.tools.nosql.mongo.view.action.DropCollectionAction;
import org.codinjutsu.tools.nosql.mongo.view.action.DropDatabaseAction;
import org.codinjutsu.tools.nosql.mongo.view.editor.MongoObjectFile;
Expand Down Expand Up @@ -179,9 +178,9 @@ public void run() {
private void addDatabasesIfAny(DatabaseServer databaseServer, DefaultMutableTreeNode serverNode) {
for (Database database : databaseServer.getDatabases()) {
DefaultMutableTreeNode databaseNode = new DefaultMutableTreeNode(database);
if (database instanceof MongoDatabase) {
MongoDatabase mongoDatabase = (MongoDatabase) database;
for (MongoCollection collection : mongoDatabase.getCollections()) {
if (database instanceof SingleMongoDatabase) {
SingleMongoDatabase singleMongoDatabase = (SingleMongoDatabase) database;
for (SingleMongoCollection collection : singleMongoDatabase.getCollections()) {
databaseNode.add(new DefaultMutableTreeNode(collection));
}
}
Expand Down Expand Up @@ -272,7 +271,7 @@ public void mouseClicked(MouseEvent mouseEvent) {
if (treeNode.getUserObject() instanceof DatabaseServer && treeNode.getChildCount() == 0) {
reloadServerConfiguration(getSelectedServerNode(), true);
}
if (treeNode.getUserObject() instanceof MongoCollection) {
if (treeNode.getUserObject() instanceof SingleMongoCollection) {
loadRecords();
}
if (treeNode.getUserObject() instanceof RedisDatabase) {
Expand Down Expand Up @@ -304,7 +303,7 @@ public DefaultMutableTreeNode getSelectedServerNode() {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) databaseTree.getLastSelectedPathComponent();
if (treeNode != null) {
Object userObject = treeNode.getUserObject();
if (userObject instanceof MongoCollection) {
if (userObject instanceof SingleMongoCollection) {
return (DefaultMutableTreeNode) treeNode.getParent().getParent();
}

Expand All @@ -324,7 +323,7 @@ private DefaultMutableTreeNode getSelectedDatabaseNode() {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) databaseTree.getLastSelectedPathComponent();
if (treeNode != null) {
Object userObject = treeNode.getUserObject();
// if (userObject instanceof MongoCollection) {
// if (userObject instanceof SingleMongoCollection) {
// return (DefaultMutableTreeNode) treeNode.getParent();
// }

Expand All @@ -340,7 +339,7 @@ private DefaultMutableTreeNode getSelectedCollectionNode() {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) databaseTree.getLastSelectedPathComponent();
if (treeNode != null) {
Object userObject = treeNode.getUserObject();
if (userObject instanceof MongoCollection) {
if (userObject instanceof SingleMongoCollection) {
return treeNode;
}
}
Expand Down Expand Up @@ -384,28 +383,28 @@ public CouchbaseDatabase getSelectedCouchaseDatabase() {
return (CouchbaseDatabase) database;
}

public MongoDatabase getSelectedMongoDatabase() {
public SingleMongoDatabase getSelectedMongoDatabase() {
DefaultMutableTreeNode databaseNode = getSelectedDatabaseNode();
if (databaseNode == null) {
return null;
}

Object database = databaseNode.getUserObject();
if (!(database instanceof MongoDatabase)) {
if (!(database instanceof SingleMongoDatabase)) {
return null;
}

return (MongoDatabase) databaseNode.getUserObject();
return (SingleMongoDatabase) databaseNode.getUserObject();

}

public MongoCollection getSelectedCollection() {
public SingleMongoCollection getSelectedCollection() {
DefaultMutableTreeNode collectionNode = getSelectedCollectionNode();
if (collectionNode == null) {
return null;
}

return (MongoCollection) collectionNode.getUserObject();
return (SingleMongoCollection) collectionNode.getUserObject();
}

public void loadRecords() {
Expand All @@ -424,13 +423,13 @@ private NoSqlDatabaseObjectFile createNoSqlObjectFile() { // TODO need to put in
}

public void dropCollection() {// TODO need to put in a customizer
MongoClient databaseClient = (MongoClient) databaseVendorClientManager.get(DatabaseVendor.MONGO);
SingleMongoClient databaseClient = (SingleMongoClient) databaseVendorClientManager.get(DatabaseVendor.MONGO);
databaseClient.dropCollection(getConfiguration(), getSelectedCollection());
reloadServerConfiguration(getSelectedServerNode(), true);
}

public void dropDatabase() {// TODO need to put in a customizer
MongoClient databaseClient = (MongoClient) databaseVendorClientManager.get(DatabaseVendor.MONGO);
SingleMongoClient databaseClient = (SingleMongoClient) databaseVendorClientManager.get(DatabaseVendor.MONGO);
databaseClient.dropDatabase(getConfiguration(), getSelectedMongoDatabase());
reloadServerConfiguration(getSelectedServerNode(), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.codinjutsu.tools.nosql.commons.model.Database;
import org.codinjutsu.tools.nosql.commons.model.DatabaseServer;
import org.codinjutsu.tools.nosql.commons.utils.GuiUtils;
import org.codinjutsu.tools.nosql.mongo.model.MongoCollection;
import org.codinjutsu.tools.nosql.mongo.model.SingleMongoCollection;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
Expand Down Expand Up @@ -57,9 +57,9 @@ public void customizeCellRenderer(@NotNull JTree mongoTree, Object value, boolea
Database noSqlDatabase = (Database) userObject;
append(noSqlDatabase.getName());
setIcon(DATABASE);
} else if (userObject instanceof MongoCollection) {
MongoCollection mongoCollection = (MongoCollection) userObject;
append(mongoCollection.getName());
} else if (userObject instanceof SingleMongoCollection) {
SingleMongoCollection singleMongoCollection = (SingleMongoCollection) userObject;
append(singleMongoCollection.getName());
setIcon(MONGO_COLLECTION);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/codinjutsu/tools/nosql/mongo/MongoUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.codinjutsu.tools.nosql.commons.view.AuthenticationView;
import org.codinjutsu.tools.nosql.commons.view.NoSqlResultView;
import org.codinjutsu.tools.nosql.commons.view.editor.NoSqlDatabaseObjectFile;
import org.codinjutsu.tools.nosql.mongo.logic.MongoClient;
import org.codinjutsu.tools.nosql.mongo.logic.SingleMongoClient;
import org.codinjutsu.tools.nosql.mongo.view.MongoAuthenticationPanel;
import org.codinjutsu.tools.nosql.mongo.view.MongoPanel;
import org.codinjutsu.tools.nosql.mongo.view.editor.MongoObjectFile;
Expand All @@ -38,7 +38,7 @@ public AuthenticationView createAythenticationView() {
public NoSqlResultView createResultPanel(Project project, NoSqlDatabaseObjectFile objectFile) {
MongoObjectFile mongoObjectFile = (MongoObjectFile) objectFile;
return new MongoPanel(project,
MongoClient.getInstance(project),
SingleMongoClient.getInstance(project),
mongoObjectFile.getConfiguration(),
mongoObjectFile.getCollection());
}
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/org/codinjutsu/tools/nosql/mongo/MongoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,26 @@

package org.codinjutsu.tools.nosql.mongo;

import org.bson.Document;
import org.codinjutsu.tools.nosql.ServerConfiguration;
import org.codinjutsu.tools.nosql.mongo.model.MongoDatabase;
import org.codinjutsu.tools.nosql.mongo.model.SingleMongoDatabase;

public class MongoUtils {

private MongoUtils() {
}

public static String buildMongoUrl(ServerConfiguration serverConfiguration, MongoDatabase database) {
public static Object parseJSON(String json) {
// todo: hacky, but works for now.
// Need to find a better way to do this
if (json.startsWith("[")) {
return Document.parse("{'x':" + json + "}").get("x");
}

return Document.parse(json);
}

public static String buildMongoUrl(ServerConfiguration serverConfiguration, SingleMongoDatabase database) {
return String.format("%s/%s", serverConfiguration.getServerUrl(), database == null ? "test" : database.getName());
}
}
Loading