All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sleepycat.bind.serial.TupleSerialBinding Maven / Gradle / Ivy

The newest version!
/*-
 * Copyright (C) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
 *
 * This file was distributed by Oracle as part of a version of Oracle Berkeley
 * DB Java Edition made available at:
 *
 * http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index.html
 *
 * Please see the LICENSE file included in the top-level directory of the
 * appropriate version of Oracle Berkeley DB Java Edition for a copy of the
 * license and additional information.
 */

package com.sleepycat.bind.serial;

import com.sleepycat.bind.EntityBinding;
import com.sleepycat.bind.tuple.TupleBase;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;
import com.sleepycat.je.DatabaseEntry;

/**
 * An abstract EntityBinding that treats an entity's key entry as
 * a tuple and its data entry as a serialized object.
 *
 * 

This class takes care of serializing and deserializing the data entry, * and converting the key entry to/from {@link TupleInput} and {@link * TupleOutput} objects. Its three abstract methods must be implemented by a * concrete subclass to convert these objects to/from an entity object.

*
    *
  • {@link #entryToObject(TupleInput,Object)}
  • *
  • {@link #objectToKey(Object,TupleOutput)}
  • *
  • {@link #objectToData(Object)}
  • *
* * @see Class Evolution * * @author Mark Hayes */ public abstract class TupleSerialBinding extends TupleBase implements EntityBinding { protected SerialBinding dataBinding; /** * Creates a tuple-serial entity binding. * * @param classCatalog is the catalog to hold shared class information and * for a database should be a {@link StoredClassCatalog}. * * @param baseClass is the base class. */ public TupleSerialBinding(ClassCatalog classCatalog, Class baseClass) { this(new SerialBinding(classCatalog, baseClass)); } /** * Creates a tuple-serial entity binding. * * @param dataBinding is the data binding. */ public TupleSerialBinding(SerialBinding dataBinding) { this.dataBinding = dataBinding; } // javadoc is inherited public E entryToObject(DatabaseEntry key, DatabaseEntry data) { return entryToObject(entryToInput(key), dataBinding.entryToObject(data)); } // javadoc is inherited public void objectToKey(E object, DatabaseEntry key) { TupleOutput output = getTupleOutput(object); objectToKey(object, output); outputToEntry(output, key); } // javadoc is inherited public void objectToData(E object, DatabaseEntry data) { D dataObject = objectToData(object); dataBinding.objectToEntry(dataObject, data); } /** * Constructs an entity object from {@link TupleInput} key entry and * deserialized data entry objects. * * @param keyInput is the {@link TupleInput} key entry object. * * @param dataInput is the deserialized data entry object. * * @return the entity object constructed from the key and data. */ public abstract E entryToObject(TupleInput keyInput, D dataInput); /** * Extracts a key tuple from an entity object. * * @param object is the entity object. * * @param keyOutput is the {@link TupleOutput} to which the key should be * written. */ public abstract void objectToKey(E object, TupleOutput keyOutput); /** * Extracts a data object from an entity object. * * @param object is the entity object. * * @return the deserialized data object. */ public abstract D objectToData(E object); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy