Changeset 37 for trunk/fmgVen/src/com/fmguler/ven/Ven.java
- Timestamp:
- Mar 20, 2012, 2:40:52 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fmgVen/src/com/fmguler/ven/Ven.java
r32 r37 53 53 * <p> 54 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 * 55 * To include the object associations (retrieve the object graph) joins 56 * should be specified, e.g. 57 * <code>SomeObject.anotherObject</code> 58 * 58 59 * @param id the id of the object to be retrieved 59 60 * @param objectClass the class of the object to be retrieved … … 76 77 77 78 /** 79 * Get the object with the specified id, of the specified objectClass type. 80 * <p> 81 * By default none of the associations will be retrieved. 82 * To include the object associations (retrieve the object graph) joins 83 * should be specified, e.g. 84 * <code>SomeObject.anotherObject</code> 85 * 86 * @param id the id of the object to be retrieved 87 * @param objectClass the class of the object to be retrieved 88 * @param joins the set of object graphs to be included with the object 89 * @param criteria to filter and order the result according to some criteria 90 * (e.g. for associations) 91 * @return the retrieved object including specified associations 92 */ 93 public Object get(int id, Class objectClass, Set joins, Criteria criteria) { 94 String query = generator.generateSelectQuery(objectClass, joins); 95 query += " where 1=1 and " + Convert.toDB(Convert.toSimpleName(objectClass.getName())) + ".id = :___id " + criteria.criteriaStringToSQL() + " and " + criteria.criteriaToSQL() + criteria.orderStringToSQL(); 96 97 criteria.getParameters().put("___id", new Integer(id)); 98 if (debug) System.out.println("Ven - SQL: " + query); 99 100 List result = mapper.list(query, criteria.getParameters(), objectClass); 101 if (result.isEmpty()) return null; 102 if (result.size() > 1) System.out.println("Ven - WARNING >> get(id) returns more than one row"); 103 return result.get(0); 104 } 105 106 /** 78 107 * List the objects of the specified objectClass type. 79 108 * <p> 80 109 * 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 * 110 * To include the object associations (retrieve the object graph) joins 111 * should be specified, e.g. 112 * <code>SomeObject.anotherObject</code> 113 * 84 114 * @param objectClass the class of the objects to be retrieved 85 115 * @param joins the set of object graphs to be included with objects … … 87 117 */ 88 118 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; 96 } 97 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 * 119 return list(objectClass, joins, new Criteria()); 120 } 121 122 /** 123 * List the objects of the specified objectClass type, filtering according 124 * to some criteria. 125 * <p> 126 * By default none of the associations will be retrieved. 127 * To include the object associations (retrieve the object graph) joins 128 * should be specified, e.g. 129 * <code>SomeObject.anotherObject</code> 130 * 105 131 * @param objectClass the class of the objects to be retrieved 106 132 * @param joins the set of object graphs to be included with objects 107 133 * @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 134 * @return the list of objects including the specified associations filtered 135 * according to the specified criteria 109 136 */ 110 137 public List list(Class objectClass, Set joins, Criteria criteria) { 111 138 String query = generator.generateSelectQuery(objectClass, joins); 112 query += " where 1=1 " + criteria.criteriaStringToSQL() + " and " + criteria.criteriaToSQL() ;139 query += " where 1=1 " + criteria.criteriaStringToSQL() + " and " + criteria.criteriaToSQL() + criteria.orderStringToSQL(); 113 140 114 141 if (debug) System.out.println("Ven - SQL: " + query); … … 119 146 120 147 /** 121 * Save the object. If it has a non null (or non zero) "id" property it will be updated. 148 * Save the object. If it has a non null (or non zero) "id" property it will 149 * be updated. 122 150 * It will be inserted otherwise. 123 151 * <p> 124 152 * The object will be saved to a table with the same name as the object, 125 153 * The fields of object will be mapped to the table fields. 126 * 154 * 127 155 * @param object the object to be saved 128 156 */ … … 144 172 145 173 /** 146 * Delete the the object with the specified id of the specified objectClass type 174 * Delete the the object with the specified id of the specified objectClass 175 * type 147 176 * @param id the id of the object to be deleted 148 177 * @param objectClass the class of the object to be deleted … … 200 229 * Set debug mode, true will log all debug messages to System.out 201 230 * <p> 202 * Note: Use debug mode to detect problems only. It is not a general purpose logging mode. 231 * Note: Use debug mode to detect problems only. It is not a general purpose 232 * logging mode. 203 233 * @param debug set true to enable debug mode 204 234 */ … … 208 238 mapper.setDebug(debug); 209 239 } 240 241 //-------------------------------------------------------------------------- 242 //GETTERS 243 244 /** 245 * @return the underlying query generator, for advanced usage. 246 */ 247 public QueryGenerator getQueryGenerator() { 248 return generator; 249 } 250 251 /** 252 * @return the underlying query mapper, for advanced usage. 253 */ 254 public QueryMapper getQueryMapper() { 255 return mapper; 256 } 210 257 }
Note: See TracChangeset
for help on using the changeset viewer.