package edu.mssm.pharm.maayanlab.Enrichr;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicInteger;

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

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.DynamicUpdate;

@Entity
@DynamicUpdate
@Table(name = "counters", catalog = "enrichr", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
public class Counter implements Serializable {

	private static final long serialVersionUID = -5318689976045747460L;
	
	private int id;
	private String name;
	private AtomicInteger count;

	public Counter() {
		this.count = new AtomicInteger();
	}

	public Counter(String name, int count) {
		this.name = name;
		this.count = new AtomicInteger(count);
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(name = "name", unique = true, nullable = false, length = 20)
	public String getName() {
		return this.name;
	}

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

	@Column(name = "count", nullable = false)
	public int getCount() {
		return this.count.get();
	}

	public void setCount(int count) {
		this.count.set(count);
	}
	
	public int incrementAndGet() {
		return this.count.incrementAndGet();
	}

	@Transient
	public int getAndIncrement() {
		return this.count.getAndIncrement();
	}
}

@@ -1,8 +1,114 @@
+/**%0D%0A * Model for storing web app counts%0D%0A * %0D%0A * @author%09%09Edward Y. Chen%0D%0A * @since%09%0904/25/2013 %0D%0A */%0D%0A%0D%0A
 package 
@@ -1785,24 +1785,90 @@
 ncrement() %7B
+%09// Transient so Hibernate doesn't look for the AndIncrement field
 %0D%0A%09%09return t

Add comments