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.portlet.expando.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.impl.BaseModelImpl;
026    import com.liferay.portal.util.PortalUtil;
027    
028    import com.liferay.portlet.expando.model.ExpandoValue;
029    import com.liferay.portlet.expando.model.ExpandoValueModel;
030    import com.liferay.portlet.expando.model.ExpandoValueSoap;
031    
032    import java.io.Serializable;
033    
034    import java.sql.Types;
035    
036    import java.util.ArrayList;
037    import java.util.HashMap;
038    import java.util.List;
039    import java.util.Map;
040    
041    /**
042     * The base model implementation for the ExpandoValue service. Represents a row in the "ExpandoValue" database table, with each column mapped to a property of this class.
043     *
044     * <p>
045     * This implementation and its corresponding interface {@link com.liferay.portlet.expando.model.ExpandoValueModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ExpandoValueImpl}.
046     * </p>
047     *
048     * @author Brian Wing Shun Chan
049     * @see ExpandoValueImpl
050     * @see com.liferay.portlet.expando.model.ExpandoValue
051     * @see com.liferay.portlet.expando.model.ExpandoValueModel
052     * @generated
053     */
054    @JSON(strict = true)
055    public class ExpandoValueModelImpl extends BaseModelImpl<ExpandoValue>
056            implements ExpandoValueModel {
057            /*
058             * NOTE FOR DEVELOPERS:
059             *
060             * Never modify or reference this class directly. All methods that expect a expando value model instance should use the {@link com.liferay.portlet.expando.model.ExpandoValue} interface instead.
061             */
062            public static final String TABLE_NAME = "ExpandoValue";
063            public static final Object[][] TABLE_COLUMNS = {
064                            { "valueId", Types.BIGINT },
065                            { "companyId", Types.BIGINT },
066                            { "tableId", Types.BIGINT },
067                            { "columnId", Types.BIGINT },
068                            { "rowId_", Types.BIGINT },
069                            { "classNameId", Types.BIGINT },
070                            { "classPK", Types.BIGINT },
071                            { "data_", Types.VARCHAR }
072                    };
073            public static final String TABLE_SQL_CREATE = "create table ExpandoValue (valueId LONG not null primary key,companyId LONG,tableId LONG,columnId LONG,rowId_ LONG,classNameId LONG,classPK LONG,data_ STRING null)";
074            public static final String TABLE_SQL_DROP = "drop table ExpandoValue";
075            public static final String ORDER_BY_JPQL = " ORDER BY expandoValue.tableId ASC, expandoValue.rowId ASC, expandoValue.columnId ASC";
076            public static final String ORDER_BY_SQL = " ORDER BY ExpandoValue.tableId ASC, ExpandoValue.rowId_ ASC, ExpandoValue.columnId 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.portlet.expando.model.ExpandoValue"),
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.portlet.expando.model.ExpandoValue"),
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.portlet.expando.model.ExpandoValue"),
088                            true);
089            public static long CLASSNAMEID_COLUMN_BITMASK = 1L;
090            public static long CLASSPK_COLUMN_BITMASK = 2L;
091            public static long COLUMNID_COLUMN_BITMASK = 4L;
092            public static long DATA_COLUMN_BITMASK = 8L;
093            public static long ROWID_COLUMN_BITMASK = 16L;
094            public static long TABLEID_COLUMN_BITMASK = 32L;
095    
096            /**
097             * Converts the soap model instance into a normal model instance.
098             *
099             * @param soapModel the soap model instance to convert
100             * @return the normal model instance
101             */
102            public static ExpandoValue toModel(ExpandoValueSoap soapModel) {
103                    if (soapModel == null) {
104                            return null;
105                    }
106    
107                    ExpandoValue model = new ExpandoValueImpl();
108    
109                    model.setValueId(soapModel.getValueId());
110                    model.setCompanyId(soapModel.getCompanyId());
111                    model.setTableId(soapModel.getTableId());
112                    model.setColumnId(soapModel.getColumnId());
113                    model.setRowId(soapModel.getRowId());
114                    model.setClassNameId(soapModel.getClassNameId());
115                    model.setClassPK(soapModel.getClassPK());
116                    model.setData(soapModel.getData());
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<ExpandoValue> toModels(ExpandoValueSoap[] soapModels) {
128                    if (soapModels == null) {
129                            return null;
130                    }
131    
132                    List<ExpandoValue> models = new ArrayList<ExpandoValue>(soapModels.length);
133    
134                    for (ExpandoValueSoap 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.portlet.expando.model.ExpandoValue"));
143    
144            public ExpandoValueModelImpl() {
145            }
146    
147            public long getPrimaryKey() {
148                    return _valueId;
149            }
150    
151            public void setPrimaryKey(long primaryKey) {
152                    setValueId(primaryKey);
153            }
154    
155            public Serializable getPrimaryKeyObj() {
156                    return new Long(_valueId);
157            }
158    
159            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
160                    setPrimaryKey(((Long)primaryKeyObj).longValue());
161            }
162    
163            public Class<?> getModelClass() {
164                    return ExpandoValue.class;
165            }
166    
167            public String getModelClassName() {
168                    return ExpandoValue.class.getName();
169            }
170    
171            @Override
172            public Map<String, Object> getModelAttributes() {
173                    Map<String, Object> attributes = new HashMap<String, Object>();
174    
175                    attributes.put("valueId", getValueId());
176                    attributes.put("companyId", getCompanyId());
177                    attributes.put("tableId", getTableId());
178                    attributes.put("columnId", getColumnId());
179                    attributes.put("rowId", getRowId());
180                    attributes.put("classNameId", getClassNameId());
181                    attributes.put("classPK", getClassPK());
182                    attributes.put("data", getData());
183    
184                    return attributes;
185            }
186    
187            @Override
188            public void setModelAttributes(Map<String, Object> attributes) {
189                    Long valueId = (Long)attributes.get("valueId");
190    
191                    if (valueId != null) {
192                            setValueId(valueId);
193                    }
194    
195                    Long companyId = (Long)attributes.get("companyId");
196    
197                    if (companyId != null) {
198                            setCompanyId(companyId);
199                    }
200    
201                    Long tableId = (Long)attributes.get("tableId");
202    
203                    if (tableId != null) {
204                            setTableId(tableId);
205                    }
206    
207                    Long columnId = (Long)attributes.get("columnId");
208    
209                    if (columnId != null) {
210                            setColumnId(columnId);
211                    }
212    
213                    Long rowId = (Long)attributes.get("rowId");
214    
215                    if (rowId != null) {
216                            setRowId(rowId);
217                    }
218    
219                    Long classNameId = (Long)attributes.get("classNameId");
220    
221                    if (classNameId != null) {
222                            setClassNameId(classNameId);
223                    }
224    
225                    Long classPK = (Long)attributes.get("classPK");
226    
227                    if (classPK != null) {
228                            setClassPK(classPK);
229                    }
230    
231                    String data = (String)attributes.get("data");
232    
233                    if (data != null) {
234                            setData(data);
235                    }
236            }
237    
238            @JSON
239            public long getValueId() {
240                    return _valueId;
241            }
242    
243            public void setValueId(long valueId) {
244                    _valueId = valueId;
245            }
246    
247            @JSON
248            public long getCompanyId() {
249                    return _companyId;
250            }
251    
252            public void setCompanyId(long companyId) {
253                    _companyId = companyId;
254            }
255    
256            @JSON
257            public long getTableId() {
258                    return _tableId;
259            }
260    
261            public void setTableId(long tableId) {
262                    _columnBitmask = -1L;
263    
264                    if (!_setOriginalTableId) {
265                            _setOriginalTableId = true;
266    
267                            _originalTableId = _tableId;
268                    }
269    
270                    _tableId = tableId;
271            }
272    
273            public long getOriginalTableId() {
274                    return _originalTableId;
275            }
276    
277            @JSON
278            public long getColumnId() {
279                    return _columnId;
280            }
281    
282            public void setColumnId(long columnId) {
283                    _columnBitmask = -1L;
284    
285                    if (!_setOriginalColumnId) {
286                            _setOriginalColumnId = true;
287    
288                            _originalColumnId = _columnId;
289                    }
290    
291                    _columnId = columnId;
292            }
293    
294            public long getOriginalColumnId() {
295                    return _originalColumnId;
296            }
297    
298            @JSON
299            public long getRowId() {
300                    return _rowId;
301            }
302    
303            public void setRowId(long rowId) {
304                    _columnBitmask = -1L;
305    
306                    if (!_setOriginalRowId) {
307                            _setOriginalRowId = true;
308    
309                            _originalRowId = _rowId;
310                    }
311    
312                    _rowId = rowId;
313            }
314    
315            public long getOriginalRowId() {
316                    return _originalRowId;
317            }
318    
319            public String getClassName() {
320                    if (getClassNameId() <= 0) {
321                            return StringPool.BLANK;
322                    }
323    
324                    return PortalUtil.getClassName(getClassNameId());
325            }
326    
327            public void setClassName(String className) {
328                    long classNameId = 0;
329    
330                    if (Validator.isNotNull(className)) {
331                            classNameId = PortalUtil.getClassNameId(className);
332                    }
333    
334                    setClassNameId(classNameId);
335            }
336    
337            @JSON
338            public long getClassNameId() {
339                    return _classNameId;
340            }
341    
342            public void setClassNameId(long classNameId) {
343                    _columnBitmask |= CLASSNAMEID_COLUMN_BITMASK;
344    
345                    if (!_setOriginalClassNameId) {
346                            _setOriginalClassNameId = true;
347    
348                            _originalClassNameId = _classNameId;
349                    }
350    
351                    _classNameId = classNameId;
352            }
353    
354            public long getOriginalClassNameId() {
355                    return _originalClassNameId;
356            }
357    
358            @JSON
359            public long getClassPK() {
360                    return _classPK;
361            }
362    
363            public void setClassPK(long classPK) {
364                    _columnBitmask |= CLASSPK_COLUMN_BITMASK;
365    
366                    if (!_setOriginalClassPK) {
367                            _setOriginalClassPK = true;
368    
369                            _originalClassPK = _classPK;
370                    }
371    
372                    _classPK = classPK;
373            }
374    
375            public long getOriginalClassPK() {
376                    return _originalClassPK;
377            }
378    
379            @JSON
380            public String getData() {
381                    if (_data == null) {
382                            return StringPool.BLANK;
383                    }
384                    else {
385                            return _data;
386                    }
387            }
388    
389            public void setData(String data) {
390                    _columnBitmask |= DATA_COLUMN_BITMASK;
391    
392                    if (_originalData == null) {
393                            _originalData = _data;
394                    }
395    
396                    _data = data;
397            }
398    
399            public String getOriginalData() {
400                    return GetterUtil.getString(_originalData);
401            }
402    
403            public long getColumnBitmask() {
404                    return _columnBitmask;
405            }
406    
407            @Override
408            public ExpandoValue toEscapedModel() {
409                    if (_escapedModel == null) {
410                            _escapedModel = (ExpandoValue)ProxyUtil.newProxyInstance(_classLoader,
411                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
412                    }
413    
414                    return _escapedModel;
415            }
416    
417            public ExpandoValue toUnescapedModel() {
418                    return (ExpandoValue)this;
419            }
420    
421            @Override
422            public Object clone() {
423                    ExpandoValueImpl expandoValueImpl = new ExpandoValueImpl();
424    
425                    expandoValueImpl.setValueId(getValueId());
426                    expandoValueImpl.setCompanyId(getCompanyId());
427                    expandoValueImpl.setTableId(getTableId());
428                    expandoValueImpl.setColumnId(getColumnId());
429                    expandoValueImpl.setRowId(getRowId());
430                    expandoValueImpl.setClassNameId(getClassNameId());
431                    expandoValueImpl.setClassPK(getClassPK());
432                    expandoValueImpl.setData(getData());
433    
434                    expandoValueImpl.resetOriginalValues();
435    
436                    return expandoValueImpl;
437            }
438    
439            public int compareTo(ExpandoValue expandoValue) {
440                    int value = 0;
441    
442                    if (getTableId() < expandoValue.getTableId()) {
443                            value = -1;
444                    }
445                    else if (getTableId() > expandoValue.getTableId()) {
446                            value = 1;
447                    }
448                    else {
449                            value = 0;
450                    }
451    
452                    if (value != 0) {
453                            return value;
454                    }
455    
456                    if (getRowId() < expandoValue.getRowId()) {
457                            value = -1;
458                    }
459                    else if (getRowId() > expandoValue.getRowId()) {
460                            value = 1;
461                    }
462                    else {
463                            value = 0;
464                    }
465    
466                    if (value != 0) {
467                            return value;
468                    }
469    
470                    if (getColumnId() < expandoValue.getColumnId()) {
471                            value = -1;
472                    }
473                    else if (getColumnId() > expandoValue.getColumnId()) {
474                            value = 1;
475                    }
476                    else {
477                            value = 0;
478                    }
479    
480                    if (value != 0) {
481                            return value;
482                    }
483    
484                    return 0;
485            }
486    
487            @Override
488            public boolean equals(Object obj) {
489                    if (this == obj) {
490                            return true;
491                    }
492    
493                    if (!(obj instanceof ExpandoValue)) {
494                            return false;
495                    }
496    
497                    ExpandoValue expandoValue = (ExpandoValue)obj;
498    
499                    long primaryKey = expandoValue.getPrimaryKey();
500    
501                    if (getPrimaryKey() == primaryKey) {
502                            return true;
503                    }
504                    else {
505                            return false;
506                    }
507            }
508    
509            @Override
510            public int hashCode() {
511                    return (int)getPrimaryKey();
512            }
513    
514            @Override
515            public void resetOriginalValues() {
516                    ExpandoValueModelImpl expandoValueModelImpl = this;
517    
518                    expandoValueModelImpl._originalTableId = expandoValueModelImpl._tableId;
519    
520                    expandoValueModelImpl._setOriginalTableId = false;
521    
522                    expandoValueModelImpl._originalColumnId = expandoValueModelImpl._columnId;
523    
524                    expandoValueModelImpl._setOriginalColumnId = false;
525    
526                    expandoValueModelImpl._originalRowId = expandoValueModelImpl._rowId;
527    
528                    expandoValueModelImpl._setOriginalRowId = false;
529    
530                    expandoValueModelImpl._originalClassNameId = expandoValueModelImpl._classNameId;
531    
532                    expandoValueModelImpl._setOriginalClassNameId = false;
533    
534                    expandoValueModelImpl._originalClassPK = expandoValueModelImpl._classPK;
535    
536                    expandoValueModelImpl._setOriginalClassPK = false;
537    
538                    expandoValueModelImpl._originalData = expandoValueModelImpl._data;
539    
540                    expandoValueModelImpl._columnBitmask = 0;
541            }
542    
543            @Override
544            public CacheModel<ExpandoValue> toCacheModel() {
545                    ExpandoValueCacheModel expandoValueCacheModel = new ExpandoValueCacheModel();
546    
547                    expandoValueCacheModel.valueId = getValueId();
548    
549                    expandoValueCacheModel.companyId = getCompanyId();
550    
551                    expandoValueCacheModel.tableId = getTableId();
552    
553                    expandoValueCacheModel.columnId = getColumnId();
554    
555                    expandoValueCacheModel.rowId = getRowId();
556    
557                    expandoValueCacheModel.classNameId = getClassNameId();
558    
559                    expandoValueCacheModel.classPK = getClassPK();
560    
561                    expandoValueCacheModel.data = getData();
562    
563                    String data = expandoValueCacheModel.data;
564    
565                    if ((data != null) && (data.length() == 0)) {
566                            expandoValueCacheModel.data = null;
567                    }
568    
569                    return expandoValueCacheModel;
570            }
571    
572            @Override
573            public String toString() {
574                    StringBundler sb = new StringBundler(17);
575    
576                    sb.append("{valueId=");
577                    sb.append(getValueId());
578                    sb.append(", companyId=");
579                    sb.append(getCompanyId());
580                    sb.append(", tableId=");
581                    sb.append(getTableId());
582                    sb.append(", columnId=");
583                    sb.append(getColumnId());
584                    sb.append(", rowId=");
585                    sb.append(getRowId());
586                    sb.append(", classNameId=");
587                    sb.append(getClassNameId());
588                    sb.append(", classPK=");
589                    sb.append(getClassPK());
590                    sb.append(", data=");
591                    sb.append(getData());
592                    sb.append("}");
593    
594                    return sb.toString();
595            }
596    
597            public String toXmlString() {
598                    StringBundler sb = new StringBundler(28);
599    
600                    sb.append("<model><model-name>");
601                    sb.append("com.liferay.portlet.expando.model.ExpandoValue");
602                    sb.append("</model-name>");
603    
604                    sb.append(
605                            "<column><column-name>valueId</column-name><column-value><![CDATA[");
606                    sb.append(getValueId());
607                    sb.append("]]></column-value></column>");
608                    sb.append(
609                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
610                    sb.append(getCompanyId());
611                    sb.append("]]></column-value></column>");
612                    sb.append(
613                            "<column><column-name>tableId</column-name><column-value><![CDATA[");
614                    sb.append(getTableId());
615                    sb.append("]]></column-value></column>");
616                    sb.append(
617                            "<column><column-name>columnId</column-name><column-value><![CDATA[");
618                    sb.append(getColumnId());
619                    sb.append("]]></column-value></column>");
620                    sb.append(
621                            "<column><column-name>rowId</column-name><column-value><![CDATA[");
622                    sb.append(getRowId());
623                    sb.append("]]></column-value></column>");
624                    sb.append(
625                            "<column><column-name>classNameId</column-name><column-value><![CDATA[");
626                    sb.append(getClassNameId());
627                    sb.append("]]></column-value></column>");
628                    sb.append(
629                            "<column><column-name>classPK</column-name><column-value><![CDATA[");
630                    sb.append(getClassPK());
631                    sb.append("]]></column-value></column>");
632                    sb.append(
633                            "<column><column-name>data</column-name><column-value><![CDATA[");
634                    sb.append(getData());
635                    sb.append("]]></column-value></column>");
636    
637                    sb.append("</model>");
638    
639                    return sb.toString();
640            }
641    
642            private static ClassLoader _classLoader = ExpandoValue.class.getClassLoader();
643            private static Class<?>[] _escapedModelInterfaces = new Class[] {
644                            ExpandoValue.class
645                    };
646            private long _valueId;
647            private long _companyId;
648            private long _tableId;
649            private long _originalTableId;
650            private boolean _setOriginalTableId;
651            private long _columnId;
652            private long _originalColumnId;
653            private boolean _setOriginalColumnId;
654            private long _rowId;
655            private long _originalRowId;
656            private boolean _setOriginalRowId;
657            private long _classNameId;
658            private long _originalClassNameId;
659            private boolean _setOriginalClassNameId;
660            private long _classPK;
661            private long _originalClassPK;
662            private boolean _setOriginalClassPK;
663            private String _data;
664            private String _originalData;
665            private long _columnBitmask;
666            private ExpandoValue _escapedModel;
667    }