@@ -0,0 +1,2859 @@
+package stormpot.examples;%0A%0Aimport java.sql.Connection;%0Aimport java.sql.SQLException;%0A%0Aimport javax.sql.DataSource;%0A%0Aimport stormpot.Allocator;%0Aimport stormpot.Config;%0Aimport stormpot.LifecycledPool;%0Aimport stormpot.Poolable;%0Aimport stormpot.Slot;%0Aimport stormpot.qpool.QueuePool;%0A%0Apublic class DaoObjectPoolExample %7B%0A  static class MyDaoObject implements Poolable %7B%0A    private final Slot slot;%0A    private final Connection connection;%0A    %0A    private MyDaoObject(Slot slot, Connection connection) %7B%0A      this.slot = slot;%0A      this.connection = connection;%0A    %7D%0A%0A    private void close() throws SQLException %7B%0A      connection.close();%0A    %7D%0A%0A    public void release() %7B%0A      slot.release(this);%0A    %7D%0A    %0A    // ...%0A    // public DAO-type methods%0A    // ...%0A    %0A    public String getFirstName() %7B%0A      // Stub: get the name from the database using the connection.%0A      // But for now, just always return %22freddy%22%0A      return %22freddy%22;%0A    %7D%0A  %7D%0A  %0A  static class MyDaoObjectAllocator implements Allocator%3CMyDaoObject%3E %7B%0A    private final DataSource dataSource;%0A    %0A    public MyDaoObjectAllocator(DataSource dataSource) %7B%0A      this.dataSource = dataSource;%0A    %7D%0A%0A    public MyDaoObject allocate(Slot slot) throws Exception %7B%0A      return new MyDaoObject(slot, dataSource.getConnection());%0A    %7D%0A%0A    public void deallocate(MyDaoObject poolable) throws Exception %7B%0A      poolable.close();%0A    %7D%0A  %7D%0A  %0A  static interface WithMyDaoObjectDo%3CT%3E %7B%0A    public T doWithDao(MyDaoObject dao);%0A  %7D%0A  %0A  static class MyDaoObjectPool %7B%0A    private final LifecycledPool%3CMyDaoObject%3E pool;%0A    %0A    public MyDaoObjectPool(DataSource dataSource) %7B%0A      MyDaoObjectAllocator allocator = new MyDaoObjectAllocator(dataSource);%0A      Config%3CMyDaoObject%3E config = new Config().setAllocator(allocator);%0A      pool = new QueuePool(config);%0A    %7D%0A    %0A    public %3CT%3E T doWithDao(WithMyDaoObjectDo%3CT%3E action)%0A    throws InterruptedException %7B%0A      MyDaoObject dao = pool.claim();%0A      try %7B%0A        return action.doWithDao(dao);%0A      %7D finally %7B%0A        dao.release();%0A      %7D%0A    %7D%0A%0A    public void close() throws InterruptedException %7B%0A      pool.shutdown().await();%0A    %7D%0A  %7D%0A  %0A  public static void main(String%5B%5D args) throws InterruptedException %7B%0A    DataSource dataSource = configureDataSource();%0A    MyDaoObjectPool pool = new MyDaoObjectPool(dataSource);%0A    String person = pool.doWithDao(new WithMyDaoObjectDo%3CString%3E() %7B%0A      public String doWithDao(MyDaoObject dao) %7B%0A        return dao.getFirstName();%0A      %7D%0A    %7D);%0A    System.out.println(%22Hello there, %22 + person + %22!%22);%0A    pool.close();%0A  %7D%0A%0A  private static DataSource configureDataSource() %7B%0A    // Stub: configure and return some kind of DataSource object.%0A    // Allocation will fail with a NullPointerException until this method%0A    // get a proper implementation.%0A    return null;%0A  %7D%0A%7D%0A

add an example where some kind of DAO object is pooled.