Changes between Version 1 and Version 2 of FmgVen/Documentation


Ignore:
Timestamp:
Apr 9, 2011, 1:12:36 PM (14 years ago)
Author:
fmguler
Comment:

added quick intro, copied code blocks from Sample.java

Legend:

Unmodified
Added
Removed
Modified
  • FmgVen/Documentation

    v1 v2  
    11= fmgVen Documentation = 
    22This page will contain documentation for the end user. Will illustrate how to use fmgVen by code samples, step by step. 
     3 
     4 
     5== Quick Intro == 
     6 
     7Here 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 
     9The 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{{{ 
     16Ven ven = getVen(); 
     17 
     18//insert 
     19SomeDomainObject obj = new SomeDomainObject(); 
     20obj.setName("name"); 
     21obj.setDescription("desc"); 
     22obj.setDate(new Date()); 
     23ven.save(obj); 
     24System.out.println(obj); 
     25 
     26//update 
     27obj.setName("name update"); 
     28ven.save(obj); 
     29System.out.println(obj); 
     30}}} 
     31 
     32=== Delete === 
     33 
     34{{{ 
     35Ven ven = getVen(); 
     36ven.delete(2, SomeDomainObject.class); 
     37}}} 
     38 
     39=== Get === 
     40 
     41{{{ 
     42Ven ven = getVen(); 
     43 
     44//get with includes 
     45Set joins = new HashSet(); 
     46joins.add("SomeDomainObject.anotherDomainObjects"); 
     47joins.add("SomeDomainObject.anotherDomainObject"); 
     48SomeDomainObject obj = (SomeDomainObject)ven.get(1, SomeDomainObject.class, joins); 
     49System.out.println(obj); 
     50 
     51Set joins2 = new HashSet(); 
     52joins2.add("AnotherDomainObject.someDomainObject"); 
     53AnotherDomainObject obj2 = (AnotherDomainObject)ven.get(1, AnotherDomainObject.class, joins2); 
     54System.out.println(obj2); 
     55}}} 
     56 
     57=== List === 
     58 
     59{{{ 
     60Ven ven = getVen(); 
     61 
     62//list with includes 
     63Set joins = new HashSet(); 
     64joins.add("SomeDomainObject.anotherDomainObjects"); 
     65joins.add("SomeDomainObject.anotherDomainObject"); 
     66List objList = ven.list(SomeDomainObject.class, joins); 
     67 
     68Iterator it = objList.iterator(); 
     69while (it.hasNext()) { 
     70    SomeDomainObject someDomainObject = (SomeDomainObject)it.next(); 
     71    System.out.println(someDomainObject); 
     72} 
     73}}} 
     74 
     75=== List by Criteria === 
     76 
     77{{{ 
     78Ven ven = getVen(); 
     79 
     80//these objects will be included 
     81Set joins = new HashSet(); 
     82joins.add("SomeDomainObject.anotherDomainObjects"); 
     83joins.add("SomeDomainObject.anotherDomainObject"); 
     84 
     85//the results will be filtered according to this criteria 
     86Criteria 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 
     92List objList = ven.list(SomeDomainObject.class, joins, criteria); 
     93 
     94//print the results 
     95Iterator it = objList.iterator(); 
     96while (it.hasNext()) { 
     97    SomeDomainObject someDomainObject = (SomeDomainObject)it.next(); 
     98    System.out.println(someDomainObject); 
     99} 
     100}}}