if you want to use straight jdbc that should be easy. what you need is a
connection pool - there is one in apache commons.

you store the connection pool reference in your Application subclass.
whether you create it there or pull it out of jndi is up to you.

then you subclass requestcycle and do something like this - if you want a
transaction-per-request which is a common pattern for webapps


class JdbcRequestCycle extends WebRequestCycle {

  private Connection connection;

  public Connection getConnection() {
      if (connection==null) {
          
connection=((MyApplication)Application.get()).getConnectionPool().getConnection();
           // configure connection
           connection.setAutoCommit(false);
      }
      return connection;
   }

   public void onEndRequest() {
         if (connection!=null) {
            connection.commit();
            // TODO return the connection to the pool here
            connection=null;
         }
    }

   public void onRuntimeException() {
          if (connection!=null) {
               connection.commit();
               // TODO return the connection to the pool here
               connection=null;
           }
    }
}

and thats pretty much all you need

whenver you need a connection just call
((MyRequestCycle)getRequestCycle()).getConnection();

-Igor


Ayodeji Aladejebi wrote:
> 
> Okay I know of all the contrib projects, databinder, hibernate stuffs etc,
> I
> have used databinder and its lovely but I think for some reason, database
> in
> wicket needs to be sort of easier to put up to encourage faster
> adaptation.
> Come to think about it, presently most of the present solutions around
> database in Wicket wraps around Hibernate and a beginner who is not
> familair
> with hibernate may get stuck. Some developers still tend to love thier SQL
> thing compared to ORM and in some cases, you want to do direct SQL cuz
> hibernate3.jar is some size you may not need to include in your portable
> web
> application. And believe me, i believe more ppl learn SQL more than they
> learn ORM in Schools
> 
> Yesterday, I was tryin to use Dababinder or wicket-contrib-dababase but at
> the same time i was using the wicket-auth framework and all these contibs
> enforce that you extend XXXApplication in your Application Class which
> means
> you cannot directly use Contrib projects e.g wicket-contrib-database and
> also Wicket-auth. There should be a more elegant way to use multiple
> contrib
> projects without this Inheritance lock jam.
> 
> Now most web applications need authentication and also need database which
> is why i believe wicket shoud somehow integrate some DAO scheme into
> wicket
> where all we do is set connection properties and from Components, you can
> fly CRUD.
> 
> Well i know there must be some good reasons to exclude this from wicket
> but
> what will be the most elegant way to do CRUD in wicket?  where should I
> store my Connection? Session or Application Class. Should I create a
> parent
> WebPage with all the SQL stuffs and then make other CRUD pages extend it.
> a
> hundred ways to do this but which way is more elegant?
> 
> Thanks Wicket dads
> 
> 
> 
> 
> -- 
> "It takes insanity to drive in sanity" - Me
> 
> Aladejebi Ayodeji A.,
> DabarObjects Solutions
> Email: [EMAIL PROTECTED]
> Mobile: +234 803 589 1780
> Web: www.dabarobjects.com
> 
> Community:
> www.cowblock.net
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Database-Integration-With-Wicket-tf2311910.html#a6622344
Sent from the Wicket - User mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to