From: Bojnourdi Date: Fri, 28 Aug 2015 12:09:55 +0000 (+0200) Subject: Setting up the cache for the relevant entities X-Git-Tag: gde-v0.1~8^2~5^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c2e1f1289477da9eef04f07f9da8d0459f5ad0c4;p=modules%2Fgde.git Setting up the cache for the relevant entities --- diff --git a/projects/GDE-test/test/com/edf/gde/test/dao/FileDaoTest.java b/projects/GDE-test/test/com/edf/gde/test/dao/FileDaoTest.java index ecea4e0..9d3097a 100644 --- a/projects/GDE-test/test/com/edf/gde/test/dao/FileDaoTest.java +++ b/projects/GDE-test/test/com/edf/gde/test/dao/FileDaoTest.java @@ -24,7 +24,8 @@ import org.junit.Test; * @author Kavoos */ public class FileDaoTest extends BaseTest { - + private static int dataSize = 1024 * 512; + protected String bytesToHex(byte[] bytes) { char[] hexArray = "0123456789ABCDEF".toCharArray(); char[] hexChars = new char[bytes.length * 2]; @@ -161,7 +162,6 @@ public class FileDaoTest extends BaseTest { @Test public void createChunkTest() throws Exception { testName("createChunk"); - int dataSize = 1024 * 1024; /* Create a new file */ Date date = new Date(); String fileName = "/home/kavoos/chunk" + date.getTime() + ".txt"; @@ -192,7 +192,6 @@ public class FileDaoTest extends BaseTest { @Test public void readChunkTest() throws Exception { testName("readChunk"); - int dataSize = 1024 * 1024; /* Create a new file */ Date date = new Date(); String fileName = "/home/kavoos/readchunk" + date.getTime() + ".txt"; diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Chunk.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Chunk.java index f7ebec6..3aed7b7 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Chunk.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Chunk.java @@ -20,6 +20,8 @@ import javax.persistence.Table; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import javax.xml.bind.annotation.XmlRootElement; +import org.eclipse.persistence.annotations.Cache; +import org.eclipse.persistence.config.CacheIsolationType; /** * @@ -33,7 +35,11 @@ import javax.xml.bind.annotation.XmlRootElement; @NamedQuery(name = "Chunk.findById", query = "SELECT c FROM Chunk c WHERE c.id = :id"), @NamedQuery(name = "Chunk.findByFileId", query = "SELECT c FROM Chunk c WHERE c.fileId = :fileId") }) +@Cache( + size = 100, + isolation = CacheIsolationType.SHARED) public class Chunk implements Serializable { + private static final long serialVersionUID = 1L; @Id @Basic(optional = false) @@ -52,7 +58,7 @@ public class Chunk implements Serializable { @Column(name = "size") private long size; @Lob - @Column(name = "data",nullable = false) + @Column(name = "data", nullable = false) private byte[] data; public Chunk() { @@ -120,7 +126,7 @@ public class Chunk implements Serializable { c.size = cto.getSize(); return c; } - + public ChunkTO toChunkTO() { ChunkTO cto = new ChunkTO(); cto.setChecksum(this.checksum); @@ -131,7 +137,7 @@ public class Chunk implements Serializable { cto.setSize(this.size); return cto; } - + @Override public String toString() { return "com.edf.gde.entities.Chunk[ id=" + id + " ]"; diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/GDEFile.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/GDEFile.java index 3d47465..a17e85a 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/GDEFile.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/GDEFile.java @@ -27,6 +27,8 @@ import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import javax.xml.bind.annotation.XmlRootElement; +import org.eclipse.persistence.annotations.Cache; +import org.eclipse.persistence.config.CacheIsolationType; /** * @@ -34,6 +36,7 @@ import javax.xml.bind.annotation.XmlRootElement; */ @Entity(name = "File") @Table(name = "gde_file") +@Cache(size = 100, isolation = CacheIsolationType.SHARED) @XmlRootElement @NamedQueries({ @NamedQuery(name = "File.findAll", query = "SELECT f FROM File f"), diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/User.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/User.java index fa77c99..d82d3d0 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/User.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/User.java @@ -17,19 +17,24 @@ import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; +import org.eclipse.persistence.annotations.Cache; +import org.eclipse.persistence.config.CacheIsolationType; /** * * @author Kavoos */ - -@Entity(name="User") +@Entity(name = "User") @Table(name = "USERS") -@NamedQueries ({ +@NamedQueries({ @NamedQuery(name = "User.findById", query = "SELECT u FROM User u where u.id=:id"), @NamedQuery(name = "User.findByName", query = "SELECT u FROM User u where u.name=:username") }) +@Cache( + size = 100, + isolation = CacheIsolationType.SHARED) public class User implements Serializable { + @Id @Basic(optional = false) @NotNull @@ -43,7 +48,7 @@ public class User implements Serializable { @Size(max = 255) @Column(name = "userPassword") private String password; - + public Long getId() { return id; } @@ -67,7 +72,7 @@ public class User implements Serializable { public void setPassword(String password) { this.password = password; } - + public static User fromUserTO(UserTO uto) { User user = new User(); user.setId(uto.getId()); @@ -75,7 +80,7 @@ public class User implements Serializable { user.setPassword(uto.getPassword()); return user; } - + public UserTO toUserTO() { UserTO uto = new UserTO(); uto.setId(id); diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/UserGroup.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/UserGroup.java index 244c9ae..6406382 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/UserGroup.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/UserGroup.java @@ -15,6 +15,8 @@ import javax.persistence.NamedQuery; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.validation.constraints.NotNull; +import org.eclipse.persistence.annotations.Cache; +import org.eclipse.persistence.config.CacheIsolationType; /** * @@ -22,6 +24,7 @@ import javax.validation.constraints.NotNull; */ @Entity(name="UserGroup") @Table(name = "USERGROUP") +@Cache(size = 100, isolation = CacheIsolationType.SHARED) @NamedQueries ({ @NamedQuery(name = "UserGroup.findById", query = "SELECT ug FROM UserGroup ug where ug.id = :id"), @NamedQuery(name = "UserGroup.findByUserId", query = "SELECT ug FROM UserGroup ug where ug.userId=:userId"),