Created
June 18, 2012 10:28
-
-
Save greenlaw110/2947784 to your computer and use it in GitHub Desktop.
How to create a play-morphia model which contains multiple gridfs blobs
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 com.google.code.morphia.annotations.Entity; | |
import play.modules.morphia.Model; | |
import java.util.List; | |
/** | |
* An album could store multiple photos persistent in the gridfs | |
*/ | |
@Entity(value = "album", noClassnameStored = true) | |
public class Album extends Model { | |
... | |
@Reference | |
public List<Asset> photos; | |
@Reference | |
public Asset frontImage; | |
@Reference | |
public Asset thumbnail; | |
... | |
} |
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 com.google.code.morphia.annotations.Entity; | |
import play.data.validation.MaxSize; | |
import play.modules.morphia.Blob; | |
import play.modules.morphia.Model; | |
import javax.activation.MimetypesFileTypeMap; | |
import java.io.File; | |
/** | |
* Store blob type assets, e.g. images, videos etc | |
*/ | |
@Entity(value = "asset", noClassnameStored = true) | |
public class Asset extends Model { | |
public Blob content; | |
@MaxSize(10000) | |
public String description; | |
public Asset(File file) { | |
content = new Blob(file); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment