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.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 {
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 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, OrderByComparator orderByComparator) {
057    
058                    if (status == WorkflowConstants.STATUS_ANY) {
059                            setStatus(WorkflowConstants.STATUS_IN_TRASH, true);
060                    }
061                    else {
062                            setStatus(status);
063                    }
064    
065                    _start = start;
066                    _end = end;
067    
068                    setOrderByComparator(orderByComparator);
069            }
070    
071            public Serializable getAttribute(String name) {
072                    if (_attributes == null) {
073                            return null;
074                    }
075    
076                    return _attributes.get(name);
077            }
078    
079            public Map<String, Serializable> getAttributes() {
080                    return _attributes;
081            }
082    
083            public int getEnd() {
084                    return _end;
085            }
086    
087            public OrderByComparator getOrderByComparator() {
088                    return _orderByComparator;
089            }
090    
091            public OrderByComparator getOrderByComparator(String tableName) {
092                    if (_orderByComparator == null) {
093                            return null;
094                    }
095    
096                    return new TableNameOrderByComparator(_orderByComparator, tableName);
097            }
098    
099            public int getStart() {
100                    return _start;
101            }
102    
103            public int getStatus() {
104                    return _status;
105            }
106    
107            public boolean isExcludeStatus() {
108                    return _excludeStatus;
109            }
110    
111            public void setAttribute(String name, Serializable value) {
112                    if (_attributes == null) {
113                            _attributes = new HashMap<String, Serializable>();
114                    }
115    
116                    _attributes.put(name, value);
117            }
118    
119            public void setAttributes(Map<String, Serializable> attributes) {
120                    _attributes = attributes;
121            }
122    
123            public void setEnd(int end) {
124                    _end = end;
125            }
126    
127            public void setOrderByComparator(OrderByComparator orderByComparator) {
128                    _orderByComparator = orderByComparator;
129            }
130    
131            public void setStart(int start) {
132                    _start = start;
133            }
134    
135            public void setStatus(int status) {
136                    setStatus(status, false);
137            }
138    
139            public void setStatus(int status, boolean exclude) {
140                    _excludeStatus = exclude;
141                    _status = status;
142            }
143    
144            private Map<String, Serializable> _attributes;
145            private int _end = QueryUtil.ALL_POS;
146            private boolean _excludeStatus;
147            private OrderByComparator _orderByComparator;
148            private int _start = QueryUtil.ALL_POS;
149            private int _status = WorkflowConstants.STATUS_ANY;
150    
151    }