|
|
Line 1: |
Line 1: |
− | {{ScoutPage|cat=HowTo 3.8}}
| |
| | | |
− | A popular use of a process service is to access data on a database.
| |
− | Assuming a simple {{ScoutLink|HowTo|Create a Dialog|Scout dialog}}, here's what we need:
| |
− |
| |
− | # create a new item (insert)
| |
− | # load an existing item (select)
| |
− | # update an existing item (update)
| |
− | # delete an existing item (delete)
| |
− |
| |
− | Create a new process service on the server in the folder '''Process Services'''.
| |
− | In our example, we'll call it SubAgreementProcessService.
| |
− | If you've already created a form to go along with it, make sure you indicate
| |
− | SubAgreementFormData.
| |
− |
| |
− | This automatically creates the following ISubAgreementProcessService for you:
| |
− |
| |
− | public interface ISubAgreementProcessService extends IService{
| |
− | SubAgreementFormData create(SubAgreementFormData formData) throws ProcessingException;
| |
− | SubAgreementFormData load(SubAgreementFormData formData) throws ProcessingException;
| |
− | SubAgreementFormData prepareCreate(SubAgreementFormData formData) throws ProcessingException;
| |
− | SubAgreementFormData store(SubAgreementFormData formData) throws ProcessingException;
| |
− | }
| |
− |
| |
− | The appropriate class is also created for you. Edit SubAgreementProcessService
| |
− | and replace all instances of "TODO business logic here" with the real thing. :)
| |
− |
| |
− | Here's an example that assumes a database and uses the SQL service to access it.
| |
− | Note that all we needed to write was the SQL statements. The bind variables
| |
− | are determined by the Form Data object, which is in turn generated based on the
| |
− | Form itself. Thus, the bind variable names are based on the field and variable names.
| |
− | If the field is called TypeField, then the bind variable will have the suffix "Field"
| |
− | removed and the first letter downcased, resulting in :type.
| |
− |
| |
− | public SubAgreementFormData prepareCreate(SubAgreementFormData formData) throws ProcessingException{
| |
− | if(!ACCESS.check(new CreateSubAgreementPermission())){
| |
− | throw new VetoException(Texts.get("YouAreNotAuthorizedToRegisterformDataData"));
| |
− | }
| |
− | // nothing to do
| |
− | return formData;
| |
− | }
| |
− |
| |
− | public SubAgreementFormData create(SubAgreementFormData formData) throws ProcessingException{
| |
− | if(!ACCESS.check(new CreateSubAgreementPermission())){
| |
− | throw new VetoException(Texts.get("YouAreNotAuthorizedToRegisterformDataData"));
| |
− | }
| |
− | SQL.insert("INSERT INTO SL_SUB_AGREEMENT (" +
| |
− | " ( PROJECT_NR," +
| |
− | " TYPE_UID," +
| |
− | " STATUS_UID," +
| |
− | " EVT_VERSION," +
| |
− | " EVT_ISSUE," +
| |
− | " EVT_SIGN," +
| |
− | " EVT_EFFECTIVE," +
| |
− | " EVT_CANCEL," +
| |
− | " EVT_TERMINATE )" +
| |
− | " VALUES ( :projectNr," +
| |
− | " :type," +
| |
− | " :status," +
| |
− | " :version," +
| |
− | " :issued," +
| |
− | " :signed," +
| |
− | " :effective," +
| |
− | " :cancellation," +
| |
− | " :termination )",
| |
− | formData);
| |
− | return formData;
| |
− | }
| |
− |
| |
− | public SubAgreementFormData load(SubAgreementFormData formData) throws ProcessingException{
| |
− | if(!ACCESS.check(new ReadSubAgreementPermission())){
| |
− | throw new VetoException(Texts.get("YouAreNotAuthorizedToRegisterformDataData"));
| |
− | }
| |
− | SQL.select("SELECT STATUS_UID," +
| |
− | " EVT_VERSION," +
| |
− | " EVT_ISSUE," +
| |
− | " EVT_SIGN," +
| |
− | " EVT_EFFECTIVE," +
| |
− | " EVT_CANCEL," +
| |
− | " EVT_TERMINATE" +
| |
− | " FROM SL_SUB_AGREEMENT" +
| |
− | " WHERE PROJECT_NR = :projectNr" +
| |
− | " AND TYPE_UID = :type" +
| |
− | " INTO :status," +
| |
− | " :version," +
| |
− | " :issued," +
| |
− | " :signed," +
| |
− | " :effective," +
| |
− | " :cancellation," +
| |
− | " :termination )",
| |
− | formData);
| |
− | return formData;
| |
− | }
| |
− |
| |
− | public SubAgreementFormData store(SubAgreementFormData formData) throws ProcessingException{
| |
− | if(!ACCESS.check(new UpdateSubAgreementPermission())){
| |
− | throw new VetoException(Texts.get("YouAreNotAuthorizedToRegisterformDataData"));
| |
− | }
| |
− | SQL.update("UPDATE SL_SUB_AGREEMENT SET" +
| |
− | " STATUS_UID = :status," +
| |
− | " EVT_VERSION = :version," +
| |
− | " EVT_ISSUE = :issued," +
| |
− | " EVT_SIGN = :signed," +
| |
− | " EVT_EFFECTIVE = :effective," +
| |
− | " EVT_CANCEL = :cancellation," +
| |
− | " EVT_TERMINATE = :termination" +
| |
− | " WHERE PROJECT_NR = :projectNr" +
| |
− | " AND TYPE_UID = :type",
| |
− | formData);
| |
− | return formData;
| |
− | }
| |