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 025import java.util.List; 026 027import dk.netarkivet.common.exceptions.ArgumentNotValid; 028import dk.netarkivet.common.exceptions.IOFailure; 029import dk.netarkivet.common.exceptions.UnknownID; 030import dk.netarkivet.harvester.datamodel.DAO; 031 032/** 033 * Interface for creating and accessing extended fields in persistent storage. 034 */ 035public abstract class ExtendedFieldDAO implements DAO { 036 037 /** The database singleton model. */ 038 protected static ExtendedFieldDAO instance; 039 040 /** 041 * constructor used when creating singleton. Do not call directly. 042 */ 043 protected ExtendedFieldDAO() { 044 } 045 046 /** 047 * Reset the DAO instance. Only for use from within tests. 048 */ 049 public static void reset() { 050 instance = null; 051 } 052 053 /** 054 * Check if an extendedfield exists for a given ID. 055 * 056 * @param aExtendedfieldId a given ID. 057 * @return true, if an extendedfield exists for the given ID 058 */ 059 public abstract boolean exists(Long aExtendedfieldId); 060 061 /** 062 * Creates an instance in persistent storage of the given extended Field. 063 * 064 * @param aExtendedField a ExtendedField to create in persistent storage. 065 */ 066 public abstract void create(ExtendedField aExtendedField); 067 068 /** 069 * Reads an ExtendedField from persistent storage. 070 * 071 * @param aExtendedFieldID The ID of the ExtendedField to read 072 * @return a ExtendedField instance 073 * @throws ArgumentNotValid If failed to create ExtendedField instance in case aExtendedFieldID is invalid 074 * @throws UnknownID If the job with the given jobID does not exist in persistent storage. 075 * @throws IOFailure If the loaded ID of ExtendedField does not match the expected. 076 */ 077 public abstract ExtendedField read(Long aExtendedFieldID) throws ArgumentNotValid, UnknownID, IOFailure; 078 079 /** 080 * Update a ExtendedField in persistent storage. 081 * 082 * @param aExtendedField The ExtendedField to update 083 * @throws IOFailure If writing the ExtendedField to persistent storage fails 084 */ 085 public abstract void update(ExtendedField aExtendedField) throws IOFailure; 086 087 /** 088 * Return a list of all ExtendedFields of the given Extended Field Type. 089 * 090 * @param aExtendedFieldTypeId extended field type. 091 * @return A list of all ExtendedFields with given Extended Field Type 092 */ 093 public abstract List<ExtendedField> getAll(long aExtendedFieldTypeId); 094 095 /** 096 * deletes an ExtendedField from persistent storage. The implementation of this method must also delete all 097 * belonging extended field values. 098 * 099 * @param aExtendedFieldID The ID of the ExtendedField to read 100 * @throws IOFailure If deleting the ExtendedField fails 101 */ 102 public abstract void delete(long aExtendedFieldID) throws IOFailure; 103 104 /** 105 * @return an instance of this class. 106 */ 107 public static synchronized ExtendedFieldDAO getInstance() { 108 if (instance == null) { 109 instance = new ExtendedFieldDBDAO(); 110 } 111 return instance; 112 } 113 114}