UserImage.java 3.21 KB
/*
 * Copyright Codecrew Ry
 * 
 * All rights reserved.
 * 
 * This license applies to any software containing a notice placed by the 
 * copyright holder. Such software is herein referred to as the Software. 
 * This license covers modification, distribution and use of the Software. 
 * 
 * Any distribution and use in source and binary forms, with or without 
 * modification is not permitted without explicit written permission from the 
 * copyright owner. 
 * 
 * A non-exclusive royalty-free right is granted to the copyright owner of the 
 * Software to use, modify and distribute all modifications to the Software in 
 * future versions of the Software. 
 * 
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fi.codecrew.moya.model;

import static javax.persistence.FetchType.LAZY;

import java.util.Calendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 
 */
@Entity
@Table(name = "user_images")
public class UserImage extends GenericEntity {

    private static final long serialVersionUID = 1L;

    @Column(name = "uploaded", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar uploaded = Calendar.getInstance();

    @Column(name = "name")
    private String name;

    @Lob
    @Column(name = "description")
    private String description;

    @Column(name = "mime_type")
    private String mimeType;

    @Lob
    @Column(name = "image_data")
    @Basic(fetch = LAZY)
    private byte[] imageData;

    @JoinColumn(name = "user_id", referencedColumnName = "id")
    @ManyToOne
    private User user;

    @OneToOne(mappedBy = "currentImage")
    private User defaultImage;

    public UserImage() {
        super();
    }

    public UserImage(User user) {
        this.user = user;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public byte[] getImageData() {
        return imageData;
    }

    public void setImageData(byte[] imageData) {
        this.imageData = imageData;
    }

    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @param user
     *            the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    public void setDefaultImage(User defaultImage) {
        this.defaultImage = defaultImage;
    }

    public User getDefaultImage() {
        return defaultImage;
    }

    public void setUploaded(Calendar uploaded) {
        this.uploaded = uploaded;
    }

    public Calendar getUploaded() {
        return uploaded;
    }
}