1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2001-2004
* Sleepycat Software. All rights reserved.
*
* $Id: AssociateCallbacks.java,v 1.3 2004/04/06 20:43:41 mjc Exp $
*/
package com.sleepycat.db.rpcserver;
import com.sleepycat.db.*;
/** Implementations of the callbacks required by the Tcl test suite. **/
class AssociateCallbacks {
/*
* Tcl passes one of these special flags for the callbacks used in the
* test suite. Note: these must match db_int.in!
*/
static final int DB_RPC2ND_REVERSEDATA = 0x00100000;
static final int DB_RPC2ND_NOOP = 0x00200000;
static final int DB_RPC2ND_CONCATKEYDATA = 0x00300000;
static final int DB_RPC2ND_CONCATDATAKEY = 0x00400000;
static final int DB_RPC2ND_REVERSECONCAT = 0x00500000;
static final int DB_RPC2ND_TRUNCDATA = 0x00600000;
static final int DB_RPC2ND_CONSTANT = 0x00700000;
static final int DB_RPC2ND_GETZIP = 0x00800000;
static final int DB_RPC2ND_GETNAME = 0x00900000;
static final int DB_RPC2ND_MASK = 0x00f00000;
static SecondaryKeyCreator getCallback(int flags) {
switch(flags & DB_RPC2ND_MASK) {
case 0:
return null;
case DB_RPC2ND_REVERSEDATA:
return new SecondaryKeyCreator() {
public boolean createSecondaryKey(SecondaryDatabase secondary,
DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
throws DatabaseException {
byte[] dataBuf = data.getData();
int dataSize = data.getSize();
byte[] buf = new byte[dataSize];
for (int i = 0; i < dataSize; i++)
buf[dataSize - 1 - i] = dataBuf[i];
result.setData(buf);
result.setSize(buf.length);
return true;
}
};
case DB_RPC2ND_NOOP:
return new SecondaryKeyCreator() {
public boolean createSecondaryKey(SecondaryDatabase secondary,
DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
throws DatabaseException {
result.setData(data.getData());
result.setSize(data.getSize());
return true;
}
};
case DB_RPC2ND_CONCATKEYDATA:
return new SecondaryKeyCreator() {
public boolean createSecondaryKey(SecondaryDatabase secondary,
DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
throws DatabaseException {
byte[] buf = new byte[key.getSize() +
data.getSize()];
System.arraycopy(key.getData(), 0,
buf, 0,
key.getSize());
System.arraycopy(data.getData(), 0,
buf, key.getSize(),
data.getSize());
result.setData(buf);
result.setSize(buf.length);
return true;
}
};
case DB_RPC2ND_CONCATDATAKEY:
return new SecondaryKeyCreator() {
public boolean createSecondaryKey(SecondaryDatabase secondary,
DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
throws DatabaseException {
byte[] buf = new byte[key.getSize() +
data.getSize()];
System.arraycopy(data.getData(), 0,
buf, 0,
data.getSize());
System.arraycopy(key.getData(), 0,
buf, data.getSize(),
key.getSize());
result.setData(buf);
result.setSize(buf.length);
return true;
}
};
case DB_RPC2ND_REVERSECONCAT:
return new SecondaryKeyCreator() {
public boolean createSecondaryKey(SecondaryDatabase secondary,
DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
throws DatabaseException {
byte[] keyBuf = key.getData();
int keySize = key.getSize();
byte[] dataBuf = data.getData();
int dataSize = data.getSize();
byte[] buf = new byte[keySize + dataSize];
for (int i = 0; i < keySize; i++)
buf[buf.length - 1 - i] = keyBuf[i];
for (int i = 0; i < dataSize; i++)
buf[dataSize - 1 - i] = dataBuf[i];
result.setData(buf);
result.setSize(buf.length);
return true;
}
};
case DB_RPC2ND_TRUNCDATA:
return new SecondaryKeyCreator() {
public boolean createSecondaryKey(SecondaryDatabase secondary,
DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
throws DatabaseException {
result.setData(data.getData());
result.setOffset(1);
result.setSize(data.getSize() - 1);
return true;
}
};
case DB_RPC2ND_CONSTANT:
return new SecondaryKeyCreator() {
public boolean createSecondaryKey(SecondaryDatabase secondary,
DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
throws DatabaseException {
byte[] buf = "constant data".getBytes();
result.setData(buf);
result.setSize(buf.length);
return true;
}
};
case DB_RPC2ND_GETZIP:
return new SecondaryKeyCreator() {
public boolean createSecondaryKey(SecondaryDatabase secondary,
DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
throws DatabaseException {
result.setData(data.getData());
result.setSize(5);
return true;
}
};
case DB_RPC2ND_GETNAME:
return new SecondaryKeyCreator() {
public boolean createSecondaryKey(SecondaryDatabase secondary,
DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
throws DatabaseException {
result.setData(data.getData());
result.setOffset(5);
result.setSize(data.getSize() - 5);
return true;
}
};
default:
Server.err.println("Warning: Java RPC server doesn't implement callback: " + (flags & DB_RPC2ND_MASK));
return null;
}
}
// Utility classes should not have a public or default constructor
protected AssociateCallbacks() {
}
}
|