1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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;
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   */
35  public class EntityColumn implements Cloneable {
36  
37      public EntityColumn(String name) {
38          this(name, null, null, false, null, null, null, true, true, null,
39               null, null, true);
40      }
41  
42      public EntityColumn(String name, String dbName, String type,
43                          boolean primary, String ejbName, String mappingKey,
44                          String mappingTable, String idType, String idParam,
45                          boolean convertNull) {
46  
47          this(name, dbName, type, primary, ejbName, mappingKey, mappingTable,
48               true, true, null, idType, idParam, convertNull);
49      }
50  
51      public EntityColumn(String name, String dbName, String type,
52                          boolean primary, String ejbName, String mappingKey,
53                          String mappingTable, boolean caseSensitive,
54                          boolean orderByAscending, String comparator,
55                          String idType, String idParam, boolean convertNull) {
56  
57          _name = name;
58          _dbName = dbName;
59          _type = type;
60          _primary = primary;
61          _methodName = TextFormatter.format(name, TextFormatter.G);
62          _ejbName = ejbName;
63          _mappingKey = mappingKey;
64          _mappingTable = mappingTable;
65          _caseSensitive = caseSensitive;
66          _orderByAscending = orderByAscending;
67          _comparator = comparator;
68          _idType = idType;
69          _idParam = idParam;
70          _convertNull = convertNull;
71      }
72  
73      public String getName() {
74          return _name;
75      }
76  
77      public String getDBName() {
78          return _dbName;
79      }
80  
81      public void setDBName(String dbName) {
82          _dbName = dbName;
83      }
84  
85      public String getType() {
86          return _type;
87      }
88  
89      public boolean isPrimitiveType() {
90          if (Character.isLowerCase(_type.charAt(0))) {
91              return true;
92          }
93          else {
94              return false;
95          }
96      }
97  
98      public boolean isCollection() {
99          if (_type.equals("Collection")) {
100             return true;
101         }
102         else {
103             return false;
104         }
105     }
106 
107     public boolean isPrimary() {
108         return _primary;
109     }
110 
111     public String getMethodName() {
112         return _methodName;
113     }
114 
115     public String getEJBName() {
116         return _ejbName;
117     }
118 
119     public String getMappingKey() {
120         return _mappingKey;
121     }
122 
123     public String getMappingTable() {
124         return _mappingTable;
125     }
126 
127     public boolean isMappingOneToMany() {
128         return Validator.isNotNull(_mappingKey);
129     }
130 
131     public boolean isMappingManyToMany() {
132         return Validator.isNotNull(_mappingTable);
133     }
134 
135     public boolean isCaseSensitive() {
136         return _caseSensitive;
137     }
138 
139     public void setCaseSensitive(boolean caseSensitive) {
140         _caseSensitive = caseSensitive;
141     }
142 
143     public boolean isOrderByAscending() {
144         return _orderByAscending;
145     }
146 
147     public void setOrderByAscending(boolean orderByAscending) {
148         _orderByAscending = orderByAscending;
149     }
150 
151     public String getComparator() {
152         return _comparator;
153     }
154 
155     public void setComparator(String comparator) {
156         _comparator = comparator;
157     }
158 
159     public String getIdType() {
160         return _idType;
161     }
162 
163     public void setIdType(String idType) {
164         _idType = idType;
165     }
166 
167     public String getIdParam() {
168         return _idParam;
169     }
170 
171     public void setIdParam(String idParam) {
172         _idParam = idParam;
173     }
174 
175     public boolean isConvertNull() {
176         return _convertNull;
177     }
178 
179     public void setConvertNull(boolean convertNull) {
180         _convertNull = convertNull;
181     }
182 
183     public Object clone() {
184         return new EntityColumn(
185             getName(), getDBName(), getType(), isPrimary(), getEJBName(),
186             getMappingKey(), getMappingTable(), isCaseSensitive(),
187             isOrderByAscending(), getComparator(), getIdType(), getIdParam(),
188             isConvertNull());
189     }
190 
191     public boolean equals(Object obj) {
192         EntityColumn col = (EntityColumn)obj;
193 
194         String name = col.getName();
195 
196         if (_name.equals(name)) {
197             return true;
198         }
199         else {
200             return false;
201         }
202     }
203 
204     private String _name;
205     private String _dbName;
206     private String _type;
207     private boolean _primary;
208     private String _methodName;
209     private String _ejbName;
210     private String _mappingKey;
211     private String _mappingTable;
212     private boolean _caseSensitive;
213     private boolean _orderByAscending;
214     private String _comparator;
215     private String _idType;
216     private String _idParam;
217     private boolean _convertNull;
218 
219 }