Exemplo n.º 1
0
 public void init(ServletConfig config) throws ServletException {
   super.init(config);
   ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
   dao = (DerbyDao) ctx.getBean("personDao");
   txManager = (PlatformTransactionManager) ctx.getBean("transactionManager");
   dao.createTable();
 }
Exemplo n.º 2
0
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    DefaultTransactionDefinition def = new DefaultTransactionDefinition();

    def.setName("cargotest");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    TransactionStatus status = txManager.getTransaction(def);
    try {
      dao.create("Adrian", "Cole");

    } catch (RuntimeException ex) {
      txManager.rollback(status);
      throw ex;
    }
    txManager.commit(status);
    if (dao.selectAll().size() != 1) throw new RuntimeException("Commit didn't work");
    PrintWriter out = response.getWriter();
    out.print("all good!");
    out.close();
  }
Exemplo n.º 3
0
 public void destroy() {
   dao.dropTable();
   super.destroy();
 }