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

package org.subethamail.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.subethamail.entity.i.Validator;

// Moved this here from package-info.java to fix JDK5/6 incompatibility problem
// For some reason package-info.java built with JDK6 doesn't work on JDK5
@org.hibernate.annotations.TypeDefs({
	@org.hibernate.annotations.TypeDef(
		name="anyImmutable",
		typeClass=org.subethamail.entity.type.AnyImmutableType.class
	)
})

/**
 * Contains config parameter, key and value.
 *
 * @author Jeff Schnitzer
 */
@Entity
@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
public class Config implements Serializable, Comparable<Config>
{
	private static final long serialVersionUID = 1L;

	/** */
	@Transient private final static Logger log = LoggerFactory.getLogger(Config.class);

	/** */
	@Id
	@Column(length=Validator.MAX_CONFIG_ID)
	String id;

	/** */
	@Type(type="anyImmutable")
	@Columns(columns={
		@Column(name="type"),
		@Column(name="value", length=Validator.MAX_CONFIG_VALUE)
	})
	Object value;

	/**
	 */
	public Config() {}

	/**
	 */
	public Config(String id, Object value)
	{
		if (log.isDebugEnabled())
			log.debug("Creating new Config: " + id);

		this.id = id;
		this.value = value;
	}

	/** */
	public String getId()		{ return this.id; }

	/**
	 * @return the value object in its native type
	 */
	public Object getValue() { return this.value; }

	public void setValue(Object val)
	{
		this.value = val;
	}

	/** */
	@Override
	public String toString()
	{
		return this.getClass() + " {id=" + this.id + "}";
	}

	/**
	 * Natural sort order is based on id
	 */
	public int compareTo(Config other)
	{
		return this.id.compareTo(other.getId());
	}
}


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

package org.subethamail.entity;

import java.io.Serializable;
import java.util.logging.Level;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

import lombok.extern.java.Log;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Type;
import org.subethamail.entity.i.Validator;

// Moved this here from package-info.java to fix JDK5/6 incompatibility problem
// For some reason package-info.java built with JDK6 doesn't work on JDK5
@org.hibernate.annotations.TypeDefs({
	@org.hibernate.annotations.TypeDef(
		name="anyImmutable",
		typeClass=org.subethamail.entity.type.AnyImmutableType.class
	)
})

/**
 * Contains config parameter, key and value.
 *
 * @author Jeff Schnitzer
 */
@Entity
@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
@Log
public class Config implements Serializable, Comparable<Config>
{
	private static final long serialVersionUID = 1L;

	/** */
	@Id
	@Column(length=Validator.MAX_CONFIG_ID)
	String id;

	/** */
	@Type(type="anyImmutable")
	@Columns(columns={
		@Column(name="type"),
		@Column(name="value", length=Validator.MAX_CONFIG_VALUE)
	})
	Object value;

	/**
	 */
	public Config() {}

	/**
	 */
	public Config(String id, Object value)
	{
	    log.log(Level.FINE,"Creating new Config: {0}", id);

		this.id = id;
		this.value = value;
	}

	/** */
	public String getId()		{ return this.id; }

	/**
	 * @return the value object in its native type
	 */
	public Object getValue() { return this.value; }

	public void setValue(Object val)
	{
		this.value = val;
	}

	/** */
	@Override
	public String toString()
	{
		return this.getClass() + " {id=" + this.id + "}";
	}

	/**
	 * Natural sort order is based on id
	 */
	public int compareTo(Config other)
	{
		return this.id.compareTo(other.getId());
	}
}


switch logging framework