Fix model composition.

This commit is contained in:
shimamoto
2013-06-28 15:05:15 +09:00
parent c308e1993a
commit f170aa0a04
9 changed files with 54 additions and 47 deletions

View File

@@ -1,15 +0,0 @@
package model
import scala.slick.driver.H2Driver.simple._
protected[model] abstract class BaseTable[T](_tableName: String) extends Table[T](_tableName) {
def userName = column[String]("USER_NAME")
def repositoryName = column[String]("REPOSITORY_NAME")
def base = userName ~ repositoryName
def repository(owner: String, repository: String) =
(userName is owner.bind) && (repositoryName is repository.bind)
def repository(other: BaseTable[T]) =
(userName is other.userName) && (repositoryName is other.repositoryName)
}

View File

@@ -0,0 +1,34 @@
package model
import scala.slick.driver.H2Driver.simple._
protected[model] trait BasicTemplate { self: Table[_] =>
def userName = column[String]("USER_NAME")
def repositoryName = column[String]("REPOSITORY_NAME")
def byRepository(owner: String, repository: String) =
(userName is owner.bind) && (repositoryName is repository.bind)
def byRepository(userName: Column[String], repositoryName: Column[String]) =
(this.userName is userName) && (this.repositoryName is repositoryName)
}
protected[model] trait IssueTemplate extends BasicTemplate { self: Table[_] =>
def issueId = column[Int]("ISSUE_ID")
def byIssue(owner: String, repository: String, issueId: Int) =
byRepository(owner, repository) && (this.issueId is issueId.bind)
def byIssue(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) =
byRepository(userName, repositoryName) && (this.issueId is issueId)
}
protected[model] trait LabelTemplate extends BasicTemplate { self: Table[_] =>
def labelId = column[Int]("LABEL_ID")
def byLabel(owner: String, repository: String, labelId: Int) =
byRepository(owner, repository) && (this.labelId is labelId.bind)
def byLabel(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) =
byRepository(userName, repositoryName) && (this.labelId is labelId)
}

View File

