View Javadoc
1   package ejava.projects.eleague.blimpl;
2   
3   import java.util.Map;
4   
5   import javax.persistence.EntityManager;
6   
7   import ejava.projects.eleague.bl.LeagueTestUtil;
8   import ejava.util.jpa.DBUtil;
9   
10  public class LeagueTestUtilImpl implements LeagueTestUtil {
11      protected static final String DROP_SCRIPT = "ddl/eLeague_drop.ddl";  
12      protected static final String CREATE_SCRIPT = "ddl/eLeague_create.ddl";      
13      private EntityManager em;
14      
15      public void setEntityManager(EntityManager em) {
16          this.em = em;
17      }
18      
19      protected DBUtil getDBUtil() {
20          DBUtil dbUtil = new DBUtil();
21          dbUtil.setEntityManager(em);
22          dbUtil.addDropPath(DROP_SCRIPT);
23          dbUtil.addCreatePath(CREATE_SCRIPT);
24          return dbUtil;
25      }
26      
27  
28      public Map<String, Number> drop() throws RuntimeException {
29          DBUtil dbUtil = getDBUtil();
30          return dbUtil.dropAll();
31      }
32      
33      public void create(Map<String, Number> sequenceVals) throws RuntimeException {
34          DBUtil dbUtil = getDBUtil();
35          dbUtil.createAll(sequenceVals);
36      }
37  
38      @Override
39      public void reset() throws RuntimeException {
40          Map<String, Number> sequenceVals = drop();
41          create(sequenceVals);
42      }
43  }