1 /***
2 * Copyright (c) 2002, Reuters America Inc. All rights reserved.<p>
3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
4 * conditions are met:<p>
5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
7 * in the documentation and/or other materials provided with the distribution. Neither the name of Reuters America Inc. nor the
8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written
9 * permission.<p>
10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p>
16 */
17
18 package com.reuters.rc.db.adb;
19
20 import com.reuters.rc.db.*;
21
22 /***
23 * ADB operation codes represented as type-safe enumerations.
24 * @author Jawaid Hakim.
25 */
26 public class AdbOpcode implements DbOpcode
27 {
28 /***
29 * Ctor. To prevent instantiation.
30 * @param opCode ADB operation code.
31 */
32 private AdbOpcode(int opCode)
33 {
34 opCode_ = opCode;
35 }
36
37 /***
38 * Override <code>toString()</code>.
39 * @return String representation of object.
40 */
41 public String toString()
42 {
43 return String.valueOf(opCode_);
44 }
45
46 /***
47 * Get the opcode value as an <code>int</code>.
48 * @return Opcode value as an <code>int</code>.
49 */
50 public final int intValue()
51 {
52 return opCode_;
53 }
54
55 /***
56 * Check if this opcode is an INSERT.
57 * @return Returns <code>true</code> if this opcode is an INSERT.
58 */
59 public final boolean isInsert()
60 {
61 return (this == AdbOpcode.INSERT);
62 }
63
64 /***
65 * Check if this opcode is an DELETE.
66 * @return Returns <code>true</code> if this opcode is an DELETE.
67 */
68 public final boolean isDelete()
69 {
70 return (this == AdbOpcode.DELETE);
71 }
72
73 /***
74 * Check if this opcode is an UPDATE.
75 * @return Returns <code>true</code> if this opcode is an UPDATE.
76 */
77 public final boolean isUpdate()
78 {
79 return (this == AdbOpcode.UPDATE);
80 }
81
82 /***
83 * Check if this opcode is an UPSERT.
84 * @return Returns <code>true</code> if this opcode is an UPSERT.
85 */
86 public final boolean isUpsert()
87 {
88 return (this == AdbOpcode.UPSERT);
89 }
90
91 /***
92 * Check if this opcode is an UNKNOWN.
93 * @return Returns <code>true</code> if this opcode is an UNKNOWN.
94 */
95 public final boolean isUnknown()
96 {
97 return (this == AdbOpcode.UNKNOWN);
98 }
99
100 /***
101 * Get <code>AdbOpcode</code> object corresponding to the opCode published by ADB.
102 * @param adbOpCode OpCode published by ADB.
103 * @return <code>AdbOpcode</code> object corresponding to the opCode published by ADB.
104 * Returns <code>UNKNOWN</code> if the adbOpcode is invalid.
105 */
106 public static final AdbOpcode getOpcode(java.lang.Integer adbOpCode)
107 {
108 return getOpcode(adbOpCode.intValue());
109 }
110
111 /***
112 * Get <code>AdbOpcode</code> object corresponding to the opCode published by ADB.
113 * @param adbOpCode OpCode published by ADB.
114 * @return <code>AdbOpcode</code> object corresponding to the opCode published by ADB.
115 * Returns <code>UNKNOWN</code> if the adbOpcode is invalid.
116 */
117 public static final AdbOpcode getOpcode(int adbOpCode)
118 {
119 AdbOpcode ret;
120 switch (adbOpCode)
121 {
122 case INSERT_CODE:
123 ret = INSERT;
124 break;
125 case UPDATE_CODE:
126 ret = UPDATE;
127 break;
128 case DELETE_CODE:
129 ret = DELETE;
130 break;
131 case UPSERT_CODE:
132 ret = UPSERT;
133 break;
134 default:
135 ret = UNKNOWN;
136 break;
137 }
138 return ret;
139 }
140
141 // Opcode published by ADB.
142 private static final int INSERT_CODE = 1;
143 private static final int UPDATE_CODE = 2;
144 private static final int DELETE_CODE = 3;
145 private static final int UPSERT_CODE = 4;
146 private static final int UNKNOWN_CODE = 0;
147
148 // Instance opcode.
149 private int opCode_;
150
151 /***
152 * INSERT opcode object.
153 */
154 public static final AdbOpcode INSERT = new AdbOpcode(INSERT_CODE);
155
156 /***
157 * UPDATE opcode object.
158 */
159 public static final AdbOpcode UPDATE = new AdbOpcode(UPDATE_CODE);
160
161 /***
162 * DELETE opcode object.
163 */
164 public static final AdbOpcode DELETE = new AdbOpcode(DELETE_CODE);
165
166 /***
167 * UPSERT opcode object - UPDATE if row exists, otherwise INSERT.
168 */
169 public static final AdbOpcode UPSERT = new AdbOpcode(UPSERT_CODE);
170
171 /***
172 * UNKNOWN opcode object- Unknown opcode.
173 */
174 public static final AdbOpcode UNKNOWN = new AdbOpcode(UNKNOWN_CODE);
175 }
This page was automatically generated by Maven