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