/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.storage.entities; import java.util.Calendar; import java.util.Date; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Index; import javax.persistence.Lob; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import org.hibernate.annotations.Type; @Entity @Table(name = "scim_meta", indexes = { @Index(columnList = "created"), @Index(columnList = "lastModified"), }) public class MetaEntity { private static final int SEQUENCE_ALLOCATION_SIZE = 1; private static final int SEQUENCE_INITIAL_VALUE = 100; @Id @SequenceGenerator(name = "sequence_scim_meta", sequenceName = "resource_server_sequence_scim_meta", allocationSize = SEQUENCE_ALLOCATION_SIZE, initialValue = SEQUENCE_INITIAL_VALUE) @GeneratedValue(generator = "sequence_scim_meta") private long id; private Date created; private Date lastModified; @Lob @Type(type = "org.hibernate.type.StringClobType") private String location; private String version; private String resourceType; public MetaEntity(Calendar instance) { created = instance.getTime(); lastModified = instance.getTime(); } public MetaEntity() { } public long getId() { return id; } public void setId(long id) { this.id = id; } public Date getCreated() { return created != null ? (Date) created.clone() : null; } public void setCreated(Date created) { this.created = created != null ? new Date(created.getTime()) : null; } public Date getLastModified() { return lastModified != null ? (Date) lastModified.clone() : null; } public void setLastModified(Date lastModified) { this.lastModified = lastModified != null ? new Date(lastModified.getTime()) : null; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public String getVersion() { return version; } public void setVersion(String version) { this.version = version; } public String getResourceType() { return resourceType; } public void setResourceType(String resourceType) { this.resourceType = resourceType; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((created == null) ? 0 : created.hashCode()); result = prime * result + ((lastModified == null) ? 0 : lastModified.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode()); result = prime * result + ((version == null) ? 0 : version.hashCode()); return result; } @Override @SuppressWarnings("all") public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } MetaEntity other = (MetaEntity) obj; if (created == null) { if (other.created != null) { return false; } } else if (!created.equals(other.created)) { return false; } if (lastModified == null) { if (other.lastModified != null) { return false; } } else if (!lastModified.equals(other.lastModified)) { return false; } if (location == null) { if (other.location != null) { return false; } } else if (!location.equals(other.location)) { return false; } if (resourceType == null) { if (other.resourceType != null) { return false; } } else if (!resourceType.equals(other.resourceType)) { return false; } if (version == null) { if (other.version != null) { return false; } } else if (!version.equals(other.version)) { return false; } return true; } @Override public String toString() { return "MetaEntity [created=" + created + ", lastModified=" + lastModified + ", location=" + location + ", version=" + version + ", resourceType=" + resourceType + "]"; } }