db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Db-derby Wiki] Update of "DerbyOnTomcatWithSpringHibernate" by JoonasKoivunen
Date Thu, 16 Apr 2009 14:59:20 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification.

The following page has been changed by JoonasKoivunen:
http://wiki.apache.org/db-derby/DerbyOnTomcatWithSpringHibernate

The comment on the change is:
Wrote up on ServletContextListener, creating and shutting down derby, cleanup

------------------------------------------------------------------------------
  === Actual work (exproject-core) ===
  
  ==== Entities ====
- (TODO: create two simple entities that have some kind of relation to each other)
+ (TODO: link to annotations docs)
  
  In this example we have two simple entities, Parent and Child. You can probably guess their
relationship.
  {{{
@@ -147, +147 @@

  }}}
  
  ==== DAO's ====
- (TODO: simple daos, HibernateDaoSupport, link to ibm generic dao article)
+ (TODO: simple daos, links to documentation)
+ 
- DAO -layer provides simple CRUD like operations to your database. While we are using Hibernate
in this example it's generally a good idea to build your DAO interfaces so that you could
later add a JDBC backend if you need or want. Though, there might be a point in encapsuling
some logic also to DAO -layer which will open possibilities like implementing the logic in
derby itself.
+ DAO -layer provides simple CRUD like operations to your database. While we are using Hibernate
in this example it's generally a good idea to build your DAO interfaces so that you could
later add a JDBC backend if you need or want. Though, there might be a point in encapsulating
some logic also to DAO -layer which will open possibilities like implementing the logic in
derby itself.
  
- Spring framework provides abstract HibernateDaoSupport -class which will make your Hibernate
DAO -code consist mostly of one-liners.
+ Spring framework provides abstract !HibernateDaoSupport -class which will make your Hibernate
DAO -code consist mostly of one-liners.
  
  Generic DAO implementation will save you a lot of trouble, essentially providing you with
CRUD -operations with the cost of one constructor parameter. IBM has a nice article on [http://www.ibm.com/developerworks/java/library/j-genericdao.html
not repeating code with DAOs], there are lot of more articles around, to name a few:
   * [http://www.hibernate.org/328.html Generic Data Access Objects] at hibernate.org
@@ -158, +159 @@

   * [http://code.google.com/p/hibernate-generic-dao/ hibernate-generic-dao] project
  
  ==== Services ====
- (TODO: simple generic crud service, @Transactional)
+ (TODO: simple generic crud service)
+ 
  Service layer adds logic that uses your DAO interfaces to provide your business logic and
handles transaction creation and commits. With Spring a @Transactional -annotation and some
configuration (in the next section) Spring will arrange creation and committing for you without
any boilerplate code.
  
  As with generic dao's you migth find the need to implement yourself a Generic Service as
well to provide simplest CRUD functionality by just delegating methods over to your generic
dao. This again, will let your ParentService implementation focus on the real business logic.
@@ -178, +180 @@

  ==== Simple controller and view skeleton ====
  (TODO: example)
  
- ==== ServletContextListener ====
+ ==== !ServletContextListener ====
- (TODO: reason, usage, derby database creation, shutdown)
+ (TODO: links to documentation, derby.system.home property)
+ 
+ !ServletContextListener is interface defines methods for listeners that need to act when
!ServletContext is getting started and stopped. For embedded derby users this means the following:
+  1. The database might need to be created
+    * Mostly likely only when developing :)
+  2. Derby has to be shut down when the web application is shut down
+    * To prevent nasties like data loss, corruption
+ 
+ Creating a database with derby is simple; just open a JDBC connection to ''jdbc:derby:myDatabaseNameComesHere;create=true.''
If the database was already created the connection will report an !SQLWarning with !SQLState
'''01J01''' (link to derby manual).
+ 
+ Shutting down a single database is equally simple; just open a JDBC connection to ''jdbc:derby:myDatabaseNameComesHere;shutdown=true.''

+ 
+ However as we'll be using tomcat and your database will be the only one, we'll be more interested
in shutting down whole derby embedded RDBMS. This can be accomplished by connecting to ''jdbc:derby:;shutdown=true.''
+ 
+ I'm not sure if there's a simple "!DerbyUtil" class already providing static methods such
as
+  * createDatabase(String name)
+  * shutdown(String dbName)
+  * shutdown()
+ 
+ ... but implementing your own and using it in your servlet context listener class might
serve as a good exercise.
+ 
+ Servlet context listeners are hooked up to your web application by adding them by class
name to web.xml as explained in the next section.
  
  ==== Configuration ====
  (TODO: context:component-scan, datasource, web.xml)

Mime
View raw message