001: /*
002: * Copyright 2004 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: GenericFieldManager.java,v 1.1 2004/01/18 03:01:05 jackknifebarber Exp $
009: */
010:
011: package com.triactive.jdo;
012:
013: import com.triactive.jdo.FieldManager;
014:
015: /**
016: * An abstract base class for a field manager that deals with all fields as
017: * generic Objects.
018: * All the type-specific field manager methods (for primitives and Strings) are
019: * funneled to fetchObjectField() and storeObjectField() and primitive values
020: * are boxed/unboxed as needed.
021: *
022: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
023: * @version $Revision: 1.1 $
024: */
025:
026: public abstract class GenericFieldManager implements FieldManager {
027: public void storeBooleanField(int field, boolean value) {
028: storeObjectField(field, new Boolean(value));
029: }
030:
031: public boolean fetchBooleanField(int field) {
032: Boolean value = (Boolean) fetchObjectField(field);
033: return value == null ? false : value.booleanValue();
034: }
035:
036: public void storeCharField(int field, char value) {
037: storeObjectField(field, new Character(value));
038: }
039:
040: public char fetchCharField(int field) {
041: Character value = (Character) fetchObjectField(field);
042: return value == null ? '\000' : value.charValue();
043: }
044:
045: public void storeByteField(int field, byte value) {
046: storeObjectField(field, new Byte(value));
047: }
048:
049: public byte fetchByteField(int field) {
050: Number value = (Number) fetchObjectField(field);
051: return value == null ? 0 : value.byteValue();
052: }
053:
054: public void storeShortField(int field, short value) {
055: storeObjectField(field, new Short(value));
056: }
057:
058: public short fetchShortField(int field) {
059: Number value = (Number) fetchObjectField(field);
060: return value == null ? 0 : value.shortValue();
061: }
062:
063: public void storeIntField(int field, int value) {
064: storeObjectField(field, new Integer(value));
065: }
066:
067: public int fetchIntField(int field) {
068: Number value = (Number) fetchObjectField(field);
069: return value == null ? 0 : value.intValue();
070: }
071:
072: public void storeLongField(int field, long value) {
073: storeObjectField(field, new Long(value));
074: }
075:
076: public long fetchLongField(int field) {
077: Number value = (Number) fetchObjectField(field);
078: return value == null ? 0 : value.longValue();
079: }
080:
081: public void storeFloatField(int field, float value) {
082: storeObjectField(field, new Float(value));
083: }
084:
085: public float fetchFloatField(int field) {
086: Number value = (Number) fetchObjectField(field);
087: return value == null ? 0 : value.floatValue();
088: }
089:
090: public void storeDoubleField(int field, double value) {
091: storeObjectField(field, new Double(value));
092: }
093:
094: public double fetchDoubleField(int field) {
095: Number value = (Number) fetchObjectField(field);
096: return value == null ? 0 : value.doubleValue();
097: }
098:
099: public void storeStringField(int field, String value) {
100: storeObjectField(field, value);
101: }
102:
103: public String fetchStringField(int field) {
104: return (String) fetchObjectField(field);
105: }
106:
107: public abstract void storeObjectField(int field, Object value);
108:
109: public abstract Object fetchObjectField(int field);
110: }
|