Home Projects Jobs Clientele Contact


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UU code

Establishing connection to the database is an expensive operation.
In most sane applications, some sort of database connection pooling
is used. Such pool will be responsible for doing establishing actual
connections, closing them, making sure single connection isn't used
by two separate requests at the same time, etc.

Such class obviously belongs to model, or, to be more precise, right
under model (i.e. model classes will call out to it).

Configuration, on the other hand, is handled by setting either servlet-
or application-level parameters (in our case application-level makes
most sense). Direct access to such objects is available to servlet classes.

Each servlet lives in ServletContainer, which, in turn, lives in
ServletContext joins multiple servlets, allowing them to share some data.
What I would do, is create that pool, and store pointer to it in
and then would create methods to retrieve database handle (or a wrapper
for it, if you feel the need) in UUServlet. Then all  data model layer
that need to talk to database, would need that handle passed to them,
either as an argument to constructor (in case the object will never have
lifetime that spans beyond single request), or as argument to a specific
function call.

sergey@total-knowledge.com wrote:
> Since DB connection/disconnection operations are located in Model classes,
> I have a question regarding passing DSN parameters to a Model class.
> I have 2 ways to do it:
> 1. Use ServletConfig parameters from engine.xml and pass them to Model
> class from Servlet each time I need to connect to DB.
> 2. Pass parameters to Model class directly.
> I think 2. is the way to go, but don't know how to pass parameters to
> model class. Are we going to have some kind of property file to handle
> things like that? What's the best way to do it in C++?

Ilya A. Volynets-Evenbakh
Total Knowledge. CTO

Authoright © Total Knowledge: 2001-2008