Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Last active December 27, 2015 07:39
Show Gist options
  • Save volgar1x/7290363 to your computer and use it in GitHub Desktop.
Save volgar1x/7290363 to your computer and use it in GitHub Desktop.
class UserRepositoryImpl extends BaseRepository[User] with UserRepository {
val executor = self.executor
val tableName = "users"
val columns = Seq("id", "name", "password", "nickname", "secret_question", "secret_answer", "community_id", "subscription_end")
protected def create(rset: ResultSet) = User(
rset.getLong("id"),
rset.getString("name"),
rset.getString("password"),
rset.getString("nickname"),
rset.getString("secret_question"),
rset.getString("secret_answer"),
rset.getInt("community_id"),
rset.getTimestamp("subscription_end"),
persisted = true
)
protected def setValues(s: PreparedStatement, o: User) {
s.setString(1, o.name)
s.setString(2, o.password)
s.setString(3, o.nickname)
s.setString(4, o.secretQuestion)
s.setString(5, o.secretAnswer)
s.setInt(6, o.communityId)
s.setTimestamp(7, o.subscriptionEnd)
}
protected def setPrimaryKey(s: PreparedStatement) = s.setLong
protected def setPersisted(o: User, rset: ResultSet) = o.copy(id = rset.getLong("id"), persisted = true)
def find(name: String): Future[User] = find("name", name)(s => s.setString) map {_ getOrElse (throw UnknownUserException())}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment