001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.dao.orm;
016    
017    import com.liferay.portal.kernel.util.OrderByComparator;
018    
019    /**
020     * @author Brian Wing Shun Chan
021     */
022    public class OrderFactoryUtil {
023    
024            public static void addOrderByComparator(
025                    DynamicQuery dynamicQuery, OrderByComparator obc) {
026    
027                    if (obc == null) {
028                            return;
029                    }
030    
031                    String[] orderByFields = obc.getOrderByFields();
032    
033                    for (String orderByField : orderByFields) {
034                            if (obc.isAscending()) {
035                                    dynamicQuery.addOrder(asc(orderByField));
036                            }
037                            else {
038                                    dynamicQuery.addOrder(desc(orderByField));
039                            }
040                    }
041            }
042    
043            public static Order asc(String propertyName) {
044                    return getOrderFactory().asc(propertyName);
045            }
046    
047            public static Order desc(String propertyName) {
048                    return getOrderFactory().desc(propertyName);
049            }
050    
051            public static OrderFactory getOrderFactory() {
052                    return _orderFactory;
053            }
054    
055            public void setOrderFactory(OrderFactory orderFactory) {
056                    _orderFactory = orderFactory;
057            }
058    
059            private static OrderFactory _orderFactory;
060    
061    }