Test Doc

Logic layer

Create method

Located

Class Methodname
[Element name]Bean.java create

Version

Version Description
X.X.X First added to expanders.
3.0.X Expandable using dd descriptor files.
3.1.0 Expandable using xml descriptor files.
3.1.0 optionNoDataLayer

Internal or external method

/////////////////////////////////// True False
Is meant to be used in custom code X  

Description

  • This method is used to call upon the create method of the data layer.
  • The create method takes in a DetailsObject wrapped in a ParameterContext and returns a DataRef wrapped in a “CrudsResult”.

    • If an Agent is used to call upon this method, the ParameterContext is added by the system.
  • It is possible to add custom code before or after the call to the data layer.

Example

Generated code:

// anchor:custom-create-annotations:start
// anchor:custom-create-annotations:end
public CrudsResult<DataRef> create(
  ParameterContext<SomeElementDetails> detailsParameter) {
    if (sessionContext.getRollbackOnly()) {
        return getDiagnosticHelper().createCrudsError(CREATE_ERROR_MSG_KEY);
    }

    @SuppressWarnings("unused")
    SomeElementDetails details = detailsParameter.getValue();
    @SuppressWarnings("unused")
    UserContext userContext = detailsParameter.getUserContext();

    // anchor:custom-preCreate:start
    // anchor:custom-preCreate:end

    CrudsResult<DataRef> result = someElementCrudsLocal.create(detailsParameter);

    if (result.isError()) {
      return result;
    }
    // anchor:custom-postCreate:start
    // anchor:custom-postCreate:end
    return result;
}

Implementation using a local agent:

public DataRef create(SomeElementDetails someElementDetails) throws CreateException {
    CrudsResult<DataRef> crudsResult = someElementAgent.create(someElementDetails);
    if (crudsResult.isError()) {
        throw new CreateException("Something went wrong.");
    }
    return crudsResult.getValue();
}

optionNoDataLayer

Description

By making use of the option: “optionNoDataLayer”, there will be a change to the create method. The call to the data layer is removed and it is expected that an implementation for the create is custom made by the developer.

Example

// anchor:custom-create-annotations:start
// anchor:custom-create-annotations:end
public CrudsResult<DataRef> create(
  ParameterContext<SomeElementDetails> detailsParameter) {
    if (sessionContext.getRollbackOnly()) {
        return getDiagnosticHelper().createCrudsError(CREATE_ERROR_MSG_KEY);
    }

    @SuppressWarnings("unused")
    SomeElementDetails details = detailsParameter.getValue();
    @SuppressWarnings("unused")
    UserContext userContext = detailsParameter.getUserContext();

    // anchor:custom-preCreate:start
    // anchor:custom-preCreate:end

    CrudsResult<DataRef> result = getDiagnosticHelper().createCrudsError("not implemented");

    // anchor:custom-postCreate:start
    // anchor:custom-postCreate:end
    return result;
}

Modify method

Located

Class Method name
[Element name]Bean.java modify

Version

Version Description
X.X.X First added to expanders.
3.0.X Expandable using dd descriptor files.
3.1.0 Expandable using xml descriptor files.
3.1.0 optionNoDataLayer

Internal or external method

/////////////////////////////////// True False
Is meant to be used in custom code X  

Description

  • This method is used to call upon the modify method of the datalayer.
  • The modify method takes in a DetailsObject wrapped in a ParameterContext and returns a DataRef wrapped in a “CrudsResult”.

    • If an Agent is used to call upon this method, the ParameterContext is added by the system.
  • It is possible to add custom code before or after the call to the data layer.

Example

Generated code:

// anchor:custom-modify-annotations:start
 // anchor:custom-modify-annotations:end
 public CrudsResult<DataRef> modify(
  ParameterContext<SomeElementDetails> detailsParameter) {
     if (sessionContext.getRollbackOnly()) {
         return getDiagnosticHelper().createCrudsError(MODIFY_ERROR_MSG_KEY);
     }

     @SuppressWarnings("unused")
     SomeElementDetails details = detailsParameter.getValue();
     @SuppressWarnings("unused")
     UserContext userContext = detailsParameter.getUserContext();

     // anchor:custom-preModify:start
     // anchor:custom-preModify:end

     CrudsResult<DataRef> result = someElementCrudsLocal.modify(detailsParameter);
     if (result.isError()) {
       return result;
     }

     // anchor:custom-postModify:start
     // anchor:custom-postModify:end

     return result;

 } // end modify

Implementation using a local agent:

public DataRef modify(SomeElementDetails someElementDetails) throws ModifyException {
    CrudsResult<DataRef> crudsResult = someElementAgent.modify(someElementDetails);
    if (crudsResult.isError()) {
        throw new ModifyException("Something went wrong.");
    }
    return crudsResult.getValue();
}

optionNoDataLayer

Description

