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