Skip to content

Commit 7897a3b

Browse files
committed
JAVA-757: Changing CommandFailureException and WriteConcernException from static inner class to top-level.
1 parent 046d662 commit 7897a3b

File tree

9 files changed

+87
-50
lines changed

9 files changed

+87
-50
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2008 - 2013 10gen, Inc. <http://10gen.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.mongodb;
19+
20+
class CommandFailureException extends MongoException {
21+
private static final long serialVersionUID = 1L;
22+
private final CommandResult commandResult;
23+
24+
/**
25+
*
26+
* @param commandResult the result
27+
*/
28+
public CommandFailureException(CommandResult commandResult){
29+
super(ServerError.getCode(commandResult), commandResult.toString());
30+
this.commandResult = commandResult;
31+
}
32+
33+
public CommandResult getCommandResult() {
34+
return commandResult;
35+
}
36+
}

src/main/com/mongodb/CommandResult.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public MongoException getException() {
7474
return new MongoException.DuplicateKey(this);
7575
}
7676
else {
77-
return new MongoException.WriteConcernException(this);
77+
return new WriteConcernException(this);
7878
}
7979
}
8080

@@ -118,21 +118,4 @@ public ServerAddress getServerUsed() {
118118
private final ServerAddress _host;
119119
private static final long serialVersionUID = 1L;
120120

121-
static class CommandFailureException extends MongoException {
122-
private static final long serialVersionUID = 1L;
123-
private final CommandResult commandResult;
124-
125-
/**
126-
*
127-
* @param commandResult the result
128-
*/
129-
public CommandFailureException(CommandResult commandResult){
130-
super(ServerError.getCode(commandResult), commandResult.toString());
131-
this.commandResult = commandResult;
132-
}
133-
134-
public CommandResult getCommandResult() {
135-
return commandResult;
136-
}
137-
}
138121
}

src/main/com/mongodb/DB.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,20 +629,20 @@ private CommandResultPair authenticateCommandHelper(String username, char[] pass
629629
try {
630630
authenticationTestCommandResult = doAuthenticate(credentials);
631631
return new CommandResultPair(authenticationTestCommandResult);
632-
} catch (CommandResult.CommandFailureException commandFailureException) {
632+
} catch (CommandFailureException commandFailureException) {
633633
return new CommandResultPair(commandFailureException);
634634
}
635635
}
636636

637637
class CommandResultPair {
638638
CommandResult result;
639-
CommandResult.CommandFailureException failure;
639+
CommandFailureException failure;
640640

641641
public CommandResultPair(final CommandResult result) {
642642
this.result = result;
643643
}
644644

645-
public CommandResultPair(final CommandResult.CommandFailureException failure) {
645+
public CommandResultPair(final CommandFailureException failure) {
646646
this.failure = failure;
647647
}
648648
}

src/main/com/mongodb/DBConnector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public Response call( DB db , DBCollection coll , OutMessage m ,
109109
*
110110
* @param credentials the credentials.
111111
* @return the result of the authentication command, if successful
112-
* @throws com.mongodb.CommandResult.CommandFailureException if the authentication failed
112+
* @throws CommandFailureException if the authentication failed
113113
* @since 2.11.0
114114
*/
115115
public CommandResult authenticate(MongoCredential credentials);

src/main/com/mongodb/MongoException.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,30 +118,6 @@ public Network( java.io.IOException ioe ){
118118
final java.io.IOException _ioe;
119119
}
120120

121-
/**
122-
* An exception representing an error reported due to a write failure.
123-
*/
124-
public static class WriteConcernException extends MongoException {
125-
126-
private static final long serialVersionUID = 841056799207039974L;
127-
128-
private final CommandResult commandResult;
129-
130-
public WriteConcernException(final CommandResult commandResult) {
131-
super(commandResult.getCode(), commandResult.toString());
132-
this.commandResult = commandResult;
133-
}
134-
135-
/**
136-
* Gets the getlasterror command result document.
137-
*
138-
* @return the command result
139-
*/
140-
public CommandResult getCommandResult() {
141-
return commandResult;
142-
}
143-
}
144-
145121
/**
146122
* Subclass of WriteConcernException representing a duplicate key error
147123
*/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2008 - 2013 10gen, Inc. <http://10gen.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package com.mongodb;
19+
20+
/**
21+
* An exception representing an error reported due to a write failure.
22+
*/
23+
public class WriteConcernException extends MongoException {
24+
25+
private static final long serialVersionUID = 841056799207039974L;
26+
27+
private final CommandResult commandResult;
28+
29+
public WriteConcernException(final CommandResult commandResult) {
30+
super(commandResult.getCode(), commandResult.toString());
31+
this.commandResult = commandResult;
32+
}
33+
34+
/**
35+
* Gets the getlasterror command result document.
36+
*
37+
* @return the command result
38+
*/
39+
public CommandResult getCommandResult() {
40+
return commandResult;
41+
}
42+
}

src/test/com/mongodb/CommandResultTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void testNullErrorCode() throws UnknownHostException {
2929
try {
3030
commandResult.throwOnError();
3131
fail("Should throw");
32-
} catch (CommandResult.CommandFailureException e) {
32+
} catch (CommandFailureException e) {
3333
assertEquals(commandResult, e.getCommandResult());
3434
assertEquals(-5, e.getCode());
3535
}
@@ -43,7 +43,7 @@ public void testCommandFailure() throws UnknownHostException {
4343
try {
4444
commandResult.throwOnError();
4545
fail("Should throw");
46-
} catch (CommandResult.CommandFailureException e) {
46+
} catch (CommandFailureException e) {
4747
assertEquals(commandResult, e.getCommandResult());
4848
assertEquals(5000, e.getCode());
4949
}

src/test/com/mongodb/DBPortTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void testAuthentication() throws IOException {
5858
try {
5959
port.checkAuth(m);
6060
fail("should throw");
61-
} catch (CommandResult.CommandFailureException e) {
61+
} catch (CommandFailureException e) {
6262
// all good
6363
}
6464
}

src/test/com/mongodb/JavaClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ public void testAuthenticateCommand() throws UnknownHostException {
694694
try {
695695
db.authenticateCommand( "xx" , "f".toCharArray());
696696
fail("Auth should have failed");
697-
} catch (CommandResult.CommandFailureException e) {
697+
} catch (CommandFailureException e) {
698698
// all good
699699
}
700700
assertTrue(db.authenticateCommand("xx", "e".toCharArray()).ok());

0 commit comments

Comments
 (0)