Changeset 29


Ignore:
Timestamp:
Feb 10, 2011, 10:06:10 PM (14 years ago)
Author:
fmguler
Message:

Refs #3 - Ven.list() is converted to the new format. Almost the same as Ven.get(). Added javadoc to Ven public methods. Added listing test, and made the sample domain object toString methods more readable.

Now, adding the criteria parameter to the operations is to be done.

Location:
trunk/fmgVen
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/fmgVen/src/com/fmguler/ven/Ven.java

    r28 r29  
    4545    } 
    4646 
    47     public List list(Class objectClass) { 
    48         return null; 
    49     } 
    50  
    5147    public int count() { 
    5248        return 0; 
    5349    } 
    5450 
     51    /** 
     52     * Get the object with the specified id, of the specified objectClass type. 
     53     * <p> 
     54     * By default none of the associations will be retrieved. 
     55     * To include the object associations (retrieve the object graph) joins should be specified, e.g. 
     56     * <code>SomeObject.anotherObject</code> 
     57     *  
     58     * @param id the id of the object to be retrieved 
     59     * @param objectClass the class of the object to be retrieved 
     60     * @param joins the set of object graphs to be included with the object 
     61     * @return the retrieved object including specified associations 
     62     */ 
    5563    public Object get(int id, Class objectClass, Set joins) { 
    5664        String query = generator.generateSelectQuery(objectClass, joins); 
     
    6573        if (result.size() > 1) System.out.println("Ven - WARNING >> get(id) returns more than one row"); 
    6674        return result.get(0); 
     75    } 
     76 
     77    /** 
     78     * List the objects of the specified objectClass type. 
     79     * <p> 
     80     * By default none of the associations will be retrieved. 
     81     * To include the object associations (retrieve the object graph) joins should be specified, e.g. 
     82     * <code>SomeObject.anotherObject</code> 
     83     *  
     84     * @param objectClass the class of the objects to be retrieved 
     85     * @param joins the set of object graphs to be included with objects 
     86     * @return the list of objects including specified associations 
     87     */ 
     88    public List list(Class objectClass, Set joins) { 
     89        String query = generator.generateSelectQuery(objectClass, joins); 
     90 
     91        Map paramMap = new HashMap(); 
     92        if (debug) System.out.println("Ven - SQL: " + query); 
     93 
     94        List result = mapper.list(query, paramMap, objectClass); 
     95        return result; 
    6796    } 
    6897 
     
    124153    //-------------------------------------------------------------------------- 
    125154    //SETTERS 
     155    /** 
     156     * Set the DataSource to be used to access to the database 
     157     */ 
    126158    public void setDataSource(DataSource dataSource) { 
    127159        if (dataSource == null) throw new RuntimeException("fmgVen - DataSource cannot be null"); 
     
    130162    } 
    131163 
     164    /** 
     165     * Add the domain packages that have corresponding database tables. 
     166     * <p> 
     167     * The objects in these packages are considered persistable. 
     168     * @param domainPackage the package of the entity classes. 
     169     * @return this instance to allow chaining. 
     170     */ 
    132171    public Ven addDomainPackage(String domainPackage) { 
    133172        generator.addDomainPackage(domainPackage); 
  • trunk/fmgVen/test/com/fmguler/ven/sample/Sample.java

    r28 r29  
    2424import java.util.Date; 
    2525import java.util.HashSet; 
     26import java.util.Iterator; 
    2627import java.util.List; 
    2728import java.util.Set; 
     
    4041        //get an object 
    4142        testGet(); 
     43        //list the objects 
     44        testList(); 
    4245        //delete an object 
    4346        testDelete(); 
     
    5154     */ 
    5255    public static void testSave() { 
     56        System.out.println("******SAVE******"); 
    5357        Ven ven = getVen(); 
    5458 
     
    7175     */ 
    7276    public static void testDelete() { 
     77        System.out.println("******DELETE******"); 
    7378        Ven ven = getVen(); 
    7479        ven.delete(2, SomeDomainObject.class); 
     
    7984     */ 
    8085    public static void testGet() { 
     86        System.out.println("******GET******"); 
    8187        Ven ven = getVen(); 
    8288 
     
    98104     */ 
    99105    public static void testList() { 
     106        System.out.println("******LIST******"); 
    100107        Ven ven = getVen(); 
    101         List objList = ven.list(SomeDomainObject.class); 
    102         System.out.println(objList); 
     108 
     109        //list with includes 
     110        Set joins = new HashSet(); 
     111        joins.add("SomeDomainObject.anotherDomainObjects"); 
     112        joins.add("SomeDomainObject.anotherDomainObject"); 
     113        List objList = ven.list(SomeDomainObject.class, joins); 
     114         
     115        Iterator it = objList.iterator(); 
     116        while (it.hasNext()) { 
     117            SomeDomainObject someDomainObject = (SomeDomainObject)it.next(); 
     118            System.out.println(someDomainObject); 
     119        } 
    103120    } 
    104121 
     
    108125    public static void testListByCriteria() { 
    109126        Ven ven = getVen(); 
    110         List objList = ven.list(SomeDomainObject.class/*, criteria */); 
    111         System.out.println(objList); 
     127        //List objList = ven.list(SomeDomainObject.class/*, criteria */); 
     128        //System.out.println(objList); 
    112129    } 
    113130 
  • trunk/fmgVen/test/com/fmguler/ven/sample/domain/AnotherDomainObject.java

    r28 r29  
    102102 
    103103    public String toString() { 
    104         return id + " " + name + " " + description + " some domain object: {" + someDomainObject + "}"; 
     104        return "{" + id + ", " + name + ", " + description + ", some domain object: " + someDomainObject + "}"; 
    105105    } 
    106106} 
  • trunk/fmgVen/test/com/fmguler/ven/sample/domain/SomeDomainObject.java

    r28 r29  
    112112 
    113113    public String toString() { 
    114         return id + " " + name + " " + description + " another domain object: {" + anotherDomainObject + "} another domain objects:\n" + anotherDomainObjects; 
     114        return "{" + id + ", " + name + ", " + description + ", another domain object: " + anotherDomainObject + ", another domain objects: " + anotherDomainObjects + "} "; 
    115115    } 
    116116} 
Note: See TracChangeset for help on using the changeset viewer.