| OrderFactoryUtil.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 *
12 *
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 }