001    /**
002     * Copyright (c) 2000-present 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    import com.liferay.portal.kernel.util.TableNameOrderByComparator;
019    import com.liferay.portal.kernel.workflow.WorkflowConstants;
020    
021    import java.io.Serializable;
022    
023    import java.util.HashMap;
024    import java.util.Map;
025    
026    /**
027     * @author Zsolt Berentey
028     */
029    public class QueryDefinition<T> {
030    
031            public QueryDefinition() {
032            }
033    
034            public QueryDefinition(int status) {
035                    if (status == WorkflowConstants.STATUS_ANY) {
036                            setStatus(WorkflowConstants.STATUS_IN_TRASH, true);
037                    }
038                    else {
039                            setStatus(status);
040                    }
041            }
042    
043            public QueryDefinition(
044                    int status, boolean excludeStatus, int start, int end,
045                    OrderByComparator<T> orderByComparator) {
046    
047                    _status = status;
048                    _excludeStatus = excludeStatus;
049                    _start = start;
050                    _end = end;
051    
052                    setOrderByComparator(orderByComparator);
053            }
054    
055            public QueryDefinition(
056                    int status, int start, int end,
057                    OrderByComparator<T> orderByComparator) {
058    
059                    if (status == WorkflowConstants.STATUS_ANY) {
060                            setStatus(WorkflowConstants.STATUS_IN_TRASH, true);
061                    }
062                    else {
063                            setStatus(status);
064                    }
065    
066                    _start = start;
067                    _end = end;
068    
069                    setOrderByComparator(orderByComparator);
070            }
071    
072            public Serializable getAttribute(String name) {
073                    if (_attributes == null) {
074                            return null;
075                    }
076    
077                    return _attributes.get(name);
078            }
079    
080            public Map<String, Serializable> getAttributes() {
081                    return _attributes;
082            }
083    
084            public int getEnd() {
085                    return _end;
086            }
087    
088            public OrderByComparator<T> getOrderByComparator() {
089                    return _orderByComparator;
090            }
091    
092            public OrderByComparator<T> getOrderByComparator(String tableName) {
093                    if (_orderByComparator == null) {
094                            return null;
095                    }
096    
097                    return new TableNameOrderByComparator<T>(_orderByComparator, tableName);
098            }
099    
100            public int getStart() {
101                    return _start;
102            }
103    
104            public int getStatus() {
105                    return _status;
106            }
107    
108            public boolean isExcludeStatus() {
109                    return _excludeStatus;
110            }
111    
112            public void setAttribute(String name, Serializable value) {
113                    if (_attributes == null) {
114                            _attributes = new HashMap<String, Serializable>();
115                    }
116    
117                    _attributes.put(name, value);
118            }
119    
120            public void setAttributes(Map<String, Serializable> attributes) {
121                    _attributes = attributes;
122            }
123    
124            public void setEnd(int end) {
125                    _end = end;
126            }
127    
128            public void setOrderByComparator(OrderByComparator<T> orderByComparator) {
129                    _orderByComparator = orderByComparator;
130            }
131    
132            public void setStart(int start) {
133                    _start = start;
134            }
135    
136            public void setStatus(int status) {
137                    setStatus(status, false);
138            }
139    
140            public void setStatus(int status, boolean exclude) {
141                    _excludeStatus = exclude;
142                    _status = status;
143            }
144    
145            private Map<String, Serializable> _attributes;
146            private int _end = QueryUtil.ALL_POS;
147            private boolean _excludeStatus;
148            private OrderByComparator<T> _orderByComparator;
149            private int _start = QueryUtil.ALL_POS;
150            private int _status = WorkflowConstants.STATUS_ANY;
151    
152    }