import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.hibernate.annotations.Type;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import org.hibernate.annotations.DiscriminatorOptions;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
@Entity
@Table(name="Employee", schema = "test")
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name="ACTIVE",
discriminatorType= DiscriminatorType.STRING
)
@DiscriminatorOptions(insert=true)
@DiscriminatorValue("Yes")
public class Employee {
@javax.persistence.Id
@SequenceGenerator(name = "", sequenceName = "")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "")
@Column(name="EMPLOYEE_ID")
private int employeeId;
@Column(name="EMPLOYEE_NAME")
@NotNull
private String employeeName;
@Column(name="DEPT")
@NotNull
private String department;
@Column(name="FULL_TIME")
@Type(type="yes_no")
@NotNull
private Boolean isFullTime;
@Column(name = "ACTIVE")
@Type(type = "yes_no")
public boolean getActive() {
return active;
}
public String getName() {
return employeeName;
}
public String getDept() {
return department;
}
}
|
// net.sf.ehcache.Cache.Cache(String name, int maxElementsInMemory, MemoryStoreEvictionPolicy
memoryStoreEvictionPolicy, boolean overflowToDisk, String diskStorePath, boolean eternal, long
timeToLiveSeconds, long timeToIdleSeconds, boolean diskPersistent, long
diskExpiryThreadIntervalSeconds, RegisteredEventListeners registeredEventListeners)
Ehcache employeeCache = new Cache("Employee", 1000, MemoryStoreEvictionPolicy.FIFO, false, "c:/EmployeeDiskCacheStorage", false, 300,
300, false, 30, null);
employeeCache = new SelfPopulatingCache(employeeCache, new CacheEntryFactory() {
@Override
public Object createEntry(Object day) throws Exception {
Employee employee = getEmployee(1234);
return employee;
}
});
CacheManager.getInstance().addCache(employeeCache);
|