Skip to content

Instantly share code, notes, and snippets.

@dilnei
Created March 18, 2016 05:44
Show Gist options
  • Save dilnei/1f4469848f9fd7e0e1e4 to your computer and use it in GitHub Desktop.
Save dilnei/1f4469848f9fd7e0e1e4 to your computer and use it in GitHub Desktop.
Entidade imagem
` package br.com.weblog.model.entity;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import br.com.weblog.model.entity.enums.ContentType;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
@Entity
@Table(name = "IMAGE")
@SequenceGenerator(name = "IMAGE_SEQ_ID", sequenceName = "IMAGE_SEQ_ID", allocationSize = 1, initialValue = 1)
public class Image {
/**
* The object primary key.
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "IMAGE_SEQ_ID")
private Long id;
@NotNull
@Size(min = 1, max = 100)
private String name;
@Size(max = 50)
private String title;
@NotNull
@Enumerated(EnumType.STRING)
private ContentType contentType;
@NotNull
@Min(1)
private long length;
@NotNull
@Min(1)
private int width;
@NotNull
@Min(1)
private int height;
@NotNull
@Lob
private byte[] fullBlob;
@NotNull
@Lob
private byte[] thumbBlob;
/**
* The datetime that this record is created.
*/
@NotNull
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
/**
* The datetime that this record is modified.
*/
@NotNull
@Temporal(TemporalType.TIMESTAMP)
private Date lastModificationDate;
public Image() {
}
public Image(String name, String title, ContentType contentType, long length, int width, int height, byte[] fullBlob, byte[] thumbBlob) {
this.name = name;
this.title = title;
this.contentType = contentType;
this.length = length;
this.width = width;
this.height = height;
this.fullBlob = fullBlob;
this.thumbBlob = thumbBlob;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public ContentType getContentType() {
return contentType;
}
public void setContentType(ContentType contentType) {
this.contentType = contentType;
}
public long getLength() {
return length;
}
public void setLength(long length) {
this.length = length;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public byte[] getFullBlob() {
return fullBlob;
}
public void setFullBlob(byte[] fullBlob) {
this.fullBlob = fullBlob;
}
public byte[] getThumbBlob() {
return thumbBlob;
}
public void setThumbBlob(byte[] thumbBlob) {
this.thumbBlob = thumbBlob;
}
public Date getCreationDate() {
return creationDate;
}
public Date getLastModificationDate() {
return lastModificationDate;
}
@PrePersist
public void whenInsert() {
creationDate = new Date();
lastModificationDate = new Date();
}
@PreUpdate
public void whenUpdate() {
lastModificationDate = new Date();
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this).addValue(getId()).toString();
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Image) {
Image other = (Image) obj;
return Objects.equal(other.getId(), getId());
}
return false;
}
}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment