From ea2cfcff9f4f5b8d06e2d8954e7e732119b6c0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Thu, 2 Sep 2010 02:04:15 -0400 Subject: Add data classes --- src/lq/PMF.java | 16 +++++++++++++++ src/lq/Quote.java | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lq/Vote.java | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 src/lq/PMF.java create mode 100644 src/lq/Quote.java create mode 100644 src/lq/Vote.java (limited to 'src') diff --git a/src/lq/PMF.java b/src/lq/PMF.java new file mode 100644 index 0000000..25ffde6 --- /dev/null +++ b/src/lq/PMF.java @@ -0,0 +1,16 @@ +package lq; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManagerFactory; + +// Based on: http://code.google.com/appengine/docs/java/datastore/usingjdo.html +public final class PMF { + private static final PersistenceManagerFactory pmfInstance = + JDOHelper.getPersistenceManagerFactory("transactions-optional"); + + private PMF() {} + + public static PersistenceManagerFactory get() { + return pmfInstance; + } +} diff --git a/src/lq/Quote.java b/src/lq/Quote.java new file mode 100644 index 0000000..7475ba0 --- /dev/null +++ b/src/lq/Quote.java @@ -0,0 +1,58 @@ +package lq; + +import java.util.Date; +import javax.jdo.annotations.IdGeneratorStrategy; +import javax.jdo.annotations.IdentityType; +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.Persistent; +import javax.jdo.annotations.PrimaryKey; + +@PersistenceCapable(identityType = IdentityType.APPLICATION) +public class Quote { + @PrimaryKey + @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) + private Long id; + + @Persistent + private Date timestamp; + + @Persistent + private Boolean approved; + + @Persistent + private Date quoteDate; + + @Persistent + private String author; + + @Persistent + private String content; + + @Persistent + private String ip; + + public Quote(Date quoteDate, String author, String content, String ip) { + this.quoteDate = quoteDate; + this.author = author; + this.content = content; + this.ip = ip; + + this.timestamp = new Date(); + } + + public Long getId() { return id; } + public Date getTimestamp() { return timestamp; } + public Boolean getApproved() { return approved; } + public Date getQuoteDate() { return quoteDate; } + public String getAuthor() { return author; } + public String getContent() { return content; } + public String getIp() { return ip; } + + public void setId(Long id) { this.id = id; } + public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } + public void setApproved(Boolean approved) { this.approved = approved; } + public void setQuoteDate(Date quoteDate) { this.quoteDate = quoteDate; } + public void setAuthor(String author) { this.author = author; } + public void setContent(String content) { this.content = content; } + public void setIp(String ip) { this.ip = ip; } +} diff --git a/src/lq/Vote.java b/src/lq/Vote.java new file mode 100644 index 0000000..0d3c9ac --- /dev/null +++ b/src/lq/Vote.java @@ -0,0 +1,40 @@ +package lq; + +import java.util.Date; +import javax.jdo.annotations.IdGeneratorStrategy; +import javax.jdo.annotations.IdentityType; +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.Persistent; +import javax.jdo.annotations.PrimaryKey; + +@PersistenceCapable(identityType = IdentityType.APPLICATION) +public class Vote { + @PrimaryKey + @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) + private Long id; + + @Persistent + private Quote quote; + + @Persistent + private Date timestamp; + + @Persistent + private String ip; + + public Vote(Quote quote, String ip) { + this.quote = quote; + this.ip = ip; + timestamp = new Date(); + } + + public Long getId() { return id; } + public Quote getQuote() { return quote; } + public Date getTimestamp() { return timestamp; } + public String getIp() { return ip; } + + public void setId(Long id) { this.id = id; } + public void setQuote(Quote quote) { this.quote = quote; } + public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } + public void setIp(String ip) { this.ip = ip; } +} -- cgit v1.2.3