001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.internal.marshall;
022:
023: import com.db4o.*;
024: import com.db4o.internal.*;
025: import com.db4o.internal.slots.*;
026:
027: /**
028: * @exclude
029: */
030: class ObjectMarshaller0 extends ObjectMarshaller {
031:
032: public void addFieldIndices(final ClassMetadata yc,
033: ObjectHeaderAttributes attributes,
034: final StatefulBuffer writer, final Slot oldSlot) {
035: TraverseFieldCommand command = new TraverseFieldCommand() {
036: public void processField(FieldMetadata field,
037: boolean isNull, ClassMetadata containingClass) {
038: field.addFieldIndex(_family, yc, writer, oldSlot);
039: }
040: };
041: traverseFields(yc, writer, attributes, command);
042: }
043:
044: public TreeInt collectFieldIDs(TreeInt tree, ClassMetadata yc,
045: ObjectHeaderAttributes attributes,
046: final StatefulBuffer writer, final String name) {
047: final TreeInt[] ret = { tree };
048: TraverseFieldCommand command = new TraverseFieldCommand() {
049: public void processField(FieldMetadata field,
050: boolean isNull, ClassMetadata containingClass) {
051: if (name.equals(field.getName())) {
052: ret[0] = field.collectIDs(_family, ret[0], writer);
053: } else {
054: field.incrementOffset(writer);
055: }
056: }
057: };
058: traverseFields(yc, writer, attributes, command);
059: return ret[0];
060: }
061:
062: public void deleteMembers(ClassMetadata yc,
063: ObjectHeaderAttributes attributes,
064: final StatefulBuffer writer, int type,
065: final boolean isUpdate) {
066: TraverseFieldCommand command = new TraverseFieldCommand() {
067: public void processField(FieldMetadata field,
068: boolean isNull, ClassMetadata containingClass) {
069: field.delete(_family, writer, isUpdate);
070: }
071: };
072: traverseFields(yc, writer, attributes, command);
073: }
074:
075: public boolean findOffset(ClassMetadata yc,
076: FieldListInfo fieldListInfo, final Buffer buffer,
077: final FieldMetadata field) {
078: final boolean[] ret = { false };
079: TraverseFieldCommand command = new TraverseFieldCommand() {
080: public void processField(FieldMetadata curField,
081: boolean isNull, ClassMetadata containingClass) {
082: if (curField == field) {
083: ret[0] = true;
084: cancel();
085: return;
086: }
087: curField.incrementOffset(buffer);
088: }
089: };
090: traverseFields(yc, buffer, fieldListInfo, command);
091: return ret[0];
092: }
093:
094: protected final int headerLength() {
095: return Const4.OBJECT_LENGTH + Const4.ID_LENGTH;
096: }
097:
098: /**
099: * @param yf
100: * @param yo
101: */
102: protected int marshalledLength(FieldMetadata yf, ObjectReference yo) {
103: return 0;
104: }
105:
106: public ObjectHeaderAttributes readHeaderAttributes(Buffer reader) {
107: return null;
108: }
109:
110: public Object readIndexEntry(ClassMetadata clazz,
111: ObjectHeaderAttributes attributes, FieldMetadata field,
112: StatefulBuffer reader) throws FieldIndexException {
113: if (clazz == null) {
114: return null;
115: }
116:
117: if (!findOffset(clazz, attributes, reader, field)) {
118: return null;
119: }
120:
121: try {
122: return field.readIndexEntry(_family, reader);
123: } catch (CorruptionException exc) {
124: throw new FieldIndexException(exc, field);
125: }
126: }
127:
128: public void readVirtualAttributes(final Transaction trans,
129: ClassMetadata yc, final ObjectReference yo,
130: ObjectHeaderAttributes attributes, final Buffer reader) {
131: TraverseFieldCommand command = new TraverseFieldCommand() {
132: public void processField(FieldMetadata field,
133: boolean isNull, ClassMetadata containingClass) {
134: field.readVirtualAttribute(trans, reader, yo);
135: }
136: };
137: traverseFields(yc, reader, attributes, command);
138: }
139:
140: protected boolean isNull(FieldListInfo fieldList, int fieldIndex) {
141: return false;
142: }
143:
144: public void defragFields(ClassMetadata yapClass,
145: ObjectHeader header, BufferPair readers) {
146: }
147:
148: public void writeObjectClassID(Buffer reader, int id) {
149: reader.writeInt(id);
150: }
151:
152: public void skipMarshallerInfo(Buffer reader) {
153: }
154:
155: }
|