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