diff --git a/project/build.scala b/project/build.scala index 51030c6..0b79bb0 100644 --- a/project/build.scala +++ b/project/build.scala @@ -38,7 +38,7 @@ "org.apache.commons" % "commons-email" % "1.3.1", "org.apache.httpcomponents" % "httpclient" % "4.3", "org.apache.sshd" % "apache-sshd" % "0.11.0", - "com.typesafe.slick" %% "slick" % "1.0.1", + "com.typesafe.slick" %% "slick" % "2.0.2", "com.novell.ldap" % "jldap" % "2009-10-07", "com.h2database" % "h2" % "1.3.173", "ch.qos.logback" % "logback-classic" % "1.0.13" % "runtime", diff --git a/src/main/scala/model/Account.scala b/src/main/scala/model/Account.scala index 8c3ff27..287bc41 100644 --- a/src/main/scala/model/Account.scala +++ b/src/main/scala/model/Account.scala @@ -1,24 +1,28 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait AccountComponent { self: Profile => + import profile.simple._ + import self._ -object Accounts extends Table[Account]("ACCOUNT") { - def userName = column[String]("USER_NAME", O PrimaryKey) - def fullName = column[String]("FULL_NAME") - def mailAddress = column[String]("MAIL_ADDRESS") - def password = column[String]("PASSWORD") - def isAdmin = column[Boolean]("ADMINISTRATOR") - def url = column[String]("URL") - def registeredDate = column[java.util.Date]("REGISTERED_DATE") - def updatedDate = column[java.util.Date]("UPDATED_DATE") - def lastLoginDate = column[java.util.Date]("LAST_LOGIN_DATE") - def image = column[String]("IMAGE") - def groupAccount = column[Boolean]("GROUP_ACCOUNT") - def removed = column[Boolean]("REMOVED") - def * = userName ~ fullName ~ mailAddress ~ password ~ isAdmin ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? ~ image.? ~ groupAccount ~ removed <> (Account, Account.unapply _) -} + lazy val Accounts = TableQuery[Accounts] -case class Account( + class Accounts(tag: Tag) extends Table[Account](tag, "ACCOUNT") { + val userName = column[String]("USER_NAME", O PrimaryKey) + val fullName = column[String]("FULL_NAME") + val mailAddress = column[String]("MAIL_ADDRESS") + val password = column[String]("PASSWORD") + val isAdmin = column[Boolean]("ADMINISTRATOR") + val url = column[String]("URL") + val registeredDate = column[java.util.Date]("REGISTERED_DATE") + val updatedDate = column[java.util.Date]("UPDATED_DATE") + val lastLoginDate = column[java.util.Date]("LAST_LOGIN_DATE") + val image = column[String]("IMAGE") + val groupAccount = column[Boolean]("GROUP_ACCOUNT") + val removed = column[Boolean]("REMOVED") + def * = (userName, fullName, mailAddress, password, isAdmin, url.?, registeredDate, updatedDate, lastLoginDate.?, image.?, groupAccount, removed) <> (Account.tupled, Account.unapply) + } + + case class Account( userName: String, fullName: String, mailAddress: String, @@ -31,4 +35,5 @@ image: Option[String], isGroupAccount: Boolean, isRemoved: Boolean -) + ) +} diff --git a/src/main/scala/model/Activity.scala b/src/main/scala/model/Activity.scala index b9d5bb5..9b8a500 100644 --- a/src/main/scala/model/Activity.scala +++ b/src/main/scala/model/Activity.scala @@ -1,25 +1,29 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait ActivityComponent extends TemplateComponent { self: Profile => + import profile.simple._ + import self._ -object Activities extends Table[Activity]("ACTIVITY") with BasicTemplate { - def activityId = column[Int]("ACTIVITY_ID", O AutoInc) - def activityUserName = column[String]("ACTIVITY_USER_NAME") - def activityType = column[String]("ACTIVITY_TYPE") - def message = column[String]("MESSAGE") - def additionalInfo = column[String]("ADDITIONAL_INFO") - def activityDate = column[java.util.Date]("ACTIVITY_DATE") - def * = activityId ~ userName ~ repositoryName ~ activityUserName ~ activityType ~ message ~ additionalInfo.? ~ activityDate <> (Activity, Activity.unapply _) - def autoInc = userName ~ repositoryName ~ activityUserName ~ activityType ~ message ~ additionalInfo.? ~ activityDate returning activityId + lazy val Activities = TableQuery[Activities] + + class Activities(tag: Tag) extends Table[Activity](tag, "ACTIVITY") with BasicTemplate { + val activityId = column[Int]("ACTIVITY_ID", O AutoInc) + val activityUserName = column[String]("ACTIVITY_USER_NAME") + val activityType = column[String]("ACTIVITY_TYPE") + val message = column[String]("MESSAGE") + val additionalInfo = column[String]("ADDITIONAL_INFO") + val activityDate = column[java.util.Date]("ACTIVITY_DATE") + def * = (activityId, userName, repositoryName, activityUserName, activityType, message, additionalInfo.?, activityDate) <> (Activity.tupled, Activity.unapply) + } + + case class Activity( + activityId: Int, + userName: String, + repositoryName: String, + activityUserName: String, + activityType: String, + message: String, + additionalInfo: Option[String], + activityDate: java.util.Date + ) } - -case class Activity( - activityId: Int, - userName: String, - repositoryName: String, - activityUserName: String, - activityType: String, - message: String, - additionalInfo: Option[String], - activityDate: java.util.Date -) diff --git a/src/main/scala/model/BasicTemplate.scala b/src/main/scala/model/BasicTemplate.scala index 2d92e64..d6800da 100644 --- a/src/main/scala/model/BasicTemplate.scala +++ b/src/main/scala/model/BasicTemplate.scala @@ -1,44 +1,47 @@ package model -import scala.slick.driver.H2Driver.simple._ +protected[model] trait TemplateComponent { self: Profile => + import profile.simple._ -protected[model] trait BasicTemplate { self: Table[_] => - def userName = column[String]("USER_NAME") - def repositoryName = column[String]("REPOSITORY_NAME") + trait BasicTemplate { self: Table[_] => + val userName = column[String]("USER_NAME") + val repositoryName = column[String]("REPOSITORY_NAME") - def byRepository(owner: String, repository: String) = - (userName is owner.bind) && (repositoryName is repository.bind) + 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) + def byRepository(userName: Column[String], repositoryName: Column[String]) = + (this.userName is userName) && (this.repositoryName is repositoryName) + } + + trait IssueTemplate extends BasicTemplate { self: Table[_] => + val 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) + } + + trait LabelTemplate extends BasicTemplate { self: Table[_] => + val 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) + } + + trait MilestoneTemplate extends BasicTemplate { self: Table[_] => + val milestoneId = column[Int]("MILESTONE_ID") + + def byMilestone(owner: String, repository: String, milestoneId: Int) = + byRepository(owner, repository) && (this.milestoneId is milestoneId.bind) + + def byMilestone(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = + byRepository(userName, repositoryName) && (this.milestoneId is milestoneId) + } + } - -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) -} - -protected[model] trait MilestoneTemplate extends BasicTemplate { self: Table[_] => - def milestoneId = column[Int]("MILESTONE_ID") - - def byMilestone(owner: String, repository: String, milestoneId: Int) = - byRepository(owner, repository) && (this.milestoneId is milestoneId.bind) - - def byMilestone(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = - byRepository(userName, repositoryName) && (this.milestoneId is milestoneId) -} \ No newline at end of file diff --git a/src/main/scala/model/Collaborator.scala b/src/main/scala/model/Collaborator.scala index f56c313..7ef52e0 100644 --- a/src/main/scala/model/Collaborator.scala +++ b/src/main/scala/model/Collaborator.scala @@ -1,17 +1,21 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait CollaboratorComponent extends TemplateComponent { self: Profile => + import profile.simple._ -object Collaborators extends Table[Collaborator]("COLLABORATOR") with BasicTemplate { - def collaboratorName = column[String]("COLLABORATOR_NAME") - def * = userName ~ repositoryName ~ collaboratorName <> (Collaborator, Collaborator.unapply _) + lazy val Collaborators = TableQuery[Collaborators] - def byPrimaryKey(owner: String, repository: String, collaborator: String) = - byRepository(owner, repository) && (collaboratorName is collaborator.bind) + class Collaborators(tag: Tag) extends Table[Collaborator](tag, "COLLABORATOR") with BasicTemplate { + val collaboratorName = column[String]("COLLABORATOR_NAME") + def * = (userName, repositoryName, collaboratorName) <> (Collaborator.tupled, Collaborator.unapply) + + def byPrimaryKey(owner: String, repository: String, collaborator: String) = + byRepository(owner, repository) && (collaboratorName is collaborator.bind) + } + + case class Collaborator( + userName: String, + repositoryName: String, + collaboratorName: String + ) } - -case class Collaborator( - userName: String, - repositoryName: String, - collaboratorName: String -) diff --git a/src/main/scala/model/GroupMembers.scala b/src/main/scala/model/GroupMembers.scala index a2a38f3..966bdba 100644 --- a/src/main/scala/model/GroupMembers.scala +++ b/src/main/scala/model/GroupMembers.scala @@ -1,16 +1,20 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait GroupMemberComponent { self: Profile => + import profile.simple._ -object GroupMembers extends Table[GroupMember]("GROUP_MEMBER") { - def groupName = column[String]("GROUP_NAME", O PrimaryKey) - def userName = column[String]("USER_NAME", O PrimaryKey) - def isManager = column[Boolean]("MANAGER") - def * = groupName ~ userName ~ isManager <> (GroupMember, GroupMember.unapply _) + lazy val GroupMembers = TableQuery[GroupMembers] + + class GroupMembers(tag: Tag) extends Table[GroupMember](tag, "GROUP_MEMBER") { + val groupName = column[String]("GROUP_NAME", O PrimaryKey) + val userName = column[String]("USER_NAME", O PrimaryKey) + val isManager = column[Boolean]("MANAGER") + def * = (groupName, userName, isManager) <> (GroupMember.tupled, GroupMember.unapply) + } + + case class GroupMember( + groupName: String, + userName: String, + isManager: Boolean + ) } - -case class GroupMember( - groupName: String, - userName: String, - isManager: Boolean -) \ No newline at end of file diff --git a/src/main/scala/model/Issue.scala b/src/main/scala/model/Issue.scala index d5ce8a3..bc594e3 100644 --- a/src/main/scala/model/Issue.scala +++ b/src/main/scala/model/Issue.scala @@ -1,32 +1,38 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait IssueComponent extends TemplateComponent { self: Profile => + import profile.simple._ + import self._ -object IssueId extends Table[(String, String, Int)]("ISSUE_ID") with IssueTemplate { - def * = userName ~ repositoryName ~ issueId - def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository) -} + lazy val IssueId = TableQuery[IssueId] + lazy val IssueOutline = TableQuery[IssueOutline] + lazy val Issues = TableQuery[Issues] -object IssueOutline extends Table[(String, String, Int, Int)]("ISSUE_OUTLINE_VIEW") with IssueTemplate { - def commentCount = column[Int]("COMMENT_COUNT") - def * = userName ~ repositoryName ~ issueId ~ commentCount -} + class IssueId(tag: Tag) extends Table[(String, String, Int)](tag, "ISSUE_ID") with IssueTemplate { + def * = (userName, repositoryName, issueId) + def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository) + } -object Issues extends Table[Issue]("ISSUE") with IssueTemplate with MilestoneTemplate { - def openedUserName = column[String]("OPENED_USER_NAME") - def assignedUserName = column[String]("ASSIGNED_USER_NAME") - def title = column[String]("TITLE") - def content = column[String]("CONTENT") - def closed = column[Boolean]("CLOSED") - def registeredDate = column[java.util.Date]("REGISTERED_DATE") - def updatedDate = column[java.util.Date]("UPDATED_DATE") - def pullRequest = column[Boolean]("PULL_REQUEST") - def * = userName ~ repositoryName ~ issueId ~ openedUserName ~ milestoneId.? ~ assignedUserName.? ~ title ~ content.? ~ closed ~ registeredDate ~ updatedDate ~ pullRequest <> (Issue, Issue.unapply _) + class IssueOutline(tag: Tag) extends Table[(String, String, Int, Int)](tag, "ISSUE_OUTLINE_VIEW") with IssueTemplate { + val commentCount = column[Int]("COMMENT_COUNT") + def * = (userName, repositoryName, issueId, commentCount) + } - def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId) -} + class Issues(tag: Tag) extends Table[Issue](tag, "ISSUE") with IssueTemplate with MilestoneTemplate { + val openedUserName = column[String]("OPENED_USER_NAME") + val assignedUserName = column[String]("ASSIGNED_USER_NAME") + val title = column[String]("TITLE") + val content = column[String]("CONTENT") + val closed = column[Boolean]("CLOSED") + val registeredDate = column[java.util.Date]("REGISTERED_DATE") + val updatedDate = column[java.util.Date]("UPDATED_DATE") + val pullRequest = column[Boolean]("PULL_REQUEST") + def * = (userName, repositoryName, issueId, openedUserName, milestoneId.?, assignedUserName.?, title, content.?, closed, registeredDate, updatedDate, pullRequest) <> (Issue.tupled, Issue.unapply) -case class Issue( + def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId) + } + + case class Issue( userName: String, repositoryName: String, issueId: Int, @@ -38,4 +44,5 @@ closed: Boolean, registeredDate: java.util.Date, updatedDate: java.util.Date, - isPullRequest: Boolean) \ No newline at end of file + isPullRequest: Boolean) +} diff --git a/src/main/scala/model/IssueComment.scala b/src/main/scala/model/IssueComment.scala index f9fd983..0641be1 100644 --- a/src/main/scala/model/IssueComment.scala +++ b/src/main/scala/model/IssueComment.scala @@ -1,21 +1,26 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait IssueCommentComponent extends TemplateComponent { self: Profile => + import profile.simple._ + import self._ -object IssueComments extends Table[IssueComment]("ISSUE_COMMENT") with IssueTemplate { - def commentId = column[Int]("COMMENT_ID", O AutoInc) - def action = column[String]("ACTION") - 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 * = userName ~ repositoryName ~ issueId ~ commentId ~ action ~ commentedUserName ~ content ~ registeredDate ~ updatedDate <> (IssueComment, IssueComment.unapply _) + lazy val IssueComments = new TableQuery(tag => new IssueComments(tag)){ + def autoInc = this returning this.map(_.commentId) + } - def autoInc = userName ~ repositoryName ~ issueId ~ action ~ commentedUserName ~ content ~ registeredDate ~ updatedDate returning commentId - def byPrimaryKey(commentId: Int) = this.commentId is commentId.bind -} + class IssueComments(tag: Tag) extends Table[IssueComment](tag, "ISSUE_COMMENT") with IssueTemplate { + val commentId = column[Int]("COMMENT_ID", O AutoInc) + val action = column[String]("ACTION") + val commentedUserName = column[String]("COMMENTED_USER_NAME") + val content = column[String]("CONTENT") + val registeredDate = column[java.util.Date]("REGISTERED_DATE") + val updatedDate = column[java.util.Date]("UPDATED_DATE") + def * = (userName, repositoryName, issueId, commentId, action, commentedUserName, content, registeredDate, updatedDate) <> (IssueComment.tupled, IssueComment.unapply) -case class IssueComment( + def byPrimaryKey(commentId: Int) = this.commentId is commentId.bind + } + + case class IssueComment( userName: String, repositoryName: String, issueId: Int, @@ -25,4 +30,5 @@ content: String, registeredDate: java.util.Date, updatedDate: java.util.Date -) \ No newline at end of file + ) +} diff --git a/src/main/scala/model/IssueLabels.scala b/src/main/scala/model/IssueLabels.scala index e26da33..413dbd7 100644 --- a/src/main/scala/model/IssueLabels.scala +++ b/src/main/scala/model/IssueLabels.scala @@ -1,15 +1,19 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait IssueLabelComponent extends TemplateComponent { self: Profile => + import profile.simple._ -object IssueLabels extends Table[IssueLabel]("ISSUE_LABEL") with IssueTemplate with LabelTemplate { - def * = userName ~ repositoryName ~ issueId ~ labelId <> (IssueLabel, IssueLabel.unapply _) - def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) = - byIssue(owner, repository, issueId) && (this.labelId is labelId.bind) + lazy val IssueLabels = TableQuery[IssueLabels] + + class IssueLabels(tag: Tag) extends Table[IssueLabel](tag, "ISSUE_LABEL") with IssueTemplate with LabelTemplate { + def * = (userName, repositoryName, issueId, labelId) <> (IssueLabel.tupled, IssueLabel.unapply) + def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) = + byIssue(owner, repository, issueId) && (this.labelId is labelId.bind) + } + + case class IssueLabel( + userName: String, + repositoryName: String, + issueId: Int, + labelId: Int) } - -case class IssueLabel( - userName: String, - repositoryName: String, - issueId: Int, - labelId: Int) \ No newline at end of file diff --git a/src/main/scala/model/Labels.scala b/src/main/scala/model/Labels.scala index 681b230..ec2744e 100644 --- a/src/main/scala/model/Labels.scala +++ b/src/main/scala/model/Labels.scala @@ -1,34 +1,37 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait LabelComponent extends TemplateComponent { self: Profile => + import profile.simple._ -object Labels extends Table[Label]("LABEL") with LabelTemplate { - def labelName = column[String]("LABEL_NAME") - def color = column[String]("COLOR") - def * = userName ~ repositoryName ~ labelId ~ labelName ~ color <> (Label, Label.unapply _) + lazy val Labels = TableQuery[Labels] - def ins = userName ~ repositoryName ~ labelName ~ color - def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId) - def byPrimaryKey(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) = byLabel(userName, repositoryName, labelId) -} + class Labels(tag: Tag) extends Table[Label](tag, "LABEL") with LabelTemplate { + override val labelId = column[Int]("LABEL_ID", O AutoInc) + val labelName = column[String]("LABEL_NAME") + val color = column[String]("COLOR") + def * = (userName, repositoryName, labelId, labelName, color) <> (Label.tupled, Label.unapply) -case class Label( - userName: String, - repositoryName: String, - labelId: Int, - labelName: String, - color: String){ - - val fontColor = { - val r = color.substring(0, 2) - val g = color.substring(2, 4) - val b = color.substring(4, 6) - - if(Integer.parseInt(r, 16) + Integer.parseInt(g, 16) + Integer.parseInt(b, 16) > 408){ - "000000" - } else { - "FFFFFF" - } + def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId) + def byPrimaryKey(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) = byLabel(userName, repositoryName, labelId) } -} \ No newline at end of file + case class Label( + userName: String, + repositoryName: String, + labelId: Int, + labelName: String, + color: String){ + + val fontColor = { + val r = color.substring(0, 2) + val g = color.substring(2, 4) + val b = color.substring(4, 6) + + if(Integer.parseInt(r, 16) + Integer.parseInt(g, 16) + Integer.parseInt(b, 16) > 408){ + "000000" + } else { + "FFFFFF" + } + } + } +} diff --git a/src/main/scala/model/Milestone.scala b/src/main/scala/model/Milestone.scala index deb0848..5ef7b17 100644 --- a/src/main/scala/model/Milestone.scala +++ b/src/main/scala/model/Milestone.scala @@ -1,24 +1,29 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait MilestoneComponent extends TemplateComponent { self: Profile => + import profile.simple._ + import self._ -object Milestones extends Table[Milestone]("MILESTONE") with MilestoneTemplate { - 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 * = userName ~ repositoryName ~ milestoneId ~ title ~ description.? ~ dueDate.? ~ closedDate.? <> (Milestone, Milestone.unapply _) + lazy val Milestones = TableQuery[Milestones] - def ins = userName ~ repositoryName ~ title ~ description.? ~ dueDate.? ~ closedDate.? - def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId) - def byPrimaryKey(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = byMilestone(userName, repositoryName, milestoneId) + class Milestones(tag: Tag) extends Table[Milestone](tag, "MILESTONE") with MilestoneTemplate { + override val milestoneId = column[Int]("MILESTONE_ID", O AutoInc) + val title = column[String]("TITLE") + val description = column[String]("DESCRIPTION") + val dueDate = column[java.util.Date]("DUE_DATE") + val closedDate = column[java.util.Date]("CLOSED_DATE") + def * = (userName, repositoryName, milestoneId, title, description.?, dueDate.?, closedDate.?) <> (Milestone.tupled, Milestone.unapply) + + def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId) + def byPrimaryKey(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = byMilestone(userName, repositoryName, milestoneId) + } + + case class Milestone( + userName: String, + repositoryName: String, + milestoneId: Int, + title: String, + description: Option[String], + dueDate: Option[java.util.Date], + closedDate: Option[java.util.Date]) } - -case class Milestone( - userName: String, - repositoryName: String, - milestoneId: Int, - title: String, - description: Option[String], - dueDate: Option[java.util.Date], - closedDate: Option[java.util.Date]) diff --git a/src/main/scala/model/Profile.scala b/src/main/scala/model/Profile.scala new file mode 100644 index 0000000..65b4e72 --- /dev/null +++ b/src/main/scala/model/Profile.scala @@ -0,0 +1,20 @@ +package model + +import slick.driver.JdbcProfile + +//private[model] +trait Profile { + val profile: JdbcProfile + import profile.simple._ + + // java.util.Date Mapped Column Types + implicit val dateColumnType = MappedColumnType.base[java.util.Date, java.sql.Timestamp]( + d => new java.sql.Timestamp(d.getTime), + t => new java.util.Date(t.getTime) + ) + + implicit class RichColumn(c1: Column[Boolean]){ + def &&(c2: => Column[Boolean], guard: => Boolean): Column[Boolean] = if(guard) c1 && c2 else c1 + } + +} diff --git a/src/main/scala/model/PullRequest.scala b/src/main/scala/model/PullRequest.scala index 0fb3205..500e8ab 100644 --- a/src/main/scala/model/PullRequest.scala +++ b/src/main/scala/model/PullRequest.scala @@ -1,28 +1,32 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait PullRequestComponent extends TemplateComponent { self: Profile => + import profile.simple._ -object PullRequests extends Table[PullRequest]("PULL_REQUEST") with IssueTemplate { - def branch = column[String]("BRANCH") - def requestUserName = column[String]("REQUEST_USER_NAME") - def requestRepositoryName = column[String]("REQUEST_REPOSITORY_NAME") - def requestBranch = column[String]("REQUEST_BRANCH") - def commitIdFrom = column[String]("COMMIT_ID_FROM") - def commitIdTo = column[String]("COMMIT_ID_TO") - def * = userName ~ repositoryName ~ issueId ~ branch ~ requestUserName ~ requestRepositoryName ~ requestBranch ~ commitIdFrom ~ commitIdTo <> (PullRequest, PullRequest.unapply _) + lazy val PullRequests = TableQuery[PullRequests] - def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) = byIssue(userName, repositoryName, issueId) - def byPrimaryKey(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) = byIssue(userName, repositoryName, issueId) + class PullRequests(tag: Tag) extends Table[PullRequest](tag, "PULL_REQUEST") with IssueTemplate { + val branch = column[String]("BRANCH") + val requestUserName = column[String]("REQUEST_USER_NAME") + val requestRepositoryName = column[String]("REQUEST_REPOSITORY_NAME") + val requestBranch = column[String]("REQUEST_BRANCH") + val commitIdFrom = column[String]("COMMIT_ID_FROM") + val commitIdTo = column[String]("COMMIT_ID_TO") + def * = (userName, repositoryName, issueId, branch, requestUserName, requestRepositoryName, requestBranch, commitIdFrom, commitIdTo) <> (PullRequest.tupled, PullRequest.unapply) + + def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) = byIssue(userName, repositoryName, issueId) + def byPrimaryKey(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) = byIssue(userName, repositoryName, issueId) + } + + case class PullRequest( + userName: String, + repositoryName: String, + issueId: Int, + branch: String, + requestUserName: String, + requestRepositoryName: String, + requestBranch: String, + commitIdFrom: String, + commitIdTo: String + ) } - -case class PullRequest( - userName: String, - repositoryName: String, - issueId: Int, - branch: String, - requestUserName: String, - requestRepositoryName: String, - requestBranch: String, - commitIdFrom: String, - commitIdTo: String -) \ No newline at end of file diff --git a/src/main/scala/model/Repository.scala b/src/main/scala/model/Repository.scala index 215b670..fe0df8a 100644 --- a/src/main/scala/model/Repository.scala +++ b/src/main/scala/model/Repository.scala @@ -1,34 +1,39 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait RepositoryComponent extends TemplateComponent { self: Profile => + import profile.simple._ + import self._ -object Repositories extends Table[Repository]("REPOSITORY") with BasicTemplate { - 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 originUserName = column[String]("ORIGIN_USER_NAME") - def originRepositoryName = column[String]("ORIGIN_REPOSITORY_NAME") - def parentUserName = column[String]("PARENT_USER_NAME") - def parentRepositoryName = column[String]("PARENT_REPOSITORY_NAME") - def * = userName ~ repositoryName ~ isPrivate ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate ~ originUserName.? ~ originRepositoryName.? ~ parentUserName.? ~ parentRepositoryName.? <> (Repository, Repository.unapply _) + lazy val Repositories = TableQuery[Repositories] - def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository) + class Repositories(tag: Tag) extends Table[Repository](tag, "REPOSITORY") with BasicTemplate { + val isPrivate = column[Boolean]("PRIVATE") + val description = column[String]("DESCRIPTION") + val defaultBranch = column[String]("DEFAULT_BRANCH") + val registeredDate = column[java.util.Date]("REGISTERED_DATE") + val updatedDate = column[java.util.Date]("UPDATED_DATE") + val lastActivityDate = column[java.util.Date]("LAST_ACTIVITY_DATE") + val originUserName = column[String]("ORIGIN_USER_NAME") + val originRepositoryName = column[String]("ORIGIN_REPOSITORY_NAME") + val parentUserName = column[String]("PARENT_USER_NAME") + val parentRepositoryName = column[String]("PARENT_REPOSITORY_NAME") + def * = (userName, repositoryName, isPrivate, description.?, defaultBranch, registeredDate, updatedDate, lastActivityDate, originUserName.?, originRepositoryName.?, parentUserName.?, parentRepositoryName.?) <> (Repository.tupled, Repository.unapply) + + def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository) + } + + case class Repository( + userName: String, + repositoryName: String, + isPrivate: Boolean, + description: Option[String], + defaultBranch: String, + registeredDate: java.util.Date, + updatedDate: java.util.Date, + lastActivityDate: java.util.Date, + originUserName: Option[String], + originRepositoryName: Option[String], + parentUserName: Option[String], + parentRepositoryName: Option[String] + ) } - -case class Repository( - userName: String, - repositoryName: String, - isPrivate: Boolean, - description: Option[String], - defaultBranch: String, - registeredDate: java.util.Date, - updatedDate: java.util.Date, - lastActivityDate: java.util.Date, - originUserName: Option[String], - originRepositoryName: Option[String], - parentUserName: Option[String], - parentRepositoryName: Option[String] -) diff --git a/src/main/scala/model/SshKey.scala b/src/main/scala/model/SshKey.scala index 39d89d4..80caf86 100644 --- a/src/main/scala/model/SshKey.scala +++ b/src/main/scala/model/SshKey.scala @@ -1,22 +1,24 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait SshKeyComponent { self: Profile => + import profile.simple._ -object SshKeys extends Table[SshKey]("SSH_KEY") { - def userName = column[String]("USER_NAME") - def sshKeyId = column[Int]("SSH_KEY_ID", O AutoInc) - def title = column[String]("TITLE") - def publicKey = column[String]("PUBLIC_KEY") + lazy val SshKeys = TableQuery[SshKeys] - def ins = userName ~ title ~ publicKey returning sshKeyId - def * = userName ~ sshKeyId ~ title ~ publicKey <> (SshKey, SshKey.unapply _) + class SshKeys(tag: Tag) extends Table[SshKey](tag, "SSH_KEY") { + val userName = column[String]("USER_NAME") + val sshKeyId = column[Int]("SSH_KEY_ID", O AutoInc) + val title = column[String]("TITLE") + val publicKey = column[String]("PUBLIC_KEY") + def * = (userName, sshKeyId, title, publicKey) <> (SshKey.tupled, SshKey.unapply) - def byPrimaryKey(userName: String, sshKeyId: Int) = (this.userName is userName.bind) && (this.sshKeyId is sshKeyId.bind) + def byPrimaryKey(userName: String, sshKeyId: Int) = (this.userName is userName.bind) && (this.sshKeyId is sshKeyId.bind) + } + + case class SshKey( + userName: String, + sshKeyId: Int, + title: String, + publicKey: String + ) } - -case class SshKey( - userName: String, - sshKeyId: Int, - title: String, - publicKey: String -) diff --git a/src/main/scala/model/WebHook.scala b/src/main/scala/model/WebHook.scala index 63b0fac..da7fb8f 100644 --- a/src/main/scala/model/WebHook.scala +++ b/src/main/scala/model/WebHook.scala @@ -1,16 +1,20 @@ package model -import scala.slick.driver.H2Driver.simple._ +trait WebHookComponent extends TemplateComponent { self: Profile => + import profile.simple._ -object WebHooks extends Table[WebHook]("WEB_HOOK") with BasicTemplate { - def url = column[String]("URL") - def * = userName ~ repositoryName ~ url <> (WebHook, WebHook.unapply _) + lazy val WebHooks = TableQuery[WebHooks] - def byPrimaryKey(owner: String, repository: String, url: String) = byRepository(owner, repository) && (this.url is url.bind) + class WebHooks(tag: Tag) extends Table[WebHook](tag, "WEB_HOOK") with BasicTemplate { + val url = column[String]("URL") + def * = (userName, repositoryName, url) <> (WebHook.tupled, WebHook.unapply) + + def byPrimaryKey(owner: String, repository: String, url: String) = byRepository(owner, repository) && (this.url is url.bind) + } + + case class WebHook( + userName: String, + repositoryName: String, + url: String + ) } - -case class WebHook( - userName: String, - repositoryName: String, - url: String -) diff --git a/src/main/scala/model/package.scala b/src/main/scala/model/package.scala index 3280c35..36a3504 100644 --- a/src/main/scala/model/package.scala +++ b/src/main/scala/model/package.scala @@ -1,20 +1,22 @@ -package object model { - import scala.slick.driver.BasicDriver.Implicit._ - import scala.slick.lifted.{Column, MappedTypeMapper} +package object model extends { + // TODO + val profile = slick.driver.H2Driver - // java.util.Date TypeMapper - implicit val dateTypeMapper = MappedTypeMapper.base[java.util.Date, java.sql.Timestamp]( - d => new java.sql.Timestamp(d.getTime), - t => new java.util.Date(t.getTime) - ) - - implicit class RichColumn(c1: Column[Boolean]){ - def &&(c2: => Column[Boolean], guard: => Boolean): Column[Boolean] = if(guard) c1 && c2 else c1 - } - +} with AccountComponent + with ActivityComponent + with CollaboratorComponent + with GroupMemberComponent + with IssueComponent + with IssueCommentComponent + with IssueLabelComponent + with LabelComponent + with MilestoneComponent + with PullRequestComponent + with RepositoryComponent + with SshKeyComponent + with WebHookComponent with Profile { /** * Returns system date. */ def currentDate = new java.util.Date() - -} \ No newline at end of file +}