@@ -1,11 +1,10 @@
package model
import scala.slick.driver.H2Driver.simple._
import model.{BaseTable => Table}
object Collaborators extends Table[Collaborator]("COLLABORATOR") {
object Collaborators extends Table[Collaborator]("COLLABORATOR") with BasicTemplate {
def collaboratorName = column[String]("COLLABORATOR_NAME")
def * = base ~ collaboratorName <> (Collaborator, Collaborator.unapply _)
def * = userName ~ repositoryName ~ collaboratorName <> (Collaborator, Collaborator.unapply _)
}
case class Collaborator(

View File

@@ -1,15 +1,12 @@
package model
import scala.slick.driver.H2Driver.simple._
import model.{BaseTable => Table}
object IssueId extends Table[(String, String, Int)]("ISSUE_ID") {
def issueId = column[Int]("ISSUE_ID")
def * = base ~ issueId
object IssueId extends Table[(String, String, Int)]("ISSUE_ID") with IssueTemplate {
def * = userName ~ repositoryName ~ issueId
}
object Issues extends Table[Issue]("ISSUE") with Functions {
def issueId = column[Int]("ISSUE_ID")
object Issues extends Table[Issue]("ISSUE") with IssueTemplate with Functions {
def openedUserName = column[String]("OPENED_USER_NAME")
def milestoneId = column[Int]("MILESTONE_ID")
def assignedUserName = column[String]("ASSIGNED_USER_NAME")
@@ -18,7 +15,7 @@ object Issues extends Table[Issue]("ISSUE") with Functions {
def closed = column[Boolean]("CLOSED")
def registeredDate = column[java.util.Date]("REGISTERED_DATE")
def updatedDate = column[java.util.Date]("UPDATED_DATE")
def * = base ~ issueId ~ openedUserName ~ milestoneId.? ~ assignedUserName.? ~ title ~ content.? ~ closed ~ registeredDate ~ updatedDate <> (Issue, Issue.unapply _)
def * = userName ~ repositoryName ~ issueId ~ openedUserName ~ milestoneId.? ~ assignedUserName.? ~ title ~ content.? ~ closed ~ registeredDate ~ updatedDate <> (Issue, Issue.unapply _)
}
case class Issue(

View File

@@ -1,18 +1,16 @@
package model
import scala.slick.driver.H2Driver.simple._
import model.{BaseTable => Table}
object IssueComments extends Table[IssueComment]("ISSUE_COMMENT") with Functions {
def issueId = column[Int]("ISSUE_ID")
object IssueComments extends Table[IssueComment]("ISSUE_COMMENT") with IssueTemplate with Functions {
def commentId = column[Int]("COMMENT_ID", O AutoInc)
def commentedUserName = column[String]("COMMENTED_USER_NAME")
def content = column[String]("CONTENT")
def registeredDate = column[java.util.Date]("REGISTERED_DATE")
def updatedDate = column[java.util.Date]("UPDATED_DATE")
def * = base ~ issueId ~ commentId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate <> (IssueComment, IssueComment.unapply _)
def * = userName ~ repositoryName ~ issueId ~ commentId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate <> (IssueComment, IssueComment.unapply _)
def autoInc = base ~ issueId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate returning commentId
def autoInc = userName ~ repositoryName ~ issueId ~ commentedUserName ~ content ~ registeredDate ~ updatedDate returning commentId
}
case class IssueComment(

View File

@@ -1,12 +1,9 @@
package model
import scala.slick.driver.H2Driver.simple._
import model.{BaseTable => Table}
object IssueLabels extends Table[IssueLabel]("ISSUE_LABEL") {
def issueId = column[Int]("ISSUE_ID")
def labelId = column[Int]("LABEL_ID")
def * = base ~ issueId ~ labelId <> (IssueLabel, IssueLabel.unapply _)
object IssueLabels extends Table[IssueLabel]("ISSUE_LABEL") with IssueTemplate with LabelTemplate {
def * = userName ~ repositoryName ~ issueId ~ labelId <> (IssueLabel, IssueLabel.unapply _)
}
case class IssueLabel(

View File

@@ -1,14 +1,13 @@
package model
import scala.slick.driver.H2Driver.simple._
import model.{BaseTable => Table}
object Labels extends Table[Label]("LABEL") {
def labelId = column[Int]("LABEL_ID", O AutoInc)
object Labels extends Table[Label]("LABEL") with LabelTemplate {
def labelName = column[String]("LABEL_NAME")
def color = column[String]("COLOR")
def * = base ~ labelId ~ labelName ~ color <> (Label, Label.unapply _)
def ins = base ~ labelName ~ color
def * = userName ~ repositoryName ~ labelId ~ labelName ~ color <> (Label, Label.unapply _)
def ins = userName ~ repositoryName ~ labelName ~ color
}
case class Label(

View File

@@ -1,17 +1,16 @@
package model
import scala.slick.driver.H2Driver.simple._
import model.{BaseTable => Table}
object Milestones extends Table[Milestone]("MILESTONE") with Functions {
object Milestones extends Table[Milestone]("MILESTONE") with BasicTemplate with Functions {
def milestoneId = column[Int]("MILESTONE_ID", O AutoInc)
def title = column[String]("TITLE")
def description = column[String]("DESCRIPTION")
def dueDate = column[java.util.Date]("DUE_DATE")
def closedDate = column[java.util.Date]("CLOSED_DATE")
def * = base ~ milestoneId ~ title ~ description.? ~ dueDate.? ~ closedDate.? <> (Milestone, Milestone.unapply _)
def * = userName ~ repositoryName ~ milestoneId ~ title ~ description.? ~ dueDate.? ~ closedDate.? <> (Milestone, Milestone.unapply _)
def autoInc = base ~ title ~ description.? ~ dueDate.? ~ closedDate.? returning milestoneId
def autoInc = userName ~ repositoryName ~ title ~ description.? ~ dueDate.? ~ closedDate.? returning milestoneId
}
case class Milestone(

View File

@@ -1,16 +1,15 @@
package model
import scala.slick.driver.H2Driver.simple._
import model.{BaseTable => Table}
object Repositories extends Table[Repository]("REPOSITORY") with Functions {
object Repositories extends Table[Repository]("REPOSITORY") with BasicTemplate with Functions {
def isPrivate = column[Boolean]("PRIVATE")
def description = column[String]("DESCRIPTION")
def defaultBranch = column[String]("DEFAULT_BRANCH")
def registeredDate = column[java.util.Date]("REGISTERED_DATE")
def updatedDate = column[java.util.Date]("UPDATED_DATE")
def lastActivityDate = column[java.util.Date]("LAST_ACTIVITY_DATE")
def * = base ~ isPrivate ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> (Repository, Repository.unapply _)
def * = userName ~ repositoryName ~ isPrivate ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> (Repository, Repository.unapply _)
}
case class Repository(