FileDocCategorySizeDatePackage
PatientDAOFactory.javaAPI DocExample1530Mon Nov 24 10:02:44 GMT 2003com.oreilly.patterns.chapter8

PatientDAOFactory

public class PatientDAOFactory extends Object

Fields Summary
private static final int
DAO_ORACLE
private static final int
DAO_DB2
private static final int
DAO_SYBASE
private static final int
DAO_LDAP
private static final int
DAO_NONE
private int
mode
Constructors Summary
public PatientDAOFactory()


      
        String dataSource = System.getProperty("app.datasource");
        if ("oracle".equalsIgnoreCase(dataSource))
            mode = DAO_ORACLE;
        else if ("db2".equalsIgnoreCase(dataSource))
            mode = DAO_DB2;
        else if ("sybase".equalsIgnoreCase(dataSource))
            mode = DAO_SYBASE;
        else if ("ldap".equalsIgnoreCase(dataSource))
            mode = DAO_LDAP;
    
Methods Summary
public PatientDAOgetPatientDAO()

        switch (mode) {
            case DAO_ORACLE:
                return new PatientDatabaseDAO(); // Generic, works with Oracle
            case DAO_DB2:
                return new PatientDatabaseDAO(); // also works with DB2
                // case DAO_SYBASE:   // We didn't actually implement these.
                //  return new PatientSybaseDAO(); // But Sybase needs special treatment
                // case DAO_LDAP:
                //   return new PatientLDAPDAO(); // Or we can just hit the directory
            default:
                throw new DAOCreationException("No Data Access Mechanism Configured");
        }