001
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
029 public class QueryDefinition<T> {
030
031 public QueryDefinition() {
032 }
033
034 public QueryDefinition(int status) {
035 this(status, 0, false);
036 }
037
038 public QueryDefinition(
039 int status, boolean excludeStatus, int start, int end,
040 OrderByComparator<T> orderByComparator) {
041
042 this(status, excludeStatus, 0, false, start, end, orderByComparator);
043 }
044
045 public QueryDefinition(
046 int status, boolean excludeStatus, long ownerUserId,
047 boolean includeOwner, int start, int end,
048 OrderByComparator<T> orderByComparator) {
049
050 _status = status;
051 _excludeStatus = excludeStatus;
052 _ownerUserId = ownerUserId;
053 _includeOwner = includeOwner;
054 _start = start;
055 _end = end;
056
057 setOrderByComparator(orderByComparator);
058 }
059
060 public QueryDefinition(
061 int status, int start, int end,
062 OrderByComparator<T> orderByComparator) {
063
064 this(status, 0, false, start, end, orderByComparator);
065 }
066
067 public QueryDefinition(int status, long ownerUserId, boolean includeOwner) {
068 if (status == WorkflowConstants.STATUS_ANY) {
069 setStatus(WorkflowConstants.STATUS_IN_TRASH, true);
070 }
071 else {
072 setStatus(status);
073 }
074
075 _ownerUserId = ownerUserId;
076 _includeOwner = includeOwner;
077 }
078
079 public QueryDefinition(
080 int status, long ownerUserId, boolean includeOwner, int start, int end,
081 OrderByComparator<T> orderByComparator) {
082
083 if (status == WorkflowConstants.STATUS_ANY) {
084 setStatus(WorkflowConstants.STATUS_IN_TRASH, true);
085 }
086 else {
087 setStatus(status);
088 }
089
090 _ownerUserId = ownerUserId;
091 _includeOwner = includeOwner;
092 _start = start;
093 _end = end;
094
095 setOrderByComparator(orderByComparator);
096 }
097
098 public Serializable getAttribute(String name) {
099 if (_attributes == null) {
100 return null;
101 }
102
103 return _attributes.get(name);
104 }
105
106 public Map<String, Serializable> getAttributes() {
107 return _attributes;
108 }
109
110 public int getEnd() {
111 return _end;
112 }
113
114 public OrderByComparator<T> getOrderByComparator() {
115 return _orderByComparator;
116 }
117
118 public OrderByComparator<T> getOrderByComparator(String tableName) {
119 if (_orderByComparator == null) {
120 return null;
121 }
122
123 return new TableNameOrderByComparator<>(_orderByComparator, tableName);
124 }
125
126 public long getOwnerUserId() {
127 return _ownerUserId;
128 }
129
130 public int getStart() {
131 return _start;
132 }
133
134 public int getStatus() {
135 return _status;
136 }
137
138 public boolean isExcludeStatus() {
139 return _excludeStatus;
140 }
141
142 public boolean isIncludeOwner() {
143 return _includeOwner;
144 }
145
146 public void setAttribute(String name, Serializable value) {
147 if (_attributes == null) {
148 _attributes = new HashMap<>();
149 }
150
151 _attributes.put(name, value);
152 }
153
154 public void setAttributes(Map<String, Serializable> attributes) {
155 _attributes = attributes;
156 }
157
158 public void setEnd(int end) {
159 _end = end;
160 }
161
162 public void setIncludeOwner(boolean includeOwner) {
163 _includeOwner = includeOwner;
164 }
165
166 public void setOrderByComparator(OrderByComparator<T> orderByComparator) {
167 _orderByComparator = orderByComparator;
168 }
169
170 public void setOwnerUserId(long ownerUserId) {
171 _ownerUserId = ownerUserId;
172 }
173
174 public void setStart(int start) {
175 _start = start;
176 }
177
178 public void setStatus(int status) {
179 setStatus(status, false);
180 }
181
182 public void setStatus(int status, boolean exclude) {
183 _excludeStatus = exclude;
184 _status = status;
185 }
186
187 private Map<String, Serializable> _attributes;
188 private int _end = QueryUtil.ALL_POS;
189 private boolean _excludeStatus;
190 private boolean _includeOwner;
191 private OrderByComparator<T> _orderByComparator;
192 private long _ownerUserId;
193 private int _start = QueryUtil.ALL_POS;
194 private int _status = WorkflowConstants.STATUS_ANY;
195
196 }