Ignore:
Timestamp:
Mar 20, 2012, 2:40:52 PM (12 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/Criteria.java

    r32 r37  
    4343public class Criteria { 
    4444    private StringBuffer criteriaStringBuffer = new StringBuffer(); //for string criteria 
     45    private StringBuffer orderStringBuffer = new StringBuffer(); //for ordering 
    4546    private LinkedList criterionList = new LinkedList(); //for typed criteria 
    4647    private Map parameters = new HashMap(); //the parameters used in criteria string 
     
    99100    } 
    100101 
     102    /** 
     103     * Return order string to SQL 
     104     */ 
     105    public String orderStringToSQL() { 
     106        if (orderStringBuffer.length() == 0) return ""; 
     107        orderStringBuffer.insert(0, " order by"); 
     108        return orderStringBuffer.toString(); 
     109    } 
     110 
    101111    //-------------------------------------------------------------------------- 
    102112    //Typed Criteria Methods 
     
    153163     */ 
    154164    public Criteria orderAsc(String attribute) { 
    155         //Not implemented yet. 
     165        if (this.orderStringBuffer.length() != 0) this.orderStringBuffer.append(","); 
     166        this.orderStringBuffer.append(" ").append(convertAttributeToAlias(attribute)).append(" asc"); 
    156167        return this; 
    157168    } 
     
    161172     */ 
    162173    public Criteria orderDesc(String attribute) { 
    163         //Not implemented yet. 
     174        if (this.orderStringBuffer.length() != 0) this.orderStringBuffer.append(","); 
     175        this.orderStringBuffer.append(" ").append(convertAttributeToAlias(attribute)).append(" desc"); 
    164176        return this; 
    165177    } 
     
    223235                    stack.push(sr); 
    224236                } else if (conn.equals(Criterion.CONN_OR)) { 
    225                         String s1 = (String)stack.pop(); 
    226                         String s2 = (String)stack.pop(); 
    227                         String sr = "(" + s1 + " or " + s2 + ")"; 
    228                         stack.push(sr); 
    229                     } else if (conn.equals(Criterion.CONN_NOT)) { 
    230                             String s = (String)stack.pop(); 
    231                             String sr = "not (" + s + ")"; 
    232                             stack.push(sr); 
    233                         } 
     237                    String s1 = (String)stack.pop(); 
     238                    String s2 = (String)stack.pop(); 
     239                    String sr = "(" + s1 + " or " + s2 + ")"; 
     240                    stack.push(sr); 
     241                } else if (conn.equals(Criterion.CONN_NOT)) { 
     242                    String s = (String)stack.pop(); 
     243                    String sr = "not (" + s + ")"; 
     244                    stack.push(sr); 
     245                } 
    234246            } 
    235247        } 
     
    284296                .and() //connect previous criteria with and 
    285297                .isNull("SomeDomainObject.description") //attribute is null 
    286                 .or(); //connect previous criteria with and 
     298                .or() //connect previous criteria with or 
     299                .orderDesc("SomeDomainObject.name"); //order by some attribute 
    287300 
    288301        //print the resulting where clause SQL 
    289302        System.out.println(criteria.criteriaToSQL()); 
     303 
     304        //print the resulting order clause SQL 
     305        System.out.println(criteria.orderStringToSQL()); 
    290306 
    291307        //the result is; 
Note: See TracChangeset for help on using the changeset viewer.