01: package com.bm.testsuite.dataloader;
02:
03: import javax.persistence.EntityManager;
04:
05: import com.bm.introspectors.EntityBeanIntrospector;
06: import com.bm.utils.UndoScriptGenerator;
07:
08: /**
09: *
10: * Represents an initial dataset for entity beans.
11: *
12: * @author Daniel Wiese
13: * @param <T> -
14: * der typ des Entity Beans welches initial angelegt wird.
15: *
16: */
17: public abstract class EntityInitialDataSet<T> implements InitialDataSet {
18:
19: private EntityManager em = null;
20:
21: private final UndoScriptGenerator<T> undo;
22:
23: /**
24: * Constructor.
25: *
26: * @param entityType -
27: * die klasse der entity benas die initial angelegt werden
28: * sollen.
29: */
30: public EntityInitialDataSet(Class<T> entityType) {
31: undo = new UndoScriptGenerator<T>(
32: new EntityBeanIntrospector<T>(entityType));
33: }
34:
35: /**
36: * Will be called by the testing framework.
37: *
38: * @param em -
39: * the entity manager
40: */
41: public void setEntityManager(EntityManager em) {
42: this .em = em;
43: }
44:
45: /**
46: * The inherited class can call this method to add some data.
47: *
48: * @param toAdd -
49: * entyties to add;
50: */
51: protected void add(T toAdd) {
52: em.persist(toAdd);
53: undo.protokollCreate(toAdd);
54: }
55:
56: /**
57: * Deletes the data.
58: *
59: * @param ds -
60: * the datasource.
61: * @author Daniel Wiese
62: * @since 17.04.2006
63: * @see com.bm.testsuite.dataloader.InitialDataSet#cleanup(EntityManager)
64: */
65: public void cleanup(EntityManager em) {
66: undo.deleteAllDataInAllUsedTables(em);
67:
68: }
69:
70: }
|