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