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