Results 1 to 2 of 2
Thread: Common DataBase Layer
- 01-01-2010, 02:50 AM #1Member
- Join Date
- Dec 2009
- Rep Power
- 01-01-2010, 04:30 AM #2
I like to use a kind of data accessor approach to database work, where I have a Java bean to "model" the table data, that is ususally one bean or every table, or entity thing I might be interested in using in my application.
And then i have an accessor that fetches me an instance of this bean by querying the database and then populating the results into the bean, or takes an instance of the bean as a parameter and uses the appropriate SQL query to store this into the databse table(s). I would even make this accessor an interface method, and then provider an second class that implements this interface, so as to allow for different low level back end implementations if I later choose to do this.
So for this, I would have
- a package for the beans.
- a package for the data accessor interfaces
- a package for the data accessor implementation
Then I discovered Hibernate and later iBatis, which i now mainly use the latter, as I prefer to have the control over the SQL queries, so this would be my data accessor implementation.
I also like to use a single interface and implementation of what I call a 'manager', where the implementation ties together one or more data accessor interfaces, such that I have a single component that has all the application level functions i want to do, so my things just need to maintian a reference to this manager, and its implementation has references to the many data accessor classes. this allows for me to have a complex method, such as one that invokes a query in one data accessor and then with each result invokes a second query in a different data accessor. this becomes really useful when the data accessors are backed by different databases, or even different types of data stores, such as LDAP. once you make everything conform to a data accessor interface that gets you a bean, many different things like this become readily possible. I think for this reason some people call this what I call a 'manager' interface, the 'facade design pattern'.
Hope thats inspirational.
- By Addez in forum New To JavaReplies: 6Last Post: 09-02-2009, 04:37 AM
- By cprash.aggarwal in forum Advanced JavaReplies: 1Last Post: 03-01-2009, 05:57 PM
- By cprash.aggarwal in forum NetworkingReplies: 1Last Post: 03-01-2009, 05:37 PM
- By Qmalq in forum AWT / SwingReplies: 2Last Post: 01-27-2009, 10:20 PM
- By trill in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 08-07-2007, 07:35 AM