Java tutorial
/** * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package net.sareweb.mshowcase.model.impl; import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.json.JSON; import com.liferay.portal.kernel.language.LanguageUtil; import com.liferay.portal.kernel.util.DateUtil; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.LocaleUtil; import com.liferay.portal.kernel.util.LocalizationUtil; import com.liferay.portal.kernel.util.ProxyUtil; import com.liferay.portal.kernel.util.StringBundler; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.model.CacheModel; import com.liferay.portal.model.impl.BaseModelImpl; import com.liferay.portal.service.ServiceContext; import com.liferay.portal.util.PortalUtil; import com.liferay.portlet.expando.model.ExpandoBridge; import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil; import net.sareweb.mshowcase.model.Offer; import net.sareweb.mshowcase.model.OfferModel; import net.sareweb.mshowcase.model.OfferSoap; import java.io.Serializable; import java.sql.Types; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; /** * The base model implementation for the Offer service. Represents a row in the "msc_Offer" database table, with each column mapped to a property of this class. * * <p> * This implementation and its corresponding interface {@link net.sareweb.mshowcase.model.OfferModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link OfferImpl}. * </p> * * @author Aritz Galdos * @see OfferImpl * @see net.sareweb.mshowcase.model.Offer * @see net.sareweb.mshowcase.model.OfferModel * @generated */ @JSON(strict = true) public class OfferModelImpl extends BaseModelImpl<Offer> implements OfferModel { /* * NOTE FOR DEVELOPERS: * * Never modify or reference this class directly. All methods that expect a offer model instance should use the {@link net.sareweb.mshowcase.model.Offer} interface instead. */ public static final String TABLE_NAME = "msc_Offer"; public static final Object[][] TABLE_COLUMNS = { { "offerId", Types.BIGINT }, { "instanceId", Types.BIGINT }, { "offerText", Types.VARCHAR }, { "beginDate", Types.TIMESTAMP }, { "endDate", Types.TIMESTAMP }, { "price", Types.DOUBLE }, { "transactions", Types.INTEGER }, { "imageId", Types.BIGINT }, { "imageURL", Types.VARCHAR }, { "userId", Types.BIGINT }, { "companyId", Types.BIGINT }, { "createDate", Types.TIMESTAMP }, { "modifyDate", Types.TIMESTAMP } }; public static final String TABLE_SQL_CREATE = "create table msc_Offer (offerId LONG not null primary key,instanceId LONG,offerText STRING null,beginDate DATE null,endDate DATE null,price DOUBLE,transactions INTEGER,imageId LONG,imageURL VARCHAR(75) null,userId LONG,companyId LONG,createDate DATE null,modifyDate DATE null)"; public static final String TABLE_SQL_DROP = "drop table msc_Offer"; public static final String ORDER_BY_JPQL = " ORDER BY offer.createDate ASC"; public static final String ORDER_BY_SQL = " ORDER BY msc_Offer.createDate ASC"; public static final String DATA_SOURCE = "liferayDataSource"; public static final String SESSION_FACTORY = "liferaySessionFactory"; public static final String TX_MANAGER = "liferayTransactionManager"; public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps .get("value.object.entity.cache.enabled.net.sareweb.mshowcase.model.Offer"), true); public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps .get("value.object.finder.cache.enabled.net.sareweb.mshowcase.model.Offer"), true); public static final boolean COLUMN_BITMASK_ENABLED = false; /** * Converts the soap model instance into a normal model instance. * * @param soapModel the soap model instance to convert * @return the normal model instance */ public static Offer toModel(OfferSoap soapModel) { Offer model = new OfferImpl(); model.setOfferId(soapModel.getOfferId()); model.setInstanceId(soapModel.getInstanceId()); model.setOfferText(soapModel.getOfferText()); model.setBeginDate(soapModel.getBeginDate()); model.setEndDate(soapModel.getEndDate()); model.setPrice(soapModel.getPrice()); model.setTransactions(soapModel.getTransactions()); model.setImageId(soapModel.getImageId()); model.setImageURL(soapModel.getImageURL()); model.setUserId(soapModel.getUserId()); model.setCompanyId(soapModel.getCompanyId()); model.setCreateDate(soapModel.getCreateDate()); model.setModifyDate(soapModel.getModifyDate()); return model; } /** * Converts the soap model instances into normal model instances. * * @param soapModels the soap model instances to convert * @return the normal model instances */ public static List<Offer> toModels(OfferSoap[] soapModels) { List<Offer> models = new ArrayList<Offer>(soapModels.length); for (OfferSoap soapModel : soapModels) { models.add(toModel(soapModel)); } return models; } public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong( com.liferay.util.service.ServiceProps.get("lock.expiration.time.net.sareweb.mshowcase.model.Offer")); public OfferModelImpl() { } public long getPrimaryKey() { return _offerId; } public void setPrimaryKey(long primaryKey) { setOfferId(primaryKey); } public Serializable getPrimaryKeyObj() { return new Long(_offerId); } public void setPrimaryKeyObj(Serializable primaryKeyObj) { setPrimaryKey(((Long) primaryKeyObj).longValue()); } public Class<?> getModelClass() { return Offer.class; } public String getModelClassName() { return Offer.class.getName(); } @JSON public long getOfferId() { return _offerId; } public void setOfferId(long offerId) { _offerId = offerId; } @JSON public long getInstanceId() { return _instanceId; } public void setInstanceId(long instanceId) { _instanceId = instanceId; } @JSON public String getOfferText() { if (_offerText == null) { return StringPool.BLANK; } else { return _offerText; } } public String getOfferText(Locale locale) { String languageId = LocaleUtil.toLanguageId(locale); return getOfferText(languageId); } public String getOfferText(Locale locale, boolean useDefault) { String languageId = LocaleUtil.toLanguageId(locale); return getOfferText(languageId, useDefault); } public String getOfferText(String languageId) { return LocalizationUtil.getLocalization(getOfferText(), languageId); } public String getOfferText(String languageId, boolean useDefault) { return LocalizationUtil.getLocalization(getOfferText(), languageId, useDefault); } public String getOfferTextCurrentLanguageId() { return _offerTextCurrentLanguageId; } @JSON public String getOfferTextCurrentValue() { Locale locale = getLocale(_offerTextCurrentLanguageId); return getOfferText(locale); } public Map<Locale, String> getOfferTextMap() { return LocalizationUtil.getLocalizationMap(getOfferText()); } public void setOfferText(String offerText) { _offerText = offerText; } public void setOfferText(String offerText, Locale locale) { setOfferText(offerText, locale, LocaleUtil.getDefault()); } public void setOfferText(String offerText, Locale locale, Locale defaultLocale) { String languageId = LocaleUtil.toLanguageId(locale); String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale); if (Validator.isNotNull(offerText)) { setOfferText(LocalizationUtil.updateLocalization(getOfferText(), "OfferText", offerText, languageId, defaultLanguageId)); } else { setOfferText(LocalizationUtil.removeLocalization(getOfferText(), "OfferText", languageId)); } } public void setOfferTextCurrentLanguageId(String languageId) { _offerTextCurrentLanguageId = languageId; } public void setOfferTextMap(Map<Locale, String> offerTextMap) { setOfferTextMap(offerTextMap, LocaleUtil.getDefault()); } public void setOfferTextMap(Map<Locale, String> offerTextMap, Locale defaultLocale) { if (offerTextMap == null) { return; } Locale[] locales = LanguageUtil.getAvailableLocales(); for (Locale locale : locales) { String offerText = offerTextMap.get(locale); setOfferText(offerText, locale, defaultLocale); } } @JSON public Date getBeginDate() { return _beginDate; } public void setBeginDate(Date beginDate) { _beginDate = beginDate; } @JSON public Date getEndDate() { return _endDate; } public void setEndDate(Date endDate) { _endDate = endDate; } @JSON public double getPrice() { return _price; } public void setPrice(double price) { _price = price; } @JSON public int getTransactions() { return _transactions; } public void setTransactions(int transactions) { _transactions = transactions; } @JSON public long getImageId() { return _imageId; } public void setImageId(long imageId) { _imageId = imageId; } @JSON public String getImageURL() { if (_imageURL == null) { return StringPool.BLANK; } else { return _imageURL; } } public void setImageURL(String imageURL) { _imageURL = imageURL; } @JSON public long getUserId() { return _userId; } public void setUserId(long userId) { _userId = userId; } public String getUserUuid() throws SystemException { return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid); } public void setUserUuid(String userUuid) { _userUuid = userUuid; } @JSON public long getCompanyId() { return _companyId; } public void setCompanyId(long companyId) { _companyId = companyId; } @JSON public Date getCreateDate() { return _createDate; } public void setCreateDate(Date createDate) { _createDate = createDate; } @JSON public Date getModifyDate() { return _modifyDate; } public void setModifyDate(Date modifyDate) { _modifyDate = modifyDate; } @Override public Offer toEscapedModel() { if (_escapedModelProxy == null) { _escapedModelProxy = (Offer) ProxyUtil.newProxyInstance(_classLoader, _escapedModelProxyInterfaces, new AutoEscapeBeanHandler(this)); } return _escapedModelProxy; } @Override public ExpandoBridge getExpandoBridge() { if (_expandoBridge == null) { _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(), Offer.class.getName(), getPrimaryKey()); } return _expandoBridge; } @Override public void setExpandoBridgeAttributes(ServiceContext serviceContext) { getExpandoBridge().setAttributes(serviceContext); } @Override public Object clone() { OfferImpl offerImpl = new OfferImpl(); offerImpl.setOfferId(getOfferId()); offerImpl.setInstanceId(getInstanceId()); offerImpl.setOfferText(getOfferText()); offerImpl.setBeginDate(getBeginDate()); offerImpl.setEndDate(getEndDate()); offerImpl.setPrice(getPrice()); offerImpl.setTransactions(getTransactions()); offerImpl.setImageId(getImageId()); offerImpl.setImageURL(getImageURL()); offerImpl.setUserId(getUserId()); offerImpl.setCompanyId(getCompanyId()); offerImpl.setCreateDate(getCreateDate()); offerImpl.setModifyDate(getModifyDate()); offerImpl.resetOriginalValues(); return offerImpl; } public int compareTo(Offer offer) { int value = 0; value = DateUtil.compareTo(getCreateDate(), offer.getCreateDate()); if (value != 0) { return value; } return 0; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } Offer offer = null; try { offer = (Offer) obj; } catch (ClassCastException cce) { return false; } long primaryKey = offer.getPrimaryKey(); if (getPrimaryKey() == primaryKey) { return true; } else { return false; } } @Override public int hashCode() { return (int) getPrimaryKey(); } @Override public void resetOriginalValues() { } @Override public CacheModel<Offer> toCacheModel() { OfferCacheModel offerCacheModel = new OfferCacheModel(); offerCacheModel.offerId = getOfferId(); offerCacheModel.instanceId = getInstanceId(); offerCacheModel.offerText = getOfferText(); String offerText = offerCacheModel.offerText; if ((offerText != null) && (offerText.length() == 0)) { offerCacheModel.offerText = null; } Date beginDate = getBeginDate(); if (beginDate != null) { offerCacheModel.beginDate = beginDate.getTime(); } else { offerCacheModel.beginDate = Long.MIN_VALUE; } Date endDate = getEndDate(); if (endDate != null) { offerCacheModel.endDate = endDate.getTime(); } else { offerCacheModel.endDate = Long.MIN_VALUE; } offerCacheModel.price = getPrice(); offerCacheModel.transactions = getTransactions(); offerCacheModel.imageId = getImageId(); offerCacheModel.imageURL = getImageURL(); String imageURL = offerCacheModel.imageURL; if ((imageURL != null) && (imageURL.length() == 0)) { offerCacheModel.imageURL = null; } offerCacheModel.userId = getUserId(); offerCacheModel.companyId = getCompanyId(); Date createDate = getCreateDate(); if (createDate != null) { offerCacheModel.createDate = createDate.getTime(); } else { offerCacheModel.createDate = Long.MIN_VALUE; } Date modifyDate = getModifyDate(); if (modifyDate != null) { offerCacheModel.modifyDate = modifyDate.getTime(); } else { offerCacheModel.modifyDate = Long.MIN_VALUE; } return offerCacheModel; } @Override public String toString() { StringBundler sb = new StringBundler(27); sb.append("{offerId="); sb.append(getOfferId()); sb.append(", instanceId="); sb.append(getInstanceId()); sb.append(", offerText="); sb.append(getOfferText()); sb.append(", beginDate="); sb.append(getBeginDate()); sb.append(", endDate="); sb.append(getEndDate()); sb.append(", price="); sb.append(getPrice()); sb.append(", transactions="); sb.append(getTransactions()); sb.append(", imageId="); sb.append(getImageId()); sb.append(", imageURL="); sb.append(getImageURL()); sb.append(", userId="); sb.append(getUserId()); sb.append(", companyId="); sb.append(getCompanyId()); sb.append(", createDate="); sb.append(getCreateDate()); sb.append(", modifyDate="); sb.append(getModifyDate()); sb.append("}"); return sb.toString(); } public String toXmlString() { StringBundler sb = new StringBundler(43); sb.append("<model><model-name>"); sb.append("net.sareweb.mshowcase.model.Offer"); sb.append("</model-name>"); sb.append("<column><column-name>offerId</column-name><column-value><![CDATA["); sb.append(getOfferId()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>instanceId</column-name><column-value><![CDATA["); sb.append(getInstanceId()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>offerText</column-name><column-value><![CDATA["); sb.append(getOfferText()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>beginDate</column-name><column-value><![CDATA["); sb.append(getBeginDate()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>endDate</column-name><column-value><![CDATA["); sb.append(getEndDate()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>price</column-name><column-value><![CDATA["); sb.append(getPrice()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>transactions</column-name><column-value><![CDATA["); sb.append(getTransactions()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>imageId</column-name><column-value><![CDATA["); sb.append(getImageId()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>imageURL</column-name><column-value><![CDATA["); sb.append(getImageURL()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>userId</column-name><column-value><![CDATA["); sb.append(getUserId()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>companyId</column-name><column-value><![CDATA["); sb.append(getCompanyId()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>createDate</column-name><column-value><![CDATA["); sb.append(getCreateDate()); sb.append("]]></column-value></column>"); sb.append("<column><column-name>modifyDate</column-name><column-value><![CDATA["); sb.append(getModifyDate()); sb.append("]]></column-value></column>"); sb.append("</model>"); return sb.toString(); } private static ClassLoader _classLoader = Offer.class.getClassLoader(); private static Class<?>[] _escapedModelProxyInterfaces = new Class[] { Offer.class }; private long _offerId; private long _instanceId; private String _offerText; private String _offerTextCurrentLanguageId; private Date _beginDate; private Date _endDate; private double _price; private int _transactions; private long _imageId; private String _imageURL; private long _userId; private String _userUuid; private long _companyId; private Date _createDate; private Date _modifyDate; private transient ExpandoBridge _expandoBridge; private Offer _escapedModelProxy; }