| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Operation |
|
| 5.666666666666667;5.667 |
| 1 | /* | |
| 2 | * #%L | |
| 3 | * Operation.java - mongodb-async-driver - Allanbank Consulting, Inc. | |
| 4 | * %% | |
| 5 | * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc. | |
| 6 | * %% | |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 | * you may not use this file except in compliance with the License. | |
| 9 | * You may obtain a copy of the License at | |
| 10 | * | |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 12 | * | |
| 13 | * Unless required by applicable law or agreed to in writing, software | |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 16 | * See the License for the specific language governing permissions and | |
| 17 | * limitations under the License. | |
| 18 | * #L% | |
| 19 | */ | |
| 20 | package com.allanbank.mongodb.client; | |
| 21 | ||
| 22 | /** | |
| 23 | * Enumeration of the possible operations allowed in MongoDB messages. | |
| 24 | * | |
| 25 | * @api.no This class is <b>NOT</b> part of the drivers API. This class may be | |
| 26 | * mutated in incompatible ways between any two releases of the driver. | |
| 27 | * @copyright 2011-2013, Allanbank Consulting, Inc., All Rights Reserved | |
| 28 | */ | |
| 29 | 128 | public enum Operation { |
| 30 | /** Delete documents. */ | |
| 31 | 1 | DELETE(2006), |
| 32 | ||
| 33 | /** Get more data from a query. */ | |
| 34 | 1 | GET_MORE(2005), |
| 35 | ||
| 36 | /** Insert new document. */ | |
| 37 | 1 | INSERT(2002), |
| 38 | ||
| 39 | /** Tell database client is done with a cursor. */ | |
| 40 | 1 | KILL_CURSORS(2007), |
| 41 | ||
| 42 | /** Query a collection. */ | |
| 43 | 1 | QUERY(2004), |
| 44 | ||
| 45 | /** Reply to a client request. */ | |
| 46 | 1 | REPLY(1), |
| 47 | ||
| 48 | /** Update a document. */ | |
| 49 | 1 | UPDATE(2001); |
| 50 | ||
| 51 | /** | |
| 52 | * Returns the {@link Operation} for the provided opCode. | |
| 53 | * | |
| 54 | * @param opCode | |
| 55 | * The operation code for the {@link Operation}. | |
| 56 | * @return The {@link Operation} for the operation code or <code>null</code> | |
| 57 | * if the operation code is invalid. | |
| 58 | */ | |
| 59 | public static Operation fromCode(final int opCode) { | |
| 60 | 3697 | if (opCode == REPLY.getCode()) { |
| 61 | 712 | return REPLY; |
| 62 | } | |
| 63 | 2985 | else if (opCode == DELETE.getCode()) { |
| 64 | 129 | return DELETE; |
| 65 | } | |
| 66 | 2856 | else if (opCode == GET_MORE.getCode()) { |
| 67 | 17 | return GET_MORE; |
| 68 | } | |
| 69 | 2839 | else if (opCode == INSERT.getCode()) { |
| 70 | 130 | return INSERT; |
| 71 | } | |
| 72 | 2709 | else if (opCode == KILL_CURSORS.getCode()) { |
| 73 | 1001 | return KILL_CURSORS; |
| 74 | } | |
| 75 | 1708 | else if (opCode == QUERY.getCode()) { |
| 76 | 682 | return QUERY; |
| 77 | } | |
| 78 | 1026 | else if (opCode == UPDATE.getCode()) { |
| 79 | 1025 | return UPDATE; |
| 80 | } | |
| 81 | 1 | return null; |
| 82 | } | |
| 83 | ||
| 84 | /** The operation code. */ | |
| 85 | private final int myCode; | |
| 86 | ||
| 87 | /** | |
| 88 | * Creates a new Operation. | |
| 89 | * | |
| 90 | * @param code | |
| 91 | * The operations code. | |
| 92 | */ | |
| 93 | 7 | private Operation(final int code) { |
| 94 | 7 | myCode = code; |
| 95 | 7 | } |
| 96 | ||
| 97 | /** | |
| 98 | * Returns the Operation's code. | |
| 99 | * | |
| 100 | * @return The operation's code. | |
| 101 | */ | |
| 102 | public int getCode() { | |
| 103 | 21677 | return myCode; |
| 104 | } | |
| 105 | } |