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