empire-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivan nemeth <ivan.nem...@forumdigital.net>
Subject Re: Best practice to access a DbDatabase?
Date Mon, 04 Aug 2014 06:52:54 GMT
Hi Rainer,

thank you for your answer.

I've used a static accessor but if I open the database on application start
it will open the database for the actual connection. I know that there are
no reference to the connection in the database instance, but in case of the
SQL Server driver some initialization SQL scripts is executed against the
actual connection only and not for other connections
(DbDatabaseDriver.attachDatabase). So it's true that there are no explicit
reference to a connection from a database instance but there is an implicit
binding through these initialization scripts.

Thanks,
Ivan


On Sun, Aug 3, 2014 at 11:12 PM, Rainer Döbele <doebele@esteam.de> wrote:

> Hi Ivan,
>
>
>
> To answer your question:
>
> First you will have to create a class derived from DBDatabase which
> defines the schema of your database.
>
> You then have to open the database when your application starts.
>
> This will attach the driver to the database, but I will not block
> resources like e.g. a connection.
>
> In most cases this class will be a singleton.
>
>
>
> Hence you may e.g. use a static accessor like this:
>
>
>
>     *private* *static* MyDatabase *myDb*;
>
>
>
>     *public* *MyDatabse* *getDatabase()* {
>
>         *if* (*myDb*==*null*)
>
>             *myDb*=*new* MyDatabase();
>
>         *return* *myDb*;
>
>     }
>
>
>
> Regards
>
> Rainer
>
>
>
>
>
> *Von:* ivan.nemeth@gmail.com [mailto:ivan.nemeth@gmail.com] *Im Auftrag
> von *ivan nemeth
> *Gesendet:* Freitag, 1. August 2014 16:44
> *An:* user
> *Betreff:* Best practice to access a DbDatabase?
>
>
>
> Hi,
>
>
>
> a month ago (June 2014) there was a discussion already about connection
> pooling but I have further questions. I use some kind of connection pooling
> and Spring's JdbcTemplate, so I have a separate connection for each
> threads. But how should I access a DbDatabase instance? The db instance is
> tied to the actual connection, so separate threads can't use the same db
> instance.
>
>
>
> 1. Create a new DbDatabase instance for every query/updates/insert. Can it
> cause any problems, if a lot of instances are created every second? I mean
> there are static variables which are storing some global states
> (DbDatabase.databaseMap, DbTable.tableCount etc.)
>
>
>
> 2. Use some kind of pooling on the DbDatabase.
>
>
>
> Thanks,
>
> Ivan
>
>
>
>
>

Mime
View raw message