Return-Path: Delivered-To: apmail-incubator-empire-db-user-archive@locus.apache.org Received: (qmail 60030 invoked from network); 25 Sep 2008 10:34:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Sep 2008 10:34:50 -0000 Received: (qmail 37655 invoked by uid 500); 25 Sep 2008 10:34:48 -0000 Delivered-To: apmail-incubator-empire-db-user-archive@incubator.apache.org Received: (qmail 37636 invoked by uid 500); 25 Sep 2008 10:34:48 -0000 Mailing-List: contact empire-db-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: empire-db-user@incubator.apache.org Delivered-To: mailing list empire-db-user@incubator.apache.org Received: (qmail 37624 invoked by uid 99); 25 Sep 2008 10:34:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Sep 2008 03:34:47 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [217.7.226.111] (HELO esteam.de) (217.7.226.111) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Sep 2008 10:33:48 +0000 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: Re: How to use it with web application? Date: Thu, 25 Sep 2008 12:34:19 +0200 Message-ID: <0864536CC6E70F4F9FF85DE7334908CC234278@esteams1.esteam.local> In-Reply-To: <48DB643B.9000106@tiscali.cz> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Re: How to use it with web application? Thread-Index: Acke92bkdS0Riy5zTumnT3iEUKcpYgAAC5WQ References: <48DB643B.9000106@tiscali.cz> From: =?iso-8859-1?Q?Rainer_D=F6bele?= To: X-Virus-Checked: Checked by ClamAV on apache.org Hi David, in a web-application you should ideally work with connection pooling, = which is usually done by the application server (i.e. Apache-Tomcat). We recommend the following: 1. create an Application object which is instantiated and initialized = once when the web-application is loaded in the web application server. = This can be done via a custom filter class registered in the web.xml = definition file of your web-application. The application object is a = singleton. 2. use a JNDI context to access a datasource provided by the application = server. When initializing your application obtain a Connection from the = data source and initialize your DB-Objects (create the driver, open the = database, check the schema, etc.) 3. for each request, obtain a connection from the pool which you can = then pass to the appropriate Empire-db function. When the request = finished close the connection which will effectively return it to the = pool. I recommend downloading and looking at our Empire-Struts2 Example = Application called DBWebSample provided with the distribution of the = empire-struts2-extentions. Even if you don't intend to use Struts2 as = your web application framework it gives a good idea on how to use = Empire-db in a web application. You should particularly look the init() = method of the SampleApplication class. However the sample application = does not implement connection pooling - but it can be easily added. Hope this is the kind of answer you expected. Regards Rainer David Marko wrote: >=20 > Hello, > can anyone share some common scenario on how to initialise necessary > things in web application using > e.g. SpringFramework? >=20 > ##### Using the code from the EmpireDB Site: > config.init((args.length > 0 ? args[0] : "config.xml")); > // STEP 1: Get a JDBC Connection > Connection conn =3D getJDBCConnection(); > In step two the sample creates and initializes a database driver = object > for the target DBMS. This is > HSQLDB by default. >=20 > // STEP 2: Choose a driver > DBDatabaseDriver driver =3D = getDatabaseDriver(config.getDatabaseProvider()); > Then in step three the database object is opened using the driver. = Only > when opened, other methods > of the database object may be used. Finally we check whether or not = our > database objects exist. >=20 > // STEP 3: Open Database and check if tables exist > db.open(driver, conn); > databaseExists(conn); > In order to check existence of the database the sample simply performs = a > query on the Departments > table ("select count(*) from DEPARTMENTS") using the following code: >=20 > DBCommand cmd =3D db.createCommand(); > cmd.select(db.DEPARTMENTS.count()); > db.querySingleInt(cmd.getSelect(), -1, conn); > ### >=20 > ... should/can be the conn and db initialised using some singleton = pattern > and used within the > application in this way? >=20 > Thanks for info, > David