001/*
002 * #%L
003 * Netarchivesuite - harvester
004 * %%
005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library,
006 *             the National Library of France and the Austrian National Library.
007 * %%
008 * This program is free software: you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation, either version 2.1 of the
011 * License, or (at your option) any later version.
012 * 
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Lesser Public License for more details.
017 * 
018 * You should have received a copy of the GNU General Lesser Public
019 * License along with this program.  If not, see
020 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
021 * #L%
022 */
023package dk.netarkivet.harvester.datamodel.extendedfield;
024
025/**
026 * Interface for creating and accessing extended fields in persistent storage.
027 */
028public abstract class ExtendedFieldValueDAO {
029
030    /** The one and only instance of this DAO. */
031    protected static ExtendedFieldValueDAO instance;
032
033    /**
034     * constructor used when creating singleton. Do not call directly.
035     */
036    protected ExtendedFieldValueDAO() {
037    }
038
039    /**
040     * Reset the DAO instance. Only for use from within tests.
041     */
042    public static void reset() {
043        instance = null;
044    }
045
046    /**
047     * Find out if there exists in persistent storage a ExtendedFieldValue with the given id.
048     *
049     * @param aExtendedFieldValueID An id associated with a ExtendedFieldValue
050     * @return true, if there already exists in persistent storage a ExtendedFieldValue with the given id.
051     */
052    public abstract boolean exists(Long aExtendedFieldValueID);
053
054    /**
055     * Create a ExtendedFieldValue in persistent storage.
056     *
057     * @param aExtendedFieldValue The ExtendedFieldValue to create in persistent storage.
058     */
059    public abstract void create(ExtendedFieldValue aExtendedFieldValue);
060
061    /**
062     * Read the ExtendedFieldValue with the given extendedFieldID.
063     *
064     * @param aExtendedFieldID A given ID for a ExtendedFieldValue
065     * @param aInstanceID A given instanceID
066     * @return the ExtendedFieldValue with the given extendedFieldID.
067     */
068    public abstract ExtendedFieldValue read(Long aExtendedFieldID, Long aInstanceID);
069
070    /**
071     * Update a ExtendedFieldValue in persistent storage.
072     *
073     * @param aExtendedFieldValue The ExtendedFieldValue to update
074     */
075    public abstract void update(ExtendedFieldValue aExtendedFieldValue);
076
077    /**
078     * Delete a ExtendedFieldValue in persistent storage.
079     *
080     * @param aExtendedfieldValueID The ID for a extendedFieldValue to delete
081     */
082    public abstract void delete(long aExtendedfieldValueID);
083
084    /**
085     * @return the singleton instance of the ExtendedFieldVAlueDAO
086     */
087    public static synchronized ExtendedFieldValueDAO getInstance() {
088        if (instance == null) {
089            instance = new ExtendedFieldValueDBDAO();
090        }
091        return instance;
092    }
093
094}