001
014
015 package com.liferay.counter.model.impl;
016
017 import com.liferay.counter.model.Counter;
018 import com.liferay.counter.model.CounterModel;
019
020 import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
021 import com.liferay.portal.kernel.util.GetterUtil;
022 import com.liferay.portal.kernel.util.ProxyUtil;
023 import com.liferay.portal.kernel.util.StringBundler;
024 import com.liferay.portal.kernel.util.StringPool;
025 import com.liferay.portal.model.CacheModel;
026 import com.liferay.portal.model.impl.BaseModelImpl;
027
028 import java.io.Serializable;
029
030 import java.sql.Types;
031
032 import java.util.HashMap;
033 import java.util.Map;
034
035
048 public class CounterModelImpl extends BaseModelImpl<Counter>
049 implements CounterModel {
050
055 public static final String TABLE_NAME = "Counter";
056 public static final Object[][] TABLE_COLUMNS = {
057 { "name", Types.VARCHAR },
058 { "currentId", Types.BIGINT }
059 };
060 public static final String TABLE_SQL_CREATE = "create table Counter (name VARCHAR(75) not null primary key,currentId LONG)";
061 public static final String TABLE_SQL_DROP = "drop table Counter";
062 public static final String DATA_SOURCE = "liferayDataSource";
063 public static final String SESSION_FACTORY = "liferaySessionFactory";
064 public static final String TX_MANAGER = "liferayTransactionManager";
065 public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
066 "value.object.entity.cache.enabled.com.liferay.counter.model.Counter"),
067 false);
068 public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
069 "value.object.finder.cache.enabled.com.liferay.counter.model.Counter"),
070 false);
071 public static final boolean COLUMN_BITMASK_ENABLED = false;
072 public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
073 "lock.expiration.time.com.liferay.counter.model.Counter"));
074
075 public CounterModelImpl() {
076 }
077
078 public String getPrimaryKey() {
079 return _name;
080 }
081
082 public void setPrimaryKey(String primaryKey) {
083 setName(primaryKey);
084 }
085
086 public Serializable getPrimaryKeyObj() {
087 return _name;
088 }
089
090 public void setPrimaryKeyObj(Serializable primaryKeyObj) {
091 setPrimaryKey((String)primaryKeyObj);
092 }
093
094 public Class<?> getModelClass() {
095 return Counter.class;
096 }
097
098 public String getModelClassName() {
099 return Counter.class.getName();
100 }
101
102 @Override
103 public Map<String, Object> getModelAttributes() {
104 Map<String, Object> attributes = new HashMap<String, Object>();
105
106 attributes.put("name", getName());
107 attributes.put("currentId", getCurrentId());
108
109 return attributes;
110 }
111
112 @Override
113 public void setModelAttributes(Map<String, Object> attributes) {
114 String name = (String)attributes.get("name");
115
116 if (name != null) {
117 setName(name);
118 }
119
120 Long currentId = (Long)attributes.get("currentId");
121
122 if (currentId != null) {
123 setCurrentId(currentId);
124 }
125 }
126
127 public String getName() {
128 if (_name == null) {
129 return StringPool.BLANK;
130 }
131 else {
132 return _name;
133 }
134 }
135
136 public void setName(String name) {
137 _name = name;
138 }
139
140 public long getCurrentId() {
141 return _currentId;
142 }
143
144 public void setCurrentId(long currentId) {
145 _currentId = currentId;
146 }
147
148 @Override
149 public Counter toEscapedModel() {
150 if (_escapedModel == null) {
151 _escapedModel = (Counter)ProxyUtil.newProxyInstance(_classLoader,
152 _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
153 }
154
155 return _escapedModel;
156 }
157
158 public Counter toUnescapedModel() {
159 return (Counter)this;
160 }
161
162 @Override
163 public Object clone() {
164 CounterImpl counterImpl = new CounterImpl();
165
166 counterImpl.setName(getName());
167 counterImpl.setCurrentId(getCurrentId());
168
169 counterImpl.resetOriginalValues();
170
171 return counterImpl;
172 }
173
174 public int compareTo(Counter counter) {
175 String primaryKey = counter.getPrimaryKey();
176
177 return getPrimaryKey().compareTo(primaryKey);
178 }
179
180 @Override
181 public boolean equals(Object obj) {
182 if (this == obj) {
183 return true;
184 }
185
186 if (!(obj instanceof Counter)) {
187 return false;
188 }
189
190 Counter counter = (Counter)obj;
191
192 String primaryKey = counter.getPrimaryKey();
193
194 if (getPrimaryKey().equals(primaryKey)) {
195 return true;
196 }
197 else {
198 return false;
199 }
200 }
201
202 @Override
203 public int hashCode() {
204 return getPrimaryKey().hashCode();
205 }
206
207 @Override
208 public void resetOriginalValues() {
209 }
210
211 @Override
212 public CacheModel<Counter> toCacheModel() {
213 CounterCacheModel counterCacheModel = new CounterCacheModel();
214
215 counterCacheModel.name = getName();
216
217 String name = counterCacheModel.name;
218
219 if ((name != null) && (name.length() == 0)) {
220 counterCacheModel.name = null;
221 }
222
223 counterCacheModel.currentId = getCurrentId();
224
225 return counterCacheModel;
226 }
227
228 @Override
229 public String toString() {
230 StringBundler sb = new StringBundler(5);
231
232 sb.append("{name=");
233 sb.append(getName());
234 sb.append(", currentId=");
235 sb.append(getCurrentId());
236 sb.append("}");
237
238 return sb.toString();
239 }
240
241 public String toXmlString() {
242 StringBundler sb = new StringBundler(10);
243
244 sb.append("<model><model-name>");
245 sb.append("com.liferay.counter.model.Counter");
246 sb.append("</model-name>");
247
248 sb.append(
249 "<column><column-name>name</column-name><column-value><![CDATA[");
250 sb.append(getName());
251 sb.append("]]></column-value></column>");
252 sb.append(
253 "<column><column-name>currentId</column-name><column-value><![CDATA[");
254 sb.append(getCurrentId());
255 sb.append("]]></column-value></column>");
256
257 sb.append("</model>");
258
259 return sb.toString();
260 }
261
262 private static ClassLoader _classLoader = Counter.class.getClassLoader();
263 private static Class<?>[] _escapedModelInterfaces = new Class[] {
264 Counter.class
265 };
266 private String _name;
267 private long _currentId;
268 private Counter _escapedModel;
269 }