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