By making use of the option: “optionNoDataLayer”, there will be a change to the modify method. The call to the data layer is removed and it is expected that an implementation for the modify is custom made by the developer.

Example

// anchor:custom-modify-annotations:start
// anchor:custom-modify-annotations:end
public CrudsResult<DataRef> modify(ParameterContext<SomeElementDetails> detailsParameter) {
    if (sessionContext.getRollbackOnly()) {
        return getDiagnosticHelper().createCrudsError(MODIFY_ERROR_MSG_KEY);
    }

    @SuppressWarnings("unused")
    someElementDetails details = detailsParameter.getValue();
    @SuppressWarnings("unused")
    UserContext userContext = detailsParameter.getUserContext();

    // anchor:custom-preModify:start
    // anchor:custom-preModify:end

    CrudsResult<DataRef> result = getDiagnosticHelper().createCrudsError("not implemented");


    // anchor:custom-postModify:start
    // anchor:custom-postModify:end

    return result;

} // end modify

ModifyWithProjection method

Located

Class Method name
[Element name]Bean.java modifyWithProjection

Version

Version Description
X.X.X First added to expanders.
3.0.X Expandable using dd descriptor files.
3.1.0 Expandable using xml descriptor files.

Internal or external method

/////////////////////////////////// True False
Is meant to be used in custom code   X

Description

  • This method is used to call upon the modifyWithProjection method of the datalayer.
  • The difference between the “modify” and “modifyWithProjection” methods is that, by using a projection as transport object not the entire object needs to be transported.

    • An alternative for this methode is a command.
  • The modifyWithProjection method takes in a DetailsObject wrapped in a ParameterContext and returns a DataRef wrapped in a “CrudsResult”.

  • It is possible to add custom code before or after the call to the data layer.

Example

Generated code:

@Override
public <P> CrudsResult<DataRef> modifyWithProjection(ParameterContext<P> projectionParameter) {
    if (sessionContext.getRollbackOnly()) {
        return getDiagnosticHelper().createCrudsError(MODIFY_ERROR_MSG_KEY);
    }

    // anchor:custom-preModify-projection:start
    // anchor:custom-preModify-projection:end


    CrudsResult<DataRef> result = someElementCrudsLocal.modifyWithProjection(projectionParameter);
    if (result.isError()) {
        return result;
    }
    // anchor:custom-postModify-projection:start
    // anchor:custom-postModify-projection:end

    return result;

}

Delete method

Located

Class Method name
[Element name]Bean.java delete

Version

Version Description
X.X.X First added to expanders.
3.0.X Expandable using dd descriptor files.
3.1.0 Expandable using xml descriptor files.
3.1.0 optionNoDataLayer

Internal or external method

/////////////////////////////////// True False
Is meant to be used in custom code X  

Description

  • This method is used to call upon the the delete method of the data layer.
  • It will remove a item form the database.
  • It takes in a Long (Id of the item that needs to be removed) wrapped in a ParameterContext.
  • It returns a CrudsResult without value.

Example

Generated code:

// anchor:custom-delete-annotations:start
// anchor:custom-delete-annotations:end
public CrudsResult<Void> delete(ParameterContext<Long> idParameter) {

        if (sessionContext.getRollbackOnly()) {
                return getDiagnosticHelper().createCrudsError(DELETE_ERROR_MSG_KEY);
        }

        Long id = idParameter.getValue();

        // anchor:custom-preDelete:start
        // anchor:custom-preDelete:end

        try {
                DataRef dataRef = idToDataRef(idParameter.getValue());
                CrudsResult<Void> result = someElementCrudsLocal.delete(idParameter.construct(dataRef));

                if (result.isError()) {
                        return result;
                }

                // anchor:custom-postDelete:start
                // anchor:custom-postDelete:end

                return CrudsResult.success(null);
        } catch (Exception e) {
                if (logger.isErrorEnabled()) {
                        logger.error(
                                "Delete failed for ID = " + id, e
                        );
                }
                return getDiagnosticHelper().createCrudsError(DELETE_ERROR_MSG_KEY);
        }

} // end delete

Implementation using CrudsLocal:

