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