jp.terasoluna.fw.service.thin
Interface BLogic<P>

Type parameter:
P - Specify JavaBean which is the input value to business logic

public interface BLogic<P>

Interface that should be implemented by business logic class.

Business logic is created by implementing this interface. JavaBean is passed to execute() method which is the entry point of business logic
Following is an implementation example (login process) of typical business logic.

Implementation example
 ...
 public BLogicResult execute(LogonBean params) {

     BLogicResult result = new BLogicResult();

     // User ID
     String userId = params.getUserId();
     // Password
     String password = params.getPassword();
     // Login failure count
     String failures = params.getFailures();

     int failCount = Integer.parseInt(failures);

     // Unconditional falure when the login failure count is greater than the specified count
     if (failCount > MAX_COUNT ) {
         result.setResultString("loginError");
         return result;
     }

     // Does user exist in DB
     if (isAuthenticated(userId, password)) {
         // Generate JavaBean which is considered as output value
         LogonResultBean bean = new LogonResultBean();
         // If it exists, generate UVO and store it in result object
         sampleUVO uvo = UserValueObject.createUserValueObject();
         bean.setUvo(uvo);
         result.setResultObject(bean);
         // Transit as authentication successful
         result.setResultString("success");
     } else {
         BLogicMessages errors = new BLogicMessages();
         BLogicMessage error = new BLogicMessage("message.error.login");
         errors.add(ActionMessages.GLOBAL_MESSAGE, error);
         result.setErrors(errors);
         ...
         // Transit as authetication failed
         result.setResultString("failure");
     }
     return result;
 }
 

Following is an example of executing DAO from internal business logic. Set DAO beforehand. For DAO settings, refer to each DAO implementation class.

DAO execution method from business logic
 private boolean isAuthenticated(String id, String pass) {

     // Create parameter which is passed to DAO
     Map<String, String> parameters = new HashMap<String, String>();
     parameters.put("ID", id);
     parameters.put("PASSWORD", pass);

     // Executing DAO
     Map<String, Object>[] result = dao.executeForMapList(
                                             USER_AUTHENTICATION, parameters);
     if (result != null) {
        // User exists
        return true;
     }
     // User does not exist
     return false;
 }
 

Declarative transaction is used for performing DB commit and rollback. Hence, the implementor does not perform directly commit and rollback for DB connection.
For the related functions, refer to the following.

See Also:
BLogicIOPlugIn, AbstractBLogicMapper, BLogicMapper, BLogicIO, BLogicProperty, BLogicResources, BLogicResult, AbstractBLogicAction, BLogicAction

Method Summary
 BLogicResult execute(P params)
          Execute business logic.
 

Method Details

execute

BLogicResult execute(P params)
Execute business logic.

Parameter:
params - Business logic input information
Returns:
Business logic process result