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
import longevity.subdomain._ | |
case class User( | |
username: String, | |
fullname: String, | |
email: Email, | |
profile: Option[UserProfile]) | |
extends Root | |
case class UserProfile( |
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
import longevity.subdomain._ | |
case class BlogPost( | |
blog: Assoc[Blog], | |
uriSuffix: String, | |
title: String, | |
slug: Markdown, | |
content: Markdown, | |
authors: Set[Assoc[User]]) | |
extends Root |
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
import java.util.Date; | |
import javax.persistence.*; | |
import org.springframework.data.annotation.*; | |
@Entity | |
@Table( | |
name = "blog_post", | |
uniqueConstraints = @UniqueConstraint(columnNames = { "blog_id", "uriSuffix" }) | |
) | |
public class BlogPost implements Serializable { |
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
import com.github.nscala_time.time.Imports._ | |
import longevity.persistence.PState | |
import scala.concurrent.Future | |
val blogState: PState[Blog] = getBlogState() | |
import BlogPost.queryDsl._ | |
val recentPosts: Future[Seq[PState[BlogPost]]] = blogPostRepo.retrieveByQuery( | |
BlogPost.props.blog eqs blogState.assoc and | |
BlogPost.props.postDate gt DateTime.now - 1.week) |
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
import com.github.nscala_time.time.Imports._ | |
import longevity.persistence.PState | |
import longevity.subdomain.root.Query | |
import scala.concurrent.Future | |
val blogState: PState[Blog] = getBlogState() | |
val queryResult: Future[Seq[PState[BlogPost]]] = blogPostRepo.retrieveByQuery( | |
Query.and( | |
Query.eqs(BlogPost.props.blog, blogState.assoc), |
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
val userRetrieveResult: Future[Option[PState[User]]] = | |
userRepo.retrieve(userKeyVal) | |
val blogRetrieveResult: Future[Option[PState[Blog]]] = | |
blogRepo.retreieve(blogKeyVal) |
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
import longevity.subdomain.Assoc | |
import longevity.subdomain.RootType | |
import longevity.subdomain.root.Key | |
import longevity.subdomain.root.KeyVal | |
object User extends RootType[User] { | |
object props { | |
val username = prop[String]("username") | |
} | |
val usernameKey = key(props.username) |
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
userRepo.create(john) flatMap { johnState => | |
repoPool.createMany( | |
frank, | |
blog.copy(authors = Set( | |
johnState.assoc, | |
Assoc(frank))) | |
johnsPost.copy(authors = Set( | |
johnState.assoc)), | |
franksPost) | |
} |
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
val john = User("smithy", "John Smith", "smithy@john-smith.ninja") | |
val frank = User("franky", "Francis Nickerson", "franky@john-smith.ninja") | |
val jerry = User("jerry", "Jerry Jones", "jerry@john-smith.ninja") | |
val blog = Blog( | |
uri = "http://blog.john-smith.ninja/", | |
title = "The Blogging Ninjas", | |
description = "We try to keep things interesting blogging about ninjas.", | |
authors = Set(Assoc(john), Assoc(frank))) |
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 longevity.persistence | |
import longevity.subdomain.PRef | |
import longevity.subdomain.Root | |
import longevity.subdomain.root.Query | |
import scala.concurrent.Future | |
/** a repository for aggregate roots of type `R` */ | |
trait Repo[R <: Root] { |