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.portlet.documentlibrary.model.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
020    import com.liferay.portal.kernel.util.GetterUtil;
021    import com.liferay.portal.kernel.util.ProxyUtil;
022    import com.liferay.portal.kernel.util.StringBundler;
023    import com.liferay.portal.kernel.util.StringPool;
024    import com.liferay.portal.model.CacheModel;
025    import com.liferay.portal.model.impl.BaseModelImpl;
026    import com.liferay.portal.service.ServiceContext;
027    
028    import com.liferay.portlet.documentlibrary.model.DLContent;
029    import com.liferay.portlet.documentlibrary.model.DLContentDataBlobModel;
030    import com.liferay.portlet.documentlibrary.model.DLContentModel;
031    import com.liferay.portlet.documentlibrary.service.DLContentLocalServiceUtil;
032    import com.liferay.portlet.expando.model.ExpandoBridge;
033    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
034    
035    import java.io.Serializable;
036    
037    import java.sql.Blob;
038    import java.sql.Types;
039    
040    import java.util.HashMap;
041    import java.util.Map;
042    
043    /**
044     * The base model implementation for the DLContent service. Represents a row in the "DLContent" database table, with each column mapped to a property of this class.
045     *
046     * <p>
047     * This implementation and its corresponding interface {@link DLContentModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link DLContentImpl}.
048     * </p>
049     *
050     * @author Brian Wing Shun Chan
051     * @see DLContentImpl
052     * @see DLContent
053     * @see DLContentModel
054     * @generated
055     */
056    @ProviderType
057    public class DLContentModelImpl extends BaseModelImpl<DLContent>
058            implements DLContentModel {
059            /*
060             * NOTE FOR DEVELOPERS:
061             *
062             * Never modify or reference this class directly. All methods that expect a document library content model instance should use the {@link DLContent} interface instead.
063             */
064            public static final String TABLE_NAME = "DLContent";
065            public static final Object[][] TABLE_COLUMNS = {
066                            { "contentId", Types.BIGINT },
067                            { "groupId", Types.BIGINT },
068                            { "companyId", Types.BIGINT },
069                            { "repositoryId", Types.BIGINT },
070                            { "path_", Types.VARCHAR },
071                            { "version", Types.VARCHAR },
072                            { "data_", Types.BLOB },
073                            { "size_", Types.BIGINT }
074                    };
075            public static final Map<String, Integer> TABLE_COLUMNS_MAP = new HashMap<String, Integer>();
076    
077            static {
078                    TABLE_COLUMNS_MAP.put("contentId", Types.BIGINT);
079                    TABLE_COLUMNS_MAP.put("groupId", Types.BIGINT);
080                    TABLE_COLUMNS_MAP.put("companyId", Types.BIGINT);
081                    TABLE_COLUMNS_MAP.put("repositoryId", Types.BIGINT);
082                    TABLE_COLUMNS_MAP.put("path_", Types.VARCHAR);
083                    TABLE_COLUMNS_MAP.put("version", Types.VARCHAR);
084                    TABLE_COLUMNS_MAP.put("data_", Types.BLOB);
085                    TABLE_COLUMNS_MAP.put("size_", Types.BIGINT);
086            }
087    
088            public static final String TABLE_SQL_CREATE = "create table DLContent (contentId LONG not null primary key,groupId LONG,companyId LONG,repositoryId LONG,path_ VARCHAR(255) null,version VARCHAR(75) null,data_ BLOB,size_ LONG)";
089            public static final String TABLE_SQL_DROP = "drop table DLContent";
090            public static final String ORDER_BY_JPQL = " ORDER BY dlContent.version DESC";
091            public static final String ORDER_BY_SQL = " ORDER BY DLContent.version DESC";
092            public static final String DATA_SOURCE = "liferayDataSource";
093            public static final String SESSION_FACTORY = "liferaySessionFactory";
094            public static final String TX_MANAGER = "liferayTransactionManager";
095            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
096                                    "value.object.entity.cache.enabled.com.liferay.portlet.documentlibrary.model.DLContent"),
097                            true);
098            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
099                                    "value.object.finder.cache.enabled.com.liferay.portlet.documentlibrary.model.DLContent"),
100                            true);
101            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
102                                    "value.object.column.bitmask.enabled.com.liferay.portlet.documentlibrary.model.DLContent"),
103                            true);
104            public static final long COMPANYID_COLUMN_BITMASK = 1L;
105            public static final long PATH_COLUMN_BITMASK = 2L;
106            public static final long REPOSITORYID_COLUMN_BITMASK = 4L;
107            public static final long VERSION_COLUMN_BITMASK = 8L;
108            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
109                                    "lock.expiration.time.com.liferay.portlet.documentlibrary.model.DLContent"));
110    
111            public DLContentModelImpl() {
112            }
113    
114            @Override
115            public long getPrimaryKey() {
116                    return _contentId;
117            }
118    
119            @Override
120            public void setPrimaryKey(long primaryKey) {
121                    setContentId(primaryKey);
122            }
123    
124            @Override
125            public Serializable getPrimaryKeyObj() {
126                    return _contentId;
127            }
128    
129            @Override
130            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
131                    setPrimaryKey(((Long)primaryKeyObj).longValue());
132            }
133    
134            @Override
135            public Class<?> getModelClass() {
136                    return DLContent.class;
137            }
138    
139            @Override
140            public String getModelClassName() {
141                    return DLContent.class.getName();
142            }
143    
144            @Override
145            public Map<String, Object> getModelAttributes() {
146                    Map<String, Object> attributes = new HashMap<String, Object>();
147    
148                    attributes.put("contentId", getContentId());
149                    attributes.put("groupId", getGroupId());
150                    attributes.put("companyId", getCompanyId());
151                    attributes.put("repositoryId", getRepositoryId());
152                    attributes.put("path", getPath());
153                    attributes.put("version", getVersion());
154                    attributes.put("data", getData());
155                    attributes.put("size", getSize());
156    
157                    attributes.put("entityCacheEnabled", isEntityCacheEnabled());
158                    attributes.put("finderCacheEnabled", isFinderCacheEnabled());
159    
160                    return attributes;
161            }
162    
163            @Override
164            public void setModelAttributes(Map<String, Object> attributes) {
165                    Long contentId = (Long)attributes.get("contentId");
166    
167                    if (contentId != null) {
168                            setContentId(contentId);
169                    }
170    
171                    Long groupId = (Long)attributes.get("groupId");
172    
173                    if (groupId != null) {
174                            setGroupId(groupId);
175                    }
176    
177                    Long companyId = (Long)attributes.get("companyId");
178    
179                    if (companyId != null) {
180                            setCompanyId(companyId);
181                    }
182    
183                    Long repositoryId = (Long)attributes.get("repositoryId");
184    
185                    if (repositoryId != null) {
186                            setRepositoryId(repositoryId);
187                    }
188    
189                    String path = (String)attributes.get("path");
190    
191                    if (path != null) {
192                            setPath(path);
193                    }
194    
195                    String version = (String)attributes.get("version");
196    
197                    if (version != null) {
198                            setVersion(version);
199                    }
200    
201                    Blob data = (Blob)attributes.get("data");
202    
203                    if (data != null) {
204                            setData(data);
205                    }
206    
207                    Long size = (Long)attributes.get("size");
208    
209                    if (size != null) {
210                            setSize(size);
211                    }
212            }
213    
214            @Override
215            public long getContentId() {
216                    return _contentId;
217            }
218    
219            @Override
220            public void setContentId(long contentId) {
221                    _contentId = contentId;
222            }
223    
224            @Override
225            public long getGroupId() {
226                    return _groupId;
227            }
228    
229            @Override
230            public void setGroupId(long groupId) {
231                    _groupId = groupId;
232            }
233    
234            @Override
235            public long getCompanyId() {
236                    return _companyId;
237            }
238    
239            @Override
240            public void setCompanyId(long companyId) {
241                    _columnBitmask |= COMPANYID_COLUMN_BITMASK;
242    
243                    if (!_setOriginalCompanyId) {
244                            _setOriginalCompanyId = true;
245    
246                            _originalCompanyId = _companyId;
247                    }
248    
249                    _companyId = companyId;
250            }
251    
252            public long getOriginalCompanyId() {
253                    return _originalCompanyId;
254            }
255    
256            @Override
257            public long getRepositoryId() {
258                    return _repositoryId;
259            }
260    
261            @Override
262            public void setRepositoryId(long repositoryId) {
263                    _columnBitmask |= REPOSITORYID_COLUMN_BITMASK;
264    
265                    if (!_setOriginalRepositoryId) {
266                            _setOriginalRepositoryId = true;
267    
268                            _originalRepositoryId = _repositoryId;
269                    }
270    
271                    _repositoryId = repositoryId;
272            }
273    
274            public long getOriginalRepositoryId() {
275                    return _originalRepositoryId;
276            }
277    
278            @Override
279            public String getPath() {
280                    if (_path == null) {
281                            return StringPool.BLANK;
282                    }
283                    else {
284                            return _path;
285                    }
286            }
287    
288            @Override
289            public void setPath(String path) {
290                    _columnBitmask |= PATH_COLUMN_BITMASK;
291    
292                    if (_originalPath == null) {
293                            _originalPath = _path;
294                    }
295    
296                    _path = path;
297            }
298    
299            public String getOriginalPath() {
300                    return GetterUtil.getString(_originalPath);
301            }
302    
303            @Override
304            public String getVersion() {
305                    if (_version == null) {
306                            return StringPool.BLANK;
307                    }
308                    else {
309                            return _version;
310                    }
311            }
312    
313            @Override
314            public void setVersion(String version) {
315                    _columnBitmask = -1L;
316    
317                    if (_originalVersion == null) {
318                            _originalVersion = _version;
319                    }
320    
321                    _version = version;
322            }
323    
324            public String getOriginalVersion() {
325                    return GetterUtil.getString(_originalVersion);
326            }
327    
328            @Override
329            public Blob getData() {
330                    if (_dataBlobModel == null) {
331                            try {
332                                    _dataBlobModel = DLContentLocalServiceUtil.getDataBlobModel(getPrimaryKey());
333                            }
334                            catch (Exception e) {
335                            }
336                    }
337    
338                    Blob blob = null;
339    
340                    if (_dataBlobModel != null) {
341                            blob = _dataBlobModel.getDataBlob();
342                    }
343    
344                    return blob;
345            }
346    
347            @Override
348            public void setData(Blob data) {
349                    if (_dataBlobModel == null) {
350                            _dataBlobModel = new DLContentDataBlobModel(getPrimaryKey(), data);
351                    }
352                    else {
353                            _dataBlobModel.setDataBlob(data);
354                    }
355            }
356    
357            @Override
358            public long getSize() {
359                    return _size;
360            }
361    
362            @Override
363            public void setSize(long size) {
364                    _size = size;
365            }
366    
367            public long getColumnBitmask() {
368                    return _columnBitmask;
369            }
370    
371            @Override
372            public ExpandoBridge getExpandoBridge() {
373                    return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
374                            DLContent.class.getName(), getPrimaryKey());
375            }
376    
377            @Override
378            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
379                    ExpandoBridge expandoBridge = getExpandoBridge();
380    
381                    expandoBridge.setAttributes(serviceContext);
382            }
383    
384            @Override
385            public DLContent toEscapedModel() {
386                    if (_escapedModel == null) {
387                            _escapedModel = (DLContent)ProxyUtil.newProxyInstance(_classLoader,
388                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
389                    }
390    
391                    return _escapedModel;
392            }
393    
394            @Override
395            public Object clone() {
396                    DLContentImpl dlContentImpl = new DLContentImpl();
397    
398                    dlContentImpl.setContentId(getContentId());
399                    dlContentImpl.setGroupId(getGroupId());
400                    dlContentImpl.setCompanyId(getCompanyId());
401                    dlContentImpl.setRepositoryId(getRepositoryId());
402                    dlContentImpl.setPath(getPath());
403                    dlContentImpl.setVersion(getVersion());
404                    dlContentImpl.setSize(getSize());
405    
406                    dlContentImpl.resetOriginalValues();
407    
408                    return dlContentImpl;
409            }
410    
411            @Override
412            public int compareTo(DLContent dlContent) {
413                    int value = 0;
414    
415                    value = getVersion().compareTo(dlContent.getVersion());
416    
417                    value = value * -1;
418    
419                    if (value != 0) {
420                            return value;
421                    }
422    
423                    return 0;
424            }
425    
426            @Override
427            public boolean equals(Object obj) {
428                    if (this == obj) {
429                            return true;
430                    }
431    
432                    if (!(obj instanceof DLContent)) {
433                            return false;
434                    }
435    
436                    DLContent dlContent = (DLContent)obj;
437    
438                    long primaryKey = dlContent.getPrimaryKey();
439    
440                    if (getPrimaryKey() == primaryKey) {
441                            return true;
442                    }
443                    else {
444                            return false;
445                    }
446            }
447    
448            @Override
449            public int hashCode() {
450                    return (int)getPrimaryKey();
451            }
452    
453            @Override
454            public boolean isEntityCacheEnabled() {
455                    return ENTITY_CACHE_ENABLED;
456            }
457    
458            @Override
459            public boolean isFinderCacheEnabled() {
460                    return FINDER_CACHE_ENABLED;
461            }
462    
463            @Override
464            public void resetOriginalValues() {
465                    DLContentModelImpl dlContentModelImpl = this;
466    
467                    dlContentModelImpl._originalCompanyId = dlContentModelImpl._companyId;
468    
469                    dlContentModelImpl._setOriginalCompanyId = false;
470    
471                    dlContentModelImpl._originalRepositoryId = dlContentModelImpl._repositoryId;
472    
473                    dlContentModelImpl._setOriginalRepositoryId = false;
474    
475                    dlContentModelImpl._originalPath = dlContentModelImpl._path;
476    
477                    dlContentModelImpl._originalVersion = dlContentModelImpl._version;
478    
479                    dlContentModelImpl._dataBlobModel = null;
480    
481                    dlContentModelImpl._columnBitmask = 0;
482            }
483    
484            @Override
485            public CacheModel<DLContent> toCacheModel() {
486                    DLContentCacheModel dlContentCacheModel = new DLContentCacheModel();
487    
488                    dlContentCacheModel.contentId = getContentId();
489    
490                    dlContentCacheModel.groupId = getGroupId();
491    
492                    dlContentCacheModel.companyId = getCompanyId();
493    
494                    dlContentCacheModel.repositoryId = getRepositoryId();
495    
496                    dlContentCacheModel.path = getPath();
497    
498                    String path = dlContentCacheModel.path;
499    
500                    if ((path != null) && (path.length() == 0)) {
501                            dlContentCacheModel.path = null;
502                    }
503    
504                    dlContentCacheModel.version = getVersion();
505    
506                    String version = dlContentCacheModel.version;
507    
508                    if ((version != null) && (version.length() == 0)) {
509                            dlContentCacheModel.version = null;
510                    }
511    
512                    dlContentCacheModel.size = getSize();
513    
514                    return dlContentCacheModel;
515            }
516    
517            @Override
518            public String toString() {
519                    StringBundler sb = new StringBundler(17);
520    
521                    sb.append("{contentId=");
522                    sb.append(getContentId());
523                    sb.append(", groupId=");
524                    sb.append(getGroupId());
525                    sb.append(", companyId=");
526                    sb.append(getCompanyId());
527                    sb.append(", repositoryId=");
528                    sb.append(getRepositoryId());
529                    sb.append(", path=");
530                    sb.append(getPath());
531                    sb.append(", version=");
532                    sb.append(getVersion());
533                    sb.append(", size=");
534                    sb.append(getSize());
535                    sb.append("}");
536    
537                    return sb.toString();
538            }
539    
540            @Override
541            public String toXmlString() {
542                    StringBundler sb = new StringBundler(28);
543    
544                    sb.append("<model><model-name>");
545                    sb.append("com.liferay.portlet.documentlibrary.model.DLContent");
546                    sb.append("</model-name>");
547    
548                    sb.append(
549                            "<column><column-name>contentId</column-name><column-value><![CDATA[");
550                    sb.append(getContentId());
551                    sb.append("]]></column-value></column>");
552                    sb.append(
553                            "<column><column-name>groupId</column-name><column-value><![CDATA[");
554                    sb.append(getGroupId());
555                    sb.append("]]></column-value></column>");
556                    sb.append(
557                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
558                    sb.append(getCompanyId());
559                    sb.append("]]></column-value></column>");
560                    sb.append(
561                            "<column><column-name>repositoryId</column-name><column-value><![CDATA[");
562                    sb.append(getRepositoryId());
563                    sb.append("]]></column-value></column>");
564                    sb.append(
565                            "<column><column-name>path</column-name><column-value><![CDATA[");
566                    sb.append(getPath());
567                    sb.append("]]></column-value></column>");
568                    sb.append(
569                            "<column><column-name>version</column-name><column-value><![CDATA[");
570                    sb.append(getVersion());
571                    sb.append("]]></column-value></column>");
572                    sb.append(
573                            "<column><column-name>size</column-name><column-value><![CDATA[");
574                    sb.append(getSize());
575                    sb.append("]]></column-value></column>");
576    
577                    sb.append("</model>");
578    
579                    return sb.toString();
580            }
581    
582            private static final ClassLoader _classLoader = DLContent.class.getClassLoader();
583            private static final Class<?>[] _escapedModelInterfaces = new Class[] {
584                            DLContent.class
585                    };
586            private long _contentId;
587            private long _groupId;
588            private long _companyId;
589            private long _originalCompanyId;
590            private boolean _setOriginalCompanyId;
591            private long _repositoryId;
592            private long _originalRepositoryId;
593            private boolean _setOriginalRepositoryId;
594            private String _path;
595            private String _originalPath;
596            private String _version;
597            private String _originalVersion;
598            private DLContentDataBlobModel _dataBlobModel;
599            private long _size;
600            private long _columnBitmask;
601            private DLContent _escapedModel;
602    }