| OrderFactoryUtil.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.portal.kernel.dao.orm;
16
17 import com.liferay.portal.kernel.util.OrderByComparator;
18
19 /**
20 * <a href="OrderFactoryUtil.java.html"><b><i>View Source</i></b></a>
21 *
22 * @author Brian Wing Shun Chan
23 */
24 public class OrderFactoryUtil {
25
26 public static void addOrderByComparator(
27 DynamicQuery dynamicQuery, OrderByComparator obc) {
28
29 if (obc == null) {
30 return;
31 }
32
33 String[] orderByFields = obc.getOrderByFields();
34
35 for (String orderByField : orderByFields) {
36 if (obc.isAscending()) {
37 dynamicQuery.addOrder(asc(orderByField));
38 }
39 else {
40 dynamicQuery.addOrder(desc(orderByField));
41 }
42 }
43 }
44
45 public static Order asc(String propertyName) {
46 return getOrderFactory().asc(propertyName);
47 }
48
49 public static Order desc(String propertyName) {
50 return getOrderFactory().desc(propertyName);
51 }
52
53 public static OrderFactory getOrderFactory() {
54 return _orderFactory;
55 }
56
57 public void setOrderFactory(OrderFactory orderFactory) {
58 _orderFactory = orderFactory;
59 }
60
61 private static OrderFactory _orderFactory;
62
63 }