In our application, we are slowly migrating to Guice from no DI but we
have hit a little bit of a road block. In our application, we use
CallableStatement to make database calls and not any persistence API.
Is there any guice based application that we can use for transactional
support. I know that warp api is used to support Hibernate, JPA and
and DB4Objects.
A post on Stack Overflow http://stackoverflow.com/questions/2347384/guice-jdbc-and-managing-database-connections
did not return any answers as yet. Dhanji's blogs http://www.jroller.com/dhanji/
and http://rethrick.wordpress.com/ did not help with that either.
Has any one done any plain jdbc set up with Guice?
Thanks,
Kartik
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
o) A way to configure and bind DataSource
x) I didn't bother with providing support for connection pool, as
Oracle Driver comes with build-in CP sames goes Postgresql
o) Did bother on making sure DS is properly closed and driver
unregistered on webapp redeploy or shutdown
o) Made a provider for a Connection (I "hardcoded" connection-per-
transaction approach)
o) Made a transaction interceptor
It looked like
@JdbcTransaction // connection is obtained from the DS set to thread
local
public void doStuff(){
Connection con = connectionProvider.get(); // connection
retrieved from TL
....
} // connection is properly closed(returned to CP) in any situation
If you tried to obtain a Connection outside @JdbcTransaction you'd get
an error.
I also had @Retry(times=3,delay=2) on the methods but that is another
story.
HTH
Cheers
Alen
On Feb 28, 4:01 am, Karthik Krishnan <krishnan.1...@gmail.com> wrote:
> Hi All,
>
> In our application, we are slowly migrating to Guice from no DI but we
> have hit a little bit of a road block. In our application, we use
> CallableStatement to make database calls and not any persistence API.
> Is there any guice based application that we can use for transactional
> support. I know that warp api is used to support Hibernate, JPA and
> and DB4Objects.
>
> A post on Stack Overflowhttp://stackoverflow.com/questions/2347384/guice-jdbc-and-managing-da...
> did not return any answers as yet. Dhanji's blogshttp://www.jroller.com/dhanji/
> andhttp://rethrick.wordpress.com/did not help with that either.
If you use e.g. c3po's datasource, you'll get pooling built in but
independent of the actual driver.
> o) Made a provider for a Connection (I "hardcoded" connection-per-
> transaction approach)
That means that you'll always have a transaction when you want to use
a connection, even if you don't really need one right? As an
alternative you could implement a workmanager-ish solution (similar to
what warp does).
Eelco
I guess I should say that you don't always want to turn off autocommit
(transaction per execution instead of per annotated method). And
thinking about it it, maybe there is no good reason.
Eelco
In my case the database server got restarted from time to time. That
is nothing special but didn't want the Connection Pool to validate
connections all the time, therefore ConnectionClosedException happens.
But the @Retry just calls the method again, the CP is smart enough to
give a good connection the second time, and the user doesn't get en
error.
Cheers
Alen
On 1 mar., 16:46, Kartik Kumar <krishnan.1...@gmail.com> wrote:
> @Alen What is @Retry annotation? Was this one of the application specific
> annotations that you implemented?
>
> On Sun, Feb 28, 2010 at 3:11 PM, Eelco Hillenius
> <eelco.hillen...@gmail.com>wrote:
>
>
>
> > > Just curious, when would you not need a transaction?
>
> > I guess I should say that you don't always want to turn off autocommit
> > (transaction per execution instead of per annotated method). And
> > thinking about it it, maybe there is no good reason.
>
> > Eelco
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "google-guice" group.
> > To post to this group, send email to google...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-guice...@googlegroups.com<google-guice%2Bunsubscribe@google groups.com>
In and of itself, Guice won't provide much unless there's a JDBC
abstraction layer (Templatized DAO's for instance) for it to work
with. We have such here, so Guice affords us the ability to just swap
out ConnectionPool's, Transaction Strategies, etc.. simply by using
different Guice Modules.
On Feb 27, 7:01 pm, Karthik Krishnan <krishnan.1...@gmail.com> wrote:
> Hi All,
>
> In our application, we are slowly migrating to Guice from no DI but we
> have hit a little bit of a road block. In our application, we use
> CallableStatement to make database calls and not any persistence API.
> Is there any guice based application that we can use for transactional
> support. I know that warp api is used to support Hibernate, JPA and
> and DB4Objects.
>
> A post on Stack Overflowhttp://stackoverflow.com/questions/2347384/guice-jdbc-and-managing-da...
> did not return any answers as yet. Dhanji's blogshttp://www.jroller.com/dhanji/
> andhttp://rethrick.wordpress.com/did not help with that either.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
Maybe bklough can share their implementation. Sounds like they have a
polished jdbc support.
HTH
Alen
On Mar 7, 5:04 am, Kartik Kumar <krishnan.1...@gmail.com> wrote:
> I apologize in advance for the long winded email. By Alen's suggestion, I
> first tried to get a thread local connection instance to be injected. So I
> first copied an implementation of ThreadLocalScope from Guice Custom Scope
> implementationhttp://pastie.org/857790.
> Then I injected this scope into my ThreadLocalConnectionProvider to inject
> the scope to provide initial seed value and to provide fall back connection
> instancehttp://pastie.org/857829. To get a thread local connection
> instance, I call the scope method of my scope implementation. My modules
> binding is given here.http://pastie.org/857810.
> My unit tests work as in I get the same connection instance every time.
> My question is related to exception handling. I inject data source to any
> Provider that requires a connection. DataSource#getConnection() throws
> SQLException in its method signature. So in my get() implementation, I have
> to swallow it or throw unchecked exception in its place as it I have done in
> my example. I know that I can used ThrowingProviders, but scope method does
> not allow an implementation of that interface as one of its method argument.
> Is there a better way to do this write this implementation or am I stuck
> with what I have?
>
> Kartik
>
> > > > google-guice...@googlegroups.com<google-guice%2Bunsu...@googlegroups.com>
> > <google-guice%2Bunsubscribe@google groups.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/google-guice?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "google-guice" group.
> > To post to this group, send email to google...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-guice...@googlegroups.com<google-guice%2Bunsu...@googlegroups.com>
To unsubscribe from this group, send email to google-guice...@googlegroups.com.