Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

GenericTransactionalServlet.java

00001 package edu.virtualschool.jwaa.dbms;
00002 
00003 import javax.servlet.ServletException;
00004 
00005 import edu.virtualschool.jwaa.Config;
00006 import edu.virtualschool.jwaa.Fault;
00007 import edu.virtualschool.jwaa.GenericServlet;
00008 import edu.virtualschool.jwaa.MetaPage;
00009 
00010 public abstract class GenericTransactionalServlet extends GenericServlet
00011 {
00012   public DBPool dbPool;
00013   
00014   public GenericTransactionalServlet(MetaPage[] metaPages)
00015   {
00016     super(metaPages);
00017   }
00018   public final void initDB(String jdbcProperties)
00019     throws ServletException
00020   {
00021     try
00022     {
00023       Config dbConfig = new Config(jdbcProperties);
00024       this.dbPool = new DBPool(dbConfig);
00025     }
00026     catch (Fault e)
00027     {
00028       throw new ServletException("Fault initializing DB connection pool", e);
00029     }
00030   }
00031   public final DB getDB() throws Fault
00032   {
00033     if (dbPool == null)
00034       throw new Fault("initDB(jdbcProperties) must be called before using transactions");
00035     else
00036       return new DB(dbPool);
00037   }
00038 }