Created
August 24, 2012 04:43
-
-
Save angeloh/3445494 to your computer and use it in GitHub Desktop.
ImageInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models; | |
import java.util.ArrayList; | |
import java.util.Date; | |
import java.util.List; | |
import javax.persistence.Entity; | |
import javax.persistence.Id; | |
import javax.persistence.Table; | |
import com.avaje.ebean.Query; | |
import play.data.format.Formats.DateTime; | |
import play.data.validation.Constraints; | |
import play.db.ebean.Model; | |
/* | |
* Interest can own multiple images. | |
* Message can own multiple images. | |
*/ | |
@Entity | |
@Table(name="image_info") | |
public class ImageInfo extends Model { | |
private static final long serialVersionUID = 1L; | |
@Id | |
private Long id; | |
@Constraints.Required | |
private String imageId; | |
@Constraints.Required | |
private String thumbnailId; | |
private String subjectId; | |
private String messageId; | |
private Integer width; | |
private Integer height; | |
@DateTime(pattern = "yyyy-MM-dd HH:mm:ss") | |
@Constraints.Required | |
private Date createdDate = new Date(); | |
/** | |
* Generic query helper for entity Computer with id Long | |
*/ | |
public static Finder<Long,ImageInfo> find = new Finder<Long,ImageInfo>(Long.class, ImageInfo.class); | |
public ImageInfo(String imageId, String thumbnailId) { | |
this.setImageId(imageId); | |
this.setThumbnailId(thumbnailId); | |
} | |
public Long getIdLong() { | |
return id; | |
} | |
public String getId() { | |
return id != null ? id.toString() : null; | |
} | |
public void setImageId(String imageId) { | |
this.imageId = imageId; | |
} | |
public String getImageId() { | |
return imageId; | |
} | |
public void setThumbnailId(String thumbnailId) { | |
this.thumbnailId = thumbnailId; | |
} | |
public String getThumbnailId() { | |
return thumbnailId; | |
} | |
public void setSubjectId(String subjectId) { | |
this.subjectId = subjectId; | |
} | |
public String getSubjectId() { | |
return subjectId; | |
} | |
public Integer getWidth() { | |
return width; | |
} | |
public void setWidth(Integer width) { | |
this.width = width; | |
} | |
public Integer getHeight() { | |
return height; | |
} | |
public void setHeight(Integer height) { | |
this.height = height; | |
} | |
public Date getCreatedDate() { | |
return createdDate; | |
} | |
public String getMessageId() { | |
return messageId; | |
} | |
public void setMessageId(String messageId) { | |
this.messageId = messageId; | |
} | |
public static ImageInfo getImageInfoByImageId(String imageId) { | |
ImageInfo imageInfo = find.where().eq("imageId", imageId).findUnique(); | |
return imageInfo; | |
} | |
public static List<ImageInfo> getImageInfosBySubjectId(String subjectId) { | |
List<ImageInfo> qresult = find.where().eq("subjectId", subjectId).findList(); | |
return qresult; | |
} | |
public static List<ImageInfo> getImageInfosBySubjectId(String subjectId, Date lastSyncDate) { | |
List<ImageInfo> list = null; | |
List<ImageInfo> result = new ArrayList<ImageInfo>(); | |
Query<ImageInfo> query = null; | |
if (lastSyncDate != null) { | |
query = find.where() | |
.ge("createdDate", lastSyncDate) | |
.order().desc("createdDate"); | |
} else { | |
query = find.where() | |
.order().desc("createdDate"); | |
} | |
list = query.where().eq("subjectId", subjectId).findList(); | |
result.addAll(list); | |
play.Logger.debug("get result size is : " + | |
result.size() + ", subjectId = " + subjectId); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment