001    /**
002     * Copyright (c) 2000-2013 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.dynamicdatamapping.model.impl;
016    
017    import com.liferay.portal.LocaleException;
018    import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.kernel.json.JSON;
021    import com.liferay.portal.kernel.language.LanguageUtil;
022    import com.liferay.portal.kernel.util.GetterUtil;
023    import com.liferay.portal.kernel.util.LocaleUtil;
024    import com.liferay.portal.kernel.util.LocalizationUtil;
025    import com.liferay.portal.kernel.util.ProxyUtil;
026    import com.liferay.portal.kernel.util.StringBundler;
027    import com.liferay.portal.kernel.util.StringPool;
028    import com.liferay.portal.kernel.util.Validator;
029    import com.liferay.portal.model.CacheModel;
030    import com.liferay.portal.model.impl.BaseModelImpl;
031    import com.liferay.portal.service.ServiceContext;
032    import com.liferay.portal.util.PortalUtil;
033    
034    import com.liferay.portlet.dynamicdatamapping.model.DDMContent;
035    import com.liferay.portlet.dynamicdatamapping.model.DDMContentModel;
036    import com.liferay.portlet.expando.model.ExpandoBridge;
037    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
038    
039    import java.io.Serializable;
040    
041    import java.sql.Types;
042    
043    import java.util.Date;
044    import java.util.HashMap;
045    import java.util.Locale;
046    import java.util.Map;
047    
048    /**
049     * The base model implementation for the DDMContent service. Represents a row in the "DDMContent" database table, with each column mapped to a property of this class.
050     *
051     * <p>
052     * This implementation and its corresponding interface {@link com.liferay.portlet.dynamicdatamapping.model.DDMContentModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link DDMContentImpl}.
053     * </p>
054     *
055     * @author Brian Wing Shun Chan
056     * @see DDMContentImpl
057     * @see com.liferay.portlet.dynamicdatamapping.model.DDMContent
058     * @see com.liferay.portlet.dynamicdatamapping.model.DDMContentModel
059     * @generated
060     */
061    public class DDMContentModelImpl extends BaseModelImpl<DDMContent>
062            implements DDMContentModel {
063            /*
064             * NOTE FOR DEVELOPERS:
065             *
066             * Never modify or reference this class directly. All methods that expect a d d m content model instance should use the {@link com.liferay.portlet.dynamicdatamapping.model.DDMContent} interface instead.
067             */
068            public static final String TABLE_NAME = "DDMContent";
069            public static final Object[][] TABLE_COLUMNS = {
070                            { "uuid_", Types.VARCHAR },
071                            { "contentId", Types.BIGINT },
072                            { "groupId", Types.BIGINT },
073                            { "companyId", Types.BIGINT },
074                            { "userId", Types.BIGINT },
075                            { "userName", Types.VARCHAR },
076                            { "createDate", Types.TIMESTAMP },
077                            { "modifiedDate", Types.TIMESTAMP },
078                            { "name", Types.VARCHAR },
079                            { "description", Types.VARCHAR },
080                            { "xml", Types.CLOB }
081                    };
082            public static final String TABLE_SQL_CREATE = "create table DDMContent (uuid_ VARCHAR(75) null,contentId LONG not null primary key,groupId LONG,companyId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,name STRING null,description STRING null,xml TEXT null)";
083            public static final String TABLE_SQL_DROP = "drop table DDMContent";
084            public static final String DATA_SOURCE = "liferayDataSource";
085            public static final String SESSION_FACTORY = "liferaySessionFactory";
086            public static final String TX_MANAGER = "liferayTransactionManager";
087            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
088                                    "value.object.entity.cache.enabled.com.liferay.portlet.dynamicdatamapping.model.DDMContent"),
089                            true);
090            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
091                                    "value.object.finder.cache.enabled.com.liferay.portlet.dynamicdatamapping.model.DDMContent"),
092                            true);
093            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
094                                    "value.object.column.bitmask.enabled.com.liferay.portlet.dynamicdatamapping.model.DDMContent"),
095                            true);
096            public static long COMPANYID_COLUMN_BITMASK = 1L;
097            public static long GROUPID_COLUMN_BITMASK = 2L;
098            public static long UUID_COLUMN_BITMASK = 4L;
099            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
100                                    "lock.expiration.time.com.liferay.portlet.dynamicdatamapping.model.DDMContent"));
101    
102            public DDMContentModelImpl() {
103            }
104    
105            public long getPrimaryKey() {
106                    return _contentId;
107            }
108    
109            public void setPrimaryKey(long primaryKey) {
110                    setContentId(primaryKey);
111            }
112    
113            public Serializable getPrimaryKeyObj() {
114                    return new Long(_contentId);
115            }
116    
117            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
118                    setPrimaryKey(((Long)primaryKeyObj).longValue());
119            }
120    
121            public Class<?> getModelClass() {
122                    return DDMContent.class;
123            }
124    
125            public String getModelClassName() {
126                    return DDMContent.class.getName();
127            }
128    
129            @Override
130            public Map<String, Object> getModelAttributes() {
131                    Map<String, Object> attributes = new HashMap<String, Object>();
132    
133                    attributes.put("uuid", getUuid());
134                    attributes.put("contentId", getContentId());
135                    attributes.put("groupId", getGroupId());
136                    attributes.put("companyId", getCompanyId());
137                    attributes.put("userId", getUserId());
138                    attributes.put("userName", getUserName());
139                    attributes.put("createDate", getCreateDate());
140                    attributes.put("modifiedDate", getModifiedDate());
141                    attributes.put("name", getName());
142                    attributes.put("description", getDescription());
143                    attributes.put("xml", getXml());
144    
145                    return attributes;
146            }
147    
148            @Override
149            public void setModelAttributes(Map<String, Object> attributes) {
150                    String uuid = (String)attributes.get("uuid");
151    
152                    if (uuid != null) {
153                            setUuid(uuid);
154                    }
155    
156                    Long contentId = (Long)attributes.get("contentId");
157    
158                    if (contentId != null) {
159                            setContentId(contentId);
160                    }
161    
162                    Long groupId = (Long)attributes.get("groupId");
163    
164                    if (groupId != null) {
165                            setGroupId(groupId);
166                    }
167    
168                    Long companyId = (Long)attributes.get("companyId");
169    
170                    if (companyId != null) {
171                            setCompanyId(companyId);
172                    }
173    
174                    Long userId = (Long)attributes.get("userId");
175    
176                    if (userId != null) {
177                            setUserId(userId);
178                    }
179    
180                    String userName = (String)attributes.get("userName");
181    
182                    if (userName != null) {
183                            setUserName(userName);
184                    }
185    
186                    Date createDate = (Date)attributes.get("createDate");
187    
188                    if (createDate != null) {
189                            setCreateDate(createDate);
190                    }
191    
192                    Date modifiedDate = (Date)attributes.get("modifiedDate");
193    
194                    if (modifiedDate != null) {
195                            setModifiedDate(modifiedDate);
196                    }
197    
198                    String name = (String)attributes.get("name");
199    
200                    if (name != null) {
201                            setName(name);
202                    }
203    
204                    String description = (String)attributes.get("description");
205    
206                    if (description != null) {
207                            setDescription(description);
208                    }
209    
210                    String xml = (String)attributes.get("xml");
211    
212                    if (xml != null) {
213                            setXml(xml);
214                    }
215            }
216    
217            public String getUuid() {
218                    if (_uuid == null) {
219                            return StringPool.BLANK;
220                    }
221                    else {
222                            return _uuid;
223                    }
224            }
225    
226            public void setUuid(String uuid) {
227                    if (_originalUuid == null) {
228                            _originalUuid = _uuid;
229                    }
230    
231                    _uuid = uuid;
232            }
233    
234            public String getOriginalUuid() {
235                    return GetterUtil.getString(_originalUuid);
236            }
237    
238            public long getContentId() {
239                    return _contentId;
240            }
241    
242            public void setContentId(long contentId) {
243                    _contentId = contentId;
244            }
245    
246            public long getGroupId() {
247                    return _groupId;
248            }
249    
250            public void setGroupId(long groupId) {
251                    _columnBitmask |= GROUPID_COLUMN_BITMASK;
252    
253                    if (!_setOriginalGroupId) {
254                            _setOriginalGroupId = true;
255    
256                            _originalGroupId = _groupId;
257                    }
258    
259                    _groupId = groupId;
260            }
261    
262            public long getOriginalGroupId() {
263                    return _originalGroupId;
264            }
265    
266            public long getCompanyId() {
267                    return _companyId;
268            }
269    
270            public void setCompanyId(long companyId) {
271                    _columnBitmask |= COMPANYID_COLUMN_BITMASK;
272    
273                    if (!_setOriginalCompanyId) {
274                            _setOriginalCompanyId = true;
275    
276                            _originalCompanyId = _companyId;
277                    }
278    
279                    _companyId = companyId;
280            }
281    
282            public long getOriginalCompanyId() {
283                    return _originalCompanyId;
284            }
285    
286            public long getUserId() {
287                    return _userId;
288            }
289    
290            public void setUserId(long userId) {
291                    _userId = userId;
292            }
293    
294            public String getUserUuid() throws SystemException {
295                    return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
296            }
297    
298            public void setUserUuid(String userUuid) {
299                    _userUuid = userUuid;
300            }
301    
302            public String getUserName() {
303                    if (_userName == null) {
304                            return StringPool.BLANK;
305                    }
306                    else {
307                            return _userName;
308                    }
309            }
310    
311            public void setUserName(String userName) {
312                    _userName = userName;
313            }
314    
315            public Date getCreateDate() {
316                    return _createDate;
317            }
318    
319            public void setCreateDate(Date createDate) {
320                    _createDate = createDate;
321            }
322    
323            public Date getModifiedDate() {
324                    return _modifiedDate;
325            }
326    
327            public void setModifiedDate(Date modifiedDate) {
328                    _modifiedDate = modifiedDate;
329            }
330    
331            public String getName() {
332                    if (_name == null) {
333                            return StringPool.BLANK;
334                    }
335                    else {
336                            return _name;
337                    }
338            }
339    
340            public String getName(Locale locale) {
341                    String languageId = LocaleUtil.toLanguageId(locale);
342    
343                    return getName(languageId);
344            }
345    
346            public String getName(Locale locale, boolean useDefault) {
347                    String languageId = LocaleUtil.toLanguageId(locale);
348    
349                    return getName(languageId, useDefault);
350            }
351    
352            public String getName(String languageId) {
353                    return LocalizationUtil.getLocalization(getName(), languageId);
354            }
355    
356            public String getName(String languageId, boolean useDefault) {
357                    return LocalizationUtil.getLocalization(getName(), languageId,
358                            useDefault);
359            }
360    
361            public String getNameCurrentLanguageId() {
362                    return _nameCurrentLanguageId;
363            }
364    
365            @JSON
366            public String getNameCurrentValue() {
367                    Locale locale = getLocale(_nameCurrentLanguageId);
368    
369                    return getName(locale);
370            }
371    
372            public Map<Locale, String> getNameMap() {
373                    return LocalizationUtil.getLocalizationMap(getName());
374            }
375    
376            public void setName(String name) {
377                    _name = name;
378            }
379    
380            public void setName(String name, Locale locale) {
381                    setName(name, locale, LocaleUtil.getDefault());
382            }
383    
384            public void setName(String name, Locale locale, Locale defaultLocale) {
385                    String languageId = LocaleUtil.toLanguageId(locale);
386                    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);
387    
388                    if (Validator.isNotNull(name)) {
389                            setName(LocalizationUtil.updateLocalization(getName(), "Name",
390                                            name, languageId, defaultLanguageId));
391                    }
392                    else {
393                            setName(LocalizationUtil.removeLocalization(getName(), "Name",
394                                            languageId));
395                    }
396            }
397    
398            public void setNameCurrentLanguageId(String languageId) {
399                    _nameCurrentLanguageId = languageId;
400            }
401    
402            public void setNameMap(Map<Locale, String> nameMap) {
403                    setNameMap(nameMap, LocaleUtil.getDefault());
404            }
405    
406            public void setNameMap(Map<Locale, String> nameMap, Locale defaultLocale) {
407                    if (nameMap == null) {
408                            return;
409                    }
410    
411                    Locale[] locales = LanguageUtil.getAvailableLocales();
412    
413                    for (Locale locale : locales) {
414                            String name = nameMap.get(locale);
415    
416                            setName(name, locale, defaultLocale);
417                    }
418            }
419    
420            public String getDescription() {
421                    if (_description == null) {
422                            return StringPool.BLANK;
423                    }
424                    else {
425                            return _description;
426                    }
427            }
428    
429            public void setDescription(String description) {
430                    _description = description;
431            }
432    
433            public String getXml() {
434                    if (_xml == null) {
435                            return StringPool.BLANK;
436                    }
437                    else {
438                            return _xml;
439                    }
440            }
441    
442            public void setXml(String xml) {
443                    _xml = xml;
444            }
445    
446            public long getColumnBitmask() {
447                    return _columnBitmask;
448            }
449    
450            @Override
451            public ExpandoBridge getExpandoBridge() {
452                    return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
453                            DDMContent.class.getName(), getPrimaryKey());
454            }
455    
456            @Override
457            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
458                    ExpandoBridge expandoBridge = getExpandoBridge();
459    
460                    expandoBridge.setAttributes(serviceContext);
461            }
462    
463            @SuppressWarnings("unused")
464            public void prepareLocalizedFieldsForImport(Locale defaultImportLocale)
465                    throws LocaleException {
466                    setName(getName(defaultImportLocale), defaultImportLocale,
467                            defaultImportLocale);
468            }
469    
470            @Override
471            public DDMContent toEscapedModel() {
472                    if (_escapedModel == null) {
473                            _escapedModel = (DDMContent)ProxyUtil.newProxyInstance(_classLoader,
474                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
475                    }
476    
477                    return _escapedModel;
478            }
479    
480            public DDMContent toUnescapedModel() {
481                    return (DDMContent)this;
482            }
483    
484            @Override
485            public Object clone() {
486                    DDMContentImpl ddmContentImpl = new DDMContentImpl();
487    
488                    ddmContentImpl.setUuid(getUuid());
489                    ddmContentImpl.setContentId(getContentId());
490                    ddmContentImpl.setGroupId(getGroupId());
491                    ddmContentImpl.setCompanyId(getCompanyId());
492                    ddmContentImpl.setUserId(getUserId());
493                    ddmContentImpl.setUserName(getUserName());
494                    ddmContentImpl.setCreateDate(getCreateDate());
495                    ddmContentImpl.setModifiedDate(getModifiedDate());
496                    ddmContentImpl.setName(getName());
497                    ddmContentImpl.setDescription(getDescription());
498                    ddmContentImpl.setXml(getXml());
499    
500                    ddmContentImpl.resetOriginalValues();
501    
502                    return ddmContentImpl;
503            }
504    
505            public int compareTo(DDMContent ddmContent) {
506                    long primaryKey = ddmContent.getPrimaryKey();
507    
508                    if (getPrimaryKey() < primaryKey) {
509                            return -1;
510                    }
511                    else if (getPrimaryKey() > primaryKey) {
512                            return 1;
513                    }
514                    else {
515                            return 0;
516                    }
517            }
518    
519            @Override
520            public boolean equals(Object obj) {
521                    if (this == obj) {
522                            return true;
523                    }
524    
525                    if (!(obj instanceof DDMContent)) {
526                            return false;
527                    }
528    
529                    DDMContent ddmContent = (DDMContent)obj;
530    
531                    long primaryKey = ddmContent.getPrimaryKey();
532    
533                    if (getPrimaryKey() == primaryKey) {
534                            return true;
535                    }
536                    else {
537                            return false;
538                    }
539            }
540    
541            @Override
542            public int hashCode() {
543                    return (int)getPrimaryKey();
544            }
545    
546            @Override
547            public void resetOriginalValues() {
548                    DDMContentModelImpl ddmContentModelImpl = this;
549    
550                    ddmContentModelImpl._originalUuid = ddmContentModelImpl._uuid;
551    
552                    ddmContentModelImpl._originalGroupId = ddmContentModelImpl._groupId;
553    
554                    ddmContentModelImpl._setOriginalGroupId = false;
555    
556                    ddmContentModelImpl._originalCompanyId = ddmContentModelImpl._companyId;
557    
558                    ddmContentModelImpl._setOriginalCompanyId = false;
559    
560                    ddmContentModelImpl._columnBitmask = 0;
561            }
562    
563            @Override
564            public CacheModel<DDMContent> toCacheModel() {
565                    DDMContentCacheModel ddmContentCacheModel = new DDMContentCacheModel();
566    
567                    ddmContentCacheModel.uuid = getUuid();
568    
569                    String uuid = ddmContentCacheModel.uuid;
570    
571                    if ((uuid != null) && (uuid.length() == 0)) {
572                            ddmContentCacheModel.uuid = null;
573                    }
574    
575                    ddmContentCacheModel.contentId = getContentId();
576    
577                    ddmContentCacheModel.groupId = getGroupId();
578    
579                    ddmContentCacheModel.companyId = getCompanyId();
580    
581                    ddmContentCacheModel.userId = getUserId();
582    
583                    ddmContentCacheModel.userName = getUserName();
584    
585                    String userName = ddmContentCacheModel.userName;
586    
587                    if ((userName != null) && (userName.length() == 0)) {
588                            ddmContentCacheModel.userName = null;
589                    }
590    
591                    Date createDate = getCreateDate();
592    
593                    if (createDate != null) {
594                            ddmContentCacheModel.createDate = createDate.getTime();
595                    }
596                    else {
597                            ddmContentCacheModel.createDate = Long.MIN_VALUE;
598                    }
599    
600                    Date modifiedDate = getModifiedDate();
601    
602                    if (modifiedDate != null) {
603                            ddmContentCacheModel.modifiedDate = modifiedDate.getTime();
604                    }
605                    else {
606                            ddmContentCacheModel.modifiedDate = Long.MIN_VALUE;
607                    }
608    
609                    ddmContentCacheModel.name = getName();
610    
611                    String name = ddmContentCacheModel.name;
612    
613                    if ((name != null) && (name.length() == 0)) {
614                            ddmContentCacheModel.name = null;
615                    }
616    
617                    ddmContentCacheModel.description = getDescription();
618    
619                    String description = ddmContentCacheModel.description;
620    
621                    if ((description != null) && (description.length() == 0)) {
622                            ddmContentCacheModel.description = null;
623                    }
624    
625                    ddmContentCacheModel.xml = getXml();
626    
627                    String xml = ddmContentCacheModel.xml;
628    
629                    if ((xml != null) && (xml.length() == 0)) {
630                            ddmContentCacheModel.xml = null;
631                    }
632    
633                    return ddmContentCacheModel;
634            }
635    
636            @Override
637            public String toString() {
638                    StringBundler sb = new StringBundler(23);
639    
640                    sb.append("{uuid=");
641                    sb.append(getUuid());
642                    sb.append(", contentId=");
643                    sb.append(getContentId());
644                    sb.append(", groupId=");
645                    sb.append(getGroupId());
646                    sb.append(", companyId=");
647                    sb.append(getCompanyId());
648                    sb.append(", userId=");
649                    sb.append(getUserId());
650                    sb.append(", userName=");
651                    sb.append(getUserName());
652                    sb.append(", createDate=");
653                    sb.append(getCreateDate());
654                    sb.append(", modifiedDate=");
655                    sb.append(getModifiedDate());
656                    sb.append(", name=");
657                    sb.append(getName());
658                    sb.append(", description=");
659                    sb.append(getDescription());
660                    sb.append(", xml=");
661                    sb.append(getXml());
662                    sb.append("}");
663    
664                    return sb.toString();
665            }
666    
667            public String toXmlString() {
668                    StringBundler sb = new StringBundler(37);
669    
670                    sb.append("<model><model-name>");
671                    sb.append("com.liferay.portlet.dynamicdatamapping.model.DDMContent");
672                    sb.append("</model-name>");
673    
674                    sb.append(
675                            "<column><column-name>uuid</column-name><column-value><![CDATA[");
676                    sb.append(getUuid());
677                    sb.append("]]></column-value></column>");
678                    sb.append(
679                            "<column><column-name>contentId</column-name><column-value><![CDATA[");
680                    sb.append(getContentId());
681                    sb.append("]]></column-value></column>");
682                    sb.append(
683                            "<column><column-name>groupId</column-name><column-value><![CDATA[");
684                    sb.append(getGroupId());
685                    sb.append("]]></column-value></column>");
686                    sb.append(
687                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
688                    sb.append(getCompanyId());
689                    sb.append("]]></column-value></column>");
690                    sb.append(
691                            "<column><column-name>userId</column-name><column-value><![CDATA[");
692                    sb.append(getUserId());
693                    sb.append("]]></column-value></column>");
694                    sb.append(
695                            "<column><column-name>userName</column-name><column-value><![CDATA[");
696                    sb.append(getUserName());
697                    sb.append("]]></column-value></column>");
698                    sb.append(
699                            "<column><column-name>createDate</column-name><column-value><![CDATA[");
700                    sb.append(getCreateDate());
701                    sb.append("]]></column-value></column>");
702                    sb.append(
703                            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
704                    sb.append(getModifiedDate());
705                    sb.append("]]></column-value></column>");
706                    sb.append(
707                            "<column><column-name>name</column-name><column-value><![CDATA[");
708                    sb.append(getName());
709                    sb.append("]]></column-value></column>");
710                    sb.append(
711                            "<column><column-name>description</column-name><column-value><![CDATA[");
712                    sb.append(getDescription());
713                    sb.append("]]></column-value></column>");
714                    sb.append(
715                            "<column><column-name>xml</column-name><column-value><![CDATA[");
716                    sb.append(getXml());
717                    sb.append("]]></column-value></column>");
718    
719                    sb.append("</model>");
720    
721                    return sb.toString();
722            }
723    
724            private static ClassLoader _classLoader = DDMContent.class.getClassLoader();
725            private static Class<?>[] _escapedModelInterfaces = new Class[] {
726                            DDMContent.class
727                    };
728            private String _uuid;
729            private String _originalUuid;
730            private long _contentId;
731            private long _groupId;
732            private long _originalGroupId;
733            private boolean _setOriginalGroupId;
734            private long _companyId;
735            private long _originalCompanyId;
736            private boolean _setOriginalCompanyId;
737            private long _userId;
738            private String _userUuid;
739            private String _userName;
740            private Date _createDate;
741            private Date _modifiedDate;
742            private String _name;
743            private String _nameCurrentLanguageId;
744            private String _description;
745            private String _xml;
746            private long _columnBitmask;
747            private DDMContent _escapedModel;
748    }