There are some excellent articles about the different mapping tiers at: http://www.martinfowler.com/isa
>From these, I had implemented a configurable command pattern DAO, much like the suggestions that Casey had offered whereby you predefine the SQL statements and properties for later use. Once created, I recommend, if at all possible, implementing an LRU cache of PreparedStatements and CallableStatements that can be looked up and executed quickly. You then receive the benefits of quick execution by the precompiled statements, without the initialization costs associated with it on every transaction. Regards, Jacob Hookom University of Wisconsin, Eau Claire -----Original Message----- From: Adolfo Miguelez [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 15, 2002 8:44 AM To: [EMAIL PROTECTED] Subject: re: re: DAO open source? Thanks Casey, I have been thinking as you, in configuring queries from XML. I will give it a look and I will post feedback when done. Regards, Adolfo. >From: Casey Forbes <[EMAIL PROTECTED]> >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> >To: [EMAIL PROTECTED] >Subject: re: re: DAO open source? >Date: Tue, 14 May 2002 20:41:47 -0400 > >Hi Adolfo, > >I wrote something which has been working well >for me - it makes extensive use of the Jakarta >Digester utility and some classes similar to >BeanUtils and PropertyUtils > >Works something like this: > > Can pass "simple" objects like Integer, String, Float > (the kinds that you can use in JDBC setObject calls) or beans. > > Can get beans, simple objects, or arrays of each back as results. > > >Java like this: > >public class UselessAction extends SubclassedAction { > > // SubclassedAction extends Action and build a DaoFactory on > // startup, passing it in to the perform method of my application > // actions > > performAction(ActionMapping mapping, blah blah, ActionForm form, > DaoFactory df) { > > Customer[] customers; > DataAccessor dao = df.getDataAccessor("invoice"); > > // just a wrapper around a hashmap that takes care of primitive > // wrapping and java.util.Date -> java.sql.Date, etc > ParameterSet params = new ParameterSet(); > params.addParameter("userId", 0) > dao.execute("retrieveCustomers", params); > customers = (Customer)dao.getResults(new Customer[0]); > > Invoice invoice = new Invoice(); > PropertyUtils.copyProperties(invoice, form); > ParameterSet invoiceParams = new ParameterSet(); > params.addParameter("userId", 0) > invoiceParams.addParameter("invoice", invoice); > dao.execute("saveInvoice", params); > } >} > > >The DaoFactory is built on startup by Digester >The XML looks like this: > ><daomap> > <connections> > <connection name="sam" alias="primary"> > </connections> > <beans> > <bean name="com.kensfoods.example.Invoice" alias="invoice"/> > <bean name="com.kensfoods.example.Customer" alias="customer"/> > </beans> > <datasources> > <datasource> > <datasource-name>invoice</datasource-name> > <connection-alias>primary</connection-alias> > <method> > <method-name>retrieveCustomers</method-name> > <statement> > <call>{call sbrGetCustomers(?)}</call> > <input> > <parameter name="userId" position="1" > type="java.lang.Integer"/> > </input> > <output/> > </statement> > <result bean="customer"> > <field property="customerId"/> > <field property="customerName"/> > <field property="address1"/> > <field property="address2"/> > <field property="address3"/> > <field property="city"/> > <!-- etc.... --> > </result> > </method> > <method> > <method> > <method-name>saveInvoice</method-name> > <statement> > <call>{? = call sbrPutInvoice(?,?,?,?,?,?,?,...</call> > <input> > <parameter name="userId" position="2" > type="java.lang.Integer"/> > <parameter name="invoiceId" bean="invoice" position="3"/> > <parameter name="invoiceNumber" bean="invoice" > position="4"/> > <!-- etc.... --> > <output> > <parameter name="return" position="1" > type="java.lang.Integer"/> > <parameter name="invoiceId" position="3" > type="java.lang.Integer"/> > </output> > </statement> > <post-call> > <set source="output" from="invoiceId" to="invoice" > to-property="invoiceId"/> > </post-call> > <result/> > </method> > </datasource> > </datasources> ></daomap> > > > >It works great for me - I hope that this gives you some ideas, > >Casey > > > > > > Subject: DAO open source? From: "Adolfo Miguelez" > > <[EMAIL PROTECTED]> Date: Tue, 14 May 2002 18:09:59 +0000 To: > > [EMAIL PROTECTED] > > > > Hi All, > > > > probably a little out of Struts scope but, not a problem for many of > > you, since it plugs in struts. I need to code an DAO class that, via > > JDBC, accesses a database. Database is Oracle 8i. We intend to manage > > any kind of database data. > > > My employer suggested my that class could have a principal method > > execute(...) signed like that: > > > > public static HashMap execute(String query, String datasource, String > > DBuser, String DBpassword, ArrayList parameters); > > > > The class accesses PL/SQL stored procedures by means of > > CallableStatements, which actually hold the business logic. > > > > * Returned hashmap contains return values indexed by return parameter > > name, including arrayList converted form resulsets and > > * ArrayList parameters holds next info about each parameter: > > - IN/OUT/INOUT > > - type > > - value > > > in order that method can be able to work out the actual > > CallableStatement. > > > That is the scenario. However, I am not sure about this design, and I > > have some questions so, I would appreciate opinions. > > > > - Firstly, passing parameter types I think is quite messy for the > > programmer. Furthermore, method can inspect in runtime database column > > types and cast, or match itself, input parameter types for database > > types. I would free this (pointless?) load to programmer that use this > > class. > > > > - Maynbe using dynabeans rather than hashmaps in the return from the > > method, > > > > - is good idea to make execute() static? > > > > - Does any of you know a open source DAO, or example to look at? > > > > Regards, > > > > Adolfo. > > > >-- >To unsubscribe, e-mail: ><mailto:[EMAIL PROTECTED]> >For additional commands, e-mail: ><mailto:[EMAIL PROTECTED]> > _________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002 -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

