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.portal.model.impl;
016    
017    import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
018    import com.liferay.portal.kernel.json.JSON;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.kernel.util.ProxyUtil;
021    import com.liferay.portal.kernel.util.StringBundler;
022    import com.liferay.portal.kernel.util.StringPool;
023    import com.liferay.portal.model.CacheModel;
024    import com.liferay.portal.model.ClassName;
025    import com.liferay.portal.model.ClassNameModel;
026    import com.liferay.portal.model.ClassNameSoap;
027    import com.liferay.portal.service.ServiceContext;
028    import com.liferay.portal.util.PortalUtil;
029    
030    import com.liferay.portlet.expando.model.ExpandoBridge;
031    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
032    
033    import java.io.Serializable;
034    
035    import java.sql.Types;
036    
037    import java.util.ArrayList;
038    import java.util.List;
039    
040    /**
041     * The base model implementation for the ClassName service. Represents a row in the "ClassName_" database table, with each column mapped to a property of this class.
042     *
043     * <p>
044     * This implementation and its corresponding interface {@link com.liferay.portal.model.ClassNameModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ClassNameImpl}.
045     * </p>
046     *
047     * @author Brian Wing Shun Chan
048     * @see ClassNameImpl
049     * @see com.liferay.portal.model.ClassName
050     * @see com.liferay.portal.model.ClassNameModel
051     * @generated
052     */
053    @JSON(strict = true)
054    public class ClassNameModelImpl extends BaseModelImpl<ClassName>
055            implements ClassNameModel {
056            /*
057             * NOTE FOR DEVELOPERS:
058             *
059             * Never modify or reference this class directly. All methods that expect a class name model instance should use the {@link com.liferay.portal.model.ClassName} interface instead.
060             */
061            public static final String TABLE_NAME = "ClassName_";
062            public static final Object[][] TABLE_COLUMNS = {
063                            { "classNameId", Types.BIGINT },
064                            { "value", Types.VARCHAR }
065                    };
066            public static final String TABLE_SQL_CREATE = "create table ClassName_ (classNameId LONG not null primary key,value VARCHAR(200) null)";
067            public static final String TABLE_SQL_DROP = "drop table ClassName_";
068            public static final String DATA_SOURCE = "liferayDataSource";
069            public static final String SESSION_FACTORY = "liferaySessionFactory";
070            public static final String TX_MANAGER = "liferayTransactionManager";
071            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
072                                    "value.object.entity.cache.enabled.com.liferay.portal.model.ClassName"),
073                            true);
074            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
075                                    "value.object.finder.cache.enabled.com.liferay.portal.model.ClassName"),
076                            true);
077            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
078                                    "value.object.column.bitmask.enabled.com.liferay.portal.model.ClassName"),
079                            true);
080            public static long VALUE_COLUMN_BITMASK = 1L;
081    
082            /**
083             * Converts the soap model instance into a normal model instance.
084             *
085             * @param soapModel the soap model instance to convert
086             * @return the normal model instance
087             */
088            public static ClassName toModel(ClassNameSoap soapModel) {
089                    ClassName model = new ClassNameImpl();
090    
091                    model.setClassNameId(soapModel.getClassNameId());
092                    model.setValue(soapModel.getValue());
093    
094                    return model;
095            }
096    
097            /**
098             * Converts the soap model instances into normal model instances.
099             *
100             * @param soapModels the soap model instances to convert
101             * @return the normal model instances
102             */
103            public static List<ClassName> toModels(ClassNameSoap[] soapModels) {
104                    List<ClassName> models = new ArrayList<ClassName>(soapModels.length);
105    
106                    for (ClassNameSoap soapModel : soapModels) {
107                            models.add(toModel(soapModel));
108                    }
109    
110                    return models;
111            }
112    
113            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
114                                    "lock.expiration.time.com.liferay.portal.model.ClassName"));
115    
116            public ClassNameModelImpl() {
117            }
118    
119            public long getPrimaryKey() {
120                    return _classNameId;
121            }
122    
123            public void setPrimaryKey(long primaryKey) {
124                    setClassNameId(primaryKey);
125            }
126    
127            public Serializable getPrimaryKeyObj() {
128                    return new Long(_classNameId);
129            }
130    
131            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
132                    setPrimaryKey(((Long)primaryKeyObj).longValue());
133            }
134    
135            public Class<?> getModelClass() {
136                    return ClassName.class;
137            }
138    
139            public String getModelClassName() {
140                    return ClassName.class.getName();
141            }
142    
143            public String getClassName() {
144                    if (getClassNameId() <= 0) {
145                            return StringPool.BLANK;
146                    }
147    
148                    return PortalUtil.getClassName(getClassNameId());
149            }
150    
151            @JSON
152            public long getClassNameId() {
153                    return _classNameId;
154            }
155    
156            public void setClassNameId(long classNameId) {
157                    _classNameId = classNameId;
158            }
159    
160            @JSON
161            public String getValue() {
162                    if (_value == null) {
163                            return StringPool.BLANK;
164                    }
165                    else {
166                            return _value;
167                    }
168            }
169    
170            public void setValue(String value) {
171                    _columnBitmask |= VALUE_COLUMN_BITMASK;
172    
173                    if (_originalValue == null) {
174                            _originalValue = _value;
175                    }
176    
177                    _value = value;
178            }
179    
180            public String getOriginalValue() {
181                    return GetterUtil.getString(_originalValue);
182            }
183    
184            public long getColumnBitmask() {
185                    return _columnBitmask;
186            }
187    
188            @Override
189            public ClassName toEscapedModel() {
190                    if (_escapedModelProxy == null) {
191                            _escapedModelProxy = (ClassName)ProxyUtil.newProxyInstance(_classLoader,
192                                            _escapedModelProxyInterfaces,
193                                            new AutoEscapeBeanHandler(this));
194                    }
195    
196                    return _escapedModelProxy;
197            }
198    
199            @Override
200            public ExpandoBridge getExpandoBridge() {
201                    if (_expandoBridge == null) {
202                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
203                                            ClassName.class.getName(), getPrimaryKey());
204                    }
205    
206                    return _expandoBridge;
207            }
208    
209            @Override
210            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
211                    getExpandoBridge().setAttributes(serviceContext);
212            }
213    
214            @Override
215            public Object clone() {
216                    ClassNameImpl classNameImpl = new ClassNameImpl();
217    
218                    classNameImpl.setClassNameId(getClassNameId());
219                    classNameImpl.setValue(getValue());
220    
221                    classNameImpl.resetOriginalValues();
222    
223                    return classNameImpl;
224            }
225    
226            public int compareTo(ClassName className) {
227                    long primaryKey = className.getPrimaryKey();
228    
229                    if (getPrimaryKey() < primaryKey) {
230                            return -1;
231                    }
232                    else if (getPrimaryKey() > primaryKey) {
233                            return 1;
234                    }
235                    else {
236                            return 0;
237                    }
238            }
239    
240            @Override
241            public boolean equals(Object obj) {
242                    if (obj == null) {
243                            return false;
244                    }
245    
246                    ClassName className = null;
247    
248                    try {
249                            className = (ClassName)obj;
250                    }
251                    catch (ClassCastException cce) {
252                            return false;
253                    }
254    
255                    long primaryKey = className.getPrimaryKey();
256    
257                    if (getPrimaryKey() == primaryKey) {
258                            return true;
259                    }
260                    else {
261                            return false;
262                    }
263            }
264    
265            @Override
266            public int hashCode() {
267                    return (int)getPrimaryKey();
268            }
269    
270            @Override
271            public void resetOriginalValues() {
272                    ClassNameModelImpl classNameModelImpl = this;
273    
274                    classNameModelImpl._originalValue = classNameModelImpl._value;
275    
276                    classNameModelImpl._columnBitmask = 0;
277            }
278    
279            @Override
280            public CacheModel<ClassName> toCacheModel() {
281                    ClassNameCacheModel classNameCacheModel = new ClassNameCacheModel();
282    
283                    classNameCacheModel.classNameId = getClassNameId();
284    
285                    classNameCacheModel.value = getValue();
286    
287                    String value = classNameCacheModel.value;
288    
289                    if ((value != null) && (value.length() == 0)) {
290                            classNameCacheModel.value = null;
291                    }
292    
293                    return classNameCacheModel;
294            }
295    
296            @Override
297            public String toString() {
298                    StringBundler sb = new StringBundler(5);
299    
300                    sb.append("{classNameId=");
301                    sb.append(getClassNameId());
302                    sb.append(", value=");
303                    sb.append(getValue());
304                    sb.append("}");
305    
306                    return sb.toString();
307            }
308    
309            public String toXmlString() {
310                    StringBundler sb = new StringBundler(10);
311    
312                    sb.append("<model><model-name>");
313                    sb.append("com.liferay.portal.model.ClassName");
314                    sb.append("</model-name>");
315    
316                    sb.append(
317                            "<column><column-name>classNameId</column-name><column-value><![CDATA[");
318                    sb.append(getClassNameId());
319                    sb.append("]]></column-value></column>");
320                    sb.append(
321                            "<column><column-name>value</column-name><column-value><![CDATA[");
322                    sb.append(getValue());
323                    sb.append("]]></column-value></column>");
324    
325                    sb.append("</model>");
326    
327                    return sb.toString();
328            }
329    
330            private static ClassLoader _classLoader = ClassName.class.getClassLoader();
331            private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
332                            ClassName.class
333                    };
334            private long _classNameId;
335            private String _value;
336            private String _originalValue;
337            private transient ExpandoBridge _expandoBridge;
338            private long _columnBitmask;
339            private ClassName _escapedModelProxy;
340    }