01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: ConverterReader.java,v 1.6.2.3 2008/01/07 15:14:19 cwl Exp $
07: */
08:
09: 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, int initVersion,
31: Format oldFormat) {
32: this .oldFormat = oldFormat;
33: }
34:
35: public Object newInstance(EntityInput input, boolean rawAccess) {
36: /* Create the old format RawObject. */
37: return oldFormat.newInstance(input, true);
38: }
39:
40: public void readPriKey(Object o, EntityInput input,
41: boolean rawAccess) {
42: /* Read the old format RawObject's primary key. */
43: oldFormat.readPriKey(o, input, true);
44: }
45:
46: public Object readObject(Object o, EntityInput input,
47: boolean rawAccess) {
48: Catalog catalog = input.getCatalog();
49:
50: /* Read the old format RawObject and convert it. */
51: o = oldFormat.readObject(o, input, true);
52: o = converter.getConversion().convert(o);
53:
54: /* Convert the current format RawObject to a live Object. */
55: if (!rawAccess && o instanceof RawObject) {
56: o = catalog.convertRawObject((RawObject) o, null);
57: }
58: return o;
59: }
60: }
|