commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From po...@free.fr
Subject Re: DbUtils Best Practices
Date Thu, 13 Sep 2007 13:30:31 GMT
add an action in the catch block and this will be perfect
;)
Jérome.



Selon diego.galdi@nurun.it:

> I have changed my class:
>
> public class QueryManager {
>
>  private static QueryManager queryManager = null;
>
>  private QueryRunner queryRunner = null;
>
>  private QueryManager() {
>  	try {
> 	queryRunner = new QueryRunner(DataSourceSingleton.getInstance()
> 					.getDataSource());
> 	} catch (Exception e) {
> 	}
>  }
>
>  public static QueryManager getInstance() {
>    if (queryManager == null) {
> 	queryManager = new QueryManager();
>    }
>     return queryManager;
>   }
>
>  public QueryRunner getQueryRunner() {
>    return this.queryRunner;
>  }
>
> Is what you meant?
>
> Thanks
>
>
>
>
> > sorry, another point...
> > queryRunner parameter must be a QueryManager member parameter, you have to
> > remove "static"
> >
> > Selon pouky@free.fr:
> >
> >> i'm seeing another point. Your QueryManager does not offer the guarantee
> >> to
> >> be a
> >> singleton, you have to declare a private constructor.
> >>
> >> Jérome.
> >>
> >>
> >> Selon pouky@free.fr:
> >>
> >> > Selon diego.galdi@nurun.it:
> >> >
> >> > > Hi,
> >> > > I'm using a dao pattern, the call
> >> > >
> >> > > QueryManager.getInstance().getQueryRunner().query(...);
> >> > >
> >> > > is executed in my dao object.
> >> > >
> >> > > Servlet calls dao method.
> >> > >
> >> > ok.
> >> >
> >> > > What do you mean with it depends of your project size?
> >> > Hi,
> >> > If you have a small project it is not mandatory to spend a lot of time
> >> in
> >> the
> >> > abstraction layers, but this is advised. If you implement this
> >> approach,
> >> life
> >> > is
> >> > wonderful. :)
> >> >
> >> > Jérome.
> >> >
> >> > >
> >> > > Thanks a lot
> >> > >
> >> > > Diego
> >> > >
> >> > >
> >> > > > Hi,
> >> > > > It seems correct, why not, QueryRunner object is thread safe.
> >> > > > Web layer which calls integration layer directly, it's a bad
> >> design but
> >> > > > this
> >> > > > depends of your project size.
> >> > > >
> >> > > > Jérome.
> >> > > >
> >> > > >
> >> > > >
> >> > > > Selon diego.galdi@nurun.it:
> >> > > >
> >> > > >> Hi, I'm developing a web application using DbUtils classes
to
> >> execute
> >> > > >> queries and so on.
> >> > > >>
> >> > > >> I user QueryRunner class with a DataSource.
> >> > > >>
> >> > > >> I red this class is thread safe, so I implemented a Singleton
to
> >> > > >> instance
> >> > > >> QueryRunner only once.
> >> > > >>
> >> > > >> This is my code:
> >> > > >>
> >> > > >> public class QueryManager {
> >> > > >>
> >> > > >>  private static QueryManager queryManager = null;
> >> > > >>
> >> > > >>  private static QueryRunner queryRunner = null;
> >> > > >>
> >> > > >>  static {
> >> > > >>    try {
> >> > > >> 	queryRunner = new QueryRunner(DataSourceSingleton.getInstance()
> >> > > >> 					.getDataSource());
> >> > > >> 	} catch (Exception e) {
> >> > > >> 	}
> >> > > >>  }
> >> > > >>
> >> > > >>  public static QueryManager getInstance() {
> >> > > >>     if (queryManager == null) {
> >> > > >> 	queryManager = new QueryManager();
> >> > > >>     }
> >> > > >>     return queryManager;
> >> > > >>  }
> >> > > >>
> >> > > >>  public QueryRunner getQueryRunner() {
> >> > > >>    return queryRunner;
> >> > > >>  }
> >> > > >>
> >> > > >> In my servlets I use:
> >> > > >>
> >> > > >> QueryManager.getInstance().getQueryRunner().query(...);
> >> > > >>
> >> > > >> Is this correct?
> >> > > >>
> >> > > >> Which is the best practice to use QueryRunner in a web context?
> >> > > >>
> >> > > >> Thanks a lot in advance
> >> > > >>
> >> > > >>
> >> > > >>
> ---------------------------------------------------------------------
> >> > > >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> > > >> For additional commands, e-mail: user-help@commons.apache.org
> >> > > >>
> >> > > >>
> >> > > >
> >> > > >
> >> > > >
> >> > > >
> ---------------------------------------------------------------------
> >> > > > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> > > > For additional commands, e-mail: user-help@commons.apache.org
> >> > > >
> >> > > >
> >> > >
> >> > >
> >> > >
> >> > > ---------------------------------------------------------------------
> >> > > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> > > For additional commands, e-mail: user-help@commons.apache.org
> >> > >
> >> > >
> >> >
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> > For additional commands, e-mail: user-help@commons.apache.org
> >> >
> >> >
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: user-help@commons.apache.org
> >>
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> > For additional commands, e-mail: user-help@commons.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message