You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@empire-db.apache.org by Francis De Brabandere <fr...@gmail.com> on 2010/05/18 12:39:48 UTC

Re: using of empire-db in multithreaded environment with multiple connections

I creaded a FAQ section on the wiki, feel free to add stuff in the future:
https://cwiki.apache.org/confluence/display/empiredb/Frequently+asked+questions

On Mon, May 17, 2010 at 1:34 PM, Rainer Döbele <do...@esteam.de> wrote:
> Hi Leszek,
>
> please appologize that I have not been able to answer your request earlier. In case you have not found out already, here are my comments to your questions of last Friday:
>
> To 1: We use empire-db a lot in Web applications which of course use mutlithreaded requests. Normally the data model definition is static i.e. once it is set up, it is not changing and thus accessing it from multiple threads is not a problem. All stateful objects used to access and manipulate data such as DBRecord and DBReader are allocated on a per thread basis. However, if you plan to make dynamic changes to your data model at runtime you will have to make sure that these changes are thread-safe. This must be done at application level.
>
> To 2: The conneciton used when opening the database is not stored with the database. It's purpose is soley to allow the driver to perform intialization functions and may not be used at all. Hence the conneciton may even be null, when opening the database. The open function on the database must only be called once in order to attach the driver. You may then use as many connections as you want - everytime a connection is needed you must supply it with the API call.
> In our (web-)projects we usually obtain a connection from a connection pool managed by the application server on a per request basis.
>
> I hope my answer is helpful for you.
>
> P.S. Thanks for your contribution of the DdlUtils interoperability code. I will have a look at it as soon as possible.
>
> Regards
> Rainer
>
>
> leszekp@Safe-mail.net wrote:
>> re: using of empire-db in multithreaded environment with multiple
>> connections
>>
>> Hello
>>
>> I am new on this list. First of all I think empire-db is a framework
>> which does a good job without
>> overuse of annotations (in fact it does not use them at all).
>>
>> I have some questions regarding use of empire-db in multithreaded
>> environment (in example in a service layer of a web server)
>>
>> 1 Is DBDatabase (and related DBTable, DBColumn) thread-safe? I mean that
>> only one instance of database model exists and
>> it may be acessed by multiple threads. I also assume that DBCommand,
>> DBRecord are created locally in functions.
>>
>> 2 DBDatabase must be opened before use by call of
>> open(driver,connection). What to do if application creates/uses multiple
>> connections? Should DBDatabase be reopened on every connection or it is
>> enough to open it only once.
>>
>> Regards
>> Leszek Piotrowicz
>



-- 
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

re: using of empire-db in multithreaded environment with multiple connections

Posted by Rainer Döbele <do...@esteam.de>.
Good idea, Thx.

Francis De Brabandere wrote:
> Re: using of empire-db in multithreaded environment with
> multiple connections
> 
> I creaded a FAQ section on the wiki, feel free to add stuff in the
> future:
> https://cwiki.apache.org/confluence/display/empiredb/Frequently+asked+qu
> estions
> 
> On Mon, May 17, 2010 at 1:34 PM, Rainer Döbele <do...@esteam.de>
> wrote:
> > Hi Leszek,
> >
> > please appologize that I have not been able to answer your request
> earlier. In case you have not found out already, here are my comments to
> your questions of last Friday:
> >
> > To 1: We use empire-db a lot in Web applications which of course use
> mutlithreaded requests. Normally the data model definition is static
> i.e. once it is set up, it is not changing and thus accessing it from
> multiple threads is not a problem. All stateful objects used to access
> and manipulate data such as DBRecord and DBReader are allocated on a per
> thread basis. However, if you plan to make dynamic changes to your data
> model at runtime you will have to make sure that these changes are
> thread-safe. This must be done at application level.
> >
> > To 2: The conneciton used when opening the database is not stored with
> the database. It's purpose is soley to allow the driver to perform
> intialization functions and may not be used at all. Hence the conneciton
> may even be null, when opening the database. The open function on the
> database must only be called once in order to attach the driver. You may
> then use as many connections as you want - everytime a connection is
> needed you must supply it with the API call.
> > In our (web-)projects we usually obtain a connection from a connection
> pool managed by the application server on a per request basis.
> >
> > I hope my answer is helpful for you.
> >
> > P.S. Thanks for your contribution of the DdlUtils interoperability
> code. I will have a look at it as soon as possible.
> >
> > Regards
> > Rainer
> >
> >
> > leszekp@Safe-mail.net wrote:
> >> re: using of empire-db in multithreaded environment with multiple
> >> connections
> >>
> >> Hello
> >>
> >> I am new on this list. First of all I think empire-db is a framework
> >> which does a good job without
> >> overuse of annotations (in fact it does not use them at all).
> >>
> >> I have some questions regarding use of empire-db in multithreaded
> >> environment (in example in a service layer of a web server)
> >>
> >> 1 Is DBDatabase (and related DBTable, DBColumn) thread-safe? I mean
> that
> >> only one instance of database model exists and
> >> it may be acessed by multiple threads. I also assume that DBCommand,
> >> DBRecord are created locally in functions.
> >>
> >> 2 DBDatabase must be opened before use by call of
> >> open(driver,connection). What to do if application creates/uses
> multiple
> >> connections? Should DBDatabase be reopened on every connection or it
> is
> >> enough to open it only once.
> >>
> >> Regards
> >> Leszek Piotrowicz
> >
> 
> 
> 
> --
> http://www.somatik.be
> Microsoft gives you windows, Linux gives you the whole house.