01: /*
02: * FrameworkState.java
03: *
04: * Created on Jun 25, 2007, 4:35:30 PM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package it.biobytes.ammentos;
11:
12: import it.biobytes.ammentos.query.Query;
13: import java.util.List;
14: import static it.biobytes.ammentos.util.Invoker.*;
15:
16: /**
17: *
18: * @author davide
19: */
20: /**
21: * Represents a status for the Framework
22: * @author davide
23: */
24: abstract class FrameworkState {
25: public abstract <T> void doSave(Class<T> c, T obj)
26: throws PersistenceException;
27:
28: public final <T> void save(Class<T> c, T obj)
29: throws PersistenceException {
30: invokeHandlers(Ammentos.getMetadata(c).getBeforeSaveHandlers(),
31: obj);
32: doSave(c, obj);
33: invokeHandlers(Ammentos.getMetadata(c).getAfterSaveHandlers(),
34: obj);
35: }
36:
37: protected abstract <T> void doDelete(Class<T> c, T obj)
38: throws PersistenceException;
39:
40: public final <T> void delete(Class<T> c, T obj)
41: throws PersistenceException {
42: invokeHandlers(Ammentos.getMetadata(c)
43: .getBeforeDeleteHandlers(), obj);
44: doDelete(c, obj);
45: invokeHandlers(
46: Ammentos.getMetadata(c).getAfterDeleteHandlers(), obj);
47: }
48:
49: protected abstract <T> boolean doLoad(Class<T> c, T obj,
50: Object primaryKey) throws PersistenceException;
51:
52: public final <T> boolean load(Class<T> c, T obj, Object primaryKey)
53: throws PersistenceException {
54: boolean res;
55: res = doLoad(c, obj, primaryKey);
56: invokeHandlers(Ammentos.getMetadata(c).getAfterLoadHandlers(),
57: obj);
58: return res;
59: }
60:
61: protected abstract <T> List<T> doLoad(Class<T> c, Query qry)
62: throws PersistenceException;
63:
64: public final <T> List<T> load(Class<T> c, Query qry)
65: throws PersistenceException {
66: List<T> res;
67: res = doLoad(c, qry);
68: return res;
69: }
70:
71: protected abstract <T> EntityIterable<T> loadIterable(Class<T> c,
72: Query qry) throws PersistenceException;
73:
74: public abstract <T> int count(Class<T> c, Query qry)
75: throws PersistenceException;
76: }
|