001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.persistency;
010:
011: import com.completex.objective.components.ocache.OdalCache;
012: import com.completex.objective.components.ocache.OdalKeyFactory;
013:
014: import java.util.Collection;
015:
016: /**
017: * Life cycle callback
018: *
019: * @author Gennady Krizhevsky
020: */
021: public interface LifeCycleController {
022: public static final NullLifeCycleController NULL_LIFE_CYCLE_CONTROLLER = new NullLifeCycleController();
023:
024: /**
025: * Called after persistentObject Select. This call corresponds to record level
026: * select as opposed to <t>afterCompositeSelect</t> method that is called
027: * after parent record with all the subtrees si retrieved.
028: *
029: * @param persistentObject PersistentObject retrieved
030: */
031: void afterSelect(AbstractPersistentObject persistentObject);
032:
033: /**
034: * Called before persistentObject insert. This call corresponds to record level
035: * insert as opposed to <t>beforeCompositeInsert</t> method which is called before
036: * any of the <t>beforeInsert</t> ones.
037: *
038: * @param persistentObject PersistentObject being inserted
039: */
040: void beforeInsert(PersistentObject persistentObject);
041:
042: /**
043: * Called after persistentObject insert
044: *
045: * @param persistentObject PersistentObject being inserted
046: */
047: void afterInsert(PersistentObject persistentObject);
048:
049: /**
050: * Called before persistentObject update
051: *
052: * @param persistentObject PersistentObject being updated
053: */
054: void beforeUpdate(PersistentObject persistentObject);
055:
056: /**
057: * Called after persistentObject update
058: *
059: * @param persistentObject PersistentObject being updated
060: */
061: void afterUpdate(PersistentObject persistentObject);
062:
063: /**
064: * Called before persistentObject delete
065: *
066: * @param persistentObject PersistentObject being deleted
067: */
068: void beforeDelete(PersistentObject persistentObject);
069:
070: /**
071: * Called after persistentObject delete
072: *
073: * @param persistentObject PersistentObject being deleted
074: */
075: void afterDelete(PersistentObject persistentObject);
076:
077: /**
078: * Concrete interpretation is up to specific persistency implementation
079: *
080: * @return Object[] parameters
081: */
082: Object[] getParameters();
083:
084: /**
085: * Concrete interpretation is up to specific persistency implementation
086: *
087: * @param parameters Object[] parameters
088: */
089: void setParameters(Object[] parameters);
090:
091: /**
092: * Factory method. Creates new LifeCycleController instance that may have some
093: * attributes inherited from this one.
094: *
095: * @return new LifeCycleController instance
096: */
097: LifeCycleController newLifeCycleInstance();
098:
099: /**
100: * Cache name is used by Persistency implementation to retrieve specified cache from
101: * the cache factory if one is set for the Persistency instance.
102: * If cache factory is not set and getCache() returns null then exeption is thrown.
103: *
104: * @return cache name
105: * @throws com.completex.objective.components.OdalRuntimeException If cache factory is not set and getCache() returns null.
106: */
107: String getCacheName();
108:
109: OdalCache getCache();
110:
111: OdalKeyFactory getKeyFactory();
112:
113: /**
114: * Called before parent record with all the subtrees inserted.
115: * @param persistentObject persistent object to be inserted
116: */
117: void beforeCompositeInsert(PersistentObject persistentObject);
118:
119: /**
120: * Called after parent record with all the subtrees si retrieved.
121: * @param collection
122: */
123: void afterCompositeSelect(Collection collection);
124:
125: /**
126: * Null implementation
127: */
128: static class NullLifeCycleController implements LifeCycleController {
129: public void afterSelect(
130: AbstractPersistentObject persistentObject) {
131: }
132:
133: public void beforeInsert(PersistentObject persistentObject) {
134: }
135:
136: public void afterInsert(PersistentObject persistentObject) {
137: }
138:
139: public void beforeUpdate(PersistentObject persistentObject) {
140: }
141:
142: public void afterUpdate(PersistentObject persistentObject) {
143: }
144:
145: public void beforeDelete(PersistentObject persistentObject) {
146: }
147:
148: public void afterDelete(PersistentObject persistentObject) {
149: }
150:
151: public Object[] getParameters() {
152: return new Object[0];
153: }
154:
155: public void setParameters(Object[] parameters) {
156: }
157:
158: public LifeCycleController newLifeCycleInstance() {
159: return this ;
160: }
161:
162: public Object clone() throws CloneNotSupportedException {
163: return this ;
164: }
165:
166: public String getCacheName() {
167: return null;
168: }
169:
170: public OdalCache getCache() {
171: return null;
172: }
173:
174: public OdalKeyFactory getKeyFactory() {
175: return null;
176: }
177:
178: public void beforeCompositeInsert(
179: PersistentObject persistentObject) {
180: }
181:
182: public void afterCompositeSelect(Collection collection) {
183: }
184:
185: }
186:
187: }
|