KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > bind > RecordNumberBinding


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

8
9 package com.sleepycat.bind;
10
11 import com.sleepycat.compat.DbCompat;
12 import com.sleepycat.je.DatabaseEntry;
13
14 /**
15  * An <code>EntryBinding</code> that treats a record number key entry as a
16  * <code>Long</code> key object.
17  *
18  * <p>Record numbers are returned as <code>Long</code> objects, although on
19  * input any <code>Number</code> object may be used.</p>
20  *
21  * @author Mark Hayes
22  */

23 public class RecordNumberBinding implements EntryBinding {
24
25     /**
26      * Creates a byte array binding.
27      */

28     public RecordNumberBinding() {
29     }
30
31     // javadoc is inherited
32
public Object JavaDoc entryToObject(DatabaseEntry entry) {
33
34         return new Long JavaDoc(entryToRecordNumber(entry));
35     }
36
37     // javadoc is inherited
38
public void objectToEntry(Object JavaDoc object, DatabaseEntry entry) {
39
40         recordNumberToEntry(((Number JavaDoc) object).longValue(), entry);
41     }
42
43     /**
44      * Utility method for use by bindings to translate a entry buffer to an
45      * record number integer.
46      *
47      * @param entry the entry buffer.
48      *
49      * @return the record number.
50      */

51     public static long entryToRecordNumber(DatabaseEntry entry) {
52
53         return DbCompat.getRecordNumber(entry) & 0xFFFFFFFFL;
54     }
55
56     /**
57      * Utility method for use by bindings to translate a record number integer
58      * to a entry buffer.
59      *
60      * @param recordNumber the record number.
61      *
62      * @param entry the entry buffer to hold the record number.
63      */

64     public static void recordNumberToEntry(long recordNumber,
65                                            DatabaseEntry entry) {
66         entry.setData(new byte[4], 0, 4);
67         DbCompat.setRecordNumber(entry, (int) recordNumber);
68     }
69 }
70
Popular Tags