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            public long getPrimaryKey() {
134                    return _classNameId;
135            }
136    
137            public void setPrimaryKey(long primaryKey) {
138                    setClassNameId(primaryKey);
139            }
140    
141            public Serializable getPrimaryKeyObj() {
142                    return _classNameId;
143            }
144    
145            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
146                    setPrimaryKey(((Long)primaryKeyObj).longValue());
147            }
148    
149            public Class<?> getModelClass() {
150                    return ClassName.class;
151            }
152    
153            public String getModelClassName() {
154                    return ClassName.class.getName();
155            }
156    
157            @Override
158            public Map<String, Object> getModelAttributes() {
159                    Map<String, Object> attributes = new HashMap<String, Object>();
160    
161                    attributes.put("classNameId", getClassNameId());
162                    attributes.put("value", getValue());
163    
164                    return attributes;
165            }
166    
167            @Override
168            public void setModelAttributes(Map<String, Object> attributes) {
169                    Long classNameId = (Long)attributes.get("classNameId");
170    
171                    if (classNameId != null) {
172                            setClassNameId(classNameId);
173                    }
174    
175                    String value = (String)attributes.get("value");
176    
177                    if (value != null) {
178                            setValue(value);
179                    }
180            }
181    
182            public String getClassName() {
183                    if (getClassNameId() <= 0) {
184                            return StringPool.BLANK;
185                    }
186    
187                    return PortalUtil.getClassName(getClassNameId());
188            }
189    
190            public void setClassName(String className) {
191                    long classNameId = 0;
192    
193                    if (Validator.isNotNull(className)) {
194                            classNameId = PortalUtil.getClassNameId(className);
195                    }
196    
197                    setClassNameId(classNameId);
198            }
199    
200            @JSON
201            public long getClassNameId() {
202                    return _classNameId;
203            }
204    
205            public void setClassNameId(long classNameId) {
206                    _classNameId = classNameId;
207            }
208    
209            @JSON
210            public String getValue() {
211                    if (_value == null) {
212                            return StringPool.BLANK;
213                    }
214                    else {
215                            return _value;
216                    }
217            }
218    
219            public void setValue(String value) {
220                    _columnBitmask |= VALUE_COLUMN_BITMASK;
221    
222                    if (_originalValue == null) {
223                            _originalValue = _value;
224                    }
225    
226                    _value = value;
227            }
228    
229            public String getOriginalValue() {
230                    return GetterUtil.getString(_originalValue);
231            }
232    
233            public long getColumnBitmask() {
234                    return _columnBitmask;
235            }
236    
237            @Override
238            public ExpandoBridge getExpandoBridge() {
239                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
240                            ClassName.class.getName(), getPrimaryKey());
241            }
242    
243            @Override
244            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
245                    ExpandoBridge expandoBridge = getExpandoBridge();
246    
247                    expandoBridge.setAttributes(serviceContext);
248            }
249    
250            @Override
251            public ClassName toEscapedModel() {
252                    if (_escapedModel == null) {
253                            _escapedModel = (ClassName)ProxyUtil.newProxyInstance(_classLoader,
254                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
255                    }
256    
257                    return _escapedModel;
258            }
259    
260            @Override
261            public Object clone() {
262                    ClassNameImpl classNameImpl = new ClassNameImpl();
263    
264                    classNameImpl.setClassNameId(getClassNameId());
265                    classNameImpl.setValue(getValue());
266    
267                    classNameImpl.resetOriginalValues();
268    
269                    return classNameImpl;
270            }
271    
272            public int compareTo(ClassName className) {
273                    long primaryKey = className.getPrimaryKey();
274    
275                    if (getPrimaryKey() < primaryKey) {
276                            return -1;
277                    }
278                    else if (getPrimaryKey() > primaryKey) {
279                            return 1;
280                    }
281                    else {
282                            return 0;
283                    }
284            }
285    
286            @Override
287            public boolean equals(Object obj) {
288                    if (obj == null) {
289                            return false;
290                    }
291    
292                    ClassName className = null;
293    
294                    try {
295                            className = (ClassName)obj;
296                    }
297                    catch (ClassCastException cce) {
298                            return false;
299                    }
300    
301                    long primaryKey = className.getPrimaryKey();
302    
303                    if (getPrimaryKey() == primaryKey) {
304                            return true;
305                    }
306                    else {
307                            return false;
308                    }
309            }
310    
311            @Override
312            public int hashCode() {
313                    return (int)getPrimaryKey();
314            }
315    
316            @Override
317            public void resetOriginalValues() {
318                    ClassNameModelImpl classNameModelImpl = this;
319    
320                    classNameModelImpl._originalValue = classNameModelImpl._value;
321    
322                    classNameModelImpl._columnBitmask = 0;
323            }
324    
325            @Override
326            public CacheModel<ClassName> toCacheModel() {
327                    ClassNameCacheModel classNameCacheModel = new ClassNameCacheModel();
328    
329                    classNameCacheModel.classNameId = getClassNameId();
330    
331                    classNameCacheModel.value = getValue();
332    
333                    String value = classNameCacheModel.value;
334    
335                    if ((value != null) && (value.length() == 0)) {
336                            classNameCacheModel.value = null;
337                    }
338    
339                    return classNameCacheModel;
340            }
341    
342            @Override
343            public String toString() {
344                    StringBundler sb = new StringBundler(5);
345    
346                    sb.append("{classNameId=");
347                    sb.append(getClassNameId());
348                    sb.append(", value=");
349                    sb.append(getValue());
350                    sb.append("}");
351    
352                    return sb.toString();
353            }
354    
355            public String toXmlString() {
356                    StringBundler sb = new StringBundler(10);
357    
358                    sb.append("<model><model-name>");
359                    sb.append("com.liferay.portal.model.ClassName");
360                    sb.append("</model-name>");
361    
362                    sb.append(
363                            "<column><column-name>classNameId</column-name><column-value><![CDATA[");
364                    sb.append(getClassNameId());
365                    sb.append("]]></column-value></column>");
366                    sb.append(
367                            "<column><column-name>value</column-name><column-value><![CDATA[");
368                    sb.append(getValue());
369                    sb.append("]]></column-value></column>");
370    
371                    sb.append("</model>");
372    
373                    return sb.toString();
374            }
375    
376            private static ClassLoader _classLoader = ClassName.class.getClassLoader();
377            private static Class<?>[] _escapedModelInterfaces = new Class[] {
378                            ClassName.class
379                    };
380            private long _classNameId;
381            private String _value;
382            private String _originalValue;
383            private long _columnBitmask;
384            private ClassName _escapedModel;
385    }