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