Ignore:
Timestamp:
Mar 20, 2012, 2:40:52 PM (13 years ago)
Author:
fmguler
Message:

Refs #7 - Implemented orderAsc and orderDesc methods of Criteria. Have been testing these for a while, no problem so far. Added BigDecimal to db classes (Numeric db type). If the column name is "order" it is escaped while insert/update. (This should be done for all db keywords). Fixed missing mapping of one to many assc. (lists) of many to one (object) assc (obj.obj.list).

File:
1 edited

Legend:

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

    r32 r37  
    5353     * <p> 
    5454     * 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     * 
    5859     * @param id the id of the object to be retrieved 
    5960     * @param objectClass the class of the object to be retrieved 
     
    7677 
    7778    /** 
     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    /** 
    78107     * List the objects of the specified objectClass type. 
    79108     * <p> 
    80109     * 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     * 
    84114     * @param objectClass the class of the objects to be retrieved 
    85115     * @param joins the set of object graphs to be included with objects 
     
    87117     */ 
    88118    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     * 
    105131     * @param objectClass the class of the objects to be retrieved 
    106132     * @param joins the set of object graphs to be included with objects 
    107133     * @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 
    109136     */ 
    110137    public List list(Class objectClass, Set joins, Criteria criteria) { 
    111138        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(); 
    113140 
    114141        if (debug) System.out.println("Ven - SQL: " + query); 
     
    119146 
    120147    /** 
    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. 
    122150     * It will be inserted otherwise. 
    123151     * <p> 
    124152     * The object will be saved to a table with the same name as the object, 
    125153     * The fields of object will be mapped to the table fields. 
    126      *  
     154     * 
    127155     * @param object the object to be saved 
    128156     */ 
     
    144172 
    145173    /** 
    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 
    147176     * @param id the id of the object to be deleted 
    148177     * @param objectClass the class of the object to be deleted 
     
    200229     * Set debug mode, true will log all debug messages to System.out 
    201230     * <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. 
    203233     * @param debug set true to enable debug mode 
    204234     */ 
     
    208238        mapper.setDebug(debug); 
    209239    } 
     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    } 
    210257} 
Note: See TracChangeset for help on using the changeset viewer.