01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.internal;
22:
23: import com.db4o.config.*;
24: import com.db4o.internal.marshall.*;
25:
26: final class TranslatedFieldMetadata extends FieldMetadata {
27: private final ObjectTranslator i_translator;
28:
29: TranslatedFieldMetadata(ClassMetadata containingClass,
30: ObjectTranslator translator) {
31: super (containingClass, translator);
32: i_translator = translator;
33: ObjectContainerBase stream = containingClass.container();
34: configure(stream.reflector().forClass(
35: translatorStoredClass(translator)), false);
36: }
37:
38: public boolean canUseNullBitmap() {
39: return false;
40: }
41:
42: void deactivate(Transaction trans, Object onObject, int depth) {
43: if (depth > 0) {
44: cascadeActivation(trans, onObject, depth, false);
45: }
46: setOn(trans, onObject, null);
47: }
48:
49: public Object getOn(Transaction a_trans, Object a_OnObject) {
50: try {
51: return i_translator.onStore(a_trans.objectContainer(),
52: a_OnObject);
53: } catch (ReflectException e) {
54: throw e;
55: } catch (RuntimeException e) {
56: throw new ReflectException(e);
57: }
58: }
59:
60: public Object getOrCreate(Transaction a_trans, Object a_OnObject) {
61: return getOn(a_trans, a_OnObject);
62: }
63:
64: public void instantiate(UnmarshallingContext context) {
65:
66: Object obj = read(context);
67:
68: // Activation of members is necessary on purpose here.
69: // Classes like Hashtable need fully activated members
70: // to be able to calculate hashCode()
71:
72: context.container().activate(context.transaction(), obj,
73: context.activationDepth());
74:
75: setOn(context.transaction(), context.persistentObject(), obj);
76: }
77:
78: void refresh() {
79: // do nothing
80: }
81:
82: private void setOn(Transaction trans, Object a_onObject,
83: Object toSet) {
84: try {
85: i_translator.onActivate(trans.objectContainer(),
86: a_onObject, toSet);
87: } catch (RuntimeException e) {
88: throw new ReflectException(e);
89: }
90: }
91:
92: protected Object indexEntryFor(Object indexEntry) {
93: return indexEntry;
94: }
95:
96: protected Indexable4 indexHandler(ObjectContainerBase stream) {
97: return (Indexable4) _handler;
98: }
99: }
|