001    /**
002     * Copyright (c) 2000-2013 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 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    /**
036     * 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.
037     *
038     * <p>
039     * This implementation and its corresponding interface {@link com.liferay.counter.model.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}.
040     * </p>
041     *
042     * @author Brian Wing Shun Chan
043     * @see CounterImpl
044     * @see com.liferay.counter.model.Counter
045     * @see com.liferay.counter.model.CounterModel
046     * @generated
047     */
048    public class CounterModelImpl extends BaseModelImpl<Counter>
049            implements CounterModel {
050            /*
051             * NOTE FOR DEVELOPERS:
052             *
053             * Never modify or reference this class directly. All methods that expect a counter model instance should use the {@link com.liferay.counter.model.Counter} interface instead.
054             */
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 ORDER_BY_JPQL = " ORDER BY counter.name ASC";
063            public static final String ORDER_BY_SQL = " ORDER BY Counter.name ASC";
064            public static final String DATA_SOURCE = "liferayDataSource";
065            public static final String SESSION_FACTORY = "liferaySessionFactory";
066            public static final String TX_MANAGER = "liferayTransactionManager";
067            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
068                                    "value.object.entity.cache.enabled.com.liferay.counter.model.Counter"),
069                            false);
070            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
071                                    "value.object.finder.cache.enabled.com.liferay.counter.model.Counter"),
072                            false);
073            public static final boolean COLUMN_BITMASK_ENABLED = false;
074            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
075                                    "lock.expiration.time.com.liferay.counter.model.Counter"));
076    
077            public CounterModelImpl() {
078            }
079    
080            public String getPrimaryKey() {
081                    return _name;
082            }
083    
084            public void setPrimaryKey(String primaryKey) {
085                    setName(primaryKey);
086            }
087    
088            public Serializable getPrimaryKeyObj() {
089                    return _name;
090            }
091    
092            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
093                    setPrimaryKey((String)primaryKeyObj);
094            }
095    
096            public Class<?> getModelClass() {
097                    return Counter.class;
098            }
099    
100            public String getModelClassName() {
101                    return Counter.class.getName();
102            }
103    
104            @Override
105            public Map<String, Object> getModelAttributes() {
106                    Map<String, Object> attributes = new HashMap<String, Object>();
107    
108                    attributes.put("name", getName());
109                    attributes.put("currentId", getCurrentId());
110    
111                    return attributes;
112            }
113    
114            @Override
115            public void setModelAttributes(Map<String, Object> attributes) {
116                    String name = (String)attributes.get("name");
117    
118                    if (name != null) {
119                            setName(name);
120                    }
121    
122                    Long currentId = (Long)attributes.get("currentId");
123    
124                    if (currentId != null) {
125                            setCurrentId(currentId);
126                    }
127            }
128    
129            public String getName() {
130                    if (_name == null) {
131                            return StringPool.BLANK;
132                    }
133                    else {
134                            return _name;
135                    }
136            }
137    
138            public void setName(String name) {
139                    _name = name;
140            }
141    
142            public long getCurrentId() {
143                    return _currentId;
144            }
145    
146            public void setCurrentId(long currentId) {
147                    _currentId = currentId;
148            }
149    
150            @Override
151            public Counter toEscapedModel() {
152                    if (_escapedModel == null) {
153                            _escapedModel = (Counter)ProxyUtil.newProxyInstance(_classLoader,
154                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
155                    }
156    
157                    return _escapedModel;
158            }
159    
160            @Override
161            public Object clone() {
162                    CounterImpl counterImpl = new CounterImpl();
163    
164                    counterImpl.setName(getName());
165                    counterImpl.setCurrentId(getCurrentId());
166    
167                    counterImpl.resetOriginalValues();
168    
169                    return counterImpl;
170            }
171    
172            public int compareTo(Counter counter) {
173                    String primaryKey = counter.getPrimaryKey();
174    
175                    return getPrimaryKey().compareTo(primaryKey);
176            }
177    
178            @Override
179            public boolean equals(Object obj) {
180                    if (obj == null) {
181                            return false;
182                    }
183    
184                    Counter counter = null;
185    
186                    try {
187                            counter = (Counter)obj;
188                    }
189                    catch (ClassCastException cce) {
190                            return false;
191                    }
192    
193                    String primaryKey = counter.getPrimaryKey();
194    
195                    if (getPrimaryKey().equals(primaryKey)) {
196                            return true;
197                    }
198                    else {
199                            return false;
200                    }
201            }
202    
203            @Override
204            public int hashCode() {
205                    return getPrimaryKey().hashCode();
206            }
207    
208            @Override
209            public void resetOriginalValues() {
210            }
211    
212            @Override
213            public CacheModel<Counter> toCacheModel() {
214                    CounterCacheModel counterCacheModel = new CounterCacheModel();
215    
216                    counterCacheModel.name = getName();
217    
218                    String name = counterCacheModel.name;
219    
220                    if ((name != null) && (name.length() == 0)) {
221                            counterCacheModel.name = null;
222                    }
223    
224                    counterCacheModel.currentId = getCurrentId();
225    
226                    return counterCacheModel;
227            }
228    
229            @Override
230            public String toString() {
231                    StringBundler sb = new StringBundler(5);
232    
233                    sb.append("{name=");
234                    sb.append(getName());
235                    sb.append(", currentId=");
236                    sb.append(getCurrentId());
237                    sb.append("}");
238    
239                    return sb.toString();
240            }
241    
242            public String toXmlString() {
243                    StringBundler sb = new StringBundler(10);
244    
245                    sb.append("<model><model-name>");
246                    sb.append("com.liferay.counter.model.Counter");
247                    sb.append("</model-name>");
248    
249                    sb.append(
250                            "<column><column-name>name</column-name><column-value><![CDATA[");
251                    sb.append(getName());
252                    sb.append("]]></column-value></column>");
253                    sb.append(
254                            "<column><column-name>currentId</column-name><column-value><![CDATA[");
255                    sb.append(getCurrentId());
256                    sb.append("]]></column-value></column>");
257    
258                    sb.append("</model>");
259    
260                    return sb.toString();
261            }
262    
263            private static ClassLoader _classLoader = Counter.class.getClassLoader();
264            private static Class<?>[] _escapedModelInterfaces = new Class[] {
265                            Counter.class
266                    };
267            private String _name;
268            private long _currentId;
269            private Counter _escapedModel;
270    }