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

com.sleepycat.bind.serial.SerialSerialBinding 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.je.DatabaseEntry;

/**
 * An abstract EntityBinding that treats an entity's key entry and
 * data entry as serialized objects.
 *
 * 

This class takes care of serializing and deserializing the key and * data entry automatically. Its three abstract methods must be implemented by * a concrete subclass to convert the deserialized objects to/from an entity * object.

*
    *
  • {@link #entryToObject(Object,Object)}
  • *
  • {@link #objectToKey(Object)}
  • *
  • {@link #objectToData(Object)}
  • *
* * @see Class Evolution * * @author Mark Hayes */ public abstract class SerialSerialBinding implements EntityBinding { private SerialBinding keyBinding; private SerialBinding dataBinding; /** * Creates a serial-serial entity binding. * * @param classCatalog is the catalog to hold shared class information and * for a database should be a {@link StoredClassCatalog}. * * @param keyClass is the key base class. * * @param dataClass is the data base class. */ public SerialSerialBinding(ClassCatalog classCatalog, Class keyClass, Class dataClass) { this(new SerialBinding(classCatalog, keyClass), new SerialBinding(classCatalog, dataClass)); } /** * Creates a serial-serial entity binding. * * @param keyBinding is the key binding. * * @param dataBinding is the data binding. */ public SerialSerialBinding(SerialBinding keyBinding, SerialBinding dataBinding) { this.keyBinding = keyBinding; this.dataBinding = dataBinding; } // javadoc is inherited public E entryToObject(DatabaseEntry key, DatabaseEntry data) { return entryToObject(keyBinding.entryToObject(key), dataBinding.entryToObject(data)); } // javadoc is inherited public void objectToKey(E object, DatabaseEntry key) { K keyObject = objectToKey(object); keyBinding.objectToEntry(keyObject, key); } // javadoc is inherited public void objectToData(E object, DatabaseEntry data) { D dataObject = objectToData(object); dataBinding.objectToEntry(dataObject, data); } /** * Constructs an entity object from deserialized key and data objects. * * @param keyInput is the deserialized key object. * * @param dataInput is the deserialized data object. * * @return the entity object constructed from the key and data. */ public abstract E entryToObject(K keyInput, D dataInput); /** * Extracts a key object from an entity object. * * @param object is the entity object. * * @return the deserialized key object. */ public abstract K objectToKey(E object); /** * 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