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