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.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.kernel.util.Validator;
024    import com.liferay.portal.model.CacheModel;
025    import com.liferay.portal.model.ClassName;
026    import com.liferay.portal.model.ClassNameModel;
027    import com.liferay.portal.model.ClassNameSoap;
028    import com.liferay.portal.service.ServiceContext;
029    import com.liferay.portal.util.PortalUtil;
030    
031    import com.liferay.portlet.expando.model.ExpandoBridge;
032    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
033    
034    import java.io.Serializable;
035    
036    import java.sql.Types;
037    
038    import java.util.ArrayList;
039    import java.util.HashMap;
040    import java.util.List;
041    import java.util.Map;
042    
043    /**
044     * 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.
045     *
046     * <p>
047     * 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}.
048     * </p>
049     *
050     * @author Brian Wing Shun Chan
051     * @see ClassNameImpl
052     * @see com.liferay.portal.model.ClassName
053     * @see com.liferay.portal.model.ClassNameModel
054     * @generated
055     */
056    @JSON(strict = true)
057    public class ClassNameModelImpl extends BaseModelImpl<ClassName>
058            implements ClassNameModel {
059            /*
060             * NOTE FOR DEVELOPERS:
061             *
062             * 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.
063             */
064            public static final String TABLE_NAME = "ClassName_";
065            public static final Object[][] TABLE_COLUMNS = {
066                            { "classNameId", Types.BIGINT },
067                            { "value", Types.VARCHAR }
068                    };
069            public static final String TABLE_SQL_CREATE = "create table ClassName_ (classNameId LONG not null primary key,value VARCHAR(200) null)";
070            public static final String TABLE_SQL_DROP = "drop table ClassName_";
071            public static final String ORDER_BY_JPQL = " ORDER BY className.classNameId ASC";
072            public static final String ORDER_BY_SQL = " ORDER BY ClassName_.classNameId ASC";
073            public static final String DATA_SOURCE = "liferayDataSource";
074            public static final String SESSION_FACTORY = "liferaySessionFactory";
075            public static final String TX_MANAGER = "liferayTransactionManager";
076            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
077                                    "value.object.entity.cache.enabled.com.liferay.portal.model.ClassName"),
078                            true);
079            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
080                                    "value.object.finder.cache.enabled.com.liferay.portal.model.ClassName"),
081                            true);
082            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
083                                    "value.object.column.bitmask.enabled.com.liferay.portal.model.ClassName"),
084                            true);
085            public static long VALUE_COLUMN_BITMASK = 1L;
086            public static long CLASSNAMEID_COLUMN_BITMASK = 2L;
087    
088            /**
089             * Converts the soap model instance into a normal model instance.
090             *
091             * @param soapModel the soap model instance to convert
092             * @return the normal model instance
093             */
094            public static ClassName toModel(ClassNameSoap soapModel) {
095                    if (soapModel == null) {
096                            return null;
097                    }
098    
099                    ClassName model = new ClassNameImpl();
100    
101                    model.setClassNameId(soapModel.getClassNameId());
102                    model.setValue(soapModel.getValue());
103    
104                    return model;
105            }
106    
107            /**
108             * Converts the soap model instances into normal model instances.
109             *
110             * @param soapModels the soap model instances to convert
111             * @return the normal model instances
112             */
113            public static List<ClassName> toModels(ClassNameSoap[] soapModels) {
114                    if (soapModels == null) {
115                            return null;
116                    }
117    
118                    List<ClassName> models = new ArrayList<ClassName>(soapModels.length);
119    
120                    for (ClassNameSoap soapModel : soapModels) {
121                            models.add(toModel(soapModel));
122                    }
123    
124                    return models;
125            }
126    
127            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
128                                    "lock.expiration.time.com.liferay.portal.model.ClassName"));
129    
130            public ClassNameModelImpl() {
131            }
132    
133            @Override
134            public long getPrimaryKey() {
135                    return _classNameId;
136            }
137    
138            @Override
139            public void setPrimaryKey(long primaryKey) {
140                    setClassNameId(primaryKey);
141            }
142    
143            @Override
144            public Serializable getPrimaryKeyObj() {
145                    return _classNameId;
146            }
147    
148            @Override
149            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
150                    setPrimaryKey(((Long)primaryKeyObj).longValue());
151            }
152    
153            @Override
154            public Class<?> getModelClass() {
155                    return ClassName.class;
156            }
157    
158            @Override
159            public String getModelClassName() {
160                    return ClassName.class.getName();
161            }
162    
163            @Override
164            public Map<String, Object> getModelAttributes() {
165                    Map<String, Object> attributes = new HashMap<String, Object>();
166    
167                    attributes.put("classNameId", getClassNameId());
168                    attributes.put("value", getValue());
169    
170                    return attributes;
171            }
172    
173            @Override
174            public void setModelAttributes(Map<String, Object> attributes) {
175                    Long classNameId = (Long)attributes.get("classNameId");
176    
177                    if (classNameId != null) {
178                            setClassNameId(classNameId);
179                    }
180    
181                    String value = (String)attributes.get("value");
182    
183                    if (value != null) {
184                            setValue(value);
185                    }
186            }
187    
188            @Override
189            public String getClassName() {
190                    if (getClassNameId() <= 0) {
191                            return StringPool.BLANK;
192                    }
193    
194                    return PortalUtil.getClassName(getClassNameId());
195            }
196    
197            @Override
198            public void setClassName(String className) {
199                    long classNameId = 0;
200    
201                    if (Validator.isNotNull(className)) {
202                            classNameId = PortalUtil.getClassNameId(className);
203                    }
204    
205                    setClassNameId(classNameId);
206            }
207    
208            @JSON
209            @Override
210            public long getClassNameId() {
211                    return _classNameId;
212            }
213    
214            @Override
215            public void setClassNameId(long classNameId) {
216                    _classNameId = classNameId;
217            }
218    
219            @JSON
220            @Override
221            public String getValue() {
222                    if (_value == null) {
223                            return StringPool.BLANK;
224                    }
225                    else {
226                            return _value;
227                    }
228            }
229    
230            @Override
231            public void setValue(String value) {
232                    _columnBitmask |= VALUE_COLUMN_BITMASK;
233    
234                    if (_originalValue == null) {
235                            _originalValue = _value;
236                    }
237    
238                    _value = value;
239            }
240    
241            public String getOriginalValue() {
242                    return GetterUtil.getString(_originalValue);
243            }
244    
245            public long getColumnBitmask() {
246                    return _columnBitmask;
247            }
248    
249            @Override
250            public ExpandoBridge getExpandoBridge() {
251                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
252                            ClassName.class.getName(), getPrimaryKey());
253            }
254    
255            @Override
256            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
257                    ExpandoBridge expandoBridge = getExpandoBridge();
258    
259                    expandoBridge.setAttributes(serviceContext);
260            }
261    
262            @Override
263            public ClassName toEscapedModel() {
264                    if (_escapedModel == null) {
265                            _escapedModel = (ClassName)ProxyUtil.newProxyInstance(_classLoader,
266                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
267                    }
268    
269                    return _escapedModel;
270            }
271    
272            @Override
273            public Object clone() {
274                    ClassNameImpl classNameImpl = new ClassNameImpl();
275    
276                    classNameImpl.setClassNameId(getClassNameId());
277                    classNameImpl.setValue(getValue());
278    
279                    classNameImpl.resetOriginalValues();
280    
281                    return classNameImpl;
282            }
283    
284            @Override
285            public int compareTo(ClassName className) {
286                    long primaryKey = className.getPrimaryKey();
287    
288                    if (getPrimaryKey() < primaryKey) {
289                            return -1;
290                    }
291                    else if (getPrimaryKey() > primaryKey) {
292                            return 1;
293                    }
294                    else {
295                            return 0;
296                    }
297            }
298    
299            @Override
300            public boolean equals(Object obj) {
301                    if (this == obj) {
302                            return true;
303                    }
304    
305                    if (!(obj instanceof ClassName)) {
306                            return false;
307                    }
308    
309                    ClassName className = (ClassName)obj;
310    
311                    long primaryKey = className.getPrimaryKey();
312    
313                    if (getPrimaryKey() == primaryKey) {
314                            return true;
315                    }
316                    else {
317                            return false;
318                    }
319            }
320    
321            @Override
322            public int hashCode() {
323                    return (int)getPrimaryKey();
324            }
325    
326            @Override
327            public void resetOriginalValues() {
328                    ClassNameModelImpl classNameModelImpl = this;
329    
330                    classNameModelImpl._originalValue = classNameModelImpl._value;
331    
332                    classNameModelImpl._columnBitmask = 0;
333            }
334    
335            @Override
336            public CacheModel<ClassName> toCacheModel() {
337                    ClassNameCacheModel classNameCacheModel = new ClassNameCacheModel();
338    
339                    classNameCacheModel.classNameId = getClassNameId();
340    
341                    classNameCacheModel.value = getValue();
342    
343                    String value = classNameCacheModel.value;
344    
345                    if ((value != null) && (value.length() == 0)) {
346                            classNameCacheModel.value = null;
347                    }
348    
349                    return classNameCacheModel;
350            }
351    
352            @Override
353            public String toString() {
354                    StringBundler sb = new StringBundler(5);
355    
356                    sb.append("{classNameId=");
357                    sb.append(getClassNameId());
358                    sb.append(", value=");
359                    sb.append(getValue());
360                    sb.append("}");
361    
362                    return sb.toString();
363            }
364    
365            @Override
366            public String toXmlString() {
367                    StringBundler sb = new StringBundler(10);
368    
369                    sb.append("<model><model-name>");
370                    sb.append("com.liferay.portal.model.ClassName");
371                    sb.append("</model-name>");
372    
373                    sb.append(
374                            "<column><column-name>classNameId</column-name><column-value><![CDATA[");
375                    sb.append(getClassNameId());
376                    sb.append("]]></column-value></column>");
377                    sb.append(
378                            "<column><column-name>value</column-name><column-value><![CDATA[");
379                    sb.append(getValue());
380                    sb.append("]]></column-value></column>");
381    
382                    sb.append("</model>");
383    
384                    return sb.toString();
385            }
386    
387            private static ClassLoader _classLoader = ClassName.class.getClassLoader();
388            private static Class<?>[] _escapedModelInterfaces = new Class[] {
389                            ClassName.class
390                    };
391            private long _classNameId;
392            private String _value;
393            private String _originalValue;
394            private long _columnBitmask;
395            private ClassName _escapedModel;
396    }