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