001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }