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

com.sleepycat.bind.serial.TupleSerialMarshalledBinding 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.tuple.MarshalledTupleKeyEntity;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

/**
 * A concrete TupleSerialBinding that delegates to the
 * MarshalledTupleKeyEntity interface of the entity class.
 *
 * 

The {@link MarshalledTupleKeyEntity} interface must be implemented by the * entity class to convert between the key/data entry and entity object.

* *

The binding is "tricky" in that it uses the entity class for both the * stored data entry and the combined entity object. To do this, the entity's * key field(s) are transient and are set by the binding after the data object * has been deserialized. This avoids the use of a "data" class completely. *

* * @see MarshalledTupleKeyEntity * @see Class Evolution * * @author Mark Hayes */ public class TupleSerialMarshalledBinding extends TupleSerialBinding { /** * Creates a tuple-serial marshalled binding object. * * @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 for serialized objects stored using * this binding -- all objects using this binding must be an instance of * this class. */ public TupleSerialMarshalledBinding(ClassCatalog classCatalog, Class baseClass) { this(new SerialBinding(classCatalog, baseClass)); } /** * Creates a tuple-serial marshalled binding object. * * @param dataBinding is the binding used for serializing and deserializing * the entity object. */ public TupleSerialMarshalledBinding(SerialBinding dataBinding) { super(dataBinding); } // javadoc is inherited public E entryToObject(TupleInput tupleInput, E javaInput) { /* * Creates the entity by combining the stored key and data. * This "tricky" binding returns the stored data as the entity, but * first it sets the transient key fields from the stored key. */ if (tupleInput != null) { // may be null if not used by key extractor javaInput.unmarshalPrimaryKey(tupleInput); } return javaInput; } // javadoc is inherited public void objectToKey(E object, TupleOutput output) { /* Creates the stored key from the entity. */ object.marshalPrimaryKey(output); } // javadoc is inherited public E objectToData(E object) { /* * Returns the entity as the stored data. There is nothing to do here * since the entity's key fields are transient. */ return object; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy