KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > collections > test > TestKeyAssigner


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: TestKeyAssigner.java,v 1.20 2006/10/30 21:14:39 bostic Exp $
7  */

8
9 package com.sleepycat.collections.test;
10
11 import com.sleepycat.bind.RecordNumberBinding;
12 import com.sleepycat.collections.PrimaryKeyAssigner;
13 import com.sleepycat.je.DatabaseEntry;
14 import com.sleepycat.je.DatabaseException;
15
16 /**
17  * @author Mark Hayes
18  */

19 class TestKeyAssigner implements PrimaryKeyAssigner {
20
21     private byte next = 1;
22     private boolean isRecNum;
23
24     TestKeyAssigner(boolean isRecNum) {
25
26         this.isRecNum = isRecNum;
27     }
28
29     public void assignKey(DatabaseEntry keyData)
30         throws DatabaseException {
31
32         if (isRecNum) {
33             RecordNumberBinding.recordNumberToEntry(next, keyData);
34         } else {
35             keyData.setData(new byte[] { next }, 0, 1);
36         }
37         next += 1;
38     }
39
40     void reset() {
41
42         next = 1;
43     }
44 }
45
Popular Tags