Changeset 30 for trunk/fmgVen/test


Ignore:
Timestamp:
Apr 9, 2011, 12:44:03 PM (14 years ago)
Author:
fmguler
Message:

Fixes #3 - Criteria object is mostly implemented. An override of Ven.list() having criteria parameter is added. Old codebase only had string based criteria. In this commit, I am also adding typed criteria as a new feauture. With this new criteria system, user can create criteria object like;

new Criteria().eq(attr,value).like(attr,value).and().gt(attr, value).or().orderAsc(attr).orderDesc(attr).limit(limit, offset);

The orderings and the limit/offset values are not taken into account in the Ven (these are trivial, I will do them later).

Not thouroughly tested, because complex scenarios are only possible when applying to a real problem in a real application (which I am planning to do next).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/fmgVen/test/com/fmguler/ven/sample/Sample.java

    r29 r30  
    1818package com.fmguler.ven.sample; 
    1919 
     20import com.fmguler.ven.Criteria; 
    2021import com.fmguler.ven.LiquibaseUtil; 
    2122import com.fmguler.ven.Ven; 
     
    4344        //list the objects 
    4445        testList(); 
     46        //list the objects by some criteria string 
     47        testListByCriteriaString(); 
     48        //list the objects by some typed criteria 
     49        testListByCriteriaObject(); 
    4550        //delete an object 
    4651        testDelete(); 
     
    112117        joins.add("SomeDomainObject.anotherDomainObject"); 
    113118        List objList = ven.list(SomeDomainObject.class, joins); 
    114          
     119 
    115120        Iterator it = objList.iterator(); 
    116121        while (it.hasNext()) { 
     
    121126 
    122127    /** 
    123      * Test list the collection of objects by some criteria 
     128     * Test list the collection of objects by some criteria (string) 
    124129     */ 
    125     public static void testListByCriteria() { 
     130    public static void testListByCriteriaString() { 
    126131        Ven ven = getVen(); 
    127         //List objList = ven.list(SomeDomainObject.class/*, criteria */); 
    128         //System.out.println(objList); 
     132 
     133        //these objects will be included 
     134        Set joins = new HashSet(); 
     135        joins.add("SomeDomainObject.anotherDomainObjects"); 
     136        joins.add("SomeDomainObject.anotherDomainObject"); 
     137 
     138        //the results will be filtered according to this criteria 
     139        Criteria criteria = new Criteria() //criteria object 
     140                //.param("and SomeDomainObject.name like :p1").param("p1", "s%") 
     141                .add("and SomeDomainObject.anotherDomainObjects.name like :p2").param("p2", "a%"); 
     142 
     143 
     144        //list with includes and criteria 
     145        List objList = ven.list(SomeDomainObject.class, joins, criteria); 
     146 
     147        //print the results 
     148        Iterator it = objList.iterator(); 
     149        while (it.hasNext()) { 
     150            SomeDomainObject someDomainObject = (SomeDomainObject)it.next(); 
     151            System.out.println(someDomainObject); 
     152        } 
     153    } 
     154 
     155    /** 
     156     * Test list the collection of objects by some criteria (object) 
     157     */ 
     158    public static void testListByCriteriaObject() { 
     159        Ven ven = getVen(); 
     160 
     161        //these objects will be included 
     162        Set joins = new HashSet(); 
     163        joins.add("SomeDomainObject.anotherDomainObjects"); 
     164        joins.add("SomeDomainObject.anotherDomainObject"); 
     165 
     166        //the results will be filtered according to this criteria 
     167        Criteria criteria = new Criteria() //criteria object 
     168                .like("SomeDomainObject.anotherDomainObjects.name", "a%") //attribute like value 
     169                .eq("SomeDomainObject.name", "sdo1") //attribute equals value 
     170                .and(); //connects previous criteria with and 
     171 
     172        //list with includes and criteria 
     173        List objList = ven.list(SomeDomainObject.class, joins, criteria); 
     174 
     175        //print the results 
     176        Iterator it = objList.iterator(); 
     177        while (it.hasNext()) { 
     178            SomeDomainObject someDomainObject = (SomeDomainObject)it.next(); 
     179            System.out.println(someDomainObject); 
     180        } 
    129181    } 
    130182 
Note: See TracChangeset for help on using the changeset viewer.