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            @Override
081            public String getPrimaryKey() {
082                    return _name;
083            }
084    
085            @Override
086            public void setPrimaryKey(String primaryKey) {
087                    setName(primaryKey);
088            }
089    
090            @Override
091            public Serializable getPrimaryKeyObj() {
092                    return _name;
093            }
094    
095            @Override
096            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
097                    setPrimaryKey((String)primaryKeyObj);
098            }
099    
100            @Override
101            public Class<?> getModelClass() {
102                    return Counter.class;
103            }
104    
105            @Override
106            public String getModelClassName() {
107                    return Counter.class.getName();
108            }
109    
110            @Override
111            public Map<String, Object> getModelAttributes() {
112                    Map<String, Object> attributes = new HashMap<String, Object>();
113    
114                    attributes.put("name", getName());
115                    attributes.put("currentId", getCurrentId());
116    
117                    return attributes;
118            }
119    
120            @Override
121            public void setModelAttributes(Map<String, Object> attributes) {
122                    String name = (String)attributes.get("name");
123    
124                    if (name != null) {
125                            setName(name);
126                    }
127    
128                    Long currentId = (Long)attributes.get("currentId");
129    
130                    if (currentId != null) {
131                            setCurrentId(currentId);
132                    }
133            }
134    
135            @Override
136            public String getName() {
137                    if (_name == null) {
138                            return StringPool.BLANK;
139                    }
140                    else {
141                            return _name;
142                    }
143            }
144    
145            @Override
146            public void setName(String name) {
147                    _name = name;
148            }
149    
150            @Override
151            public long getCurrentId() {
152                    return _currentId;
153            }
154    
155            @Override
156            public void setCurrentId(long currentId) {
157                    _currentId = currentId;
158            }
159    
160            @Override
161            public Counter toEscapedModel() {
162                    if (_escapedModel == null) {
163                            _escapedModel = (Counter)ProxyUtil.newProxyInstance(_classLoader,
164                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
165                    }
166    
167                    return _escapedModel;
168            }
169    
170            @Override
171            public Object clone() {
172                    CounterImpl counterImpl = new CounterImpl();
173    
174                    counterImpl.setName(getName());
175                    counterImpl.setCurrentId(getCurrentId());
176    
177                    counterImpl.resetOriginalValues();
178    
179                    return counterImpl;
180            }
181    
182            @Override
183            public int compareTo(Counter counter) {
184                    String primaryKey = counter.getPrimaryKey();
185    
186                    return getPrimaryKey().compareTo(primaryKey);
187            }
188    
189            @Override
190            public boolean equals(Object obj) {
191                    if (this == obj) {
192                            return true;
193                    }
194    
195                    if (!(obj instanceof Counter)) {
196                            return false;
197                    }
198    
199                    Counter counter = (Counter)obj;
200    
201                    String primaryKey = counter.getPrimaryKey();
202    
203                    if (getPrimaryKey().equals(primaryKey)) {
204                            return true;
205                    }
206                    else {
207                            return false;
208                    }
209            }
210    
211            @Override
212            public int hashCode() {
213                    return getPrimaryKey().hashCode();
214            }
215    
216            @Override
217            public void resetOriginalValues() {
218            }
219    
220            @Override
221            public CacheModel<Counter> toCacheModel() {
222                    CounterCacheModel counterCacheModel = new CounterCacheModel();
223    
224                    counterCacheModel.name = getName();
225    
226                    String name = counterCacheModel.name;
227    
228                    if ((name != null) && (name.length() == 0)) {
229                            counterCacheModel.name = null;
230                    }
231    
232                    counterCacheModel.currentId = getCurrentId();
233    
234                    return counterCacheModel;
235            }
236    
237            @Override
238            public String toString() {
239                    StringBundler sb = new StringBundler(5);
240    
241                    sb.append("{name=");
242                    sb.append(getName());
243                    sb.append(", currentId=");
244                    sb.append(getCurrentId());
245                    sb.append("}");
246    
247                    return sb.toString();
248            }
249    
250            @Override
251            public String toXmlString() {
252                    StringBundler sb = new StringBundler(10);
253    
254                    sb.append("<model><model-name>");
255                    sb.append("com.liferay.counter.model.Counter");
256                    sb.append("</model-name>");
257    
258                    sb.append(
259                            "<column><column-name>name</column-name><column-value><![CDATA[");
260                    sb.append(getName());
261                    sb.append("]]></column-value></column>");
262                    sb.append(
263                            "<column><column-name>currentId</column-name><column-value><![CDATA[");
264                    sb.append(getCurrentId());
265                    sb.append("]]></column-value></column>");
266    
267                    sb.append("</model>");
268    
269                    return sb.toString();
270            }
271    
272            private static ClassLoader _classLoader = Counter.class.getClassLoader();
273            private static Class<?>[] _escapedModelInterfaces = new Class[] {
274                            Counter.class
275                    };
276            private String _name;
277            private long _currentId;
278            private Counter _escapedModel;
279    }