Return-Path: Delivered-To: apmail-incubator-ibatis-user-java-archive@www.apache.org Received: (qmail 18182 invoked from network); 2 May 2005 17:46:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 May 2005 17:46:02 -0000 Received: (qmail 43145 invoked by uid 500); 2 May 2005 17:47:27 -0000 Delivered-To: apmail-incubator-ibatis-user-java-archive@incubator.apache.org Received: (qmail 43112 invoked by uid 500); 2 May 2005 17:47:27 -0000 Mailing-List: contact ibatis-user-java-help@incubator.apache.org; run by ezmlm Precedence: bulk Reply-To: ibatis-user-java@incubator.apache.org List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list ibatis-user-java@incubator.apache.org Received: (qmail 43095 invoked by uid 99); 2 May 2005 17:47:27 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of brandon.goodin@gmail.com designates 64.233.170.203 as permitted sender) Received: from rproxy.gmail.com (HELO rproxy.gmail.com) (64.233.170.203) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 02 May 2005 10:47:27 -0700 Received: by rproxy.gmail.com with SMTP id c16so1143255rne for ; Mon, 02 May 2005 10:45:55 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Tqwyv3uFseyCUcX+4Eu6atj2B0p6nICGCc386Cx/GAX0X9iSEv1ZWNv7RvpYjbLHJCMvxRlWiFBrDqD+xq69w+KTGAfKk/wNjL9V9yXrhTrJ+VY73BoF9zPlwPfcDyVHC89GgcMGcx5Ra/ixAqJ+6bFdGuRmjsIh4yDCWKKm7g0= Received: by 10.38.67.69 with SMTP id p69mr6510746rna; Mon, 02 May 2005 10:45:55 -0700 (PDT) Received: by 10.38.74.62 with HTTP; Mon, 2 May 2005 10:45:55 -0700 (PDT) Message-ID: <2fe5ef5b05050210454ecc5f08@mail.gmail.com> Date: Mon, 2 May 2005 11:45:55 -0600 From: Brandon Goodin Reply-To: Brandon Goodin To: Folashade Adeyosoye Subject: Re: iBatis DAO Loading dao.xml Cc: ibatis-user-java@incubator.apache.org In-Reply-To: <4276668b.20befcf3.7255.ffffe67f@mx.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <2fe5ef5b0505021035754855f2@mail.gmail.com> <4276668b.20befcf3.7255.ffffe67f@mx.gmail.com> X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Is your configuration on the classpath or in a web directory? There _should_ be no resource issues if your Service class is initalizing the DaoManager. I'd like to hear a little more about how you have things configured. Thanks, Brandon On 5/2/05, Folashade Adeyosoye wrote: > I do not think am mingling ibatis and my struts layer.... >=20 > The iniSystem calls a Service class that loads the cache, I only noticed > that whenever super.init(config); is invoked rather than super.init();, > iBatis in the DaoConfig has problems with the ResourceReader... >=20 > Hope that clears it.. >=20 > -----Original Message----- > From: Brandon Goodin [mailto:brandon.goodin@gmail.com] > Sent: Monday, May 02, 2005 1:35 PM > To: ibatis-user-java@incubator.apache.org > Subject: Re: iBatis DAO Loading dao.xml >=20 > Why are you mingling iBatis with the servlet layer? Initialization > would be better placed in the service layer. >=20 > Brandon >=20 > On 5/2/05, Folashade Adeyosoye wrote: > > I found it strange enough that it did make a diff if I pass in a > > ServletConfig config or not... > > > > public void init(ServletConfig config) throws ServletException { > > logger.info("ExtendedActionServlet init()..."); > > super.init(config); <----------------- THIS > > initSystem(config); > > } > > > > If super.init(config) is called it has problems reading the dao.xml fil= e, > I > > think this it's the ResourceReader. As soon as I took the config off, i= t > > went pass the ResourceReader line. > > > > And this a class that extends the ActionServlet, this is called on star= tup > > of the application.. > > > > The initSystem calls methods to setup my cache... > > > > > > -----Original Message----- > > From: Ron Grabowski [mailto:rongrabowski@yahoo.com] > > Sent: Monday, May 02, 2005 1:04 PM > > To: ibatis-user-java@incubator.apache.org > > Subject: RE: iBatis DAO Loading dao.xml > > > > Calls to buildDaoManager resolve to this class: > > > > http://tinyurl.com/9qymm > > > http://svn.apache.org/repos/asf/incubator/ibatis/trunk/java/mapper/mapper= 2/s > > rc/com/ibatis/dao/engine/builder/xml/XmlDaoManagerBuilder.java > > > > Have you browsed the JPetstore source code: > > > > http://tinyurl.com/bpgl7 > > > http://svn.apache.org/repos/asf/incubator/ibatis/trunk/java/jpetstore/jpe= tst > > ore4/src/com/ibatis/jpetstore/persistence/DaoConfig.java > > > > to see how everything fits together? > > > > Is something not working? Are calls to buildDaoManager throwing an > > exception? > > > > --- Folashade Adeyosoye wrote: > > > > > The best way to find this out is to use your IDE to step thru the > > > code and > > > but break points. I have resulted to that in the last couple of days > > > to > > > actually see how the framework works.... but sadly have not been able > > > to get > > > pass the daoManager =3D DaoManagerBuilder.buildDaoManager(reader); in > > > my big > > > project that am converting..... > > > > > > But able to do it on a small one class (service class) file. > > > > > > > > > > > > > > > -----Original Message----- > > > From: Gregg D Bolinger [mailto:gthought@gmail.com] > > > Sent: Monday, May 02, 2005 12:39 PM > > > To: Brandon Goodin > > > Cc: ibatis-user-java@incubator.apache.org > > > Subject: Re: iBatis DAO Loading dao.xml > > > > > > >The dao manager does not parse it every time. It only parses once. > > > > > > Is this documented somewhere? How does that work if my code is > > > telling the builder to build everytime a service request is made? Is > > > it cached somewhere in memory much like the hand made singleton class > > > I am using? I don't want to perform extra logic if I don't have to > > > but I need proof it is doing as expected. :) > > > > > > Thanks. > > > > > > > > > > > > On 5/2/05, Brandon Goodin wrote: > > > > It would be perfectly fine to instantiate the Service class in your > > > > web layer. But, you might want to follow a similar pattern as the > > > > service layer does with the Dao classes. Instantiate your service > > > > classes in the constructor and assign them to instance variables in > > > > your Servlet, Action(Struts) or whatever you are using on the web > > > > layer. Considering your Service classes and your Dao classes should > > > be > > > > thread safe you will have no problem setting them as instance > > > > variables in the constructor. > > > > > > > > Brandon > > > > > > > > On 5/1/05, Gregg D Bolinger wrote: > > > > > Thanks for the reply. I actually did something similar to this > > > before > > > > > I saw your response. I made the following class > > > > > > > > > > DaoManagerLoader.java > > > > > public class DaoManagerLoader { > > > > > > > > > > public static final String DAO_XML_PATH =3D > > > > > "com/intrust/anykey/database/dao/iBatis/dao.xml"; > > > > > public static DaoManager daoManager =3D null; > > > > > > > > > > public static DaoManager getInstance() { > > > > > if (daoManager =3D=3D null){ > > > > > System.out.println("Need a new one"); > > > > > try{ > > > > > final Reader reader =3D > > > > > Resources.getResourceAsReader(DAO_XML_PATH); > > > > > daoManager =3D > > > DaoManagerBuilder.buildDaoManager(reader); > > > > > }catch(IOException e) { > > > > > e.printStackTrace(); > > > > > } > > > > > }else{ > > > > > System.out.println("Don't need a new one"); > > > > > } > > > > > return daoManager; > > > > > } > > > > > } > > > > > > > > > > And then in my XxxxServiceImpl I do: > > > > > > > > > > daoManager =3D DaoManagerLoader.getInstance(); > > > > > > > > > > That seems to work pretty good. With that being said, can I ask > > > > > another question. If I have my UserService, UserServiceImpl, > > > UserDao, > > > > > and UserDaoImpl all setup like the documentation states, and then > > > in > > > > > my application/web application I need to access the UserDAO, is > > > it > > > > > appropriate to instantiate it like this.... > > > > > > > > > > UserService userDAO =3D new UserServiceImpl(); > > > > > > > > > > Or am I supposed to do it a differnet way. I have attached the > > > files. > > > > > I'd really like to know if I am doing this correctly. Thanks. > > > > > > > > > > Gregg > > > > > > > > > > > > > > > On 5/2/05, Brandon Goodin wrote: > > > > > > Saw a typo! oopsie :-) > > > > > > > > > > > > " I would not place the dao in my base service class." > > > > > > > > > > > > Should be: > > > > > > "I would not place the dao manager in my base service class." > > > > > > > > > > > > On 5/1/05, Brandon Goodin wrote: > > > > > > > Hi Gregg, > > > > > > > > > > > > > > The dao manager does not parse it every time. It only parses > > > once. > > > > > > > > > > > > > > Also, I would do things a bit different than you are doing. I > > > would > > > > > > > not place the dao in my base service class. I would use a > > > DaoConfig > > > > > > > class that holds the DaoManager reference as an static final > > > instance > > > > > > > variable. I would setup my Service classes to contain > > > instance > > > > > > > variable DAO classes that are loaded via the DaoConfig class > > > in the > > > > > > > constructor. See the examples below. > > > > > > > > > > > > > > --- DaoConfig.java --- > > > > > > > public class DaoConfig { > > > > > > > > > > > > > > private static final DaoManager daoManager; > > > > > > > > > > > > > > static { > > > > > > > > > > > > > > try { > > > > > > > String resource =3D > > > "org/apache/ibatis/jgamestore/dao/sqlmap/dao.xml"; > > > > > > > Reader reader =3D > > > Resources.getResourceAsReader(resource); > > > > > > > daoManager =3D DaoManagerBuilder.buildDaoManager(reader= ); > > > > > > > } catch (Exception e) { > > > > > > > throw new RuntimeException("Could not initialize > > > DaoConfig. > > > > > > > Cause: " + e); > > > > > > > } > > > > > > > } > > > > > > > > > > > > > > public static DaoManager getDaoManager() { > > > > > > > return daoManager; > > > > > > > } > > > > > > > > > > > > > > } > > > > > > > > > > > > > > --- CatalogServiceImpl.java --- > > > > > > > > > > > > > > public class CatalogServiceImpl implements CatalogService { > > > > > > > > > > > > > > private DaoManager daoManager; > > > > > > > private CategoryDao categoryDao; > > > > > > > private ProductDao productDao; > > > > > > > private ProductImageDao productImageDao; > > > > > > > private ImageDao imageDao; > > > > > > > > > > > > > > /** > > > > > > > * regular empty constructor > > > > > > > */ > > > > > > > public CatalogServiceImpl() { > > > > > > > this.daoManager =3D DaoConfig.getDaoManager(); > > > > > > > this.categoryDao =3D (CategoryDao) > > > daoManager.getDao(CategoryDao.class); > > > > > > > this.productDao =3D (ProductDao) > > > daoManager.getDao(ProductDao.class); > > > > > > > this.productImageDao =3D (ProductImageDao) > > > > > > > daoManager.getDao(ProductImageDao.class); > > > > > > > this.imageDao =3D (ImageDao) > > > daoManager.getDao(ImageDao.class); > > > > > > > } > > > > > > > ... > > > > > > > > > > > > > > public void addProduct(Product product) { > > > > > > > try { > > > > > > > daoManager.startTransaction(); > > > > > > > > > > > > > > // save product > > > > > > > productDao.addProduct(product); > > > > > > > ... > > > > > > > daoManager.commitTransaction(); > > > > > > > } finally { > > > > > > > daoManager.endTransaction(); > > > > > > > } > > > > > > > } > > > > > > > > > > > > > > Hope that helps, > > > > > > > > > > > > > > It is a BAD policy to make your service layer dependent on > > > the > > > > > > > view/web layer. Your web layer can depend on your service > > > layer. > > > But, > > > > > > > your service layer should never depend on your web layer. > > > Likewise > > > > > > > your Service Layer can depend on your DAO layer. But, your > > > DAO layer > > > > > =3D=3D=3D message truncated =3D=3D=3D > > > > >=20 >