001: /*
002: * ====================================================================
003: * JAFFA - Java Application Framework For All
004: *
005: * Copyright (C) 2002 JAFFA Development Group
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Redistribution and use of this software and associated documentation ("Software"),
022: * with or without modification, are permitted provided that the following conditions are met:
023: * 1. Redistributions of source code must retain copyright statements and notices.
024: * Redistributions must also contain a copy of this document.
025: * 2. Redistributions in binary form must reproduce the above copyright notice,
026: * this list of conditions and the following disclaimer in the documentation
027: * and/or other materials provided with the distribution.
028: * 3. The name "JAFFA" must not be used to endorse or promote products derived from
029: * this Software without prior written permission. For written permission,
030: * please contact mail to: jaffagroup@yahoo.com.
031: * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
032: * appear in their names without prior written permission.
033: * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
034: *
035: * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: */
049:
050: package org.jaffa.persistence.engines;
051:
052: import java.util.Collection;
053: import org.jaffa.persistence.Criteria;
054: import org.jaffa.persistence.IPersistent;
055: import org.jaffa.persistence.exceptions.*;
056:
057: /** The interface for a Persistence Engine.
058: */
059: public interface IPersistenceEngine {
060:
061: /** Generates an appropriate instance for the input persistentClass.
062: * If the persistentClass is a 'Class', then it should implement the 'IPersistent' interface. The persistence engine will simply instantiate the class.
063: * If the persistentClass is an 'Interface', then the persistence engine will generate a dynamic proxy, to implement the IPersistent and the 'persistentClass' interfaces.
064: * @param persistentClass The actual persistentClass which can represent a 'Class' or an 'Interface'
065: * @return an instance implementing the IPersistent interface.
066: */
067: public IPersistent newPersistentInstance(Class persistentClass);
068:
069: /** This is a helper method to determine the actual class which was used to create an IPersistent instance.
070: * It is quite possible that the input object is a dynamic proxy.
071: * @param object The object which implements the IPersistent instance.
072: * @return The class which was used for instantiating the instance.
073: */
074: public Class getActualPersistentClass(Object persistentObject);
075:
076: /**
077: * Adds an object to the persistent store.
078: * The persistence engine may choose to add the object(s) only on a <code>commit</code>.
079: * @param object The object to persist.
080: * @throws AddFailedException if any error occurs during the process.
081: */
082: public void add(IPersistent object) throws AddFailedException;
083:
084: /**
085: * Updates an object from the persistent store.
086: * The persistence engine may choose to update the object(s) only on a <code>commit</code>.
087: * @param object The object to update.
088: * @throws UpdateFailedException if any error occurs during the process.
089: */
090: public void update(IPersistent object) throws UpdateFailedException;
091:
092: /**
093: * Deletes an object from the persistent store.
094: * The persistence engine may choose to delete the object(s) only on a <code>commit</code>.
095: * @param object The object to delete from persistent storage.
096: * @throws DeleteFailedException if any error occurs during the process.
097: */
098: public void delete(IPersistent object) throws DeleteFailedException;
099:
100: /**
101: * Queries the underlying persistent store based on the search profile passed in the Criteria object.
102: * @param criteria search profile for the query.
103: * @return a Collection of persistent objects.
104: * @throws QueryFailedException if any error occurs during the process.
105: * @throws PostLoadFailedException if any error occurs during the invocation of the PostLoad trigger on the persistent object.
106: */
107: public Collection query(Criteria criteria)
108: throws QueryFailedException, PostLoadFailedException;
109:
110: /**
111: * Objects that have been added, objects that have been deleted,
112: * and objects that have been updated, will all be persisted via
113: * an invocation of this method.
114: * @throws AddFailedException if any error occurs during the addition of objects to the persistent store.
115: * @throws UpdateFailedException if any error occurs while updating the objects of the persistent store.
116: * @throws DeleteFailedException if any error occurs while deleting the objects of the persistent store.
117: * @throws CommitFailedException if any error occurs during the commit.
118: */
119: public void commit() throws AddFailedException,
120: UpdateFailedException, DeleteFailedException,
121: CommitFailedException;
122:
123: /**
124: * Rollbacks all the additions, deletions, updations.
125: * @throws RollbackFailedException if any error occurs during the process.
126: */
127: public void rollback() throws RollbackFailedException;
128:
129: /** Frees up the connection to the database. */
130: public void close();
131:
132: /**
133: * This will acquire a lock on the database row corrsponding to the input persistent object.
134: * @param object The persistent object to be locked.
135: * @throws AlreadyLockedObjectException if the database row has been locked by another process.
136: */
137: public void acquireLock(IPersistent object)
138: throws AlreadyLockedObjectException;
139: }
|