View Javadoc
1   package org.myorg.jpatickets.ejb;
2   
3   import java.util.concurrent.TimeUnit;
4   
5   import javax.annotation.PostConstruct;
6   import javax.ejb.AccessTimeout;
7   import javax.ejb.ConcurrencyManagement;
8   import javax.ejb.ConcurrencyManagementType;
9   import javax.ejb.EJB;
10  import javax.ejb.Lock;
11  import javax.ejb.LockType;
12  import javax.ejb.Singleton;
13  import javax.ejb.Startup;
14  import javax.ejb.TransactionAttribute;
15  import javax.ejb.TransactionAttributeType;
16  
17  import org.slf4j.Logger;
18  import org.slf4j.LoggerFactory;
19  
20  @Singleton
21  @Startup
22  @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
23  @AccessTimeout(value=3, unit=TimeUnit.SECONDS)
24  public class TicketsInitEJB implements TicketsInitRemote {
25      private static final Logger logger = LoggerFactory.getLogger(TicketsInitEJB.class);
26      
27      @EJB
28      private TicketsInitTxEJB txHelper;
29      
30      @PostConstruct
31      public void init() {
32          resetDB();
33      }
34      
35      @Override
36      @Lock(LockType.WRITE)
37      @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
38      public void resetDB() {
39          logger.info("*** resetDB ***");
40          //execute the following in separate transactions
41          txHelper.dropDB();
42          txHelper.createDB();
43      }
44      
45  }