.NET
  Home arrow .NET arrow Page 2 - Providing a Complete Data Persistence Solu...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Providing a Complete Data Persistence Solution
By: Dwight Peltzer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 5
    2005-04-27

    Table of Contents:
  • Providing a Complete Data Persistence Solution
  • A Mapping Architectural Overview
  • Mapping Tool Types
  • Writing XML, Reading from Java

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Providing a Complete Data Persistence Solution - A Mapping Architectural Overview


    (Page 2 of 4 )

    Mapping data requires using a series of primary classes to map data. Let’s put together a Java Mapper series of interfaces that encapsulate common mapping behavior required to create, update, delete, and read from a relational database. The interfaces presented here conform to the Model, View, and Controller (MVC) design pattern so widely adopted in most distributed enterprise applications today. Note that the Java Mapper interface is independent from both the domain model and persistence technologies, as should be the case with all data mappings. The JDBCMapper interface represents an abstract implementation of the JDBC interface.

    Examples

    Let’s extract some methods from the JDBC Mapper Interfaces and see how they work.

    Below are two examples demonstrating how you could implement a Mapper method.

    public void update (DomainObject domainObject)
    throws NoSuchObjectException {
      Connection cn = null;
      try { 
          cn = getConnection();
          updateImpl(cn,domainObject);
      }catch (Exception e) { 
          System.out.println(“Exception “ + e + “caught in update()”);
      throw new NoSuchObjectException(“Wrapped
    Exception“ + e + “caught in update()”);
      }finally { close(cn);
        }
    }
    protected abstract void updateImpl(Connection cn, DomainObject 
                                       anObject;
        throws SQLException, MappingException;

    We have presented two methods, public void update(), and protected abstract void updateImpl(). The first method implements the JDBC-specific interface by managing connection-management and JDBC exception handling. The second method calls the abstract method updateImpl, a representation of the domain model object-related behavior. The domain object-specific mapper must implement the abstract Impl methods in order to create, update, delete, and read instances of the object in the relational database. You must call the abstract activate method in order for it to be implemented by domain object-specific subclasses. The RegistrantMapper doActivate() and passivate() methods execute the mappings to and from the results, reading and/or updating the relational database.

    Here are examples of both of the doActivate and passivate methods.

    protected void doActivate(DomainObject <insert
    variable here>,ResultSet rs)
      throws SQLException, MappingException {
      Registrant r = (Registrant)domainObject;
      r.setName(rs.getString(2));
      r.setAddress(new address (r));
      r.getAddress().setStreet (rs.getString(3));
      r.getAddress().setCity(rs.getString(4));

    }
    protected void passivate (DomainObject <insert
    variable here>, PreparedStatement ps) 
    throws SqlException, Mapping Exception { 
    Registrant r = (Registrant) domainObject; 
    ps.setString(1, r.getId()); 
    ps.setString(2.r.getName()); 
    if (r.getAddress() != null){
        ps.setString(3, r.getAddress() 
    .setStreet());
    ps.setString(4, r.getAddress().getCity());
        }
    }



    Also notice how the RegistrantMapper interface provides the necessary SQL statements to execute the abstract Impl() methods such as read, create, update, and delete. For example, the createImpl method creates a database row and maps the registrant department attributes to the columns in the expression that match the primary key of the table.

    The other mapper interfaces, including MapperRegistry, DomainObject, and UnitOfWork, are interfaces provided by Martin Fowler in his Patterns of Enterprise Application Architecture, published by Addison-Wesley. The MapperRegistry interface provides access to specific mappers being used for each unique object residing in the domain model. The UnitOfWork interface maintains a list of objects affected by a business transaction and coordinates the writing of changes.

    Figure 1 JDBC interfaces that facilitate mapping from Java to a relational database.

    More .NET Articles
    More By Dwight Peltzer


     

    .NET ARTICLES

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT