KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > inside > marshall > ArrayMarshaller0


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.inside.marshall;
22
23 import com.db4o.*;
24
25
26 class ArrayMarshaller0 extends ArrayMarshaller{
27     
28     public void deleteEmbedded(YapArray arrayHandler, YapWriter reader) {
29         int address = reader.readInt();
30         int length = reader.readInt();
31         if (address <= 0) {
32             return;
33         }
34         Transaction trans = reader.getTransaction();
35         if (reader.cascadeDeletes() > 0 && arrayHandler.i_handler instanceof YapClass) {
36             YapWriter bytes =
37                 reader.getStream().readWriterByAddress(
38                     trans,
39                     address,
40                     length);
41             if (bytes != null) {
42                 if (Deploy.debug) {
43                     bytes.readBegin(arrayHandler.identifier());
44                 }
45                 bytes.setCascadeDeletes(reader.cascadeDeletes());
46                 for (int i = arrayHandler.elementCount(trans, bytes); i > 0; i--) {
47                     arrayHandler.i_handler.deleteEmbedded(_family, bytes);
48                 }
49             }
50         }
51         trans.slotFreeOnCommit(address, address, length);
52     }
53     
54     public void calculateLengths(Transaction trans, ObjectHeaderAttributes header, YapArray handler, Object JavaDoc obj, boolean topLevel){
55         // do nothing
56
}
57     
58     public Object JavaDoc writeNew(YapArray arrayHandler, Object JavaDoc a_object, boolean topLevel, YapWriter a_bytes) {
59         if (a_object == null) {
60             a_bytes.writeEmbeddedNull();
61             return null;
62         }
63         int length = arrayHandler.objectLength(a_object);
64         YapWriter bytes = new YapWriter(a_bytes.getTransaction(), length);
65         bytes.setUpdateDepth(a_bytes.getUpdateDepth());
66         arrayHandler.writeNew1(a_object, bytes);
67         bytes.setID(a_bytes._offset);
68         a_bytes.getStream().writeEmbedded(a_bytes, bytes);
69         a_bytes.incrementOffset(YapConst.ID_LENGTH);
70         a_bytes.writeInt(length);
71         return a_object;
72     }
73     
74     public Object JavaDoc read(YapArray arrayHandler, YapWriter a_bytes) throws CorruptionException{
75         YapWriter bytes = a_bytes.readEmbeddedObject();
76         if (bytes == null) {
77             return null;
78         }
79         return arrayHandler.read1(_family, bytes);
80     }
81     
82     public void readCandidates(YapArray arrayHandler, YapReader reader, QCandidates candidates) {
83         YapReader bytes = reader.readEmbeddedObject(candidates.i_trans);
84         if (bytes == null) {
85             return;
86         }
87         if(Deploy.debug){
88             bytes.readBegin(arrayHandler.identifier());
89         }
90         int count = arrayHandler.elementCount(candidates.i_trans, bytes);
91         for (int i = 0; i < count; i++) {
92             candidates.addByIdentity(new QCandidate(candidates, null, bytes.readInt(), true));
93         }
94     }
95
96     
97     public final Object JavaDoc readQuery(YapArray arrayHandler, Transaction trans, YapReader reader) throws CorruptionException{
98         YapReader bytes = reader.readEmbeddedObject(trans);
99         if (bytes == null) {
100             return null;
101         }
102         Object JavaDoc array = arrayHandler.read1Query(trans,_family, bytes);
103         return array;
104     }
105     
106     protected YapReader prepareIDReader(Transaction trans,YapReader reader) {
107         return reader.readEmbeddedObject(trans);
108     }
109     
110     public void defragIDs(YapArray arrayHandler,ReaderPair readers) {
111     }
112 }
113
Popular Tags