Changeset 30
- Timestamp:
- Apr 9, 2011, 12:44:03 PM (14 years ago)
- Location:
- trunk/fmgVen
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fmgVen/src/com/fmguler/ven/Ven.java
r29 r30 97 97 98 98 /** 99 * List the objects of the specified objectClass type, filtering according to some criteria. 100 * <p> 101 * By default none of the associations will be retrieved. 102 * To include the object associations (retrieve the object graph) joins should be specified, e.g. 103 * <code>SomeObject.anotherObject</code> 104 * 105 * @param objectClass the class of the objects to be retrieved 106 * @param joins the set of object graphs to be included with objects 107 * @param criteria to filter and order the result according to some criteria 108 * @return the list of objects including the specified associations filtered according to the specified criteria 109 */ 110 public List list(Class objectClass, Set joins, Criteria criteria) { 111 String query = generator.generateSelectQuery(objectClass, joins); 112 query += " where 1=1 " + criteria.criteriaStringToSQL() + " and " + criteria.criteriaToSQL(); 113 114 if (debug) System.out.println("Ven - SQL: " + query); 115 116 List result = mapper.list(query, criteria.getParameters(), objectClass); 117 return result; 118 } 119 120 /** 99 121 * Save the object. If it has a non null (or non zero) "id" property it will be updated. 100 122 * It will be inserted otherwise. -
trunk/fmgVen/test/com/fmguler/ven/sample/Sample.java
r29 r30 18 18 package com.fmguler.ven.sample; 19 19 20 import com.fmguler.ven.Criteria; 20 21 import com.fmguler.ven.LiquibaseUtil; 21 22 import com.fmguler.ven.Ven; … … 43 44 //list the objects 44 45 testList(); 46 //list the objects by some criteria string 47 testListByCriteriaString(); 48 //list the objects by some typed criteria 49 testListByCriteriaObject(); 45 50 //delete an object 46 51 testDelete(); … … 112 117 joins.add("SomeDomainObject.anotherDomainObject"); 113 118 List objList = ven.list(SomeDomainObject.class, joins); 114 119 115 120 Iterator it = objList.iterator(); 116 121 while (it.hasNext()) { … … 121 126 122 127 /** 123 * Test list the collection of objects by some criteria 128 * Test list the collection of objects by some criteria (string) 124 129 */ 125 public static void testListByCriteria () {130 public static void testListByCriteriaString() { 126 131 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 } 129 181 } 130 182
Note: See TracChangeset
for help on using the changeset viewer.