KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > persist > impl > ConverterReader


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

8
9 package com.sleepycat.persist.impl;
10
11 import com.sleepycat.persist.evolve.Converter;
12 import com.sleepycat.persist.raw.RawObject;
13
14 /**
15  * Reader for invoking a class Converter mutation.
16  *
17  * @author Mark Hayes
18  */

19 public class ConverterReader implements Reader {
20
21     private static final long serialVersionUID = -305788321064984348L;
22
23     private Converter converter;
24     private transient Format oldFormat;
25
26     ConverterReader(Converter converter) {
27         this.converter = converter;
28     }
29
30     public void initializeReader(Catalog catalog, Format oldFormat) {
31         this.oldFormat = oldFormat;
32     }
33
34     public Object JavaDoc newInstance(EntityInput input, boolean rawAccess) {
35         /* Create the old format RawObject. */
36         return oldFormat.newInstance(input, true);
37     }
38
39     public void readPriKey(Object JavaDoc o, EntityInput input, boolean rawAccess) {
40         /* Read the old format RawObject's primary key. */
41         oldFormat.readPriKey(o, input, true);
42     }
43
44     public Object JavaDoc readObject(Object JavaDoc o, EntityInput input, boolean rawAccess) {
45         Catalog catalog = input.getCatalog();
46
47         /* Read the old format RawObject and convert it. */
48         o = oldFormat.readObject(o, input, true);
49         o = converter.getConversion().convert(o);
50
51         /* Convert the current format RawObject to a live Object. */
52         if (!rawAccess && o instanceof RawObject) {
53             o = catalog.convertRawObject((RawObject) o, null);
54         }
55         return o;
56     }
57 }
58
Popular Tags