FileDocCategorySizeDatePackage
PersonDAO.javaAPI DocExample5889Thu Dec 15 21:42:18 GMT 2005com.oreilly.jent.people

PersonDAO

public abstract class PersonDAO extends Object
Interface to a data access object for Person objects. This provides a facade that hides the particulars of the persistence scheme from the rest of the application, allowing us to swap in/out different implementations if the persistence changes.
author
Jim Farley

Fields Summary
public static Logger
sLog
private static PersonDAO
sDAO
private static final String
sDefaultConfig
public static final String
FIRST_NAME
public static final String
LAST_NAME
public static final String
EMAIL
Constructors Summary
Methods Summary
public abstract java.util.CollectionfindPeople(java.util.Map searchParams)
Search method. Search parameters are given as name/value pairs in the Map argument. Known subclasses currently support the following search parameter names: "firstName": Pattern matched against first names. "lastName" : Pattern matched against last names. "email" : Pattern matches against email addresses. The known implementations also all support the "*" wildcard, converting it to the appropriate search syntax for their underlying persistence scheme. If no search parameters are given, or if unsuported search parameters are given, the DAO implementation should throw an InvalidSearchException.

public abstract PersonfindPerson(java.lang.String id)
Find a person, given their unique identifier.

public abstract PersonfindPersonByAcct(java.lang.String acctID)
Match a person to a given login account. If no match possible, throw an InvalidSearchException.

public static com.oreilly.jent.people.PersonDAOgetInstance()
Accessor for the PersonDAO singleton

        if (sDAO == null) {
            initSingleton(sDefaultConfig);
        }
        return sDAO;
    
public abstract voidinit(com.oreilly.jent.people.util.ConfigSet config)
Initialize the DAO from the data provided in the config file. Sub-classes implement this method to look for implementation-specific config parameters.

public static voidinitSingleton(java.lang.String configRef)

    
    // Static initializer of PersonDAO singleton.  Reads configuration
    // parameters from an XML file loaded from the classpath using the 
    // reference passed as an argument.
    //
    // The classpath reference must point to an XML file with the format:
    //
    //     <dao>
    //         <classname>org.jsmith.MyPersonDAOImpl</classname>
    //         <parameters>
    //           <my-param-1>foo</my-param-1>
    //           <my-param-2>bar</my-param-2>
    //         </parameters>
    //     </dao>
    //
    // The classname in the config file will be used to initialize a DAO 
    // implementation (using reflection to invoke the no-argument constructor
    // on the named class).  Then the entire config set will be passed to the 
    // DAO's init() method as a ConfigSet instance, so it can parse any
    // implementation-specific parameters from the rest of the file.
    
         
        try {
            sLog.info("Initializing from " + configRef);
            ConfigSet config = new ConfigSet(configRef);
            String daoClass = config.getParameter("dao.classname");
            sDAO = (PersonDAO)Class.forName(daoClass).newInstance();
            sDAO.init(config);
        }
        catch (IllegalArgumentException iae1) {
            sLog.severe("Failed to initialize ConfigReader: " + 
                        iae1.getMessage());
        }
        catch (InstantiationException ie) {
            sLog.severe("Failed to initialize PersonDAO singleton: " + 
                        ie.getMessage());
        }
        catch (IllegalAccessException iae2) {
            sLog.severe("Failed to initialize PersonDAO singleton: " + 
                        iae2.getMessage());
        }
        catch (ClassNotFoundException cnfe) {
            sLog.severe("Failed to initialize PersonDAO singleton: " + 
                        cnfe.getMessage());
        }