1 /* 2 * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved. 3 * 4 * Project: OpenSubsystems 5 * 6 * $Id: DataFactory.java,v 1.8 2007/01/28 06:54:51 bastafidli Exp $ 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; version 2 of the License. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 22 package org.opensubsystems.core.persist; 23 24 import org.opensubsystems.core.data.DataObject; 25 import org.opensubsystems.core.error.OSSException; 26 27 /** 28 * Base interface for all data factories responsible for loading and persisting 29 * data. Data factory is here to implement Data Access Object pattern as described 30 * in http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html 31 * or more generically the Abstract Factory pattern as described in 32 * http://homepage.mac.com/loeffler/java/patterns/absfac.html by GoF95 33 * http://homepage.mac.com/loeffler/java/patterns.html. 34 * It's main purpose is to persist, retrieve and change the persisted data objects 35 * in the underlying persistence store without exposing any persistence store 36 * dependent information to the rest of the application. 37 * 38 * This interface doesn't dictate implementation therefore it is possible 39 * to have FileDataFactory, DatabaseDataFactory, etc. 40 * 41 * @version $Id: DataFactory.java,v 1.8 2007/01/28 06:54:51 bastafidli Exp $ 42 * @author Miro Halas 43 * @code.reviewer Miro Halas 44 * @code.reviewed 1.5 2005/03/26 03:49:48 bastafidli 45 */ 46 public interface DataFactory 47 { 48 /** 49 * Get data type code for DataObject derived class managed by the data factory 50 * which implements this interface. 51 * 52 * @return int - unique data type code 53 */ 54 int getDataType( 55 ); 56 57 /** 58 * Get specific data object identified by its id from the persistence store. 59 * 60 * Every data factory has to support this method otherwise we wouldn't have 61 * any way hot to load and test existence of the data. 62 * 63 * @param iId - id of the data object to get, if the id is NEW_ID a new data 64 * object initialized to default values 65 * @param iDomainId - if the data object exists in a domain then by specifying 66 * the domain id it allows the persistance store to limit 67 * the data that will be searched and also possibly 68 * enforce in what domain the id can possibly exist. This 69 * allows to enforce security on the persistance layer 70 * that by ensuring that if the data object doesn't exist 71 * in the domain where it is expected to exist, it will 72 * not be even retrieved. If the data object doesnt exist 73 * in the domain, you can pass DataObject.NEW_ID here 74 * since it won't be used. 75 * @return DataObject - specified data object or null if it couldn't be 76 * retrieved 77 * @throws OSSException - an error while getting data 78 */ 79 DataObject get( 80 int iId, 81 int iDomainId 82 ) throws OSSException; 83 } 84