incubator-empire-db-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Döbele <doeb...@esteam.de>
Subject re: Spring Configuration
Date Mon, 01 Feb 2010 21:19:19 GMT
Hi Eike,

Yes, if you could have a look at our basic example and tell us whether making a spring version
of it makes sense, it would be great.
The basic example can be found in the distribution in src/empire-db-examples/empire-db-example-basic
folder.
It contains four code files:
- SampleApp.java (the main class)
- SampleBean.java (the bean for the employee entity)
- SampleConfig.java (the application config bean)
- SampleDB.java (the Empire-db data model description)
Together with the config.xml configuration files this sample may be used with various databases.
Default is HSQLDB.

The focus of the Sample App is to show people what Empire-db can do and to provide a basic
application outline.
Now if you could provide us with a similar project that is built on top of Spring we would
be very gateful.

Let me know if you need any more help?
Thanks.

Rainer


Eike Kettner wrote:
> Re: Spring Configuration
> 
> Hello Rainer
> 
> thank you for your response. I sure like to help, if I can. What did
> you have in mind? If you like, I could have a look at the example
> trying to create a spring version of it.
> 
> regards, eike
> 
> On [Sun, 31.01.2010 10:44], Rainer Döbele wrote:
> > Hello Eike,
> >
> > thank you very much for your Empire-db Spring tip and we very much
> appreciate your contribution.
> > Personally I am not using Spring but I know that many people out
> there are.
> > And I think we should give them some aid on how to best bring Empire-
> db and Spring together.
> >
> > So what we really need, is an example application that we can supply
> with our distribution.
> > My idea is to take the basic example that we have (empire-db-example-
> basic) and provide a Spring version of it.
> >
> > Would you be willing to help us here?
> > It be really great if you would.
> >
> > Looking forward to hearing from you.
> > Best regards
> >
> > Rainer
> >
> >
> > Eike Kettner wrote:
> > > Re: Spring Configuration
> > >
> > >
> > > Hi there
> > >
> > > As it happens that i like to use spring :), I might contribute to
> this
> > > with something that works for me so far...
> > >
> > > as empire-db sits on top of JDBC, all I do is extending Springs
> > > JDBCDaoSupport (calling it EmpireDaoSupport) and adding some
> setters
> > > for the DBDatabase and DBDriver class. In the application context I
> > > setup the DBDatabaseDriver and my DBDatabase and have them injected
> in
> > > any Dao that extends the EmpireDaoSupport class. I have just played
> > > with it using the BasicDatasource and a
> DatasourceTransactionManager
> > > provided by commons-dbcp and spring. The database driver class and
> the
> > > JDBC Settings are injected using normal placeholders from some
> > > configuration file (xml or whatever you like, if it is a
> > > java.util.Property at the end) - like you'd do it with spring.
> > >
> > > more concrete, my spring applicationXyz.xml:
> > > <xml>
> > > ...
> > > <!-- Data Source / DB Settings -->
> > > <bean id="dataSource"
> class="org.apache.commons.dbcp.BasicDataSource"
> > > destroy-method="close">
> > >   <property name="driverClassName" value="${jdbc.driverClassName}"
> />
> > >      <property name="url" value="${jdbc.url}" />
> > >      <property name="username" value="${jdbc.username}" />
> > >      <property name="password" value="${jdbc.password}" />
> > > </bean>
> > >
> > > <!-- Transaction manager for a single JDBC DataSource -->
> > > <bean id="transactionManager"
> > >
> class="org.springframework.jdbc.datasource.DataSourceTransactionManager
> > > ">
> > >     <constructor-arg ref="dataSource" />
> > > </bean>
> > > <bean id="transactionTemplate"
> > >
> class="org.springframework.transaction.support.TransactionTemplate">
> > >     <property name="transactionManager" ref="transactionManager" />
> > > </bean>
> > >
> > > <tx:annotation-driven transaction-manager="transactionManager" />
> > >
> > > <bean id="databaseDriver" class="${empiredb.drivername}">
> > >    <property name="databaseName" value="${empiredb.databasename}"
> />
> > > </bean>
> > > <!-- this is my DBDatabase subclass -->
> > > <bean id="ebxDatabase" class="org.eknet.ebx.db.EbxDatabase">
> > > </bean>
> > >
> > > <bean id="userDao" class="org.eknet.ebx.impl.UserDaoImpl">
> > >     <property name="dataSource" ref="dataSource" />
> > >     <property name="database" ref="ebxDatabase" />
> > >     <property name="databaseDriver" ref="databaseDriver" />
> > > </bean>
> > >
> > >
> > > And this is the EmpireDaoSupport class:
> > >
> > > public class EmpiredbDaoSupport extends JdbcDaoSupport {
> > >
> > >   private DBDatabase db;
> > >   private DBDatabaseDriver dbdriver;
> > >
> > >   public EmpiredbDaoSupport() {
> > >   }
> > >
> > >   public void setDatabase(DBDatabase db) {
> > >     this.db = db;
> > >   }
> > >
> > >   public void setDatabaseDriver(DBDatabaseDriver dbdriver) {
> > >    this.dbdriver = dbdriver;
> > >   }
> > >
> > >   @Override
> > >   protected void checkDaoConfig() {
> > >     super.checkDaoConfig();
> > >     if (db == null)
> > >       throw new IllegalArgumentException("'database' must be
> given!");
> > >     if (dbdriver == null)
> > >       throw new IllegalArgumentException("'databaseDriver' must be
> > > given!");
> > >   }
> > >
> > >  public DBDatabase getDatabase() {
> > >    if (!db.isOpen())
> > >       db.open(dbdriver, getConnection());
> > >       return db;
> > >   }
> > >
> > >   @SuppressWarnings("unchecked")
> > >   public <T extends DBDatabase> T getDB() {
> > >      return (T) getDatabase();
> > >   }
> > >
> > >   public DBDatabaseDriver getDatabasedriver() {
> > >     return dbdriver;
> > >   }
> > >
> > >   public RuntimeException translateEmpireException(EmpireException
> e) {
> > >     return new
> > > DataAccessResourceFailureException(e.getLocalizedMessage());
> > >   }
> > >
> > >   protected DBReader openReader(DBCommand cmd, Connection conn) {
> > >      DBReader r = new DBReader();
> > >      r.open(cmd, conn);
> > >      return r;
> > >   }
> > >
> > > }
> > >
> > > Then implementing any DAO object is the same like with jdbc or
> > > hibernate - extend the support class and implement it with empire-
> db:
> > >
> > > public class UserDaoImpl extends EmpiredbDaoSupport implements
> UserDao
> > > {
> > >
> > >     @Override
> > >     public int findAllUserCount() {
> > >         EbxDatabase db = getDB();
> > >         Connection conn = getConnection();
> > >
> > >         UserTable ut = db.TBL_USER;
> > >         DBCommand cmd = db.createCommand();
> > >         cmd.select(ut.count());
> > >     ...
> > >
> > > }
> > >
> > > bye, eike
> > >
> > > On [Mon, 04.01.2010 14:23], Jaco van Tonder wrote:
> > > > Hello guys,
> > > >
> > > > I am busy investigating Empire-DB as a replacement for Hibernate
> in
> > > our organization (so far so good). :) I have a couple of questions
> > > though.
> > > >
> > > > I put together a config class that does not make use of a config
> file
> > > (looked at the examples, and just used the defaults), but instead
> is
> > > wired using Spring (simple setter injection). I could not find any
> > > examples that uses this method so I am not sure if this is the best
> way
> > > to do it. I looked at the source code and could not find any other
> way
> > > of configuring Empire-DB that is not XML based.
> > > >
> > > > Q: Is there a recommended way of configuring Empire-DB using
> Spring?
> > > >
> > > > I read that there is no built-in transaction support. Obviously
> this
> > > is important for databases. :)
> > > >
> > > > Q: What transaction managers are known to work well with Empire-
> DB?
> > > JOTM, etc etc etc? Are there any examples of this available
> somewhere?
> > > >
> > > > I am willing to document any of the answers (ie spring
> configuration,
> > > transaction manager examples) on the project wiki.
> > > >
> > > > Thank you in advance.
> > > >
> > > > ---Jaco
> > > >
> > > >
> > > >
> > >
> #######################################################################
> > > ##############
> > > > Attention:
> > > > The information contained in this message and or attachments is
> > > intended
> > > > only for the person or entity to which it is addressed and may
> > > contain
> > > > confidential and/or privileged material.  Any review,
> retransmission,
> > > > dissemination or other use of, or taking of any action in
> reliance
> > > upon,
> > > > this information by persons or entities other than the intended
> > > recipient
> > > > is prohibited. If you received this in error, please contact the
> > > sender and
> > > > delete the material from any system and destroy any copies.
> > > >
> > > > Thank You.
> > > >
> > >
> #######################################################################
> > > ##############
> > > >
> > > >
> > >
> #######################################################################
> > > ##############
> > > > This e-mail message has been scanned for Viruses and Content and
> > > cleared
> > > > by MailMarshal
> > > >
> > >
> #######################################################################
> > > ##############
> > >
> > > --
> > > email: eike@eknet.org   https://www.eknet.org  pgp: 481161A0
> >
> 
> --
> email: eike@eknet.org   https://www.eknet.org  pgp: 481161A0

Mime
View raw message