001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.counter.model.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.counter.model.Counter;
020    import com.liferay.counter.model.CounterModel;
021    
022    import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
023    import com.liferay.portal.kernel.util.GetterUtil;
024    import com.liferay.portal.kernel.util.ProxyUtil;
025    import com.liferay.portal.kernel.util.StringBundler;
026    import com.liferay.portal.kernel.util.StringPool;
027    import com.liferay.portal.model.CacheModel;
028    import com.liferay.portal.model.impl.BaseModelImpl;
029    
030    import java.io.Serializable;
031    
032    import java.sql.Types;
033    
034    import java.util.HashMap;
035    import java.util.Map;
036    
037    /**
038     * The base model implementation for the Counter service. Represents a row in the "Counter" database table, with each column mapped to a property of this class.
039     *
040     * <p>
041     * This implementation and its corresponding interface {@link CounterModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link CounterImpl}.
042     * </p>
043     *
044     * @author Brian Wing Shun Chan
045     * @see CounterImpl
046     * @see Counter
047     * @see CounterModel
048     * @generated
049     */
050    @ProviderType
051    public class CounterModelImpl extends BaseModelImpl<Counter>
052            implements CounterModel {
053            /*
054             * NOTE FOR DEVELOPERS:
055             *
056             * Never modify or reference this class directly. All methods that expect a counter model instance should use the {@link Counter} interface instead.
057             */
058            public static final String TABLE_NAME = "Counter";
059            public static final Object[][] TABLE_COLUMNS = {
060                            { "name", Types.VARCHAR },
061                            { "currentId", Types.BIGINT }
062                    };
063            public static final String TABLE_SQL_CREATE = "create table Counter (name VARCHAR(75) not null primary key,currentId LONG)";
064            public static final String TABLE_SQL_DROP = "drop table Counter";
065            public static final String ORDER_BY_JPQL = " ORDER BY counter.name ASC";
066            public static final String ORDER_BY_SQL = " ORDER BY Counter.name ASC";
067            public static final String DATA_SOURCE = "liferayDataSource";
068            public static final String SESSION_FACTORY = "liferaySessionFactory";
069            public static final String TX_MANAGER = "liferayTransactionManager";
070            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
071                                    "value.object.entity.cache.enabled.com.liferay.counter.model.Counter"),
072                            false);
073            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
074                                    "value.object.finder.cache.enabled.com.liferay.counter.model.Counter"),
075                            false);
076            public static final boolean COLUMN_BITMASK_ENABLED = false;
077            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
078                                    "lock.expiration.time.com.liferay.counter.model.Counter"));
079    
080            public CounterModelImpl() {
081            }
082    
083            @Override
084            public String getPrimaryKey() {
085                    return _name;
086            }
087    
088            @Override
089            public void setPrimaryKey(String primaryKey) {
090                    setName(primaryKey);
091            }
092    
093            @Override
094            public Serializable getPrimaryKeyObj() {
095                    return _name;
096            }
097    
098            @Override
099            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
100                    setPrimaryKey((String)primaryKeyObj);
101            }
102    
103            @Override
104            public Class<?> getModelClass() {
105                    return Counter.class;
106            }
107    
108            @Override
109            public String getModelClassName() {
110                    return Counter.class.getName();
111            }
112    
113            @Override
114            public Map<String, Object> getModelAttributes() {
115                    Map<String, Object> attributes = new HashMap<String, Object>();
116    
117                    attributes.put("name", getName());
118                    attributes.put("currentId", getCurrentId());
119    
120                    attributes.put("entityCacheEnabled", isEntityCacheEnabled());
121                    attributes.put("finderCacheEnabled", isFinderCacheEnabled());
122    
123                    return attributes;
124            }
125    
126            @Override
127            public void setModelAttributes(Map<String, Object> attributes) {
128                    String name = (String)attributes.get("name");
129    
130                    if (name != null) {
131                            setName(name);
132                    }
133    
134                    Long currentId = (Long)attributes.get("currentId");
135    
136                    if (currentId != null) {
137                            setCurrentId(currentId);
138                    }
139            }
140    
141            @Override
142            public String getName() {
143                    if (_name == null) {
144                            return StringPool.BLANK;
145                    }
146                    else {
147                            return _name;
148                    }
149            }
150    
151            @Override
152            public void setName(String name) {
153                    _name = name;
154            }
155    
156            @Override
157            public long getCurrentId() {
158                    return _currentId;
159            }
160    
161            @Override
162            public void setCurrentId(long currentId) {
163                    _currentId = currentId;
164            }
165    
166            @Override
167            public Counter toEscapedModel() {
168                    if (_escapedModel == null) {
169                            _escapedModel = (Counter)ProxyUtil.newProxyInstance(_classLoader,
170                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
171                    }
172    
173                    return _escapedModel;
174            }
175    
176            @Override
177            public Object clone() {
178                    CounterImpl counterImpl = new CounterImpl();
179    
180                    counterImpl.setName(getName());
181                    counterImpl.setCurrentId(getCurrentId());
182    
183                    counterImpl.resetOriginalValues();
184    
185                    return counterImpl;
186            }
187    
188            @Override
189            public int compareTo(Counter counter) {
190                    String primaryKey = counter.getPrimaryKey();
191    
192                    return getPrimaryKey().compareTo(primaryKey);
193            }
194    
195            @Override
196            public boolean equals(Object obj) {
197                    if (this == obj) {
198                            return true;
199                    }
200    
201                    if (!(obj instanceof Counter)) {
202                            return false;
203                    }
204    
205                    Counter counter = (Counter)obj;
206    
207                    String primaryKey = counter.getPrimaryKey();
208    
209                    if (getPrimaryKey().equals(primaryKey)) {
210                            return true;
211                    }
212                    else {
213                            return false;
214                    }
215            }
216    
217            @Override
218            public int hashCode() {
219                    return getPrimaryKey().hashCode();
220            }
221    
222            @Override
223            public boolean isEntityCacheEnabled() {
224                    return ENTITY_CACHE_ENABLED;
225            }
226    
227            @Override
228            public boolean isFinderCacheEnabled() {
229                    return FINDER_CACHE_ENABLED;
230            }
231    
232            @Override
233            public void resetOriginalValues() {
234            }
235    
236            @Override
237            public CacheModel<Counter> toCacheModel() {
238                    CounterCacheModel counterCacheModel = new CounterCacheModel();
239    
240                    counterCacheModel.name = getName();
241    
242                    String name = counterCacheModel.name;
243    
244                    if ((name != null) && (name.length() == 0)) {
245                            counterCacheModel.name = null;
246                    }
247    
248                    counterCacheModel.currentId = getCurrentId();
249    
250                    return counterCacheModel;
251            }
252    
253            @Override
254            public String toString() {
255                    StringBundler sb = new StringBundler(5);
256    
257                    sb.append("{name=");
258                    sb.append(getName());
259                    sb.append(", currentId=");
260                    sb.append(getCurrentId());
261                    sb.append("}");
262    
263                    return sb.toString();
264            }
265    
266            @Override
267            public String toXmlString() {
268                    StringBundler sb = new StringBundler(10);
269    
270                    sb.append("<model><model-name>");
271                    sb.append("com.liferay.counter.model.Counter");
272                    sb.append("</model-name>");
273    
274                    sb.append(
275                            "<column><column-name>name</column-name><column-value><![CDATA[");
276                    sb.append(getName());
277                    sb.append("]]></column-value></column>");
278                    sb.append(
279                            "<column><column-name>currentId</column-name><column-value><![CDATA[");
280                    sb.append(getCurrentId());
281                    sb.append("]]></column-value></column>");
282    
283                    sb.append("</model>");
284    
285                    return sb.toString();
286            }
287    
288            private static final ClassLoader _classLoader = Counter.class.getClassLoader();
289            private static final Class<?>[] _escapedModelInterfaces = new Class[] {
290                            Counter.class
291                    };
292            private String _name;
293            private long _currentId;
294            private Counter _escapedModel;
295    }