Permalink
Browse files

Manage Mongo Database.

  • Loading branch information...
angelozerr committed Sep 4, 2012
1 parent 14944f5 commit 84177abf07eb81af78e2f53003e6cab0f17f92c0
Showing with 577 additions and 155 deletions.
  1. +7 −2 com.mongodb.tools/src/com/mongodb/tools/driver/MongoDriverHelper.java
  2. +1 −1 ...hing/src/fr/opensagres/mongodb/ide/launching/internal/launchConfigurations/mongod/PingThread.java
  3. +2 −2 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/extensions/AbstractServerFactory.java
  4. +1 −1 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/extensions/IServerFactory.java
  5. +22 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/internal/Messages.java
  6. +8 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/internal/Messages.properties
  7. +8 −3 ...gres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/internal/settings/ServersContentHandler.java
  8. +24 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/AbstractCollection.java
  9. +52 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/AbstractCollectionsCategory.java
  10. +23 −1 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/AbstractServer.java
  11. +1 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/Error.java
  12. +5 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ICollection.java
  13. +5 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ICollectionsCategory.java
  14. +0 −2 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/IDatabase.java
  15. +2 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/IServer.java
  16. +2 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ITreeContainerNode.java
  17. +2 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/ITreeSimpleNode.java
  18. +4 −0 fr.opensagres.nosql.ide.core/src/fr/opensagres/nosql/ide/core/model/TreeSimpleNode.java
  19. +17 −2 ...ongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/extensions/ConnectServerRunner.java
  20. +1 −1 ...mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/extensions/MongoServerFactory.java
  21. +16 −0 ...godb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/shell/DBAuthenticateShellCommand.java
  22. +15 −0 ...odb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/shell/ShowCollectionsShellCommand.java
  23. +14 −0 ...sql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/internal/shell/UseShellCommand.java
  24. +19 −0 fr.opensagres.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/Collection.java
  25. +24 −0 ...es.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/CollectionsCategory.java
  26. +45 −1 fr.opensagres.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/Database.java
  27. +6 −4 fr.opensagres.nosql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/model/MongoServer.java
  28. +33 −0 ...sql.ide.mongodb.core/src/fr/opensagres/nosql/ide/mongodb/core/shell/MongoShellCommandManager.java
  29. +9 −8 ...nsagres.nosql.ide.orientdb.core/src/fr/opensagres/nosql/ide/orientdb/core/model/OrientServer.java
  30. +4 −2 ...e.orientdb.core/src/fr/opensagres/nosql/ide/orientdb/core/model/internal/OrientServerFactory.java
  31. +7 −6 ...l.ide.orientdb.ui/src/fr/opensagres/nosql/ide/orientdb/ui/wizards/server/NewServerWizardPage.java
  32. BIN fr.opensagres.nosql.ide.ui/icons/obj16/command.gif
  33. +5 −2 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/ImageResources.java
  34. +10 −2 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/viewers/ServerLabelProvider.java
  35. +20 −0 ...res.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/viewers/ShellCommandContentProvider.java
  36. +32 −0 ...agres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/viewers/ShellCommandLabelProvider.java
  37. +80 −115 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/views/ShellCommandsView.java
  38. +51 −0 fr.opensagres.nosql.ide.ui/src/fr/opensagres/nosql/ide/ui/internal/views/ShellServerItem.java