someElementCrudsLocal.delete(ParameterContext.create(userContext, someElementDetails.getDataRef());

optionNoDataLayer

Description

By making use of the option: “optionNoDataLayer”, there will be a change to the delete method. The call to the data layer is removed and it is expected that an implementation for the delete is custom made by the developer.

Example

// anchor:custom-delete-annotations:start
// anchor:custom-delete-annotations:end
public CrudsResult<Void> delete(ParameterContext<Long> idParameter) {

        if (sessionContext.getRollbackOnly()) {
                return getDiagnosticHelper().createCrudsError(DELETE_ERROR_MSG_KEY);
        }

        Long id = idParameter.getValue();

        // anchor:custom-preDelete:start
        // anchor:custom-preDelete:end

        try {
                DataRef dataRef = idToDataRef(idParameter.getValue());
                CrudsResult<DataRef> result = getDiagnosticHelper().createCrudsError("not implemented");

                // anchor:custom-postDelete:start
                // anchor:custom-postDelete:end

                return CrudsResult.success(null);
        } catch (Exception e) {
                if (logger.isErrorEnabled()) {
                        logger.error(
                                "Delete failed for ID = " + id, e
                        );
                }
                return getDiagnosticHelper().createCrudsError(DELETE_ERROR_MSG_KEY);
        }

} // end delete

lookupHomeInterfaces

Located

Class Method name
[Element name]Bean.java lookupHomeInterfaces

Version

Version Description
X.X.X First added to expanders.
3.0.X Expandable using dd descriptor files.
3.1.0 Expandable using xml descriptor files.

Internal or external method

/////////////////////////////////// True False
Is meant to be used in custom code   X

Description

  • Unknown

Example

Generated code:

@javax.annotation.PostConstruct
public void lookupHomeInterfaces() {
        try {
                if (initialContext == null) {
                        initialContext = new InitialContext();
                }
                // anchor:initialize-context-variables:start
                // anchor:initialize-context-variables:end
        } catch (Exception e) {
                if (logger.isErrorEnabled()) {
                        logger.error(
                        "Cannot get initCtx and lookup home interfaces", e
                        );
                }
        }
}

getId method

Located

Class Method name
[Element name]Bean.java getId

Version

Version Description
X.X.X First added to expanders.
3.0.X Expandable using dd descriptor files.
3.1.0 Expandable using xml descriptor files.

Internal or external method

/////////////////////////////////// True False
Is meant to be used in custom code   X

Description

  • This method takes in the value from field name.
  • It returns a DataRef wrapped in a CrudsResult.
  • If the option: “nameNotWanted” is added on the element, then name is the same as Id.
  • Because “name” is not unique bye default it is better to use the method

Example

Generated code:

public CrudsResult<DataRef> getId(ParameterContext<String> nameParameter) {
    return someElementCrudsLocal.getDataRefFromName(nameParameter);
}

Find method

Located

Class Method name
[Element name]Bean.java find

Version

Version Description
X.X.X First added to expanders.
3.0.X Expandable using dd descriptor files.
3.1.0 Expandable using xml descriptor files.
3.1.0 optionNoDataLayer

Internal or external method

/////////////////////////////////// True False
Is meant to be used in custom code X  

Description

  • This method is used to call upon the find method in the Datalayer.
  • The find method takes in a FinderDetailsObject wrapped in a ParameterContext and returns a list containing the results of the find action wrapped in a “SearchResult”.

    • If an Agent is used to call upon this method, the ParameterContext is added by the system.
  • It is possible to add custom code before or after the call to the Datalayer.

Example

Generated code:

// anchor:custom-find-annotations:start
// anchor:custom-find-annotations:end
public <S,T> SearchResult<T> find(ParameterContext<SearchDetails<S>> searchParameter) {
  SearchResult<T> result;
  // anchor:custom-before-find:start
  // anchor:custom-before-find:end

  result = someElementCrudsLocal.find(searchParameter);

  // anchor:custom-after-find:start
  // anchor:custom-after-find:end

  return result;
}

Implementation using a local agent:

public List<SomeElementDetails> findAll(UserContext userContext) {
    SomeElementFindAllSomeElementsDetails finder = new SomeElementFindAllSomeElementsDetails();

    SearchDetails<SomeElementFindAllSomeElementsDetails> searchDetails = makeSearchDetails(finder);

    SearchResult<SomeElementDetails> searchResult =
            SomeElementLocalAgent.getSomeElementAgent(userContext).find(searchDetails);

    if (searchResult.isSuccess()) {
        return searchResult.getResults();
    }
    return Collections.<SomeElementDetails>emptyList();
}

private SearchDetails<SomeElementFindAllSomeElementsDetails> makeSearchDetails(
  SomeElementFindAllSomeElementsDetails finder) {
    SearchDetails<SomeElementFindAllSomeElementsDetails> searchDetails =
            new SearchDetails<SomeElementFindAllSomeElementsDetails>(finder);
    searchDetails.setProjection("details");
    searchDetails.setPaging(Paging.fetchAll());
    return searchDetails;
}

optionNoDataLayer

Description

By making use of the option: “optionNoDataLayer”, there will be a change to the find method. The call to the data layer is removed and it is expected that an implementation for the find is custom made by the developer for each possible find action.

Example

// anchor:custom-find-annotations:start
// anchor:custom-find-annotations:end
public <S,T> SearchResult<T> find(ParameterContext<SearchDetails<S>> searchParameter) {
   SearchResult<T> result = getDiagnosticHelper().createSearchError(SEARCH_ERROR_MSG_KEY);

   // anchor:custom-noDataLayer-search:start
    ...
   // anchor:custom-noDataLayer-search:end

   return result;
}