01: package com.mockrunner.mock.jdbc;
02:
03: import java.sql.RowId;
04: import java.util.Arrays;
05:
06: import com.mockrunner.base.NestedApplicationException;
07:
08: /**
09: * Mock implementation of <code>RowId</code>.
10: */
11: public class MockRowId implements RowId, Cloneable {
12: private byte[] rowIdData;
13:
14: public MockRowId(byte[] data) {
15: rowIdData = data.clone();
16: }
17:
18: public byte[] getBytes() {
19: return rowIdData;
20: }
21:
22: public boolean equals(Object otherObject) {
23: if (null == otherObject)
24: return false;
25: if (!otherObject.getClass().equals(this .getClass()))
26: return false;
27: MockRowId otherRowId = (MockRowId) otherObject;
28: return Arrays.equals(rowIdData, otherRowId.getBytes());
29: }
30:
31: public int hashCode() {
32: int value = 17;
33: for (int ii = 0; ii < rowIdData.length; ii++) {
34: value = (31 * value) + rowIdData[ii];
35: }
36: return value;
37: }
38:
39: public String toString() {
40: StringBuffer buffer = new StringBuffer();
41: buffer.append(this .getClass().getName() + ": [");
42: for (int ii = 0; ii < rowIdData.length; ii++) {
43: buffer.append(rowIdData[ii]);
44: if (ii < rowIdData.length - 1) {
45: buffer.append(", ");
46: }
47: }
48: buffer.append("]");
49: return buffer.toString();
50: }
51:
52: public Object clone() {
53: try {
54: MockRowId copy = (MockRowId) super .clone();
55: copy.rowIdData = rowIdData.clone();
56: return copy;
57: } catch (CloneNotSupportedException exc) {
58: throw new NestedApplicationException(exc);
59: }
60: }
61: }
|