@@ -61,8 +61,13 @@ public static void stopMongoServer(Mongo mongo, String username,
shutdownResult.throwOnError();
}
- public static void tryConnection(Mongo mongo) throws MongoException {
- mongo.getDatabaseNames();
+ public static void tryConnection(Mongo mongo, String dbname)
+ throws MongoException {
+ if (dbname == null || dbname.length() < 1) {
+ mongo.getDatabaseNames();
+ } else {
+ mongo.getDB(dbname).getCollectionNames();
+ }
}
/**
@@ -72,7 +72,7 @@ protected void ping() {
count++;
Trace.trace(Trace.STRING_FINEST, "Ping: pinging " + count);
- MongoDriverHelper.tryConnection(server.getMongo());
+ MongoDriverHelper.tryConnection(server.getMongo(), server.getDatabaseName());
// ping worked - server is up
if (!stop) {
@@ -9,7 +9,7 @@
public abstract class AbstractServerFactory implements IServerFactory {
- public IServer create(Attributes attributes) {
+ public IServer create(Attributes attributes) throws Exception {
String id = attributes.getValue(ServersConstants.ID_ATTR);
String name = attributes.getValue(ServersConstants.NAME_ATTR);
String url = attributes.getValue(ServersConstants.URL_ATTR);
@@ -36,5 +36,5 @@ public IServer create(Attributes attributes) {
}
protected abstract IServer doCreate(String id, String name, String url,
- Attributes attributes);
+ Attributes attributes) throws Exception ;
}
@@ -6,6 +6,6 @@
public interface IServerFactory {
- IServer create(Attributes attributes);
+ IServer create(Attributes attributes) throws Exception;
}
@@ -0,0 +1,22 @@
+package fr.opensagres.nosql.ide.core.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "fr.opensagres.nosql.ide.core.internal.Messages";//$NON-NLS-1$
+
+ public static String errorStopAlreadyStopped;
+
+ public static String Collections_label;
+ public static String GridFS_label;
+ public static String StoredJavascript_label;
+ public static String Users_label;
+ public static String Indexes_label;
+
+ static {
+ // load message values from bundle file
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+}
@@ -0,0 +1,8 @@
+errorStopAlreadyStopped=The server cannot be stopped because it is already stopped or stopping.
+
+# Static name of the nodes of tree of server explorer
+Collections_label=Collections
+GridFS_label=GridFS
+StoredJavascript_label=Stored Javascript
+Users_label=Users
+Indexes_label=Indexes
@@ -8,6 +8,7 @@
import fr.opensagres.nosql.ide.core.Platform;
import fr.opensagres.nosql.ide.core.extensions.IServerFactory;
import fr.opensagres.nosql.ide.core.extensions.IServerType;
+import fr.opensagres.nosql.ide.core.internal.Trace;
import fr.opensagres.nosql.ide.core.model.IServer;
import fr.opensagres.nosql.ide.core.settings.ServersConstants;
import fr.opensagres.nosql.ide.core.utils.StringUtils;
@@ -31,9 +32,13 @@ public void startElement(String uri, String localName, String qName,
IServerFactory factory = Platform
.getServerFactoryRegistry().getFactory(serverType);
if (factory != null) {
- IServer server = factory.create(attributes);
- if (server != null) {
- super.list.add(server);
+ try {
+ IServer server = factory.create(attributes);
+ if (server != null) {
+ super.list.add(server);
+ }
+ } catch (Exception e) {
+ Trace.trace(Trace.STRING_SEVERE, e.getMessage());
}
}
}
@@ -0,0 +1,24 @@
+package fr.opensagres.nosql.ide.core.model;
+
+public abstract class AbstractCollection extends
+ TreeContainerNode<ICollectionsCategory> implements ICollection {
+
+ private String name;
+
+ public AbstractCollection(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getLabel() {
+ return getName();
+ }
+
+ public final int getType() {
+ return NodeTypeConstants.Collection;
+ }
+
+}
@@ -0,0 +1,52 @@
+package fr.opensagres.nosql.ide.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import fr.opensagres.nosql.ide.core.internal.Messages;
+
+public abstract class AbstractCollectionsCategory extends
+ TreeContainerNode<IDatabase> implements ICollectionsCategory {
+
+ protected final List<ICollection> collections;
+
+ public AbstractCollectionsCategory() {
+ this.collections = new ArrayList<ICollection>();
+ }
+
+ public String getName() {
+ return Messages.Collections_label;
+ }
+
+ public String getLabel() {
+ return getName();
+ }
+
+ public final IServer getServer() {
+ return getParent().getServer();
+ }
+
+ public final int getType() {
+ return NodeTypeConstants.CollectionsCategory;
+ }
+
+ public List<ICollection> getCollections() {
+ // Compute if needed list of collection.
+ getChildren();
+ return collections;
+ }
+
+ @Override
+ public void clearNodes() {
+ super.clearNodes();
+ this.collections.clear();
+ }
+
+ @Override
+ protected void doGetChildren() throws Exception {
+ this.collections.clear();
+ loadCollections();
+ }
+
+ protected abstract void loadCollections() throws Exception;
+}
@@ -23,6 +23,8 @@
private IServerRuntime runtime;
private IServerType serverType;
+ private IDatabase currentDatabase;
+
public AbstractServer(String serverTypeId, String name) {
this(serverTypeId, String.valueOf(System.currentTimeMillis()), name);
}
@@ -224,6 +226,11 @@ public IServerType getServerType() {
return serverType;
}
+ @Override
+ public IServer getServer() {
+ return this;
+ }
+
public final void save(Writer writer) throws IOException {
writer.append("<");
writer.append(ServersConstants.SERVER_ELT);
@@ -264,7 +271,22 @@ protected void doSave(Writer writer) throws IOException {
}
- protected abstract String getDatabaseName();
+ /**
+ * Select the given database and returns true if current database is not the
+ * same than the given database.
+ *
+ * @param database
+ * @return
+ */
+ public boolean selectDatabase(IDatabase database) {
+ if (currentDatabase == null) {
+ currentDatabase = database;
+ return true;
+ }
+ boolean result = currentDatabase.getId().equals(database.getId());
+ currentDatabase = database;
+ return !result;
+ }
protected abstract void loadDatabases() throws Exception;
@@ -23,5 +23,6 @@ public String getId() {
public String getName() {
return null;
}
+
}
@@ -0,0 +1,5 @@
+package fr.opensagres.nosql.ide.core.model;
+
+public interface ICollection extends ITreeContainerNode<ICollectionsCategory> {
+
+}
@@ -0,0 +1,5 @@
+package fr.opensagres.nosql.ide.core.model;
+
+public interface ICollectionsCategory extends ITreeContainerNode<IDatabase> {
+
+}
@@ -2,6 +2,4 @@
public interface IDatabase extends ITreeContainerNode<IServer> {
- IServer getServer();
-
}
@@ -29,4 +29,6 @@
void setServerState(ServerState serverState);
String getURL();
+
+ String getDatabaseName();
}
@@ -7,4 +7,6 @@
List<ITreeSimpleNode> getChildren();
+ NodeStatus getStatus();
+
}
@@ -3,6 +3,8 @@
public interface ITreeSimpleNode<Parent extends ITreeContainerNode> extends
IModelIdentity {
+ IServer getServer();
+
Parent getParent();
void setParent(Parent parent);
@@ -25,4 +25,8 @@ protected String computeId() {
public String getId() {
return computeId();
}
+
+ public IServer getServer() {
+ return getParent().getServer();
+ }
}
@@ -2,6 +2,7 @@
import fr.opensagres.nosql.ide.core.extensions.AbstractServerRunner;
import fr.opensagres.nosql.ide.core.model.IServer;
+import fr.opensagres.nosql.ide.core.model.NodeStatus;
import fr.opensagres.nosql.ide.core.model.ServerState;
public class ConnectServerRunner extends AbstractServerRunner {
@@ -13,10 +14,24 @@ protected boolean doCanSupport(IServer server) {
public void start(IServer server) throws Exception {
server.setServerState(ServerState.Connecting);
- // Try to connect
+ //server.getChildren();
+ //if (server.getStatus() == NodeStatus.StartedWithError) {
+ // server.setServerState(ServerState.Disconnected);
+ //}
+ //else {
+ server.setServerState(ServerState.Connected);
+ //}
+// // Try to connect
+// try {
+// MongoDriverHelper.tryConnection(((MongoServer) server).getMongo(),
+// server.getDatabaseName());
+// server.setServerState(ServerState.Connected);
+// } catch (Throwable e) {
+// server.getChildren().add(new Error(e));
+// server.setServerState(ServerState.Disconnected);
+// }
// MongoDriverHelper.tryConnection(getMongo());
// Connection is OK, update the server state as connected.
- server.setServerState(ServerState.Connected);
}
@@ -12,7 +12,7 @@
@Override
protected IServer doCreate(String id, String name, String url,
- Attributes attributes) {
+ Attributes attributes) throws Exception {
MongoURI mongoURI = new MongoURI(url);
return new MongoServer(id, name, mongoURI);
}
@@ -0,0 +1,16 @@
+package fr.opensagres.nosql.ide.mongodb.core.internal.shell;
+
+import com.mongodb.tools.shell.ShellScriptBuilder;
+
+import fr.opensagres.nosql.ide.core.model.IServer;
+import fr.opensagres.nosql.ide.core.shell.AbstractShellCommand;
+
+public class DBAuthenticateShellCommand extends AbstractShellCommand {
+
+ public DBAuthenticateShellCommand(IServer server, String username,
+ char[] passwd) {
+ super(server, SHELL_DB_AUTHENTICATE, ShellScriptBuilder.dbAuthenticate(
+ username, passwd));
+ }
+
+}
@@ -0,0 +1,15 @@
+package fr.opensagres.nosql.ide.mongodb.core.internal.shell;
+
+import com.mongodb.tools.shell.ShellScriptBuilder;
+
+import fr.opensagres.nosql.ide.core.model.IServer;
+import fr.opensagres.nosql.ide.core.shell.AbstractShellCommand;
+
+public class ShowCollectionsShellCommand extends AbstractShellCommand {
+
+ public ShowCollectionsShellCommand(IServer server) {
+ super(server, SHELL_SHOW_COLLECTIONS, ShellScriptBuilder
+ .showCollections());
+ }
+
+}
@@ -0,0 +1,14 @@
+package fr.opensagres.nosql.ide.mongodb.core.internal.shell;
+
+import com.mongodb.tools.shell.ShellScriptBuilder;
+
+import fr.opensagres.nosql.ide.core.model.IServer;
+import fr.opensagres.nosql.ide.core.shell.AbstractShellCommand;
+
+public class UseShellCommand extends AbstractShellCommand {
+
+ public UseShellCommand(IServer server, String dbname) {
+ super(server, SHELL_USE, ShellScriptBuilder.use(dbname));
+ }
+
+}
@@ -0,0 +1,19 @@
+package fr.opensagres.nosql.ide.mongodb.core.model;
+
+import fr.opensagres.nosql.ide.core.model.AbstractCollection;
+
+public class Collection extends AbstractCollection {
+
+ public Collection(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void doGetChildren() throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+}
Oops, something went wrong.

0 comments on commit 84177ab

Please sign in to comment.