Feeling really good! ! ! Reprinted a small paragraph:
CatalogDaFactory
/ *
* Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in Source and Binary Forms, with or wel
* Modification, Are Permitted Provided That The Following Conditions
* Are Met:
*
* - Redistributions of Source Code Must Retain The Above Copyright
* NOTICE, this List of conditions and the folload disclaimer.
*
* - Redistribution in Binary Form Must Reproduce The Above Copyright
* Notice, this List of conditions and the following disclaimer in
* The documentation and / or other matials provided with the
* distribution.
*
* Neither The Name of Sun Microsystems, Inc. or the names of
* Contributors May Be Used to Endorse or Promote Products Derived
* From this Software Without Specific Prior Written Permission.
*
* This Software Is Provided "As IS," WITHOUT A WARRANTY OF ANY
* Kind. All Express or Implied Conditions, Reperestations and
* Warranties, Including Any Implied Warranty of Merchantability,
* Fitness for a Particular Purpose or non-infringement, Are Hereby
* Excluded. Sun and its licensors Shall Not Be Liable for Any DAMAGES
* SUFFERED by licensee as a result of using, modify
* Distributing The Software Or ITS DeriVATIVES. In no Event will sun
* OR ITS LICENSORS BE LIABLE for Any Lost Revenue, Profit or Data, OR
* For Direct, Indirect, Special, Consesequential, Incidental OR
* PUNTIVE DAMAGES, HOWEVER CAUSED AND Regardless of the theory of
* Liability, Arising Out of the use of or inain, to use software,
* Even if sunhas been advised of the Possibility of Such Damages.
*
* You Acknowledge That Software Is Not Designed, licensed or intended
* for use in the design, construction, Operation or Maintenance of * Any Nuclear Facility.
* /
Package com.sun.j2ee.blueprints.catalog.da;
Import javax.naming.namingexception;
Import javax.naming.initialcontext;
Import com.sun.j2ee.blueprints.catalog.util.jndinames;
Import com.sun.j2ee.blueprints.catalog.exceptions.catalogdaosysexception;
Public class catalogdaofactory {
/ **
* This Method Instantiates a Particular Subclass IMPLEMENTING
* The dao methods based on the information obtained from the information keta
* Deployment Descriptor
* /
Public static catalogdao getdao () throws catalogdaosystem {
Catalogdao catdao = null;
Try {
InitialContext IC = New InitialContext ();
String classname = (string) Ic.lookup (JNDINAMES.CATALOG_DAO_CLASS);
CATDAO = (CatalogDao) Class.Forname (classname) .newinstance ();
} catch (namingexception ne) {
Throw New CatalogDaosystemsException ("CatalogDaFactory.getdao: Namingexception while getting dao type: / n" ne.getMessage ());
} catch (exception se) {
Throw new catalogdaosystemsException ("CatalogDaFactory.GetDao: Exception While Getting Dao Type: / N" se.getMessage ());
}
Return CATDAO;
}
} Just explain :: DAO is the data access object, mainly for separating DB, etc., the main call mode of JPS is DAO Interface - Different DB with different DAO IMPLEMENT and these DAO import must be DAO Interface Implementation, DAO Factory is used to generate specific DAO objects, there is a different SQL statement in each specific DAO Implement, which can return the corresponding data, cut these DAOs to be called by EJB objects, so code is very beautiful! ! ! ! ! As follows: public class catalogjb imports sessionbean {
Protected catalogdao dau;
Public void ejbcreate () {
Try {
DAO = catalogdaofactory.getdao ();
}
Catch (CatalogDaosystemXception SE) {
Debug.println ("Exception Getting Dao" Se); throw new ejbexception (se.getMessage ());
}
}
Public void setsessionContext (sessioncontext sc) {}
Public void ejbremove () {}
// Activate is Empty for Stateless Session EJBS
Public void ejbactivate () {}
// Passivate is Empty for Stateless Session EJBS
Public void ejbpassiVate () {}
Public void destroy () {DAO = NULL;}
Public Category Getcategory (String CategoryID, Locale L) {
Try {
Return DAO.GETCATEGORY (CategoryID, L);
}
Catch (CatalogDaosystemXception SE) {
Throw new ejbexception (se.getMessage ());
}
}
Public Page getcategories (int Start, int count, local l) {
Try {
Return DAO.GETCATEGORIES (Start, Count, L);
}
Catch (CatalogDaosystemXception SE) {
Throw new ejbexception (se.getMessage ());
}
}
Public page getProducts (String CategoryID, int Start,
INT Count, Locale L) {
Try {
Return DAO.GETPRODUCTS (CategoryID, Start, Count, L);
}
Catch (CatalogDaosystemXception SE) {
Throw new ejbexception (se.getMessage ());
}
}
. . . . .