/*******************************************************************************
* ===========================================================
* Ankush : Big Data Cluster Management Solution
* ===========================================================
*
* (C) Copyright 2014, by Impetus Technologies
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License (LGPL v3) as
* published by the Free Software Foundation;
*
* This software 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
******************************************************************************/
/**
*
*/
package com.impetus.ankush.common.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.springframework.util.SerializationUtils;
/**
* @author hokam
*
*/
@Entity
@Table(name = "eventhistory")
public class EventHistory extends BaseObject {
/**
*
*/
private static final long serialVersionUID = 1L;
/** The id. */
private Long id;
/** event bytes **/
private byte[] eventBytes;
/** The event id **/
private Long eventId;
/** The event id **/
private Long clusterId;
/**
* Gets the id.
*
* @return the id
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the eventBytes
*/
@Lob
@Column(length = Integer.MAX_VALUE - 1)
public byte[] getEventBytes() {
return eventBytes;
}
/**
* @param eventBytes the eventBytes to set
*/
public void setEventBytes(byte[] eventBytes) {
this.eventBytes = eventBytes;
}
/**
* To set the event bytes.
* @param event
*/
@Transient
public void setEvent(Event event) {
setEventBytes(SerializationUtils.serialize(event));
}
/**
* Method to get the events.
* @return
*/
@Transient
public Event getEvent() {
if (getEventBytes() == null) {
return null;
}
return (Event) SerializationUtils.deserialize(getEventBytes());
}
/**
* @param eventId the eventId to set
*/
public void setEventId(Long eventId) {
this.eventId = eventId;
}
/**
* @return the eventId
*/
public Long getEventId() {
return eventId;
}
/**
* Sets the cluster id.
*
* @param clusterId
* the clusterId to set
*/
public void setClusterId(Long clusterId) {
this.clusterId = clusterId;
}
/**
* Gets the cluster id.
*
* @return the clusterId
*/
@JsonIgnore
public Long getClusterId() {
return clusterId;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((clusterId == null) ? 0 : clusterId.hashCode());
result = prime * result + ((eventId == null) ? 0 : eventId.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof EventHistory))
return false;
EventHistory other = (EventHistory) obj;
if (clusterId == null) {
if (other.clusterId != null)
return false;
} else if (!clusterId.equals(other.clusterId))
return false;
if (eventId == null) {
if (other.eventId != null)
return false;
} else if (!eventId.equals(other.eventId))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}