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