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