/**
 * Copyright (c) 2000-present 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 com.cmcti.cmts.domain.model.impl;

import com.cmcti.cmts.domain.model.Option;
import com.cmcti.cmts.domain.model.OptionModel;
import com.cmcti.cmts.domain.model.OptionSoap;

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.util.GetterUtil;
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.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 java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the Option service. Represents a row in the &quot;CMTS_Option&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.cmcti.cmts.domain.model.OptionModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link OptionImpl}.
 * </p>
 *
 * @author richard
 * @see OptionImpl
 * @see com.cmcti.cmts.domain.model.Option
 * @see com.cmcti.cmts.domain.model.OptionModel
 * @generated
 */
@JSON(strict = true)
public class OptionModelImpl extends BaseModelImpl<Option>
	implements OptionModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a option model instance should use the {@link com.cmcti.cmts.domain.model.Option} interface instead.
	 */
	public static final String TABLE_NAME = "CMTS_Option";
	public static final Object[][] TABLE_COLUMNS = {
			{ "optionId", Types.BIGINT },
			{ "groupId", Types.BIGINT },
			{ "companyId", Types.BIGINT },
			{ "userId", Types.BIGINT },
			{ "userName", Types.VARCHAR },
			{ "createDate", Types.TIMESTAMP },
			{ "modifiedDate", Types.TIMESTAMP },
			{ "optionType", Types.VARCHAR },
			{ "optionKey", Types.VARCHAR },
			{ "optionValue", Types.VARCHAR },
			{ "description", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table CMTS_Option (optionId LONG not null primary key,groupId LONG,companyId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,optionType VARCHAR(75) null,optionKey VARCHAR(75) null,optionValue VARCHAR(75) null,description VARCHAR(75) null)";
	public static final String TABLE_SQL_DROP = "drop table CMTS_Option";
	public static final String ORDER_BY_JPQL = " ORDER BY option.optionId ASC";
	public static final String ORDER_BY_SQL = " ORDER BY CMTS_Option.optionId 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.com.cmcti.cmts.domain.model.Option"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.cmcti.cmts.domain.model.Option"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.cmcti.cmts.domain.model.Option"),
			true);
	public static long OPTIONKEY_COLUMN_BITMASK = 1L;
	public static long OPTIONTYPE_COLUMN_BITMASK = 2L;
	public static long USERID_COLUMN_BITMASK = 4L;
	public static long OPTIONID_COLUMN_BITMASK = 8L;

	/**
	 * 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 Option toModel(OptionSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		Option model = new OptionImpl();

		model.setOptionId(soapModel.getOptionId());
		model.setGroupId(soapModel.getGroupId());
		model.setCompanyId(soapModel.getCompanyId());
		model.setUserId(soapModel.getUserId());
		model.setUserName(soapModel.getUserName());
		model.setCreateDate(soapModel.getCreateDate());
		model.setModifiedDate(soapModel.getModifiedDate());
		model.setOptionType(soapModel.getOptionType());
		model.setOptionKey(soapModel.getOptionKey());
		model.setOptionValue(soapModel.getOptionValue());
		model.setDescription(soapModel.getDescription());

		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<Option> toModels(OptionSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<Option> models = new ArrayList<Option>(soapModels.length);

		for (OptionSoap 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.com.cmcti.cmts.domain.model.Option"));

	public OptionModelImpl() {
	}

	@Override
	public long getPrimaryKey() {
		return _optionId;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setOptionId(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _optionId;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Class<?> getModelClass() {
		return Option.class;
	}

	@Override
	public String getModelClassName() {
		return Option.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("optionId", getOptionId());
		attributes.put("groupId", getGroupId());
		attributes.put("companyId", getCompanyId());
		attributes.put("userId", getUserId());
		attributes.put("userName", getUserName());
		attributes.put("createDate", getCreateDate());
		attributes.put("modifiedDate", getModifiedDate());
		attributes.put("optionType", getOptionType());
		attributes.put("optionKey", getOptionKey());
		attributes.put("optionValue", getOptionValue());
		attributes.put("description", getDescription());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long optionId = (Long)attributes.get("optionId");

		if (optionId != null) {
			setOptionId(optionId);
		}

		Long groupId = (Long)attributes.get("groupId");

		if (groupId != null) {
			setGroupId(groupId);
		}

		Long companyId = (Long)attributes.get("companyId");

		if (companyId != null) {
			setCompanyId(companyId);
		}

		Long userId = (Long)attributes.get("userId");

		if (userId != null) {
			setUserId(userId);
		}

		String userName = (String)attributes.get("userName");

		if (userName != null) {
			setUserName(userName);
		}

		Date createDate = (Date)attributes.get("createDate");

		if (createDate != null) {
			setCreateDate(createDate);
		}

		Date modifiedDate = (Date)attributes.get("modifiedDate");

		if (modifiedDate != null) {
			setModifiedDate(modifiedDate);
		}

		String optionType = (String)attributes.get("optionType");

		if (optionType != null) {
			setOptionType(optionType);
		}

		String optionKey = (String)attributes.get("optionKey");

		if (optionKey != null) {
			setOptionKey(optionKey);
		}

		String optionValue = (String)attributes.get("optionValue");

		if (optionValue != null) {
			setOptionValue(optionValue);
		}

		String description = (String)attributes.get("description");

		if (description != null) {
			setDescription(description);
		}
	}

	@JSON
	@Override
	public long getOptionId() {
		return _optionId;
	}

	@Override
	public void setOptionId(long optionId) {
		_optionId = optionId;
	}

	@JSON
	@Override
	public long getGroupId() {
		return _groupId;
	}

	@Override
	public void setGroupId(long groupId) {
		_groupId = groupId;
	}

	@JSON
	@Override
	public long getCompanyId() {
		return _companyId;
	}

	@Override
	public void setCompanyId(long companyId) {
		_companyId = companyId;
	}

	@JSON
	@Override
	public long getUserId() {
		return _userId;
	}

	@Override
	public void setUserId(long userId) {
		_columnBitmask |= USERID_COLUMN_BITMASK;

		if (!_setOriginalUserId) {
			_setOriginalUserId = true;

			_originalUserId = _userId;
		}

		_userId = userId;
	}

	@Override
	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	@Override
	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	public long getOriginalUserId() {
		return _originalUserId;
	}

	@JSON
	@Override
	public String getUserName() {
		if (_userName == null) {
			return StringPool.BLANK;
		}
		else {
			return _userName;
		}
	}

	@Override
	public void setUserName(String userName) {
		_userName = userName;
	}

	@JSON
	@Override
	public Date getCreateDate() {
		return _createDate;
	}

	@Override
	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	@JSON
	@Override
	public Date getModifiedDate() {
		return _modifiedDate;
	}

	@Override
	public void setModifiedDate(Date modifiedDate) {
		_modifiedDate = modifiedDate;
	}

	@JSON
	@Override
	public String getOptionType() {
		if (_optionType == null) {
			return StringPool.BLANK;
		}
		else {
			return _optionType;
		}
	}

	@Override
	public void setOptionType(String optionType) {
		_columnBitmask |= OPTIONTYPE_COLUMN_BITMASK;

		if (_originalOptionType == null) {
			_originalOptionType = _optionType;
		}

		_optionType = optionType;
	}

	public String getOriginalOptionType() {
		return GetterUtil.getString(_originalOptionType);
	}

	@JSON
	@Override
	public String getOptionKey() {
		if (_optionKey == null) {
			return StringPool.BLANK;
		}
		else {
			return _optionKey;
		}
	}

	@Override
	public void setOptionKey(String optionKey) {
		_columnBitmask |= OPTIONKEY_COLUMN_BITMASK;

		if (_originalOptionKey == null) {
			_originalOptionKey = _optionKey;
		}

		_optionKey = optionKey;
	}

	public String getOriginalOptionKey() {
		return GetterUtil.getString(_originalOptionKey);
	}

	@JSON
	@Override
	public String getOptionValue() {
		if (_optionValue == null) {
			return StringPool.BLANK;
		}
		else {
			return _optionValue;
		}
	}

	@Override
	public void setOptionValue(String optionValue) {
		_optionValue = optionValue;
	}

	@JSON
	@Override
	public String getDescription() {
		if (_description == null) {
			return StringPool.BLANK;
		}
		else {
			return _description;
		}
	}

	@Override
	public void setDescription(String description) {
		_description = description;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
			Option.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Option toEscapedModel() {
		if (_escapedModel == null) {
			_escapedModel = (Option)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelInterfaces, new AutoEscapeBeanHandler(this));
		}

		return _escapedModel;
	}

	@Override
	public Object clone() {
		OptionImpl optionImpl = new OptionImpl();

		optionImpl.setOptionId(getOptionId());
		optionImpl.setGroupId(getGroupId());
		optionImpl.setCompanyId(getCompanyId());
		optionImpl.setUserId(getUserId());
		optionImpl.setUserName(getUserName());
		optionImpl.setCreateDate(getCreateDate());
		optionImpl.setModifiedDate(getModifiedDate());
		optionImpl.setOptionType(getOptionType());
		optionImpl.setOptionKey(getOptionKey());
		optionImpl.setOptionValue(getOptionValue());
		optionImpl.setDescription(getDescription());

		optionImpl.resetOriginalValues();

		return optionImpl;
	}

	@Override
	public int compareTo(Option option) {
		long primaryKey = option.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof Option)) {
			return false;
		}

		Option option = (Option)obj;

		long primaryKey = option.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		OptionModelImpl optionModelImpl = this;

		optionModelImpl._originalUserId = optionModelImpl._userId;

		optionModelImpl._setOriginalUserId = false;

		optionModelImpl._originalOptionType = optionModelImpl._optionType;

		optionModelImpl._originalOptionKey = optionModelImpl._optionKey;

		optionModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Option> toCacheModel() {
		OptionCacheModel optionCacheModel = new OptionCacheModel();

		optionCacheModel.optionId = getOptionId();

		optionCacheModel.groupId = getGroupId();

		optionCacheModel.companyId = getCompanyId();

		optionCacheModel.userId = getUserId();

		optionCacheModel.userName = getUserName();

		String userName = optionCacheModel.userName;

		if ((userName != null) && (userName.length() == 0)) {
			optionCacheModel.userName = null;
		}

		Date createDate = getCreateDate();

		if (createDate != null) {
			optionCacheModel.createDate = createDate.getTime();
		}
		else {
			optionCacheModel.createDate = Long.MIN_VALUE;
		}

		Date modifiedDate = getModifiedDate();

		if (modifiedDate != null) {
			optionCacheModel.modifiedDate = modifiedDate.getTime();
		}
		else {
			optionCacheModel.modifiedDate = Long.MIN_VALUE;
		}

		optionCacheModel.optionType = getOptionType();

		String optionType = optionCacheModel.optionType;

		if ((optionType != null) && (optionType.length() == 0)) {
			optionCacheModel.optionType = null;
		}

		optionCacheModel.optionKey = getOptionKey();

		String optionKey = optionCacheModel.optionKey;

		if ((optionKey != null) && (optionKey.length() == 0)) {
			optionCacheModel.optionKey = null;
		}

		optionCacheModel.optionValue = getOptionValue();

		String optionValue = optionCacheModel.optionValue;

		if ((optionValue != null) && (optionValue.length() == 0)) {
			optionCacheModel.optionValue = null;
		}

		optionCacheModel.description = getDescription();

		String description = optionCacheModel.description;

		if ((description != null) && (description.length() == 0)) {
			optionCacheModel.description = null;
		}

		return optionCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(23);

		sb.append("{optionId=");
		sb.append(getOptionId());
		sb.append(", groupId=");
		sb.append(getGroupId());
		sb.append(", companyId=");
		sb.append(getCompanyId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", userName=");
		sb.append(getUserName());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", modifiedDate=");
		sb.append(getModifiedDate());
		sb.append(", optionType=");
		sb.append(getOptionType());
		sb.append(", optionKey=");
		sb.append(getOptionKey());
		sb.append(", optionValue=");
		sb.append(getOptionValue());
		sb.append(", description=");
		sb.append(getDescription());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(37);

		sb.append("<model><model-name>");
		sb.append("com.cmcti.cmts.domain.model.Option");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>optionId</column-name><column-value><![CDATA[");
		sb.append(getOptionId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>groupId</column-name><column-value><![CDATA[");
		sb.append(getGroupId());
		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>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userName</column-name><column-value><![CDATA[");
		sb.append(getUserName());
		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>modifiedDate</column-name><column-value><![CDATA[");
		sb.append(getModifiedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>optionType</column-name><column-value><![CDATA[");
		sb.append(getOptionType());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>optionKey</column-name><column-value><![CDATA[");
		sb.append(getOptionKey());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>optionValue</column-name><column-value><![CDATA[");
		sb.append(getOptionValue());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>description</column-name><column-value><![CDATA[");
		sb.append(getDescription());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Option.class.getClassLoader();
	private static Class<?>[] _escapedModelInterfaces = new Class[] { Option.class };
	private long _optionId;
	private long _groupId;
	private long _companyId;
	private long _userId;
	private String _userUuid;
	private long _originalUserId;
	private boolean _setOriginalUserId;
	private String _userName;
	private Date _createDate;
	private Date _modifiedDate;
	private String _optionType;
	private String _originalOptionType;
	private String _optionKey;
	private String _originalOptionKey;
	private String _optionValue;
	private String _description;
	private long _columnBitmask;
	private Option _escapedModel;
}