KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > log > entry > SingleItemLogEntry


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

8
9 package com.sleepycat.je.log.entry;
10
11 import java.nio.ByteBuffer JavaDoc;
12
13 import com.sleepycat.je.DatabaseException;
14 import com.sleepycat.je.log.LogReadable;
15
16 /**
17  * This class embodies log entries that have a single loggable item.
18  */

19 public class SingleItemLogEntry implements LogEntry {
20
21     private Class JavaDoc logClass;
22     LogReadable item;
23
24     public SingleItemLogEntry(Class JavaDoc logClass) {
25         this.logClass = logClass;
26     }
27
28     /**
29      * @see LogEntry#readEntry
30      */

31     public void readEntry(ByteBuffer JavaDoc entryBuffer,
32               int entrySize,
33                           byte entryTypeVersion,
34               boolean readFullItem)
35         throws DatabaseException {
36
37         try {
38             item = (LogReadable) logClass.newInstance();
39             item.readFromLog(entryBuffer, entryTypeVersion);
40         } catch (IllegalAccessException JavaDoc e) {
41             throw new DatabaseException(e);
42         } catch (InstantiationException JavaDoc e) {
43             throw new DatabaseException(e);
44         }
45     }
46
47     /**
48      * @see LogEntry#dumpEntry
49      */

50     public StringBuffer JavaDoc dumpEntry(StringBuffer JavaDoc sb, boolean verbose) {
51         item.dumpLog(sb, verbose);
52         return sb;
53     }
54
55     /**
56      * @see LogEntry#getMainItem
57      */

58     public Object JavaDoc getMainItem() {
59         return item;
60     }
61
62     /**
63      * @see LogEntry#clone
64      */

65     public Object JavaDoc clone()
66     throws CloneNotSupportedException JavaDoc {
67
68         return super.clone();
69     }
70
71     /**
72      * @see LogEntry#isTransactional
73      */

74     public boolean isTransactional() {
75     return item.logEntryIsTransactional();
76     }
77
78     /**
79      * @see LogEntry#getTransactionId
80      */

81     public long getTransactionId() {
82     return item.getTransactionId();
83     }
84
85     /**
86      * @return a new instance
87      */

88     public LogEntry getNewInstance()
89     throws DatabaseException {
90
91         try {
92             return (LogEntry) logClass.newInstance();
93         } catch (InstantiationException JavaDoc e){
94             throw new DatabaseException(e);
95         } catch (IllegalAccessException JavaDoc e){
96             throw new DatabaseException(e);
97         }
98     }
99 }
100
Popular Tags