| 3 | |
| 4 | |
| 5 | == Quick Intro == |
| 6 | |
| 7 | Here is a quick and dirty introduction to Ven. For more, see the [source:trunk/fmgVen/test/com/fmguler/ven/sample/Sample.java Sample.java] file in the test classes. (In the future, I am also planning to implement Pet Clinic sample application using Ven, which will be much more explanatory). |
| 8 | |
| 9 | The domain model used in the examples; |
| 10 | |
| 11 | !SomeDomainObject has both many to one and one to many relationship with !AnotherDomainObject (SDO.ado, SDO.ados). !AnotherDomainObject has many to one relationship with !SomeDomainObject (ADO.sdo). |
| 12 | |
| 13 | === Save and Update === |
| 14 | |
| 15 | {{{ |
| 16 | Ven ven = getVen(); |
| 17 | |
| 18 | //insert |
| 19 | SomeDomainObject obj = new SomeDomainObject(); |
| 20 | obj.setName("name"); |
| 21 | obj.setDescription("desc"); |
| 22 | obj.setDate(new Date()); |
| 23 | ven.save(obj); |
| 24 | System.out.println(obj); |
| 25 | |
| 26 | //update |
| 27 | obj.setName("name update"); |
| 28 | ven.save(obj); |
| 29 | System.out.println(obj); |
| 30 | }}} |
| 31 | |
| 32 | === Delete === |
| 33 | |
| 34 | {{{ |
| 35 | Ven ven = getVen(); |
| 36 | ven.delete(2, SomeDomainObject.class); |
| 37 | }}} |
| 38 | |
| 39 | === Get === |
| 40 | |
| 41 | {{{ |
| 42 | Ven ven = getVen(); |
| 43 | |
| 44 | //get with includes |
| 45 | Set joins = new HashSet(); |
| 46 | joins.add("SomeDomainObject.anotherDomainObjects"); |
| 47 | joins.add("SomeDomainObject.anotherDomainObject"); |
| 48 | SomeDomainObject obj = (SomeDomainObject)ven.get(1, SomeDomainObject.class, joins); |
| 49 | System.out.println(obj); |
| 50 | |
| 51 | Set joins2 = new HashSet(); |
| 52 | joins2.add("AnotherDomainObject.someDomainObject"); |
| 53 | AnotherDomainObject obj2 = (AnotherDomainObject)ven.get(1, AnotherDomainObject.class, joins2); |
| 54 | System.out.println(obj2); |
| 55 | }}} |
| 56 | |
| 57 | === List === |
| 58 | |
| 59 | {{{ |
| 60 | Ven ven = getVen(); |
| 61 | |
| 62 | //list with includes |
| 63 | Set joins = new HashSet(); |
| 64 | joins.add("SomeDomainObject.anotherDomainObjects"); |
| 65 | joins.add("SomeDomainObject.anotherDomainObject"); |
| 66 | List objList = ven.list(SomeDomainObject.class, joins); |
| 67 | |
| 68 | Iterator it = objList.iterator(); |
| 69 | while (it.hasNext()) { |
| 70 | SomeDomainObject someDomainObject = (SomeDomainObject)it.next(); |
| 71 | System.out.println(someDomainObject); |
| 72 | } |
| 73 | }}} |
| 74 | |
| 75 | === List by Criteria === |
| 76 | |
| 77 | {{{ |
| 78 | Ven ven = getVen(); |
| 79 | |
| 80 | //these objects will be included |
| 81 | Set joins = new HashSet(); |
| 82 | joins.add("SomeDomainObject.anotherDomainObjects"); |
| 83 | joins.add("SomeDomainObject.anotherDomainObject"); |
| 84 | |
| 85 | //the results will be filtered according to this criteria |
| 86 | Criteria criteria = new Criteria() //criteria object |
| 87 | .like("SomeDomainObject.anotherDomainObjects.name", "a%") //attribute like value |
| 88 | .eq("SomeDomainObject.name", "sdo1") //attribute equals value |
| 89 | .and(); //connects previous criteria with logical and (postfix notation) |
| 90 | |
| 91 | //list with includes and criteria |
| 92 | List objList = ven.list(SomeDomainObject.class, joins, criteria); |
| 93 | |
| 94 | //print the results |
| 95 | Iterator it = objList.iterator(); |
| 96 | while (it.hasNext()) { |
| 97 | SomeDomainObject someDomainObject = (SomeDomainObject)it.next(); |
| 98 | System.out.println(someDomainObject); |
| 99 | } |
| 100 | }}} |