001    /**
002     * Copyright (c) 2000-2012 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.security.pacl.permission.PortalRuntimePermission;
018    import com.liferay.portal.kernel.util.OrderByComparator;
019    
020    /**
021     * @author Brian Wing Shun Chan
022     */
023    public class OrderFactoryUtil {
024    
025            public static void addOrderByComparator(
026                    DynamicQuery dynamicQuery, OrderByComparator obc) {
027    
028                    if (obc == null) {
029                            return;
030                    }
031    
032                    String[] orderByFields = obc.getOrderByFields();
033    
034                    for (String orderByField : orderByFields) {
035                            if (obc.isAscending()) {
036                                    dynamicQuery.addOrder(asc(orderByField));
037                            }
038                            else {
039                                    dynamicQuery.addOrder(desc(orderByField));
040                            }
041                    }
042            }
043    
044            public static Order asc(String propertyName) {
045                    return getOrderFactory().asc(propertyName);
046            }
047    
048            public static Order desc(String propertyName) {
049                    return getOrderFactory().desc(propertyName);
050            }
051    
052            public static OrderFactory getOrderFactory() {
053                    PortalRuntimePermission.checkGetBeanProperty(OrderFactoryUtil.class);
054    
055                    return _orderFactory;
056            }
057    
058            public void setOrderFactory(OrderFactory orderFactory) {
059                    PortalRuntimePermission.checkSetBeanProperty(getClass());
060    
061                    _orderFactory = orderFactory;
062            }
063    
064            private static OrderFactory _orderFactory;
065    
066    }