DAO Pattern and the ServiceLocator

I have been developing a lightweight framework for working with AIR and the SQL API. This framework has no dependencies on Cairngorm however it is built around a typical DAO implementation.
While developing this I considered how it should be integrated with Cairngorm, which lead me to wonder if a simple DAO marker interface which could be retrieved from the ServiceLocator (and cast to the correct abstraction by a business delegate) would not be all that is needed to have a rather flexible service layer in Cairngorm?
For example, consider the following pseudo code which is what I would imagine a business delegate to look like:
class FooDelegate {
protected fooDAO:IFooDAO;
public FooDelegate(responder:IResponder) {
fooDAO = ServiceLocator.getinstance().getDAO(Service.FOODAO) as IFooDAO;
fooDAO.addResponder( responder );
public getFoo() void {
fooDAO.getFoo();
public addFoo(foo:IFoo) {
fooDAO.addFoo(foo);
public deleteFoo(foo:IFoo) {
fooDAO.deleteFoo(foo);
As you can see the delegate would cast the dao to the correct abstraction and then just wrap the DAOs API (somewhat similar to an Assembler in LCDS).
A custom DAO interface would extend the DAO marker interface so that the ServiceLocator could find it:
interface IFooDAO extends IDAO
getFoo() void;
addFoo(foo:IFoo);
deleteFoo(foo:IFoo);
Service.mxml would define an instance of the dao as an abstraction and then call a factory to get the appropriate implementation:
public fooDAO:IFooDAO = DAOFactory.getDAO("foo");
I see much potential in this type of implementation as it would allow services to be swaped out with different implementations via a config or with an IoC implementation etc, thus allowing the services themselves to be completely transparent to client code.
I wanted to see if anyone had any thoughts on this as well?
Best,
Eric

Thanks, duffymo, that makes sense. However ... having read through numerous threads in which you voice your opinion of the DAO World According to Sun, I'd be interested to know your thoughts on the following ...
Basically, I'm in the process of proposing an enterprise system architecture, which will use DAO as the primary persistence abstraction, and DAO + JPA in the particular case of persistence to a RDBMS. In doing so, I'd like to illustrate the various elements of the DAO pattern, a la the standard class diagram that relates BusinessObject / DataAccessObject / DataSource / TransferObject (http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html). With reference to this model, I know that you have a view on the concept of TransferObject (aka ValueObject?) - how would you depict the DAO pattern in its most generic form? Or is the concept of a generic DAO pattern compromised by the specific implementation that is used (in this case JPA)?

Similar Messages

  • Is dao pattern is the best practice in projects

    let me know if dao pattern is the best followed in all almost all the
    projects though finding alternatives to it. please clarify this for me and also i do want to know the best practices of the industry in using design patterns.

    There is no 'best' pattern. It is just all abouthow
    and where to apply them. This is very true,but these are common
    design patterns used in industry for standard
    problems.
    ost of the time patterns are used not for some
    special reason but for more manageability and ease of
    change.So if you have a small application than it's
    ok but if you are working on big application which
    are needed to be maintained over a time and changes
    are frequent.Than its better to start learning about
    patterns because their will be problems which right
    now you can't see but eventually you have to take
    care of.That is either incorrect or phrased poorly.
    Patterns come about because someone analyzes different existing code bases and notes that there are similarities in the way they are built.
    It isn't that they are easier to maintain but rather that because the pattern has similarities it is easier to comprehend, understand the limitations, understand the possible related patterns, etc. That might lead to easier maintainance but it isn't the reason. The reason is because, if and only if, the requirements/architecture lead to a situation where that pattern could be properly used.

  • DAO pattern and Java Persistence API

    Hi
    This is a question for anyone who might be familiar with the standard DAO design pattern and the Java Persistence API (JPA - part of EJB3). I'm new to this technology, so apologies for any terminology aberrations.
    I am developing the overall architecture for an enterprise system. I intend to use the DAO pattern as the conceptual basis for all data access - this data will reside in a number of forms (e.g. RDBMS, flat file). In the specific case of the RDBMS, I intend to use JPA. My understanding of JPA is that it does/can support the DAO concept, but I'm struggling to get my head around how the two ideas (can be made to) relate to each other.
    For example, the DAO pattern is all about how business objects, data access objects, data transfer objects, data sources, etc relate to each other; JPA is all about entities and persistence units/contexts relate to each other. Further, JPA uses ORM, which is not a DAO concept.
    So, to summarise - can DAO and JPA work together and if so how?
    Thanks
    P.S. Please let me know if you think this topic would be more visible in another forum (e.g. EJB).

    Thanks, duffymo, that makes sense. However ... having read through numerous threads in which you voice your opinion of the DAO World According to Sun, I'd be interested to know your thoughts on the following ...
    Basically, I'm in the process of proposing an enterprise system architecture, which will use DAO as the primary persistence abstraction, and DAO + JPA in the particular case of persistence to a RDBMS. In doing so, I'd like to illustrate the various elements of the DAO pattern, a la the standard class diagram that relates BusinessObject / DataAccessObject / DataSource / TransferObject (http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html). With reference to this model, I know that you have a view on the concept of TransferObject (aka ValueObject?) - how would you depict the DAO pattern in its most generic form? Or is the concept of a generic DAO pattern compromised by the specific implementation that is used (in this case JPA)?

  • Hibernate, DAO pattern and tree hierarchy

    Hi all,
    I use Hibernate for a short period of time and now I'm facing a complex problem . I try figure it out what is the best practice for the following scenario:
    I have the following classes: Department, Team, Position, all of them inherited from a Entity class even there is almost no difference between them. But I wanted different classes for different entities.
    I try to create a tree hierachy, each object is with all others in a bidirectional one-to-many relationship. For example a Department can have Teams and Positions as children and a Position can have Departments and Teams as children.
    I created the mapping files and I don't know how to create all necessary methods without duplicating the code.
    Questions:
    1. Do I need a DAO pattern implemented for this design?
    2. Can you recomend some documentation or ideas that will help me find out what is the best approach in this case?
    Thanks

    Write the DAO for the class that is the root of the tree. Sounds like it should be DepartmentDao.
    I don't know of much better documentation than the Hibernate docs. Check their forum, too.
    %

  • 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

  • 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

  • DAO pattern & Lookup datasource with NamingException in the same J2EE APP

    Hello Experts:
    I'm developing an J2EE application with EJB's for transactional operations (that works fine!) and I'm implementing the J2EE DAO Pattern using a DAO ConnectionFactory with OpenSQL/JDBC standard for Querying the DB, but here my problems begins:
    The DAOConnectionFactory Singleton Class is placed in a java package inside the same application that holds my Entitys & Sessions (remember this ejb's works fine!) and I'm trying to get the "localy-configured-in-the-j2ee-application" alias-datasource for my DAO Querys, but "lookup" doesn't find this resource!!!.
    I'm thinking, there's not remote access to this resouce because the DAO-CF is in the same context and JVM, but this appreciation is correct? or  what I miss?
    Another remark: I've been used the Telnet Administrator and the same lookup string is founded correctly!.
    Here is the Codec:
    public class ConexionFactory implements Serializable {
         private static ConexionFactory singleton = null;
         private DataSource ds;
         protected ConexionFactory() {
              String source = "jdbc/BURO_COMM";
              try {
                   Context ctx = new InitialContext();
                   ds = (DataSource) ctx.lookup(source);
                   if (null == ds) {
                        throw new RuntimeException("Couldn't get the datasource");
              } catch (NameNotFoundException e) {
                   throw new RuntimeException(e.getMessage());
              } catch (NamingException e) {
                   throw new RuntimeException(e.getMessage());
         public static ConexionFactory getInstance() {
              if (null == singleton) {
                   singleton = new ConexionFactory();
              return singleton;
    .... (some other methods)

    Hello all again:
    I've been making some tests (and investigation reading other posts) and I found that everything is related with the Resource Sharing Scope of my Session Object that commands the process. And it works fine.
    By now, for my conceptual test is Ok and finally i must work in this app arquitecure path:
    ->Web Service (with a POJO in a web module)
    >ProcessRender Class (a POJO with the main control logic)
    >BussinesDelegate's -->ServiceLocator
    >SessionFacades --->Entity's
    >DAO Connection Factory---->OpenSQL/JDBC Querys

  • 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

  • DAO pattern Value Objects and Data Streams

    Suppose we have a PersonVO (java bean) with simple attributes i.e. first and last name then the DAO is quite simple and clients of the DAO layer pass VO back and forth (really cleanly).
    But it is a different story if a person has a picture. If the picture is small then we
    could define a field that is simple an array of bytes i.e. byte pic[], and would work ,
    but will not scale if our pic becomes too large or there are lots of persons.
    How can streams be used in this case ? (without dao code leaking into the client layer) and does this break the DAO pattern ?

    I can picture not saving the image bytes themselves
    but a link to a JPG or GIF on the file system.And how would that be guarenteed on a cluster? Or even per OS?
    Putting streams into a database like that can choke
    performance. Can't do WHERE clauses on byte
    streams.For example in PostgreSQL:
    CREATE TABLE images (
      name VARCHAR(32) NOT NULL,
      image bytea NOT NULL,
      imagetype VARCHAR(4),
      CONSTRAINT image_pk PRIMARY KEY (name)
    );After retrieving the image into a byte[] you can either
    - directly serve it to the client (browser) over HTTP through a servlet
    (don't forget to set your content type through HttpServletResponse.setContentType())
    - convert the byte[] to a java.awt.image.BufferedImage using javax.imageio.ImageIO.read(byte[]), and ofcourse do everything you want (including transformations) from there.
    - What ever you can think off.
    Now if you're passing that VO to a JSP, the link to
    the image on the server file system fits nicely into
    the <img> tag and Bob's your uncle.But this will still not be guarenteed to work on a cluster, across platforms, etc.
    10 % 0
    java.lang.ArithmeticException: / by zero;-)

  • How do I watch a movie downloaded to my MacBook on my ATV?     The movie works fine on the computer but I just get a checkerboard pattern on the TV screen with audio but no video.  Apple support is useless and suggested that I reload the software...

    Just downloaded a HD movie to my computer (brand new MacBook Pro, all software up to date) and can't watch it on my Apple TV (brand new last year, all software upto date).  Using Airplay mirroring works fine in general but when I press play on the movie I lose the picture and get only a checkerboard pattern and sound.  Another MacBook we have gives a black screen with no sound.  Apple assistance is completely useless.  They suggested that I download the most recent software (all upto date), reload the movie (done and no help) or read the FAQs (no help, although this board suggests that there is a fundamental compatibility issue with mirroring of HD content...!)   That's what the ATV is for!   The new MacBook uses a different connector and I can't plug it directly into the monitor input on my TV with the connector I had from the old computer.   I ordered a new connector for fifty bucks and they stupidly sent it UPS with a signature required for delivery since it is such a high value item so now I have a hassle to receive it.  In any case plugging in a wire from across the room isn't a solution.  Is there any way to make all of this supposedly integrated hardware and software work or has Apple completely lost their way and turned into a Microsoft clone?   Hopefully some of their market mavens will read this and steer the ship back on course.  In the meantime any help you may provide would be much appreciated.

    The movie is from iTunes.   You would think that a download from iTunes to a MacBook could be watched on an HDTV using Apple TV without any headaches bit this does not appear to be the case. 

  • I am using the pattern stamp tool. when i select my pattern it adds a hatching to teh source pattern and copies that hatching to the destination image

    I am using the pattern stamp tool. when i select my pattern it adds a hatching to the source pattern and copies that hatching to the destination image

    Please post screenshots to illustrate what you are talking about.

  • Desktop appearance problem:  For no apparent reason my Mac running OSX 10.4.11 imposed a mesh-like pattern over the folders on my desktop and also across the top of the screen and down the right-hand side where I have the dock.  How do I remove it?

    For no apparent reason my Mac (2 GHz PowerPC G5) running 10.4.11 has put a mesh-like pattern over the folders on my desktop and also a band of the same pattern across the top of the screen and down the right-hand side over the dock.  (See screen grabs below.)
    It doesn't affect any operations but makes folder names and drop-down menus difficult to read through the pattern.
    I'm not aware of changing any settings so suspect I must have clicked on something without noticing.  How do I get rid of the overlaid pattern, please?

    Information about my computer is as follows:
    Machine Name:          iMac G5
    Machine Model:          PowerMac8,2
    CPU Type:          PowerPC G5  (3.1)
    Number Of CPUs:          1
    CPU Speed:          2 GHz
    L2 Cache (per CPU):          512 KB
    Memory:          1 GB
    Bus Speed:          667 MHz
    Boot ROM Version:          5.2.5f1
    It looks like this at the back:

  • Satellite Pro 6000 locks up and the screen has weird random pattern

    Hi
    I recently bought a SP6000 second hand advertised as having "graphics problems". After 10 minutes or so use the laptop locks up and the screen has a weird random pattern all acorss it. The speakers also make a strange buzzing sound. i have to shut down the laptop and reboot.
    I updated the bios and the videocard drivers from the toshiba site but it is still doing it. Can anyone help?

    You need to make sure that you have a very steady hand and you have a .4mm soldering tip. The joins are very close and surface mounted, one slip of your hand and you can end up soldering 3 or 4 of the connections together and then spend 30 minutes trying to desolder them.
    Just like the page said, use a dental pick, or a small plastic pin and see if you can move any of the pins around. I must warn you though, the more you press down and flex the laptop to turn it on the more damage you have probably done to the pins, you may end up with about 8 of them disconnected from the board. Dont use a high wattage soldering iron either...10 to 15watt iron should do the trick. Tin the tip, let it heat up and tap the join between the board and the pin for 1 or 2 seconds and it should do the trick. Easy way to know is you should have a nice shiny bead of solder connecting the pin to the board. If you have that then it has taken. if you see only a dull grey colour then it hasnt taken and is a "dry" solder joint.
    One thing you should do before soldering, take some non abrasive rubbing alcohol, dip a cotton swab and rub all along the joins in the top and bottom. Solder oxidises after time...if you dont take the oxidisation off your more than likely to suffer from dry joints. The pins on the right of the connector (front of the laptop facing you" will probably be the ones which have came loose...check them first on the top and bottom of the connector.

  • I am using Photoshop CC2014 15.00.  In the pop-up menu for the Fill command there is a place for Scripted patterns.  Within that part, the tree and the picture frame are grayed. Why?   I've seen demonstrations on how to use the feature but mine doesn't wo

    I am using Photoshop CC2014 15.00.  In the pop-up menu for the Fill command there is a place for Scripted patterns.  Within that part, the tree and the picture frame are grayed.
    Why?   I've seen demonstrations on how to use the feature but mine doesn't work.  I checked the updates and I have the current version.
    Thanks.      LM

    I am running CC 2014.2.1 and I've updated to Yosemite. Not seeing tree or frame as an option in the menu. Coworker still on Mavericks has it.

  • Using a two separate 6534 cards I'm trying to code-up a simple test for my UUT (memory device). I need to write a pattern into the device and read back the pattern and verify it matches the value written.

    I need the simplest method of using two 6534 cards for a memory (UUT) test. I want to write (byte-wide) a pattern (A5,5A) into the UUT, then read it back and verify it matches the value written. Things that change are: Address inputs (increment by 1 for each read/write) with the control signals (card 1) and data values written/read (card 2). If I detect a mis-match, the test stops, I read the location one more time and verify it's really incorrect, the correct value is written back into the same location just read, a counter is incremented to keep track of the tota
    l errors detected and the test (memory read/verify) is resumed. Each time through the memory another counter is incremented to track the number of passes through the memory read test. The test should terminate when the operator hits the VI panel STOP TEST button.

    Dave
    Check out chapter two of the 653x User Manual for information on the different modes of operation. There it explains the difference between strobed and unstrobed I/O as well as Pattern I/O and Handshaking. It sounds as though unstrobed should work unless your UUT requires hardware timing or handshaking. You will have to keep track of errors in software however since the 6534 does not have any counters on it.
    Brian

Maybe you are looking for

  • Small Parcel Shipping and Manifesting Systems

    What small parcel shipping and manifesting system are you using? Is it integrated with SAP? What are the pros and cons? We are researching systems and would appreciate any input. We are familiar with XPS and Shiptec, but are there others that you wou

  • How to use local interface in my easy code ?

    hi everybody I work on an ejb project. My code is like that to test remote interface (and it works) : public class TestStudent {    Properties properties;    public TestStudent() {       properties = new Properties();       properties.put("java.namin

  • Returns to AR integration

    My ct's requirement is to create AR Invoice for Purchase Returns. I don't think this integration is provided out of the box. Has anyone else faced this requirement before and what solution did you implement? If you had to customize, how hard was it t

  • Where can I download weblogic 9.0 DTD file

    Where can I download weblogic 9.0 DTD file? such as the DTD for weblogic-ejb-jar.dtd. Thanks Zhong

  • Depreciation Run gone wrong for Manual Assets

    Hi All We ran the depreciation run for period 4 - and now we see that the 2 manual assets are wrong because after changing the depreciation key from LINS to MANU - I forgot to 'recalculate values'  of the asset again so now the depreciation posted fo