Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JAVA-757: Changing CommandFailureException and WriteConcernException …

…from static inner class to top-level.
  • Loading branch information...
commit 7897a3bf4fe88cfc67769d291a026a87a0c27710 1 parent 046d662
@jyemin jyemin authored
View
36 src/main/com/mongodb/CommandFailureException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2008 - 2013 10gen, Inc. <http://10gen.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.mongodb;
+
+class CommandFailureException extends MongoException {
+ private static final long serialVersionUID = 1L;
+ private final CommandResult commandResult;
+
+ /**
+ *
+ * @param commandResult the result
+ */
+ public CommandFailureException(CommandResult commandResult){
+ super(ServerError.getCode(commandResult), commandResult.toString());
+ this.commandResult = commandResult;
+ }
+
+ public CommandResult getCommandResult() {
+ return commandResult;
+ }
+}
View
19 src/main/com/mongodb/CommandResult.java
@@ -74,7 +74,7 @@ public MongoException getException() {
return new MongoException.DuplicateKey(this);
}
else {
- return new MongoException.WriteConcernException(this);
+ return new WriteConcernException(this);
}
}
@@ -118,21 +118,4 @@ public ServerAddress getServerUsed() {
private final ServerAddress _host;
private static final long serialVersionUID = 1L;
- static class CommandFailureException extends MongoException {
- private static final long serialVersionUID = 1L;
- private final CommandResult commandResult;
-
- /**
- *
- * @param commandResult the result
- */
- public CommandFailureException(CommandResult commandResult){
- super(ServerError.getCode(commandResult), commandResult.toString());
- this.commandResult = commandResult;
- }
-
- public CommandResult getCommandResult() {
- return commandResult;
- }
- }
}
View
6 src/main/com/mongodb/DB.java
@@ -629,20 +629,20 @@ private CommandResultPair authenticateCommandHelper(String username, char[] pass
try {
authenticationTestCommandResult = doAuthenticate(credentials);
return new CommandResultPair(authenticationTestCommandResult);
- } catch (CommandResult.CommandFailureException commandFailureException) {
+ } catch (CommandFailureException commandFailureException) {
return new CommandResultPair(commandFailureException);
}
}
class CommandResultPair {
CommandResult result;
- CommandResult.CommandFailureException failure;
+ CommandFailureException failure;
public CommandResultPair(final CommandResult result) {
this.result = result;
}
- public CommandResultPair(final CommandResult.CommandFailureException failure) {
+ public CommandResultPair(final CommandFailureException failure) {
this.failure = failure;
}
}
View
2  src/main/com/mongodb/DBConnector.java
@@ -109,7 +109,7 @@ public Response call( DB db , DBCollection coll , OutMessage m ,
*
* @param credentials the credentials.
* @return the result of the authentication command, if successful
- * @throws com.mongodb.CommandResult.CommandFailureException if the authentication failed
+ * @throws CommandFailureException if the authentication failed
* @since 2.11.0
*/
public CommandResult authenticate(MongoCredential credentials);
View
24 src/main/com/mongodb/MongoException.java
@@ -119,30 +119,6 @@ public Network( java.io.IOException ioe ){
}
/**
- * An exception representing an error reported due to a write failure.
- */
- public static class WriteConcernException extends MongoException {
-
- private static final long serialVersionUID = 841056799207039974L;
-
- private final CommandResult commandResult;
-
- public WriteConcernException(final CommandResult commandResult) {
- super(commandResult.getCode(), commandResult.toString());
- this.commandResult = commandResult;
- }
-
- /**
- * Gets the getlasterror command result document.
- *
- * @return the command result
- */
- public CommandResult getCommandResult() {
- return commandResult;
- }
- }
-
- /**
* Subclass of WriteConcernException representing a duplicate key error
*/
public static class DuplicateKey extends WriteConcernException {
View
42 src/main/com/mongodb/WriteConcernException.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 - 2013 10gen, Inc. <http://10gen.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.mongodb;
+
+/**
+ * An exception representing an error reported due to a write failure.
+ */
+public class WriteConcernException extends MongoException {
+
+ private static final long serialVersionUID = 841056799207039974L;
+
+ private final CommandResult commandResult;
+
+ public WriteConcernException(final CommandResult commandResult) {
+ super(commandResult.getCode(), commandResult.toString());
+ this.commandResult = commandResult;
+ }
+
+ /**
+ * Gets the getlasterror command result document.
+ *
+ * @return the command result
+ */
+ public CommandResult getCommandResult() {
+ return commandResult;
+ }
+}
View
4 src/test/com/mongodb/CommandResultTest.java
@@ -29,7 +29,7 @@ public void testNullErrorCode() throws UnknownHostException {
try {
commandResult.throwOnError();
fail("Should throw");
- } catch (CommandResult.CommandFailureException e) {
+ } catch (CommandFailureException e) {
assertEquals(commandResult, e.getCommandResult());
assertEquals(-5, e.getCode());
}
@@ -43,7 +43,7 @@ public void testCommandFailure() throws UnknownHostException {
try {
commandResult.throwOnError();
fail("Should throw");
- } catch (CommandResult.CommandFailureException e) {
+ } catch (CommandFailureException e) {
assertEquals(commandResult, e.getCommandResult());
assertEquals(5000, e.getCode());
}
View
2  src/test/com/mongodb/DBPortTest.java
@@ -58,7 +58,7 @@ public void testAuthentication() throws IOException {
try {
port.checkAuth(m);
fail("should throw");
- } catch (CommandResult.CommandFailureException e) {
+ } catch (CommandFailureException e) {
// all good
}
}
View
2  src/test/com/mongodb/JavaClientTest.java
@@ -694,7 +694,7 @@ public void testAuthenticateCommand() throws UnknownHostException {
try {
db.authenticateCommand( "xx" , "f".toCharArray());
fail("Auth should have failed");
- } catch (CommandResult.CommandFailureException e) {
+ } catch (CommandFailureException e) {
// all good
}
assertTrue(db.authenticateCommand("xx", "e".toCharArray()).ok());
Please sign in to comment.
Something went wrong with that request. Please try again.