001    /**
002     * Copyright (c) 2000-2013 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.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(orderByField)) {
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    }