KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > YapFieldVirtual


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 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;
22
23 import com.db4o.foundation.*;
24 import com.db4o.inside.marshall.*;
25 import com.db4o.inside.replication.*;
26 import com.db4o.inside.slots.*;
27
28 /**
29  * @exclude
30  */

31 public abstract class YapFieldVirtual extends YapField {
32
33     YapFieldVirtual() {
34         super(null);
35     }
36     
37     public abstract void addFieldIndex(MarshallerFamily mf, YapClass yapClass, YapWriter a_writer, Slot oldSlot);
38     
39     public boolean alive() {
40         return true;
41     }
42     
43     public void calculateLengths(Transaction trans, ObjectHeaderAttributes header, Object JavaDoc obj){
44         header.addBaseLength(linkLength());
45     }
46     
47     boolean canAddToQuery(String JavaDoc fieldName){
48         return fieldName.equals(getName());
49     }
50     
51     public boolean canUseNullBitmap(){
52         return false;
53     }
54     
55     void collectConstraints(Transaction a_trans, QConObject a_parent,
56         Object JavaDoc a_template, Visitor4 a_visitor) {
57         
58         // QBE constraint collection call
59
// There isn't anything useful to do here, since virtual fields
60
// are not on the actual object.
61

62     }
63     
64     void deactivate(Transaction a_trans, Object JavaDoc a_onObject, int a_depth) {
65         // do nothing
66
}
67     
68     public abstract void delete(MarshallerFamily mf, YapWriter a_bytes, boolean isUpdate);
69     
70     public Object JavaDoc getOrCreate(Transaction a_trans, Object JavaDoc a_OnObject) {
71         // This is the first part of marshalling
72
// Virtual fields do it all in #marshall() so it's fine to return null here
73
return null;
74     }
75     
76     public boolean needsArrayAndPrimitiveInfo(){
77         return false;
78     }
79
80     public boolean needsHandlerId(){
81         return false;
82     }
83
84     public void instantiate(MarshallerFamily mf, YapObject a_yapObject, Object JavaDoc a_onObject, YapWriter a_bytes)
85         throws CorruptionException {
86         a_yapObject.produceVirtualAttributes();
87         instantiate1(a_bytes.getTransaction(), a_yapObject, a_bytes);
88     }
89
90     abstract void instantiate1(Transaction a_trans, YapObject a_yapObject, YapReader a_bytes);
91     
92     public void loadHandler(YapStream a_stream){
93         // do nothing
94
}
95
96     public final void marshall(
97             YapObject a_yapObject,
98             Object JavaDoc a_object,
99             MarshallerFamily mf,
100             YapWriter a_bytes,
101             Config4Class a_config,
102             boolean a_new) {
103         
104         Transaction trans = a_bytes.i_trans;
105         
106         if(! trans.supportsVirtualFields()){
107             marshallIgnore(a_bytes);
108             return;
109         }
110         
111         YapStream stream = trans.stream();
112         YapHandlers handlers = stream.i_handlers;
113         boolean migrating = false;
114         
115         
116         if (stream._replicationCallState != YapConst.NONE) {
117             if (stream._replicationCallState == YapConst.OLD) {
118                 
119                 // old replication code
120

121                 migrating = true;
122                 if (a_yapObject.virtualAttributes() == null) {
123                     Object JavaDoc obj = a_yapObject.getObject();
124                     YapObject migrateYapObject = null;
125                     MigrationConnection mgc = handlers.i_migration;
126                     if(mgc != null){
127                         migrateYapObject = mgc.referenceFor(obj);
128                         if(migrateYapObject == null){
129                             migrateYapObject = mgc.peer(stream).getYapObject(obj);
130                         }
131                     }
132                     if (migrateYapObject != null){
133                         VirtualAttributes migrateAttributes = migrateYapObject.virtualAttributes();
134                         if(migrateAttributes != null && migrateAttributes.i_database != null){
135                             migrating = true;
136                             a_yapObject.setVirtualAttributes((VirtualAttributes)migrateAttributes.shallowClone());
137                             migrateAttributes.i_database.bind(trans);
138                         }
139                     }
140                 }
141             }else {
142                 
143                 // new dRS replication
144

145                 Db4oReplicationReferenceProvider provider = handlers._replicationReferenceProvider;
146                 Object JavaDoc parentObject = a_yapObject.getObject();
147                 Db4oReplicationReference ref = provider.referenceFor(parentObject);
148                 if(ref != null){
149                     migrating = true;
150                     VirtualAttributes va = a_yapObject.produceVirtualAttributes();
151                     va.i_version = ref.version();
152                     va.i_uuid = ref.longPart();
153                     va.i_database = ref.signaturePart();
154                 }
155             }
156         }
157         
158         if (a_yapObject.virtualAttributes() == null) {
159             a_yapObject.produceVirtualAttributes();
160             migrating = false;
161         }
162         marshall1(a_yapObject, a_bytes, migrating, a_new);
163     }
164
165     abstract void marshall1(YapObject a_yapObject, YapWriter a_bytes,
166         boolean a_migrating, boolean a_new);
167     
168     abstract void marshallIgnore(YapReader writer);
169     
170     public void readVirtualAttribute(Transaction a_trans, YapReader a_reader, YapObject a_yapObject) {
171         if(! a_trans.supportsVirtualFields()){
172             a_reader.incrementOffset(linkLength());
173             return;
174         }
175         instantiate1(a_trans, a_yapObject, a_reader);
176     }
177     
178     public boolean isVirtual() {
179         return true;
180     }
181
182 }
Popular Tags