/*
 * $Id: Attachment.java 988 2008-12-30 08:51:13Z lhoriman $
 * $URL: http://subetha.tigris.org/svn/subetha/branches/resin/core/src/org/subethamail/entity/Attachment.java $
 */

package org.subethamail.entity;

import java.io.InputStream;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.SQLException;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.subethamail.entity.i.Validator;

/**
 * Entity for a single piece of mail.
 * 
 * @author Jeff Schnitzer
 */
@Entity
// Disabled caching until instrumentation problem with 4.0.4.GA resolved
//@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL, include="non-lazy")
public class Attachment implements Serializable
{
	private static final long serialVersionUID = 1L;

	/** */
	@Transient private final static Logger log = LoggerFactory.getLogger(Attachment.class);
	
	/** */
	@Id
	@GeneratedValue
	Long id;
	
	/** */
	@Column(nullable=false, length=Validator.MAX_ATTACHMENT_CONTENT_TYPE)
	String contentType;
	
	/** */
	@Lob
	@Basic(fetch=FetchType.LAZY)
	@Column(nullable=false, length=Validator.MAX_ATTACHMENT_CONTENT)
	Blob content;
	
	/** */
	@ManyToOne
	@JoinColumn(name="mailId", nullable=false)
	Mail mail;
	
	/**
	 */
	public Attachment() {}
	
	/**
	 * Creates a new attachment.
	 */
	public Attachment(Mail mail, Blob content, String contentType)
	{
		if (log.isDebugEnabled())
			log.debug("Creating new attachment");

		this.mail = mail;
		this.content = content;
		this.contentType = contentType;
	}
	
	/** */
	public Long getId() { return this.id; }

	/** */
	public Blob getContent() { return this.content; }
	
	/**
	 * Convenience method
	 */
	public InputStream getContentStream()
	{
		try
		{
			return this.content.getBinaryStream();
		}
		catch (SQLException ex)
		{
			throw new RuntimeException(ex);
		}
	}
	
	/** */
	public String getContentType() { return this.contentType; }
	
	/** */
	public Mail getMail() { return this.mail; }
	
	/** */
	public String toString()
	{
		return this.getClass() + " {id=" + this.id + "}";
	}
}


@@ -325,16 +325,49 @@
 eption;%0D
+%0Aimport java.util.logging.Level;%0D
 %0A%0D%0Aimpor
@@ -681,104 +681,42 @@
 e;%0D%0A
-import javax.persistence.Transient;%0D%0A%0D%0Aimport org.slf4j.Logger;%0D%0Aimport org.slf4j.LoggerFactory;
+%0D%0Aimport lombok.extern.java.Log;%0D%0A
 %0D%0Aim
@@ -999,16 +999,22 @@
 lazy%22)%0D%0A
+@Log%0D%0A
 public c
@@ -1111,109 +1111,8 @@
 1L;%0D
-%0A%0D%0A%09/** */%0D%0A%09@Transient private final static Logger log = LoggerFactory.getLogger(Attachment.class);%0D
 %0A%09%0D%0A
@@ -1637,49 +1637,31 @@
 %7B%0D%0A%09
-%09if (log.isDebugEnabled())%0D%0A%09%09%09log.debug(
+    log.log(Level.FINE,
 %22Cre

switch logging framework