4 | | `<entity name="Example" decorator="decorators.ExampleDecorator">`[[BR]][[BR]]This will put a template decorator '!ExampleDecorator.java' in a package 'decorators' in your Java source folder. If you open this file, you will notice three functions:[[BR]][[BR]]`public int add(List<E> entities)public int update(List<E> entities)public int remove(List<E> entities)`[[BR]][[BR]]Each of these functions can be customized with new pre-, post- and database action behaviour, in a sequential layout:[[BR]][[BR]]`// add your pre-processing here// here we call the standard 'add'int count = super.add(entities);// add your post-processing here// if you throw an exception the previous add will be rolled back` |
| 4 | {{{ |
| 5 | <entity name="Example" decorator="decorators.ExampleDecorator"> |
| 6 | }}} |
| 7 | |
| 8 | This will put a template decorator '!ExampleDecorator.java' in a package 'decorators' in your Java source folder. If you open this file, you will notice three functions: |
| 9 | |
| 10 | {{{ |
| 11 | public int add(List<E> entities) |
| 12 | public int update(List<E> entities) |
| 13 | public int remove(List<E> entities) |
| 14 | }}} |
| 15 | |
| 16 | Each of these functions can be customized with new pre-, post- and database action behaviour, in a sequential layout: |
| 17 | |
| 18 | {{{ |
| 19 | // add your pre-processing here |
| 20 | |
| 21 | // here we call the standard 'add' |
| 22 | int count = super.add(entities); |
| 23 | |
| 24 | // add your post-processing here |
| 25 | // if you throw an exception the previous add will be rolled back |
| 26 | }}} |
7 | | For example, change the value of the field 'name' by turning it into uppercase before adding:[[BR]][[BR]]`public int add(List<E> entities) throws DatabaseException{ try{ for (Entity e : entities){ e.set("name", e.get("name").toString().toUpperCase()); } } catch (ParseException pe) { throw new DatabaseException(pe); } int count = super.add(entities); return count;}` |
| 29 | For example, change the value of the field 'name' by turning it into uppercase before adding: |
| 30 | |
| 31 | {{{ |
| 32 | public int add(List<E> entities) throws DatabaseException{ |
| 33 | try{ |
| 34 | for (Entity e : entities){ |
| 35 | e.set("name", e.get("name").toString().toUpperCase()); |
| 36 | } |
| 37 | } catch (ParseException pe) { |
| 38 | throw new DatabaseException(pe); |
| 39 | } |
| 40 | int count = super.add(entities); |
| 41 | return count; |
| 42 | } |
| 43 | }}} |