1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.tools.servicebuilder;
16  
17  import com.liferay.portal.kernel.util.Validator;
18  import com.liferay.util.TextFormatter;
19  
20  /**
21   * <a href="EntityColumn.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Brian Wing Shun Chan
24   * @author Charles May
25   */
26  public class EntityColumn implements Cloneable {
27  
28      public EntityColumn(String name) {
29          this(
30              name, null, null, false, null, null, null, true, true, null, null,
31              null, true, false);
32      }
33  
34      public EntityColumn(
35          String name, String dbName, String type, boolean primary,
36          String ejbName, String mappingKey, String mappingTable,
37          boolean caseSensitive, boolean orderByAscending, String comparator,
38          String idType, String idParam, boolean convertNull, boolean localized) {
39  
40          _name = name;
41          _dbName = dbName;
42          _type = type;
43          _primary = primary;
44          _methodName = TextFormatter.format(name, TextFormatter.G);
45          _ejbName = ejbName;
46          _mappingKey = mappingKey;
47          _mappingTable = mappingTable;
48          _caseSensitive = caseSensitive;
49          _orderByAscending = orderByAscending;
50          _comparator = comparator;
51          _idType = idType;
52          _idParam = idParam;
53          _convertNull = convertNull;
54          _localized = localized;
55      }
56  
57      public EntityColumn(
58          String name, String dbName, String type, boolean primary,
59          String ejbName, String mappingKey, String mappingTable, String idType,
60          String idParam, boolean convertNull, boolean localized) {
61  
62          this(
63              name, dbName, type, primary, ejbName, mappingKey, mappingTable,
64              true, true, null, idType, idParam, convertNull, localized);
65      }
66  
67      public Object clone() {
68          return new EntityColumn(
69              getName(), getDBName(), getType(), isPrimary(), getEJBName(),
70              getMappingKey(), getMappingTable(), isCaseSensitive(),
71              isOrderByAscending(), getComparator(), getIdType(), getIdParam(),
72              isConvertNull(), isLocalized());
73      }
74  
75      public boolean equals(Object obj) {
76          EntityColumn col = (EntityColumn)obj;
77  
78          String name = col.getName();
79  
80          if (_name.equals(name)) {
81              return true;
82          }
83          else {
84              return false;
85          }
86      }
87  
88      public String getComparator() {
89          return _comparator;
90      }
91  
92      public String getDBName() {
93          return _dbName;
94      }
95  
96      public String getEJBName() {
97          return _ejbName;
98      }
99  
100     public String getIdParam() {
101         return _idParam;
102     }
103 
104     public String getIdType() {
105         return _idType;
106     }
107 
108     public String getMappingKey() {
109         return _mappingKey;
110     }
111 
112     public String getMappingTable() {
113         return _mappingTable;
114     }
115 
116     public String getMethodName() {
117         return _methodName;
118     }
119 
120     public String getMethodNames() {
121         return TextFormatter.formatPlural(new String(_methodName));
122     }
123 
124     public String getMethodUserUuidName() {
125         return _methodName.substring(0, _methodName.length() - 2) + "Uuid";
126     }
127 
128     public String getName() {
129         return _name;
130     }
131 
132     public String getNames() {
133         return TextFormatter.formatPlural(new String(_name));
134     }
135 
136     public String getType() {
137         return _type;
138     }
139 
140     public String getUserUuidName() {
141         return _name.substring(0, _name.length() - 2) + "Uuid";
142     }
143 
144     public int hashCode() {
145         return _name.hashCode();
146     }
147 
148     public boolean isCaseSensitive() {
149         return _caseSensitive;
150     }
151 
152     public boolean isCollection() {
153         if (_type.equals("Collection")) {
154             return true;
155         }
156         else {
157             return false;
158         }
159     }
160 
161     public boolean isConvertNull() {
162         return _convertNull;
163     }
164 
165     public boolean isFetchFinderPath() {
166         return _fetchFinderPath;
167     }
168 
169     public boolean isLocalized() {
170         return _localized;
171     }
172 
173     public boolean isMappingManyToMany() {
174         return Validator.isNotNull(_mappingTable);
175     }
176 
177     public boolean isMappingOneToMany() {
178         return Validator.isNotNull(_mappingKey);
179     }
180 
181     public boolean isOrderByAscending() {
182         return _orderByAscending;
183     }
184 
185     public boolean isPrimary() {
186         return _primary;
187     }
188 
189     public boolean isPrimitiveType() {
190         return isPrimitiveType(true);
191     }
192 
193     public boolean isPrimitiveType(boolean includeWrappers) {
194         if (Character.isLowerCase(_type.charAt(0))) {
195             return true;
196         }
197 
198         if (!includeWrappers) {
199             return false;
200         }
201 
202         if (_type.equals("Boolean")) {
203             return true;
204         }
205         else if (_type.equals("Double")) {
206             return true;
207         }
208         else if (_type.equals("Float")) {
209             return true;
210         }
211         else if (_type.equals("Integer")) {
212             return true;
213         }
214         else if (_type.equals("Long")) {
215             return true;
216         }
217         else if (_type.equals("Short")) {
218             return true;
219         }
220         else {
221             return false;
222         }
223     }
224 
225     public boolean isUserUuid() {
226         if (_type.equals("long") && _methodName.endsWith("UserId")) {
227             return true;
228         }
229         else {
230             return false;
231         }
232     }
233 
234     public void setCaseSensitive(boolean caseSensitive) {
235         _caseSensitive = caseSensitive;
236     }
237 
238     public void setComparator(String comparator) {
239         _comparator = comparator;
240     }
241 
242     public void setConvertNull(boolean convertNull) {
243         _convertNull = convertNull;
244     }
245 
246     public void setDBName(String dbName) {
247         _dbName = dbName;
248     }
249 
250     public void setFetchFinderPath(boolean fetchFinderPath) {
251         _fetchFinderPath = fetchFinderPath;
252     }
253 
254     public void setIdParam(String idParam) {
255         _idParam = idParam;
256     }
257 
258     public void setIdType(String idType) {
259         _idType = idType;
260     }
261 
262     public void setLocalized(boolean localized) {
263         _localized = localized;
264     }
265 
266     public void setOrderByAscending(boolean orderByAscending) {
267         _orderByAscending = orderByAscending;
268     }
269 
270     private boolean _caseSensitive;
271     private String _comparator;
272     private boolean _convertNull;
273     private String _dbName;
274     private String _ejbName;
275     private boolean _fetchFinderPath;
276     private String _idParam;
277     private String _idType;
278     private boolean _localized;
279     private String _mappingKey;
280     private String _mappingTable;
281     private String _methodName;
282     private String _name;
283     private boolean _orderByAscending;
284     private boolean _primary;
285     private String _type;
286 
287 }