/**
 * 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 ru.tiis.srv.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.lar.StagedModelType;
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 ru.tiis.srv.model.Book;
import ru.tiis.srv.model.BookBookLogoBlobModel;
import ru.tiis.srv.model.BookModel;
import ru.tiis.srv.service.BookLocalServiceUtil;

import java.io.Serializable;

import java.sql.Blob;
import java.sql.Types;

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

/**
 * The base model implementation for the Book service. Represents a row in the &quot;TIISBook&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link ru.tiis.srv.model.BookModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link BookImpl}.
 * </p>
 *
 * @author Michael
 * @see BookImpl
 * @see ru.tiis.srv.model.Book
 * @see ru.tiis.srv.model.BookModel
 * @generated
 */
public class BookModelImpl extends BaseModelImpl<Book> implements BookModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a book model instance should use the {@link ru.tiis.srv.model.Book} interface instead.
	 */
	public static final String TABLE_NAME = "TIISBook";
	public static final Object[][] TABLE_COLUMNS = {
			{ "uuid_", Types.VARCHAR },
			{ "bookId", Types.BIGINT },
			{ "companyId", Types.BIGINT },
			{ "groupId", Types.BIGINT },
			{ "userId", Types.BIGINT },
			{ "userName", Types.VARCHAR },
			{ "createDate", Types.TIMESTAMP },
			{ "modifiedDate", Types.TIMESTAMP },
			{ "gDriveId", Types.VARCHAR },
			{ "title", Types.VARCHAR },
			{ "description", Types.VARCHAR },
			{ "googleDriveLink", Types.VARCHAR },
			{ "bookLogo", Types.BLOB },
			{ "bookLogoDlId", Types.BIGINT }
		};
	public static final String TABLE_SQL_CREATE = "create table TIISBook (uuid_ VARCHAR(75) null,bookId LONG not null primary key,companyId LONG,groupId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,gDriveId VARCHAR(75) null,title VARCHAR(75) null,description VARCHAR(750) null,googleDriveLink VARCHAR(750) null,bookLogo BLOB,bookLogoDlId LONG)";
	public static final String TABLE_SQL_DROP = "drop table TIISBook";
	public static final String ORDER_BY_JPQL = " ORDER BY book.bookId ASC";
	public static final String ORDER_BY_SQL = " ORDER BY TIISBook.bookId 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.ru.tiis.srv.model.Book"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.ru.tiis.srv.model.Book"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.ru.tiis.srv.model.Book"),
			true);
	public static long COMPANYID_COLUMN_BITMASK = 1L;
	public static long GROUPID_COLUMN_BITMASK = 2L;
	public static long UUID_COLUMN_BITMASK = 4L;
	public static long BOOKID_COLUMN_BITMASK = 8L;
	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.ru.tiis.srv.model.Book"));

	public BookModelImpl() {
	}

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

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

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

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

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

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

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

		attributes.put("uuid", getUuid());
		attributes.put("bookId", getBookId());
		attributes.put("companyId", getCompanyId());
		attributes.put("groupId", getGroupId());
		attributes.put("userId", getUserId());
		attributes.put("userName", getUserName());
		attributes.put("createDate", getCreateDate());
		attributes.put("modifiedDate", getModifiedDate());
		attributes.put("gDriveId", getGDriveId());
		attributes.put("title", getTitle());
		attributes.put("description", getDescription());
		attributes.put("googleDriveLink", getGoogleDriveLink());
		attributes.put("bookLogo", getBookLogo());
		attributes.put("bookLogoDlId", getBookLogoDlId());

		return attributes;
	}

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

		if (uuid != null) {
			setUuid(uuid);
		}

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

		if (bookId != null) {
			setBookId(bookId);
		}

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

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

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

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

		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 gDriveId = (String)attributes.get("gDriveId");

		if (gDriveId != null) {
			setGDriveId(gDriveId);
		}

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

		if (title != null) {
			setTitle(title);
		}

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

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

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

		if (googleDriveLink != null) {
			setGoogleDriveLink(googleDriveLink);
		}

		Blob bookLogo = (Blob)attributes.get("bookLogo");

		if (bookLogo != null) {
			setBookLogo(bookLogo);
		}

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

		if (bookLogoDlId != null) {
			setBookLogoDlId(bookLogoDlId);
		}
	}

	@Override
	public String getUuid() {
		if (_uuid == null) {
			return StringPool.BLANK;
		}
		else {
			return _uuid;
		}
	}

	@Override
	public void setUuid(String uuid) {
		if (_originalUuid == null) {
			_originalUuid = _uuid;
		}

		_uuid = uuid;
	}

	public String getOriginalUuid() {
		return GetterUtil.getString(_originalUuid);
	}

	@Override
	public long getBookId() {
		return _bookId;
	}

	@Override
	public void setBookId(long bookId) {
		_bookId = bookId;
	}

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

	@Override
	public void setCompanyId(long companyId) {
		_columnBitmask |= COMPANYID_COLUMN_BITMASK;

		if (!_setOriginalCompanyId) {
			_setOriginalCompanyId = true;

			_originalCompanyId = _companyId;
		}

		_companyId = companyId;
	}

	public long getOriginalCompanyId() {
		return _originalCompanyId;
	}

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

	@Override
	public void setGroupId(long groupId) {
		_columnBitmask |= GROUPID_COLUMN_BITMASK;

		if (!_setOriginalGroupId) {
			_setOriginalGroupId = true;

			_originalGroupId = _groupId;
		}

		_groupId = groupId;
	}

	public long getOriginalGroupId() {
		return _originalGroupId;
	}

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

	@Override
	public void setUserId(long userId) {
		_userId = userId;
	}

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

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

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

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

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

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

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

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

	@Override
	public String getGDriveId() {
		if (_gDriveId == null) {
			return StringPool.BLANK;
		}
		else {
			return _gDriveId;
		}
	}

	@Override
	public void setGDriveId(String gDriveId) {
		_gDriveId = gDriveId;
	}

	@Override
	public String getTitle() {
		if (_title == null) {
			return StringPool.BLANK;
		}
		else {
			return _title;
		}
	}

	@Override
	public void setTitle(String title) {
		_title = title;
	}

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

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

	@Override
	public String getGoogleDriveLink() {
		if (_googleDriveLink == null) {
			return StringPool.BLANK;
		}
		else {
			return _googleDriveLink;
		}
	}

	@Override
	public void setGoogleDriveLink(String googleDriveLink) {
		_googleDriveLink = googleDriveLink;
	}

	@Override
	public Blob getBookLogo() {
		if (_bookLogoBlobModel == null) {
			try {
				_bookLogoBlobModel = BookLocalServiceUtil.getBookLogoBlobModel(getPrimaryKey());
			}
			catch (Exception e) {
			}
		}

		Blob blob = null;

		if (_bookLogoBlobModel != null) {
			blob = _bookLogoBlobModel.getBookLogoBlob();
		}

		return blob;
	}

	@Override
	public void setBookLogo(Blob bookLogo) {
		if (_bookLogoBlobModel == null) {
			_bookLogoBlobModel = new BookBookLogoBlobModel(getPrimaryKey(),
					bookLogo);
		}
		else {
			_bookLogoBlobModel.setBookLogoBlob(bookLogo);
		}
	}

	@Override
	public long getBookLogoDlId() {
		return _bookLogoDlId;
	}

	@Override
	public void setBookLogoDlId(long bookLogoDlId) {
		_bookLogoDlId = bookLogoDlId;
	}

	@Override
	public StagedModelType getStagedModelType() {
		return new StagedModelType(PortalUtil.getClassNameId(
				Book.class.getName()));
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

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

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

		expandoBridge.setAttributes(serviceContext);
	}

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

		return _escapedModel;
	}

	@Override
	public Object clone() {
		BookImpl bookImpl = new BookImpl();

		bookImpl.setUuid(getUuid());
		bookImpl.setBookId(getBookId());
		bookImpl.setCompanyId(getCompanyId());
		bookImpl.setGroupId(getGroupId());
		bookImpl.setUserId(getUserId());
		bookImpl.setUserName(getUserName());
		bookImpl.setCreateDate(getCreateDate());
		bookImpl.setModifiedDate(getModifiedDate());
		bookImpl.setGDriveId(getGDriveId());
		bookImpl.setTitle(getTitle());
		bookImpl.setDescription(getDescription());
		bookImpl.setGoogleDriveLink(getGoogleDriveLink());
		bookImpl.setBookLogoDlId(getBookLogoDlId());

		bookImpl.resetOriginalValues();

		return bookImpl;
	}

	@Override
	public int compareTo(Book book) {
		long primaryKey = book.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 Book)) {
			return false;
		}

		Book book = (Book)obj;

		long primaryKey = book.getPrimaryKey();

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

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

	@Override
	public void resetOriginalValues() {
		BookModelImpl bookModelImpl = this;

		bookModelImpl._originalUuid = bookModelImpl._uuid;

		bookModelImpl._originalCompanyId = bookModelImpl._companyId;

		bookModelImpl._setOriginalCompanyId = false;

		bookModelImpl._originalGroupId = bookModelImpl._groupId;

		bookModelImpl._setOriginalGroupId = false;

		bookModelImpl._bookLogoBlobModel = null;

		bookModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Book> toCacheModel() {
		BookCacheModel bookCacheModel = new BookCacheModel();

		bookCacheModel.uuid = getUuid();

		String uuid = bookCacheModel.uuid;

		if ((uuid != null) && (uuid.length() == 0)) {
			bookCacheModel.uuid = null;
		}

		bookCacheModel.bookId = getBookId();

		bookCacheModel.companyId = getCompanyId();

		bookCacheModel.groupId = getGroupId();

		bookCacheModel.userId = getUserId();

		bookCacheModel.userName = getUserName();

		String userName = bookCacheModel.userName;

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

		Date createDate = getCreateDate();

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

		Date modifiedDate = getModifiedDate();

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

		bookCacheModel.gDriveId = getGDriveId();

		String gDriveId = bookCacheModel.gDriveId;

		if ((gDriveId != null) && (gDriveId.length() == 0)) {
			bookCacheModel.gDriveId = null;
		}

		bookCacheModel.title = getTitle();

		String title = bookCacheModel.title;

		if ((title != null) && (title.length() == 0)) {
			bookCacheModel.title = null;
		}

		bookCacheModel.description = getDescription();

		String description = bookCacheModel.description;

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

		bookCacheModel.googleDriveLink = getGoogleDriveLink();

		String googleDriveLink = bookCacheModel.googleDriveLink;

		if ((googleDriveLink != null) && (googleDriveLink.length() == 0)) {
			bookCacheModel.googleDriveLink = null;
		}

		bookCacheModel.bookLogoDlId = getBookLogoDlId();

		return bookCacheModel;
	}

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

		sb.append("{uuid=");
		sb.append(getUuid());
		sb.append(", bookId=");
		sb.append(getBookId());
		sb.append(", companyId=");
		sb.append(getCompanyId());
		sb.append(", groupId=");
		sb.append(getGroupId());
		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(", gDriveId=");
		sb.append(getGDriveId());
		sb.append(", title=");
		sb.append(getTitle());
		sb.append(", description=");
		sb.append(getDescription());
		sb.append(", googleDriveLink=");
		sb.append(getGoogleDriveLink());
		sb.append(", bookLogoDlId=");
		sb.append(getBookLogoDlId());
		sb.append("}");

		return sb.toString();
	}

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

		sb.append("<model><model-name>");
		sb.append("ru.tiis.srv.model.Book");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>uuid</column-name><column-value><![CDATA[");
		sb.append(getUuid());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>bookId</column-name><column-value><![CDATA[");
		sb.append(getBookId());
		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>groupId</column-name><column-value><![CDATA[");
		sb.append(getGroupId());
		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>gDriveId</column-name><column-value><![CDATA[");
		sb.append(getGDriveId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>title</column-name><column-value><![CDATA[");
		sb.append(getTitle());
		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(
			"<column><column-name>googleDriveLink</column-name><column-value><![CDATA[");
		sb.append(getGoogleDriveLink());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>bookLogoDlId</column-name><column-value><![CDATA[");
		sb.append(getBookLogoDlId());
		sb.append("]]></column-value></column>");

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

		return sb.toString();
	}

	private static ClassLoader _classLoader = Book.class.getClassLoader();
	private static Class<?>[] _escapedModelInterfaces = new Class[] { Book.class };
	private String _uuid;
	private String _originalUuid;
	private long _bookId;
	private long _companyId;
	private long _originalCompanyId;
	private boolean _setOriginalCompanyId;
	private long _groupId;
	private long _originalGroupId;
	private boolean _setOriginalGroupId;
	private long _userId;
	private String _userUuid;
	private String _userName;
	private Date _createDate;
	private Date _modifiedDate;
	private String _gDriveId;
	private String _title;
	private String _description;
	private String _googleDriveLink;
	private BookBookLogoBlobModel _bookLogoBlobModel;
	private long _bookLogoDlId;
	private long _columnBitmask;
	private Book _escapedModel;
}