001    /**
002     * Copyright (c) 2000-2012 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    /**
033     * 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.
034     *
035     * <p>
036     * 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}.
037     * </p>
038     *
039     * @author Brian Wing Shun Chan
040     * @see CounterImpl
041     * @see com.liferay.counter.model.Counter
042     * @see com.liferay.counter.model.CounterModel
043     * @generated
044     */
045    public class CounterModelImpl extends BaseModelImpl<Counter>
046            implements CounterModel {
047            /*
048             * NOTE FOR DEVELOPERS:
049             *
050             * 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.
051             */
052            public static final String TABLE_NAME = "Counter";
053            public static final Object[][] TABLE_COLUMNS = {
054                            { "name", Types.VARCHAR },
055                            { "currentId", Types.BIGINT }
056                    };
057            public static final String TABLE_SQL_CREATE = "create table Counter (name VARCHAR(75) not null primary key,currentId LONG)";
058            public static final String TABLE_SQL_DROP = "drop table Counter";
059            public static final String DATA_SOURCE = "liferayDataSource";
060            public static final String SESSION_FACTORY = "liferaySessionFactory";
061            public static final String TX_MANAGER = "liferayTransactionManager";
062            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
063                                    "value.object.entity.cache.enabled.com.liferay.counter.model.Counter"),
064                            false);
065            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
066                                    "value.object.finder.cache.enabled.com.liferay.counter.model.Counter"),
067                            false);
068            public static final boolean COLUMN_BITMASK_ENABLED = false;
069            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
070                                    "lock.expiration.time.com.liferay.counter.model.Counter"));
071    
072            public CounterModelImpl() {
073            }
074    
075            public String getPrimaryKey() {
076                    return _name;
077            }
078    
079            public void setPrimaryKey(String primaryKey) {
080                    setName(primaryKey);
081            }
082    
083            public Serializable getPrimaryKeyObj() {
084                    return _name;
085            }
086    
087            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
088                    setPrimaryKey((String)primaryKeyObj);
089            }
090    
091            public Class<?> getModelClass() {
092                    return Counter.class;
093            }
094    
095            public String getModelClassName() {
096                    return Counter.class.getName();
097            }
098    
099            public String getName() {
100                    if (_name == null) {
101                            return StringPool.BLANK;
102                    }
103                    else {
104                            return _name;
105                    }
106            }
107    
108            public void setName(String name) {
109                    _name = name;
110            }
111    
112            public long getCurrentId() {
113                    return _currentId;
114            }
115    
116            public void setCurrentId(long currentId) {
117                    _currentId = currentId;
118            }
119    
120            @Override
121            public Counter toEscapedModel() {
122                    if (_escapedModelProxy == null) {
123                            _escapedModelProxy = (Counter)ProxyUtil.newProxyInstance(_classLoader,
124                                            _escapedModelProxyInterfaces,
125                                            new AutoEscapeBeanHandler(this));
126                    }
127    
128                    return _escapedModelProxy;
129            }
130    
131            @Override
132            public Object clone() {
133                    CounterImpl counterImpl = new CounterImpl();
134    
135                    counterImpl.setName(getName());
136                    counterImpl.setCurrentId(getCurrentId());
137    
138                    counterImpl.resetOriginalValues();
139    
140                    return counterImpl;
141            }
142    
143            public int compareTo(Counter counter) {
144                    String primaryKey = counter.getPrimaryKey();
145    
146                    return getPrimaryKey().compareTo(primaryKey);
147            }
148    
149            @Override
150            public boolean equals(Object obj) {
151                    if (obj == null) {
152                            return false;
153                    }
154    
155                    Counter counter = null;
156    
157                    try {
158                            counter = (Counter)obj;
159                    }
160                    catch (ClassCastException cce) {
161                            return false;
162                    }
163    
164                    String primaryKey = counter.getPrimaryKey();
165    
166                    if (getPrimaryKey().equals(primaryKey)) {
167                            return true;
168                    }
169                    else {
170                            return false;
171                    }
172            }
173    
174            @Override
175            public int hashCode() {
176                    return getPrimaryKey().hashCode();
177            }
178    
179            @Override
180            public void resetOriginalValues() {
181            }
182    
183            @Override
184            public CacheModel<Counter> toCacheModel() {
185                    CounterCacheModel counterCacheModel = new CounterCacheModel();
186    
187                    counterCacheModel.name = getName();
188    
189                    String name = counterCacheModel.name;
190    
191                    if ((name != null) && (name.length() == 0)) {
192                            counterCacheModel.name = null;
193                    }
194    
195                    counterCacheModel.currentId = getCurrentId();
196    
197                    return counterCacheModel;
198            }
199    
200            @Override
201            public String toString() {
202                    StringBundler sb = new StringBundler(5);
203    
204                    sb.append("{name=");
205                    sb.append(getName());
206                    sb.append(", currentId=");
207                    sb.append(getCurrentId());
208                    sb.append("}");
209    
210                    return sb.toString();
211            }
212    
213            public String toXmlString() {
214                    StringBundler sb = new StringBundler(10);
215    
216                    sb.append("<model><model-name>");
217                    sb.append("com.liferay.counter.model.Counter");
218                    sb.append("</model-name>");
219    
220                    sb.append(
221                            "<column><column-name>name</column-name><column-value><![CDATA[");
222                    sb.append(getName());
223                    sb.append("]]></column-value></column>");
224                    sb.append(
225                            "<column><column-name>currentId</column-name><column-value><![CDATA[");
226                    sb.append(getCurrentId());
227                    sb.append("]]></column-value></column>");
228    
229                    sb.append("</model>");
230    
231                    return sb.toString();
232            }
233    
234            private static ClassLoader _classLoader = Counter.class.getClassLoader();
235            private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
236                            Counter.class
237                    };
238            private String _name;
239            private long _currentId;
240            private Counter _escapedModelProxy;
241    }