DAO question

I am working on a slightly different variation of DAO pattern as shown by Sun:
* I have 2 Singleton classes "MSSqlServerConnectionManager" and "OracleConnectionManager". ( For brevity I will consider only 1):
public class MSSqlServerConnectionManager {
public static String s_driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
public static String s_databaseUrl;
public static String s_userId;
public static String s_password;
public static Connection getConnection(  ) {
}* I have a DAO Factory "DAOFactory":
public abstract class DAOFactory {
public static final int MSSQLSERVER = 1;
public static final int ORACLE = 2;
public static DAOFactory getDAOFactory( int whichFactory ) {
switch (whichFactory) {
case MSSQLSERVER:
return new MSSqlServerDAOFactory();
case ORACLE:
return new OracleDAOFactory();
default:
return null;
// specifies the DAOs
}* I have 2 concrete DAO Factories for each DAO type which to get Connection call their respective ConnectionManagers:
public class MSSqlServerDAOFactory implements DAOFactory {
public static Connection getConnection() { returns MSSqlServerConnectionManager.getConnection(); }
public class OracleDAOFactory implements DAOFactory { ...
public static Connection getConnection() { returns OracleConnectionManager.getConnection(); }
}* Then I have the DAOs (as interfaces) and their implementation for each DAO type. In each DAO method the first statement is to call the getConnection() method. For example:
public interface CustomerDAO {
public int insertCustomer(...);
public class MSSqlServerCustomerDAO implements CustomerDAO {
public int insertCustomer(...) {
Connection conn = MSSqlServerDAOFactory.getConnection();
}First of all is this desgin ok?
Second the database url, user id and password are not hard-coded as users have choices in these areas. Right now after login they are available in the HttpSession. My question is at what time I needs to put them in the ConnectionManager?
Thirdly I want my connection mangers to also be able provide connection through jndi look up. In my development environment i want to use DriverManager; In QA environment i want to use jndi. How is it possible?
Thanks
thanks

ok I am confused. This is the final code I was thinking:
public interface ConnectionManager {
  public void configure( Properties properties );
  public Connection getConnection();
  public void closeConnection( Connection );
public class DriverManagerConnectionManager implements ConnectionManager {
  private String _driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
  private String _databaseUrl;
  private String _userId;
  private String _password;
  public void configure( Properties properties ) {
    _databaseUrl = properties.getProperty("DATABASEURL");
    _userId= properties.getProperty("USERID");
    _password= properties.getProperty("PASSWORD");
public class JNDIConnectionManager implements ConnectionManager {
  private String _jndiName;
  public void configure( Properties properties ) {
    _jndiName = properties.getProperty("JNDINAME");
public class ConnectionManagerFactory {
  public static final int DRIVERMANAGER = 1;
  public static final int JNDI = 2;
  public static ConnectionManager getConnectionManager( Properties properties ) {
  ConnectionManager connectionManager;
  int connectionClass = new Int(properties.getProperty("CONNECTIONCLASS")).intValue();
  switch ( connectionClass ) {
    case DRIVERMANAGER:
      connectionManager = new DriverManagerConnectionManager ();
    case JNDI:
      connectionManager = new JNDIConnectionManager ();
    default:
      return null;
  connectionManager.configure( properties );
  return connectionManager;
public abstract class DAOFactory {
  public static final int MSSQLSERVER = 1;
  public static final int ORACLE = 2;
  public static DAOFactory getDAOFactory( int whichFactory , ConnectionManager connectionManager ) {
    switch (whichFactory) {
      case MSSQLSERVER:
        return new MSSqlServerDAOFactory( connectionManager );
      case ORACLE:
        return new OracleDAOFactory( connectionManager );
      default:
        return null;
  // specifies the DAOs
public class MSSqlServerDAOFactory implements DAOFactory {
  private ConnectionManager _connectionManager;
  private MSSqlServerDAOFactory() {}
  public MSSqlServerDAOFactory( ConnectionManager connectionManager ) {
     _connectionManager = connectionManager;
  public static Connection getConnection() { returns _connectionManager.getConnection(); }
public class OracleDAOFactory implements DAOFactory {
  private ConnectionManager _connectionManager;
  private OracleDAOFactory() {}
  public OracleDAOFactory( ConnectionManager connectionManager ) {
     _connectionManager = connectionManager;
  public static Connection getConnection() { returns _connectionManager.getConnection(); }
public interface CustomerDAO {
  public int insertCustomer(...);
public class MSSqlServerCustomerDAO implements CustomerDAO {
  public int insertCustomer(...) {
    Connection conn = MSSqlServerDAOFactory.getConnection();
}the ConnectionManagerFactory is a class which hands out ConnectionManager interface. Each type (JNDI and DriverManager) implements the ConnectionManager interface with its own class. Then I passes that ConnectionManager interface to the DAO Factory.
Define an interface for the ConnectionFactory that
each type will implement (JNDI and DriverManager).First of all I am assuming that ConnectionFactory you mentioned is actually ConnectionManagerFactory. Please correct me if I am wrong.
If I understand correctly, what you are suggesting is to make ConnectionManagerFactory an interface. which will be implemented by each type. That means each type will be implementing 2 interfaces: ConnectionManagerFactory and ConnectionManager? Is it true? If yes then what is the reason?
I think I am understanding you wrong. Please explain.
Thanks

Similar Messages

  • Two DAO questions

    Hi all,
    I wrote a Session Bean that directly retrieved
    data from a DB using DataSource (obtained via JNDI code).
    If I want to use a DAO to separate the Session Bean
    from the DB can I put JNDI code, to get DataSource,
    into the DAO ?
    DAO can have a method that return, to the Session Bean,
    the Data Transfer Object that Session Bean will
    send to the client ? (the alternative is that Session
    Bean builds the DTO, after having called many DAO's methods).
    Many thanks in advance,
    Moreno

    U can put the JNDI code in DAO.About u r next question I think the "Session
    Bean builds the DTO, after having called many DAO's methods" is the best.
    Bye

  • Questions about DAO pattern

    Hi,
    I am a junior programmer and I am trying to understand somewhat more about best practices and design patterns.
    I am looking for more information regarding the DAO pattern, not the easy examples you find everywhere on the internet, but actual implementations of real world examples.
    Questions:
    1) Does a DAO always map with a single table in the database?
    2) Does a DAO contain any validation logic or is all validation logic contained in the Business Object?
    3) In a database I have 2 tables: Person and Address. As far as I understand the DAO pattern, I now create a PersonDAO and an AddressDAO who will perform the CRUD operations for the Person and Address objects. PersonDAO only has access to the Person table and AddressDAO only has access to the Address table. This seems correct to me, but what if I must be able to look up all persons who live in the same city? What if I also want to look up persons via their telephone numbers? I could add a findPersonByCity and findPersonByTelephoneNumber method to the PersonDAO, but that would result in the PersonDAO also accessing the Address table in the database (even though there already is an AddressDAO). Is that permitted? And why?
    I hope someone can help me out.
    Thanks for your time!
    Jeroen

    That is exactly what I am trying to do. I am writing it all myself to get a better understanding of it.
    Please bear with me, because there are some things I dont understand in your previous answer.
    1) Each BO validates his corresponding DTO and exposes operations to persist that DTO. Each DTO will be persisted in the database via his corresponding DAO. So this would be:
    - in PersonBO
    public void save(PersonDTO personDTO) {
    this.validate(personDTO); // does not validate the nested address DTOs
    this.personDAO.save(personDTO); // does not save the nested address DTOs
    - in AddressBO
    public void save(AddressDTO addressDTO) {
    this.validate(addressDTO);
    this.addressDAO.save(addressDTO);
    Am I viewing it from the right side now?
    2) Imagine a form designed to insert a new person in the database, it contains all fields for the Person DTO and 2 Address DTOs.
    How would I do this using my Business Objects?
    This is how I see it:
    // fill the DTOs
    daoManager.beginTransaction();
    try {
    personBO.setDao(daoManager.getDao(PersonDAO.class));
    personBO.save(personDTO); // save 1
    addressBO.setDao(daoManager.getDao(AddressDAO.class));
    addressBO.save(personDTO.getAddress(1)); // save 2
    addressBO.save(personDTO.getAddress(2)); // save 3
    daoManager.commit();
    catch(Exception e) {
    daoManager.rollBack();
    If I insert the transaction management inside the DAOs, I can never rollback save 1 when save 2 or save 3 fail.
    It can be that I am viewing it all wrong, please correct me if that is the case.
    Thanks!
    Jeroen

  • Questions about DAO

    Hi,
    we have some questions about DAO, Someone knows the answers?
    In versión 10g, one could create DAOs (Data Access Objects) from DB and then they could use them for extract and store data.
    In BPM 11g, how one could store information in the DB? How can they integrate them?
    Thanks in advance
    Antonio

    In 11g Database Adapters are used for direct access to the database. You add a DB adapter reference to your composite then this gets exposed as a service that can be invoked from the BPMN/BPEL process.
    Some documentation can be found here:
    http://download.oracle.com/docs/cd/E14571_01/integration.1111/e10231/adptr_db.htm#BGBBHJGC

  • A design question related to generic dao pattern

    I follow this link https://www.hibernate.org/328.html to design my DAO layer using jpa/ hibernate. And basically it works ok. However, I encounter a dilemma regarding to persistence relation between domain objects.
    My classes include
    User <--(many to many)--> Group
    Tables are USERS, USERS_GROUPS, GROUPS
    In User class, I have properties
         @JoinTable(name="USERS_GROUPS",
              joinColumns=
              @JoinColumn(name="USER_ID"),
              inverseJoinColumns=
              @JoinColumn(name="GROUP_ID")
         private List<Group> groups = new ArrayList<Group>();
         public User(String id, String account, String name, String password){
              this.id = id;
              this.account = account;
              this.name = name;
              this.password = password;
         public List<Group> getGroups(){
              return this.groups;
         public void setGroups(List<Group> groups){
              this.groups = groups;
         }In Group class,
         @ManyToMany(mappedBy="groups",fetch=FetchType.EAGER)
         private List<User> users;  
         public Group(String id, GroupName name){
              this.id = id;
              this.name = name;
         public List<User> getUsers(){
              return this.users;
         public void setUsers(List<User> users){
              this.users = users;
    ...Now in the database (mysql), I have already had two groups existing. They are
    mysql> select * from GROUPS;
    +----+------+
    | ID | NAME |
    +----+------+
    | 1  | Root |
    | 2  | User |
    +----+------+and in the table USERS_GROUPS
    mysql> select * from USERS_GROUPS;
    +--------------------------------------+----------------+
    | USER_ID                               | GROUP_ID |
    +--------------------------------------+----------------+
    | 1                                               | 1                 |
    | 1                                               | 2                 |
    +--------------------------------------+----------------+When I want to create a new user object and assig user object with an existing GROUP (e.g. GroupName.User)
    At the moment the way how I implement it is done in the DAO layer (e.g. UserDaoImpl). (But what I want is to get this procedure done in the domain object layer i.e. User class, not DAO layer. )
    steps:
    1.) search the GROUP table (entityManager.cerateQuery(" from Group").getReulstList())
    So it will return a list of all groups in GROUPS table.
    2.) then check if the group (e.g GroupName.User) I want to assign to the User object existing in the GROUP table or not.
    3.) if not existing, create a new Group and add it to a list; then User.setGroups(newList);
    or
    if the group (to be assigned to User class) already exists, use the group retrieved from the GROUP table and assign this group to the User class (e.g. groupList.add(groupFoundInGroupTable) User.setGroups(groupList))
    However, what I want to do is to encapsulate this procedure into User calss. So that in DAO class whilst performing function createUser(), it would only need to do
    User user = new User(....);
    user.addGroup(GroupName.User); // GroupName is an enum in which it contains two values - Root, User
    entityManager.merge(user);Unfortunately, because I need to obtaining Group collections from GROUP table first by using entityManager, which does not exist in the domain object (e.g. User class). So this road looks like blocked.
    I am thinking about this issue, but at the moment there is no better solution popped upon my head.
    Is there any chance that this procedure can be done more elegantly?
    I appreciate any suggestion.
    Edited by: shogun1234 on Oct 10, 2009 7:25 PM

    You should be able to link your objects using methods in your entities to create an object graph.
    When you save your user the associated objects will also be persisted based on the cascade types that you have specified on the relationships between the entities.

  • DAO pattern question

    According to the DAO pattern, all fields of the table has to be put in the class, e.g. if I have a table called customer, I have to create a Customer class and then I have another class called CustomerDAO class. In CustomerDAO, I should have a method called getCustomer that returns Customer. But if my table is quite large, and I don't need to get all the attributes of the customer every time, what approach should I use, do I define another method to return, e.g. customer name. customer age etc.? Is there any standard convention?
    Thanks

    hi,
    according to my understanding, u should use Value Object pattern.
    for Example:
    In Customer table if u have Id, name.
    then u have CustomerVO in which u have the following code.
    public class CustomerVO
    private Long id;
    private String name;
    public Long getID()
    return this.id;
    public String getName()
    return this.name;
    public void setID(Long id)
    return this.id=id;
    public String setName(String name)
    return this.name=name;
    So now u have craete object of CustomerVO and get ur required fields only and Enjoy!!!!!!!!!

  • Question about DAO pattern

    Greetings.
    If I'm using EJB's in my application when does DAO fits in?? I mean, it is DAO an alternative to EJB's or a complement ??
    Thanks in advance.

    DAO fits in if you are using entity beans using bean managed persistence. In this case, the DAO brokers the database calls during the EJB's lifecycle. The other instance when you would use DAO would be if you forgo entity beans altogether. In this model, stateful or stateless session beans would use DAO's to broker the database calls directly, outside of the normal entity bean lifecycle. The DAO pattern can also be used with POJO's (plain 'ole Java objects).
    The only instance where DAO would not apply is in the case of a container managed entity bean. In this case, there is no need to write a DAO, as the container will persist the bean for you.
    - Saish
    "My karma ran over your dogma." - Anon

  • Questions on DAO design

    This is the first time I used DAO design.
    I have a machine class and each machine has a few parts.
    How should I design the DAO? Especially regarding the inner parts.
    Should I create a DAO for machine and for part and put the PartDAO as an atribute of MachineDAO so that I can populate the Machine's parts with the help of PartDAOOr is it better to retrieve the parts directly when retrieving machine by JOINING the 2 tables (inside MachineDAO).
    Or are there other best practices regarding DAO design?
    Please help me,
    Thx in advance,
    David Limanus

    Right sorry. When you think from the user of the DAO
    yes, one DAO should deal with one object. Then when
    you start implementing the DAO, You will try to
    reduce the overall number of tables. I don't agree - the number of tables should be designed according to the data's needs and normalization rules, and the objects according to the problem's needs. Then you map one to the other. I don't understand what you mean by "reduce the overall number of tables".
    But its true
    that I may have 3 different DAOs that access the same
    table. Meaning that one may access the table directly and others JOIN to it? Yes.
    Also, that I have one DAO that uses multiple tables.Meaning JOINs? Yes.
    Actually what I tried was to handle one table from
    one class file. That didn't really work
    either because of the joins and subqueries.
    Inefficient by design: suffers from the (n+1)query
    problem.Could you explain that problem? It seems to work
    well for me and is easily managed.If you measure the performance and find that it meets your service level agreement, then it "works". But it depends on the number of Parts a Machine has, right? If you do one query for each Part, that means one network roundtrip for each one. As the number of Parts gets large, so does the number of network roundtrips. Since network latency is one of the biggest bottlenecks in your app, the more of them you do, the worse your performance.
    A Machine that requires a small number of Parts might perform fine, but if the number increases you might find that performance is unacceptable. Maybe yours is "working well" because your Machines are simple.
    %

  • Using DAO using a JDBC data source with struts

    Hello,
    I have created a number of Data Access Objects and Transfer Objects to use in a non EJB, struts web application I am developing. I had tested these with a kind of a Service Locator custom class to provide access to a JDBC connection. My custom class is a bit clunky and not very configurable. I would like to use a data source using the struts config XML file e.g.
        <data-sources>
            <!-- configuration for commons BasicDataSource -->
            <data-source type="org.apache.commons.dbcp.BasicDataSource">
                <set-property
                  property="description"
                  value="My MySQL Database Connection" />
                <set-property
                  property="driverClassName"
                  value="com.mysql.jdbc.Driver" />
                <set-property
                  property="url"
                  value="jdbc:mysql://localhost/databaseName" />
                <set-property
                  property="username"
                  value="myUsername" />
                <set-property
                  property="password"
                  value="xxxxxxxxx" />
                <set-property
                  property="maxActive"
                  value="10" />
                <set-property
                  property="maxWait"
                  value="5000" />
                <set-property
                  property="defaultAutoCommit"
                  value="false" />
                <set-property
                  property="defaultReadOnly"
                  value="false" />
             </data-source>
        </data-sources>This is great, and precisely the kind of thing I would like to use. However, this datasource is only available AFAIK through a HttpServletRequest instance like in the example I found below...
        public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                     HttpServletResponse response)     throws Exception
            javax.sql.DataSource dataSource = null;
            java.sql.Connection myConnection = null;
            try {
             dataSource = getDataSource(request);
             myConnection = dataSource.getConnection();
             // do what you wish with myConnection
            } catch (SQLException sqle) {
               getServlet().log("Connection.process", sqle);
            } finally {
               //enclose this in a finally block to make
               //sure the connection is closed
               try {
                  if(myConnection != null)
                      myConnection.close();
               } catch (SQLException e) {
                  getServlet().log("Connection.close", e);
            return (mapping.findForward("success"));
        }That would be great if I wanted to use the database connection anywhere near a struts Action (wrong tier!). I want access like that to to a data source in my DAOs. Is it possible for me to use the data-sources aproach to access the DB from my DAOs or will I need to use something like JNDI to do this in a similar way but separate from struts. If so I have a big gap in my knowledge as far as JNDI goes which I need to fill and that will be my next question
    I'm relatively new to using patterns inn Java and any help or pointers would be great.
    Thanks :)

    Create a JAAS Authentication Entry in the Server configuration.
    This should then appear in the drop-down when specifying your DataSource.

  • How to retrieve values from the struts DAO to Struts JSP

    Hi friends,
    I have one question. i want to display values in the struts jsp file from the struts DAO class. can anyone tell how do it.
    Appreciated for your help.
    Thanks
    G1 :)

    Hi Santosh,
    Thanks for your prompt reply.
    Actually, my problem is i want to display complete rows from the DAO to JSP page. I'm displaying all the rows in the DAO from DB.
    But i dont know how to retrieve all these data from DAO. Can i take arraylist.??
    DAO:
    ------------     public Customers getData(Customers customers){ // Reading data from DB
         //ArrayList list = null ;
         try
              Connection conn = getSQLConnection();
              Statement statement = conn.createStatement();
              String qry = "select * from register";
              ResultSet resultSet = null;
              PreparedStatement pstat = conn.prepareStatement(qry);
              // pstat.setString(1, customers.getFname());
              resultSet = pstat.executeQuery();
    //Print the data to the console
    while(resultSet.next()){
              String fnam = resultSet.getString(1);
              String lnam = resultSet.getString(2);
              String gen = resultSet.getString(3);
              String addres = resultSet.getString(4);
              String cit = resultSet.getString(5);
              String zip = resultSet.getString(6);
              String county = resultSet.getString(7);
              String emal = resultSet.getString(8);
              System.out.println("First name:"+fnam);
              System.out.println("Last name:"+lnam);
              System.out.println("Address:"+addres);
              customers.setFname(fnam);
              customers.setLname(lnam);
              customers.setGender(gen);
              customers.setAddress(addres);
              customers.setCity(cit);
              customers.setZipcode(zip);
              customers.setCountry(county);
              customers.setEmail(emal);
                   statement.close();
                   conn.close();
              }catch(Exception e1){
                   e1.printStackTrace();
              return customers;
    Bean:
    I have specified in this line in Bean:
    request.getSession().setAttribute("customers", customers);
    But in JSP. how will i populate all these data. Pls..send some code.
    I'm sorry this is just practicals. i'm not doin any real time project. that;s why i have placed all these code.
    Thanks for your patience for resolving my problems.
    Thanks
    G1

  • DAO and Domain Object

    hi,
    Normally when i want to persist a domain object like Customer object to a database, my statements will be below,
    // code from my facade
    Customer cust = new Customer();
    cust.setFirstName("myname");
    cust.setLastName("mylastname");
    // set another attributes
    cust.create();
    with this code i have a CustomerPersistence object to handler for create this customer record to a database. Now j2ee have a DAO pattern. So my question is,
    1.where is a domain object within DAO pattern? --> because of we can reused domain object.
    2.DTO is Domain Object, isn't it?
    3.when i look at some articles about DAO, many of it will present in this way
    facade -->create DTO --> call DAO (plus something about factory pattern)
    i never see something like this
    facade --> domain object --> dao
    any suggestion?
    anurakth
    sorry for my english!!

    Hi,
    I am a bit confused about implementation of the domain model and I wondered if you could help. My main concern is that I am introducing too many layers and data holders into the mix. Here is what I am thinking.
    DTO - used to carry data between the presentation and the services layer
    Service Class - coordinates the calling of domain objects
    Domain Object - models a domain entity, service layer logic specific to this object is to be implemented here.
    Data Object - an exact representation of a database table. many to many relationship between domain object and data object.
    Hibernate DAO Class - has no properties, just methods used for read and writing the object to the database. It is passed in the Data Object for persistence. Is it wrong that the DAO contains no properties?
    Perhaps the domain object will contain each data object it is comprised of. I was originally going to keep calls to DAOs in the Services class (as recommended in http://jroller.com/page/egervari/20050109#how_to_change_services_logic ) but I am thinking that each domain object could expose a save method, and that method would co-ordinate persisting itself to the various tables it is derived from.
    Does this sound resonable? I have trouble finding a pattern on the net that clealy defines the Domain Model. I was tempted to map Domain Objects directly to database tables, and simply persist the Domain Object, but this 1-1 relationship may not always hold true.
    Thanks.

  • Use of synchronisation with the SUN DAO Pattern

    With reference to the design pattern Core J2EE Patterns Data Access Object: http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
    I am writing a DAO package to handle access to multiple datasources at a record level (e.g. user records may be located at datasource A, but customer records at datasource B). The role of the package is to provide DAO objects to clients (e.g. business objects in an application package to come later). Nothing too unusual. I have digested the SUN design pattern for DAO.
    As I understand it, it can be summarised as: client code calls on an abstract DAOFactory to provide the appropriate concrete DAOFactory . The concrete factory can then supply the correct DAO object. The concrete DAOFactory is also responsible for providing the connection services (such as pooling). So far so good. I have pasted the concrete DAOFactory code form the design pattern page:
    // Cloudscape concrete DAO Factory implementation
    import java.sql.*;
    public class CloudscapeDAOFactory extends DAOFactory {
    public static final String DRIVER=
    "COM.cloudscape.core.RmiJdbcDriver";
    public static final String DBURL=
    "jdbc:cloudscape:rmi://localhost:1099/CoreJ2EEDB";
    // method to create Cloudscape connections
    public static Connection createConnection() {
    // Use DRIVER and DBURL to create a connection
    // Recommend connection pool implementation/usage
    *** can a connection pool be implemented in a static method? ***
    public CustomerDAO getCustomerDAO() {
    // CloudscapeCustomerDAO implements CustomerDAO
    return new CloudscapeCustomerDAO();
    public AccountDAO getAccountDAO() {
    // CloudscapeAccountDAO implements AccountDAO
    return new CloudscapeAccountDAO();
    public OrderDAO getOrderDAO() {
    // CloudscapeOrderDAO implements OrderDAO
    return new CloudscapeOrderDAO();
    I have some questions on this overall design.
    1)     The design for the factories as given looks inelegant and requires upgrading each time a new DAO is added ? much better surely to dynamically generate the DAOs using reflection. If I implement a mapping of data type to data source using a properties file (typical entry, Key = Role, Value = Oracle), the use of abstract and concrete factories can be reduced to a single factory. The single factory reads in the mapping on initialisation and provides a method getDAO to client code. The method takes the data type, looks up the data source and returns the correct DAO class using reflection (e.g. the client passes ?Role? to getDAO and the factory returns Oracle + DAO + Role = OracleDAORole.class). This also has the advantage that the client code does not need to specify the data source to use. I have read some forums and note that performance is an issue with reflection; however I have not seen any significant difference in performance between using reflection to generate a class name and using a factory pattern (e.g. testing just the code paths, for 10 million operations, both reflection and factory took 2.5 seconds each). Does anyone have any opinions on the pros and cons of this approach?
    2)     If we go with the original DAO design (ignoring 1 above) I have marked the part of the concrete factory code that I have a problem with: using a connection pool in the concrete factory. As the factory?s createConnection method is static, you cannot use NotifyAll or Wait methods here, and therefore you cannot synchronise access to the pool (correct?). I have therefore created a separate connection pool class (which uses the singleton pattern and uses synchronised methods to manage the pool). Is this a sensible way to approach this or is there a clever way to synchronise access to static methods?
    Thanks in advance - Alan

    These resources may be helpful:
    http://daoexamples.sourceforge.net/related.html
    http://daoexamples.sourceforge.net/index.html

  • Implementing DAO Pattern in ABAP

    This discussion implement DAO pattern asked the question of how to develop a DAO pattern in ABAP but i'd like to go a little deeper.
    The only answer given suggested the following design pattern:
    I don't have an coded example here, but isn't it sufficient for this pattern  to build an interface with some get- and set-methods? This interface can be implemented by several classes with different data retrieval logic. Then a static factory-method could do the job to decide during runtime which actual class is instantiated, returning the interface.
    Can anyone give an abstract description of this implementation relative to an SAP module (How would one approach this implementation in MM, PM, FICO, HR)
    Can anyone see any issues in this design?
    Can anyone provide an alternate design?
    Are we missing any steps?
    Together we can build a solid abap DAO everyone can use.

    I started to read about DAO pattern some days ago and found this great blog post:
    ABAP Unit Tests without database dependency - DAO concept
    I am starting to implement unit test in my developments and DAO pattern seems to be a clever choice.
    Regards,
    Felipe

  • Using DAO and DTO, or changing Patterns

    I have been working on a web project that revolves around scheduling events and enrolling people is said events. The schema is fairly straight forward, but does not lend itself well to OO, or at least what I have been used to. Before I get to the questions, I'll layout the basic idea of the trouble part of the schema.
    An Event has a 1:m relationship to Time Slots.
    A Time Slot has a 1:m relationship to Participants.
    A Time Slot also has a 1:M relationship to Tables.
    So, a given Event can run in multiple Time Slots, have multiple Participants in a Time Slot, and occupy multiple Tables in a Time Slot.
    Now, here's where I'd love some input because I know I'm lacking the experience. I've been reading in the forums here and in my books, many of which are included in the "must have" category as I've been reading here. I've adopted the DAO Pattern with DTOs the encompass the Event as a primary object/class. It has Lists which will get populated with the children. However, technically the way the schema is modelled, you cannot have participants or tables without a time slot. So, would I create separate bean or DTO to model the time slot that would also contains Lists for participants and tables? I imagine trying to represent nested relationships like the to a business layer might get hairy to maintain.
    So, in one scenario, an administrator would like to update event details, I'd use a findById() method to retrieve the full depth of the relationship in the schema.
    In a second scenario, a report is needed to list events, their times slots and tables in each time slot. Now, I have a List in my DTO that really has no need to be populated and would be wasteful to bring back from the database.
    A third scenario is a user comes to the site and wishes to search for events that they could enroll in. This time, for the search, I just want a few pieces from the primary table to displayed, I don't want to get the whole of the nested relationships and I want to get the search results by time slot. So, the way I've modelled the first DTO is now pretty much useless.
    So, is it better to construct to separate DTOs? I know I'd need different find() methods to support scenario 1 and 3. And in the case of retrieving non-needed data in scenario 2, should I provide a way to tell the DAO not to retrieve participants or just create yet another find() method that just doesn't populate participants?
    While I do have a say in the schema, I cannot just up and change it. I am more than willing to hear any and all critiques on code, schema, and how any part of this is implemented. As far as questions to why I'm not using Spring, Hibernate, or X framework, I just haven't had time to review them, but as this is still in design, it's fair game.
    Thanks in advance.

    >
    So, in one scenario, an administrator would like to
    update event details, I'd use a findById() method to
    retrieve the full depth of the relationship in the
    schema.
    In a second scenario, a report is needed to list
    events, their times slots and tables in each time
    slot. Now, I have a List in my DTO that really has
    no need to be populated and would be wasteful to
    bring back from the database.
    Ok - so don't do it.
    A third scenario is a user comes to the site and
    wishes to search for events that they could enroll
    in. This time, for the search, I just want a few
    pieces from the primary table to displayed, I don't
    want to get the whole of the nested relationships and
    I want to get the search results by time slot. So,
    the way I've modelled the first DTO is now pretty
    much useless.
    You can have more than one DTO. Or just don't populate everything in some cases.

  • JDO or JDBC that is the question?

    I've noticed that there is alot more postings regaurding JDBC rather than JDO.
    Is this the correct fourm for questions reguarding JDO or is JDBC people's prefferd choice?
    Ideally i would prefer to use JDO. But if there is little support, then im going to have to resort to JDBC.

    The relational model has a lot going for it that the
    object model does not:
    (1) A mathematical basis (set theory),Give me the intersection of these two collections of objects.
    (2) A ubiquitous, standard language (SQL),EJBQL
    (3) A huge installed base,Agreed.
    (4) Familiar to a large user and client community,Depends on who you talk to. Thinking of data as Collections of Entity beans is a natural fit to me, and I have no qualms about abstracting away the data layer to fit this model. I've had much success using CMP Entities.
    (5) Large institutions have critical data tied up in
    them (e.g., banks)Agreed. However, J2EE 1.4 spec. allows you to map relationships and object instances to database tables, so you can add the Object representation later.
    (6) No compelling reason to switch.Agreed. Adding the Object representation would take considerable work. If the developers working with the data are happy to stay with plain old DAOs and write SQL themselves, then there's definitely no reason to switch. As J2EE technology matures, however, the benefits of having the Object representation available will become clearer. IMHO, teaching OO developers to treat their data as objects as well can only lead to Good Things(tm).
    Brian

Maybe you are looking for

  • Sending an error/ok to sender web service

    Hi I'm using a SOAP(async) adapter to receive and send messages from and to a web service. The sender party would like to receive a error/ok status from XI if the SOAP message was delivered successfully. Can someone please advise here. Thanks in adva

  • Broadcom BCM4331 drivers - b43 can't scan, wl won't install

    I have a Macbook Pro 9,2 with a Broadcom BCM4331 wireless card. I've had issues with the wireless card ever since switching to Arch a bit over a year ago, and I'm trying to fix them once-and-for-all, but I'm not having much luck. Right now, if I use

  • Inbound Error message in SMQ2

    Dear All Experts, 1 ) I am facing one error in SMQ2 of SRM sytem that XI restart in qRFC not allowed. I am having the scenario ECC->XI->SRM. The messages are getting stuck in both XI system and SRM system. The contents of the errored message in SRM i

  • Error while linking dms document with cProject.

    Hi,    I am encountering an error while try to link the document in cProject under SAP DMS tab. The error message is Link Not Possible: The SAP R/3 DMS document info record contains orig (Message number 26 000). Pls help me out to solve the this issu

  • PO related question

    Hi All, i have a problem to use CDPOS table and you may be knowing y. please let me know if the in the EDI tech. if the RFCUSER changes the details in the PO the confirmation no ie(sequential no.) gets incremented and the data is updated. but i want