123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package com.hcks.cmfds.commons.lang;
- import java.io.Serializable;
- /**
- *
- * 查询时的顺序
- *
- * @author:liusha
- * @date:Feb 3, 2011 11:12:44 AM
- */
- public class QueryOrder implements Serializable {
- private static final long serialVersionUID = 5291198501266064857L;
-
- /**
- * 是否升序
- */
- private boolean ascending;
-
- /**
- * 忽略排序
- */
- private boolean ignoreCase;
-
- public boolean isIgnoreCase() {
- return ignoreCase;
- }
- public void setIgnoreCase(boolean ignoreCase) {
- this.ignoreCase = ignoreCase;
- }
- /**
- * 属性名称
- */
- private String propertyName;
-
- /**
- * 返回字符串
- */
- public String toString(){
- return propertyName + " " +(ascending ? "asc" : "desc");
- }
-
- /**
- * 带参数的构造方法
- * @param propertyName
- * @param ascending
- */
- public QueryOrder(String propertyName,boolean ascending){
- this.propertyName = propertyName;
- this.ascending = ascending;
- }
-
- /**
- * 带参数的构造方法
- * @param propertyName
- * @param ascending
- */
- public QueryOrder(String propertyName,String ascending){
-
- this.propertyName = propertyName;
-
-
- if(null !=ascending)
- {
- if(ascending.equals("asc"))
- {
- this.ascending = true;
- }else if(ascending.equals("desc"))
- {
- this.ascending = false;
- }
- }
-
- }
-
- /**
- * 静态方法:返回升序的QueryOrder实例
- * @param propertyName
- * @return
- */
- public static QueryOrder asc(String propertyName){
- return new QueryOrder(propertyName,true);
- }
-
- /**
- * 静态方法:返回降序的QueryOrder实例
- * @param propertyName
- * @return
- */
- public static QueryOrder desc(String propertyName){
- return new QueryOrder(propertyName,false);
- }
-
- /**
- * 忽略排序方法
- * @return
- */
- public QueryOrder ignoreCase(){
- ignoreCase = true;
- return this;
- }
-
- public void appendSqlOrder(StringBuilder sb){
- if(sb == null)
- sb = new StringBuilder();
- if(sb.toString().indexOf("order by") == -1){
- sb.append(" order by ");
- }
- sb.append(" ").append(toString());
- }
-
- public void appendSqlOrder(StringBuilder sb,boolean isSplit){
- if(sb == null)
- sb = new StringBuilder();
- if(sb.toString().indexOf("order by") == -1){
- sb.append(" order by ");
- }
-
- if(isSplit)
- {
- sb.append(" ").append(toString()).append(",");
- }else
- {
- sb.append(" ").append(toString());
- }
-
- }
- }
|