DAO CRUD Qualifier Pattern

Discussions

Performance and scalability: DAO CRUD Qualifier Pattern

  1. DAO CRUD Qualifier Pattern (1 messages)

    I have been working with an architect who is forcing this implementation of our DAO layer. I think that it is crazy but I would like other opinions.

    DAOs will be used to call stored procedures, which contains extensive business logic. The architect designed a persistence framework that acts as a black box to the business layer.

    1. All DAOs are allowed to have only 4 CRUD methods, so if a stored procedure does several things, we just put it under the update method.

    2. When multiple stored procedures are grouped under one DAO, we use qualifiers to differentiate them.

    3. In the business layer (EJBs), we write:
    public ReviewXXXOrderRes reviewXXXOrder(ReviewXXXOrderReq request) {

    init(request);
    //persistence layer will use qualifiers to locate stored procedures and call it.
    ReviewXXXOrderSO tvSO = (ReviewXXXOrderSO) PersistenceService.getInstance().create(request, QUALIFIER_INSERT_ORDER);

    return tvResponse;
    }

    4. In the following sample DAO code, the persistence framework will callback the processException, getParameters and getResult methods. Note the AbstractServiceRequest is part of the EJB method signatures.

    public class XXXDAO extends AbstractStoredProcedureDAO {
    //transfer parameters from EJB request to data map.
    protected Map getParameters(AbstractServiceRequest request, String action, String qualifier) {

    if ( ACTION_READ.equals(action) ) {
    if ( qualifier.equalsIgnoreCase(QUALIFIER_GET_XXX_TYPE) ||
    qualifier.equalsIgnoreCase(QUALIFIER_IS_IN) ) {

    tvDataMap = new HashMap();
    QueryXXXInfoReq tvRequest = (QueryXXXInfoReq) request;
    tvDataMap.put(PARAM_IN_IS_XXX_NUMBER, tvRequest.getAcct());
    }
    }

    return tvDataMap;
    }

    /**
    * Get results from stored procedures
    */
    protected IResponseSO getResult(CallableStatement stmt, String action, String qualifier) throws SQLException {

    if ( ACTION_READ.equals(action) ) {

    if ( qualifier.equalsIgnoreCase(QUALIFIER_GET_XXX_TYPE)) {

    QueryAccountInfoSO tvSO = new QueryAccountInfoSO();
    tvSO.setStatusCode( tvRPSReturnStatus );

    if ( tvRPSReturnStatus == PersistenceCode.RPS_OK ) {

    tvSO.setAccountType( stmt.getString(PARAM_OUT_XXX_TYPE) );
    }

    tvISO = tvSO;

    } else if ( qualifier.equalsIgnoreCase(QUALIFIER_IS_IN)) {

    QueryXXXInfoSO tvSO = new QueryXXXInfoSO();
    tvSO.setStatusCode( tvRPSReturnStatus );
    tvISO = tvSO;
    }
    }

    return tvISO;
    }

    //process exceptions
    protected IResponseSO processException(SQLException e, String action, String qualifier) throws DAOException {
    IResponseSO tvISO = null;

    if (ACTION_READ.equals(action)) {
    if ( qualifier == QUALIFIER_REVIEW_xxx ) { // null
    throw new DAOException(e);
    }
    } else if ( ACTION_CREATE.equals( action )) {
    if ( QUALIFIER_LOG_xxx.equals(qualifier) ) {
    throw new DAOException(e);
    } else if (QUALIFIER_INSERT_xxx.equals(qualifier)) {

    if ( e.getErrorCode() > -20129 && e.getErrorCode() < -20120 ) {
    ....
    } else {
    throw new DAOException(e);
    }
    } else if ( QUALIFIER_INSERT_xxx2.equals(qualifier) ) {
    throw new DAOException(e);
    }
    }

    return tvISO;
    }

    }



    George
  2. DAO CRUD Qualifier Pattern[ Go to top ]

    Hallo

    I don't think the construction is all that crazy, but I have some concerns.

    1) The use of the action and qualification in the method signature.
    2) AbstractServiceRequest is part of the EJB method signatures

    To clear those two issues I would have done the following;

    1) Build on a command pattern instead so that each StoredProcedure has a java command object, You get alot of object, but you don't have the messy if-then code.
    (you'll might be able to codegenerate these commands objects??)
    2) It looks to me that the AbstractServiceRequest is beimg converted into a Map, if that the case make the conversion into the Map either in the factory .. (PersistenceService.getInstance().create(request, QUALIFIER_INSERT_ORDER)) ..
    or in the EJB itself.

    Hope this helps.

    Per LJ
    Lentz Consulting