/**
 * Copyright (c) 2000-2013 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.meera.dbservice.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
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.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.meera.dbservice.model.Student;
import com.meera.dbservice.model.StudentModel;
import com.meera.dbservice.model.StudentSoap;

import java.io.Serializable;

import java.sql.Types;

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

/**
 * The base model implementation for the Student service. Represents a row in the &quot;LS_Student&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.meera.dbservice.model.StudentModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link StudentImpl}.
 * </p>
 *
 * @author LiferaySavvy
 * @see StudentImpl
 * @see com.meera.dbservice.model.Student
 * @see com.meera.dbservice.model.StudentModel
 * @generated
 */
@JSON(strict = true)
public class StudentModelImpl extends BaseModelImpl<Student>
	implements StudentModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a student model instance should use the {@link com.meera.dbservice.model.Student} interface instead.
	 */
	public static final String TABLE_NAME = "LS_Student";
	public static final Object[][] TABLE_COLUMNS = {
			{ "studentId", Types.BIGINT },
			{ "firstName", Types.VARCHAR },
			{ "lastName", Types.VARCHAR },
			{ "studentAge", Types.INTEGER },
			{ "studentGender", Types.INTEGER },
			{ "studentAddress", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table LS_Student (studentId LONG not null primary key,firstName VARCHAR(75) null,lastName VARCHAR(75) null,studentAge INTEGER,studentGender INTEGER,studentAddress VARCHAR(75) null)";
	public static final String TABLE_SQL_DROP = "drop table LS_Student";
	public static final String ORDER_BY_JPQL = " ORDER BY student.studentId ASC";
	public static final String ORDER_BY_SQL = " ORDER BY LS_Student.studentId 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.meera.dbservice.model.Student"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.meera.dbservice.model.Student"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.meera.dbservice.model.Student"),
			true);
	public static long STUDENTGENDER_COLUMN_BITMASK = 1L;
	public static long STUDENTID_COLUMN_BITMASK = 2L;

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

		Student model = new StudentImpl();

		model.setStudentId(soapModel.getStudentId());
		model.setFirstName(soapModel.getFirstName());
		model.setLastName(soapModel.getLastName());
		model.setStudentAge(soapModel.getStudentAge());
		model.setStudentGender(soapModel.getStudentGender());
		model.setStudentAddress(soapModel.getStudentAddress());

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

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

		for (StudentSoap 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.meera.dbservice.model.Student"));

	public StudentModelImpl() {
	}

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

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

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

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

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

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

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

		attributes.put("studentId", getStudentId());
		attributes.put("firstName", getFirstName());
		attributes.put("lastName", getLastName());
		attributes.put("studentAge", getStudentAge());
		attributes.put("studentGender", getStudentGender());
		attributes.put("studentAddress", getStudentAddress());

		return attributes;
	}

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

		if (studentId != null) {
			setStudentId(studentId);
		}

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

		if (firstName != null) {
			setFirstName(firstName);
		}

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

		if (lastName != null) {
			setLastName(lastName);
		}

		Integer studentAge = (Integer)attributes.get("studentAge");

		if (studentAge != null) {
			setStudentAge(studentAge);
		}

		Integer studentGender = (Integer)attributes.get("studentGender");

		if (studentGender != null) {
			setStudentGender(studentGender);
		}

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

		if (studentAddress != null) {
			setStudentAddress(studentAddress);
		}
	}

	@JSON
	@Override
	public long getStudentId() {
		return _studentId;
	}

	@Override
	public void setStudentId(long studentId) {
		_columnBitmask = -1L;

		_studentId = studentId;
	}

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

	@Override
	public void setFirstName(String firstName) {
		_firstName = firstName;
	}

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

	@Override
	public void setLastName(String lastName) {
		_lastName = lastName;
	}

	@JSON
	@Override
	public int getStudentAge() {
		return _studentAge;
	}

	@Override
	public void setStudentAge(int studentAge) {
		_studentAge = studentAge;
	}

	@JSON
	@Override
	public int getStudentGender() {
		return _studentGender;
	}

	@Override
	public void setStudentGender(int studentGender) {
		_columnBitmask |= STUDENTGENDER_COLUMN_BITMASK;

		if (!_setOriginalStudentGender) {
			_setOriginalStudentGender = true;

			_originalStudentGender = _studentGender;
		}

		_studentGender = studentGender;
	}

	public int getOriginalStudentGender() {
		return _originalStudentGender;
	}

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

	@Override
	public void setStudentAddress(String studentAddress) {
		_studentAddress = studentAddress;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

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

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

		expandoBridge.setAttributes(serviceContext);
	}

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

		return _escapedModel;
	}

	@Override
	public Object clone() {
		StudentImpl studentImpl = new StudentImpl();

		studentImpl.setStudentId(getStudentId());
		studentImpl.setFirstName(getFirstName());
		studentImpl.setLastName(getLastName());
		studentImpl.setStudentAge(getStudentAge());
		studentImpl.setStudentGender(getStudentGender());
		studentImpl.setStudentAddress(getStudentAddress());

		studentImpl.resetOriginalValues();

		return studentImpl;
	}

	@Override
	public int compareTo(Student student) {
		int value = 0;

		if (getStudentId() < student.getStudentId()) {
			value = -1;
		}
		else if (getStudentId() > student.getStudentId()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		return 0;
	}

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

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

		Student student = (Student)obj;

		long primaryKey = student.getPrimaryKey();

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

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

	@Override
	public void resetOriginalValues() {
		StudentModelImpl studentModelImpl = this;

		studentModelImpl._originalStudentGender = studentModelImpl._studentGender;

		studentModelImpl._setOriginalStudentGender = false;

		studentModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Student> toCacheModel() {
		StudentCacheModel studentCacheModel = new StudentCacheModel();

		studentCacheModel.studentId = getStudentId();

		studentCacheModel.firstName = getFirstName();

		String firstName = studentCacheModel.firstName;

		if ((firstName != null) && (firstName.length() == 0)) {
			studentCacheModel.firstName = null;
		}

		studentCacheModel.lastName = getLastName();

		String lastName = studentCacheModel.lastName;

		if ((lastName != null) && (lastName.length() == 0)) {
			studentCacheModel.lastName = null;
		}

		studentCacheModel.studentAge = getStudentAge();

		studentCacheModel.studentGender = getStudentGender();

		studentCacheModel.studentAddress = getStudentAddress();

		String studentAddress = studentCacheModel.studentAddress;

		if ((studentAddress != null) && (studentAddress.length() == 0)) {
			studentCacheModel.studentAddress = null;
		}

		return studentCacheModel;
	}

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

		sb.append("{studentId=");
		sb.append(getStudentId());
		sb.append(", firstName=");
		sb.append(getFirstName());
		sb.append(", lastName=");
		sb.append(getLastName());
		sb.append(", studentAge=");
		sb.append(getStudentAge());
		sb.append(", studentGender=");
		sb.append(getStudentGender());
		sb.append(", studentAddress=");
		sb.append(getStudentAddress());
		sb.append("}");

		return sb.toString();
	}

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

		sb.append("<model><model-name>");
		sb.append("com.meera.dbservice.model.Student");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>studentId</column-name><column-value><![CDATA[");
		sb.append(getStudentId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>firstName</column-name><column-value><![CDATA[");
		sb.append(getFirstName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>lastName</column-name><column-value><![CDATA[");
		sb.append(getLastName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>studentAge</column-name><column-value><![CDATA[");
		sb.append(getStudentAge());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>studentGender</column-name><column-value><![CDATA[");
		sb.append(getStudentGender());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>studentAddress</column-name><column-value><![CDATA[");
		sb.append(getStudentAddress());
		sb.append("]]></column-value></column>");

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

		return sb.toString();
	}

	private static ClassLoader _classLoader = Student.class.getClassLoader();
	private static Class<?>[] _escapedModelInterfaces = new Class[] {
			Student.class
		};
	private long _studentId;
	private String _firstName;
	private String _lastName;
	private int _studentAge;
	private int _studentGender;
	private int _originalStudentGender;
	private boolean _setOriginalStudentGender;
	private String _studentAddress;
	private long _columnBitmask;
	private Student _escapedModel;
}