2222
2323import com .cloud .utils .Pair ;
2424import com .cloud .utils .ReflectUtil ;
25+ import org .apache .commons .lang3 .StringUtils ;
2526
2627/**
2728 * Try to use static initialization to help you in finding incorrect
@@ -59,6 +60,11 @@ public Filter(long limit) {
5960 _orderBy = " ORDER BY RAND() LIMIT " + limit ;
6061 }
6162
63+ public Filter (Long offset , Long limit ) {
64+ _offset = offset ;
65+ _limit = limit ;
66+ }
67+
6268 /**
6369 * Note that this copy constructor does not copy offset and limit.
6470 * @param that filter
@@ -70,6 +76,10 @@ public Filter(Filter that) {
7076 }
7177
7278 public void addOrderBy (Class <?> clazz , String field , boolean ascending ) {
79+ addOrderBy (clazz , field , ascending , null );
80+ }
81+
82+ public void addOrderBy (Class <?> clazz , String field , boolean ascending , String tableAlias ) {
7383 if (field == null ) {
7484 return ;
7585 }
@@ -83,7 +93,9 @@ public void addOrderBy(Class<?> clazz, String field, boolean ascending) {
8393 String name = column != null ? column .name () : field ;
8494
8595 StringBuilder order = new StringBuilder ();
86- if (column == null || column .table () == null || column .table ().length () == 0 ) {
96+ if (StringUtils .isNotBlank (tableAlias )) {
97+ order .append (tableAlias );
98+ } else if (column == null || column .table () == null || column .table ().length () == 0 ) {
8799 order .append (DbUtil .getTableName (clazz ));
88100 } else {
89101 order .append (column .table ());
0 commit comments