本文整理汇总了Scala中com.google.inject.ImplementedBy类的典型用法代码示例。如果您正苦于以下问题:Scala ImplementedBy类的具体用法?Scala ImplementedBy怎么用?Scala ImplementedBy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImplementedBy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: add
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy, Inject}
import model.{Artist, ArtistDAO, Temp}
import play.api.libs.json.{JsValue, Json, Writes}
import play.api.Logger
import scala.concurrent.ExecutionContext
@ImplementedBy(classOf[ArtistServicesImpl])
trait ArtistServices {
def add (discActor : Artist) : Boolean
def findAllByType(value: String) : ArtistResponse
}
case class ArtistResponse(artists : List[Artist])
object ArtistResponse {
//implicit val formatter1 = Json.format[Artist]
implicit val formatter2 = Json.format[ArtistResponse]
Logger.debug("Attempting risky calculation.")
implicit val implicitFooWrites = new Writes[ArtistResponse] {
def writes(discActors : ArtistResponse): JsValue = {
Json.obj(
"artists" -> discActors.artists
)
}
}
}
class ArtistServicesImpl @Inject()(dao: ArtistDAO )(implicit ec: ExecutionContext) extends ArtistServices {
override def add(artist : Artist ): Boolean = {
if(dao.addNew(artist)!=null)
true
else
false
}
override def findAllByType(value: String): ArtistResponse = {
println("Find Artist by Name: " + value)
ArtistResponse(dao.getAllByName(value).filter(a => a.isDefined).map(a => a.get))
}
}
开发者ID:ralekar,项目名称:play-scala-casbah,代码行数:47,代码来源:ArtistServices.scala
示例2: PushService
//设置package包名称以及导入依赖的类
package push
import scala.Left
import scala.Right
import scala.concurrent.Future
import com.google.inject.ImplementedBy
import javax.inject.Inject
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.json.Json
import play.api.libs.ws.WSClient
import javax.inject.Singleton
import play.api.Configuration
@ImplementedBy(classOf[GcmPushService])
abstract class PushService {
def sendMessage(message: PushMessage): Future[Either[String, Unit]]
}
@Singleton
class GcmPushService @Inject() (ws: WSClient, conf: Configuration) extends PushService {
val endpoint = conf.getString("gcm.endpoint").get
val apiKey = conf.getString("gcm.apiKey").get
override def sendMessage(message: PushMessage): Future[Either[String, Unit]] = {
val pushRequest = ws
.url(endpoint)
.withHeaders(
"Content-Type" -> "application/json",
"Authorization" -> s"key=$apiKey")
pushRequest.post(Json.toJson(message)).map { pushResponse =>
if (pushResponse.status >= 300) {
Left(pushResponse.statusText)
} else {
Right(())
}
}
}
}
开发者ID:esurijon,项目名称:ravazzo-chat,代码行数:43,代码来源:PushService.scala
示例3: LanguageTable
//设置package包名称以及导入依赖的类
package repository
import com.google.inject.Inject
import com.google.inject.ImplementedBy
import models.Language
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfigProvider
import slick.driver.JdbcProfile
import scala.concurrent.Future
trait LanguageTable extends UserTable{ self: HasDatabaseConfigProvider[JdbcProfile] =>
import driver.api._
class LanguageTable(tag:Tag) extends Table[Language](tag,"language") {
val id=column[Int]("id")
val name= column[String]("name", O.SqlType("VARCHAR(200)"))
val fluency=column[String]("fluency", O.SqlType("VARCHAR(200)"))
def * = (id, name,fluency) <>(Language.tupled, Language.unapply)
}
val languageTableQuery = TableQuery[LanguageTable]
}
//@ImplementedBy(classOf[LanguageImpl])
class LanguageRepo @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends LanguageTable with HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
def insert(id: Int, name: String, fluency: String): Future[Int] = {
val insertQuery=languageTableQuery += Language(id, name, fluency)
db.run {insertQuery}
}
def update(id: Int, name: String, fluency: String): Future[Int] = db.run {languageTableQuery.filter(_.id === id).update(Language(id, name, fluency))}
def delete(name:String): Future[Int] = db.run { languageTableQuery.filter(_.name === name).delete}
def getAll(): Future[List[Language]] = db.run {
val test=languageTableQuery.to[List]
test.result
}
def getLanguage(id:Int): Future[Seq[Language]] = {
db.run(languageTableQuery.filter(_.id === id).result)
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:48,代码来源:LanguageRepo.scala
示例4: insertUser
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy, Inject}
import models.User
import repository.UserRepo
import scala.concurrent.Future
@ImplementedBy(classOf[UserService])
trait UserServiceApi{
def insertUser(id:Int,name:String,email:String,mobile:String,password:String):Future[Int]
def updateUser(id:Int,name:String,email:String,mobile:String,password:String):Future[Int]
def deleteUser(id:Int):Future[Int]
def getUser:Future[List[User]]
def getUserByEmail(email:String):Future[Option[User]]
}
class UserService @Inject()(user:UserRepo) extends UserServiceApi{
def insertUser(id:Int,name:String,email:String,mobile:String,password:String):Future[Int]={
user.insert(id,name,email,mobile,password)
}
def updateUser(id:Int,name:String,email:String,mobile:String,password:String):Future[Int]={
user.update(id,name,email,mobile,password )
}
def deleteUser(id:Int):Future[Int]={
user.delete(id)
}
def getUser:Future[List[User]]={
user.getAll()
}
def getUserByEmail(email:String):Future[Option[User]]={
user.getUser(email)
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:41,代码来源:UserService.scala
示例5: insertAward
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy, Inject}
import models.Award
import repository.AwardRepo
import scala.concurrent.Future
@ImplementedBy(classOf[AwardService])
trait AwardServiceApi{
def insertAward(id:Int,name:String,details:String):Future[Int]
def updateAward(id:Int,name:String,details:String):Future[Int]
def deleteAward(name:String):Future[Int]
def getAward:Future[List[Award]]
def getAwardById(id:Int):Future[Seq[Award]]
}
class AwardService @Inject()(award:AwardRepo) extends AwardServiceApi{
def insertAward(id:Int,name:String,details:String):Future[Int]={
award.insert(id,name,details)
}
def updateAward(id:Int,name:String,details:String):Future[Int]={
award.update(id,name,details)
}
def deleteAward(name:String):Future[Int]={
award.delete(name)
}
def getAward:Future[List[Award]]={
award.getAll()
}
def getAwardById(id:Int):Future[Seq[Award]]={
award.getAward(id)
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:43,代码来源:AwardService.scala
示例6: insertLanguage
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy,Inject}
import models.Language
import repository.LanguageRepo
import scala.concurrent.Future
@ImplementedBy(classOf[LanguageService])
trait LanguageServiceApi {
def insertLanguage(id: Int, name: String, fluency: String): Future[Int]
def updateLanguage(id: Int, name: String, fluency: String): Future[Int]
def deleteLanguage(name: String): Future[Int]
def getLanguage(): Future[List[Language]]
def getLanguageById(id:Int):Future[Seq[Language]]
}
class LanguageService @Inject()(language: LanguageRepo) extends LanguageServiceApi{
def insertLanguage(id: Int, name: String, fluency: String): Future[Int] = {
language.insert(id, name, fluency)
}
def updateLanguage(id: Int, name: String, fluency: String): Future[Int] = {
language.update(id, name, fluency)
}
def deleteLanguage(name:String): Future[Int] = {
language.delete(name)
}
def getLanguage(): Future[List[Language]] = {
language.getAll()
}
def getLanguageById(id:Int):Future[Seq[Language]]={
language.getLanguage(id)
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:41,代码来源:LanguageService.scala
示例7: insertAssignment
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy, Inject}
import models.Assignment
import repository.AssignmentRepo
import scala.concurrent.Future
@ImplementedBy(classOf[AssignmentService])
trait AssignmentServiceApi{
def insertAssignment(id:Int,name:String,marks:Int,remarks:String):Future[Int]
def updateAssignment(id:Int,name:String,marks:Int,remarks:String):Future[Int]
def deleteAssignment(id:Int):Future[Int]
def getAssignment:Future[List[Assignment]]
def getAssignmentById(id:Int):Future[Seq[Assignment]]
}
class AssignmentService @Inject()(assignment:AssignmentRepo) extends AssignmentServiceApi{
def insertAssignment(id:Int,name:String,marks:Int,remarks:String):Future[Int]={
assignment.insert(id,name,marks,remarks)
}
def updateAssignment(id:Int,name:String,marks:Int,remarks:String):Future[Int]={
assignment.update(id,name,marks,remarks)
}
def deleteAssignment(id:Int):Future[Int]={
assignment.delete(id)
}
def getAssignment:Future[List[Assignment]]={
assignment.getAll()
}
def getAssignmentById(id:Int):Future[Seq[Assignment]]= {
assignment.getAssignment(id)
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:40,代码来源:AssignmentService.scala
示例8: insertProg
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy, Inject}
import models.ProgLanguage
import repository.ProgLanguageRepo
import scala.concurrent.Future
@ImplementedBy(classOf[ProgLanguageService])
trait ProgLanguageApi{
def insertProg(id:Int,name:String): Future[Int]
def updateProg(id:Int,name:String): Future[Int]
def deleteProg(name:String):Future[Int]
def getProg():Future[List[ProgLanguage]]
def getProgId(id:Int):Future[Seq[ProgLanguage]]
}
class ProgLanguageService @Inject()(progLanguage:ProgLanguageRepo) extends ProgLanguageApi {
def insertProg(id:Int,name:String): Future[Int]={
progLanguage.insert(id,name)
}
def updateProg(id:Int,name:String): Future[Int]={
progLanguage.update(id,name)
}
def deleteProg(name:String):Future[Int]={
progLanguage.delete(name)
}
def getProg():Future[List[ProgLanguage]]={
progLanguage.getAll()
}
def getProgId(id:Int):Future[Seq[ProgLanguage]]={
progLanguage.getProgLanguage(id)
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:41,代码来源:ProgLanguageService.scala
示例9: getAllRecords
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy, Inject}
import models.User
import slick.lifted.Query
import scala.concurrent.Future
@ImplementedBy(classOf[AdminService])
trait AdminServiceApi{
def getAllRecords:Future[List[User]]
//def getAllRecords():Future[Seq[(Int,String,String,String,String,String,String)]]
}
class AdminService @Inject()(admin:AdminRepo) extends AdminServiceApi{
// def getAllRecords():Future[Seq[(Int,String,String,String,String,String,String)]]={
// admin.getAll().map(res=>res)
// }
def getAllRecords:Future[List[User]]={
admin.getAll()
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:22,代码来源:AdminService.scala
示例10: thankYou
//设置package包名称以及导入依赖的类
package org.ababup1192
import com.google.inject.ImplementedBy
@ImplementedBy(classOf[JapaneseSpeaker])
trait Speaker {
def thankYou(): String
}
class JapaneseSpeaker extends Speaker {
override def thankYou(): String = "?????"
}
class EnglishSpeaker extends Speaker {
override def thankYou(): String = "Thank you"
}
开发者ID:ababup1192,项目名称:GuiceTutorial,代码行数:17,代码来源:Speaker.scala
示例11: updateV4thValue
//设置package包名称以及导入依赖的类
package services
import javax.inject.{Inject, Singleton}
import com.google.inject.ImplementedBy
import models.{CalculationResult, V1thResult}
@ImplementedBy(classOf[DefaultNumberCalculationService])
trait NumberCalculationService {
def updateV4thValue(v2: Int, v3: Int, v4: Int): CalculationResult
def getV1thResult(v1: Int): V1thResult
}
@Singleton
class DefaultNumberCalculationService @Inject() (f1Container: F1Container, f2Container: F2Container) extends NumberCalculationService {
override def getV1thResult(v1: Int): V1thResult = {
val f2 = f2Container.getValueByIndex(v1)
if (f2 > 10) {
V1thResult(f2 - 10)
} else {
V1thResult(f2)
}
}
override def updateV4thValue(v2: Int, v3: Int, v4: Int): CalculationResult = {
val f1 = f1Container.getValueByIndex(v3)
if (f1 + v2 < 10) {
f2Container.writeByIndex(v4, f1+v2+10)
CalculationResult(0)
} else {
f2Container.writeByIndex(v4, f1+v2)
CalculationResult(1)
}
}
}
开发者ID:ydalekorey,项目名称:rest-calculator,代码行数:43,代码来源:NumberCalculationService.scala
示例12: store
//设置package包名称以及导入依赖的类
package dao
import javax.inject._
import com.google.inject.ImplementedBy
import play.api.db.Database
import models.Archivo
@ImplementedBy(classOf[DoobieStore])
trait FileStore {
def store(name: String, bytes: Array[Byte], hash: String): Long
def archivos(): List[Archivo]
}
class DoobieStore @Inject() (db: Database) extends FileStore {
import doobie.imports._
import cats._, cats.data._, cats.implicits._
val xa = DataSourceTransactor[IOLite](db.dataSource)
def insert(name: String, bytes: Array[Byte], hash: String): ConnectionIO[Long] =
sql"""insert into file_info(name, hash, data)
values($name, $hash, $bytes)""".update.withUniqueGeneratedKeys("id")
def all: ConnectionIO[List[Archivo]] = {
sql"""select id, name, hash, fecha from file_info""".query[Archivo].list
}
def store(name: String, bytes: Array[Byte], hash: String): Long = {
insert(name, bytes, hash).transact(xa).unsafePerformIO
}
def archivos() = all.transact(xa).unsafePerformIO
}
开发者ID:kdoomsday,项目名称:secStore,代码行数:36,代码来源:FileStore.scala
示例13: tableNames
//设置package包名称以及导入依赖的类
package au.id.tmm.senatedb.api.persistence.daos
import com.google.inject.{ImplementedBy, Inject, Singleton}
import play.api.cache.SyncCacheApi
import scalikejdbc.DB
import scalikejdbc.interpolation.SQLSyntax
@ImplementedBy(classOf[ConcreteDbStructureCache])
trait DbStructureCache {
def tableNames(): Set[String]
def columnNamesFor(tableName: String): Set[String]
def aliasedColumnNamesFor(tableNames: String*): Set[String] = {
val aliasedColumnNames = for {
tableName <- tableNames
columnName <- columnNamesFor(tableName)
} yield s"$tableName.$columnName"
aliasedColumnNames.toSet
}
def columnListFor(tableNames: String*): SQLSyntax = {
val aliasedColumnNames = aliasedColumnNamesFor(tableNames: _*)
val columnList = aliasedColumnNames
.map(aliasedColumnName => s"""$aliasedColumnName AS "$aliasedColumnName"""")
.mkString(", ")
SQLSyntax.createUnsafely(columnList)
}
}
@Singleton
class ConcreteDbStructureCache @Inject() (cacheApi: SyncCacheApi) extends DbStructureCache {
private val cacheName = "dbStructureCache"
private val tableNameCacheKey = s"$cacheName.tableNames"
private def columnNamesCacheKey(tableName: String) = s"$cacheName.columnNames.$tableName"
override def tableNames(): Set[String] =
cacheApi.getOrElseUpdate[Set[String]](tableNameCacheKey)(DB.getAllTableNames().toSet)
override def columnNamesFor(tableName: String): Set[String] =
cacheApi.getOrElseUpdate[Set[String]](columnNamesCacheKey(tableName))(DB.getColumnNames(tableName).toSet)
}
开发者ID:tmccarthy,项目名称:SenateDB,代码行数:47,代码来源:DbStructureCache.scala
示例14: findById
//设置package包名称以及导入依赖的类
package services
import java.util.UUID
import javax.inject.Inject
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import com.google.inject.ImplementedBy
import models.TablesExtend._
import forms._
import services.dao._
import org.apache.commons.codec.digest.DigestUtils
@ImplementedBy(classOf[UserAccountService])
trait UserAccountServiceLike {
def findById(id: Int): Future[Option[AccountRow]]
def findByEmail(email: String): Future[Option[AccountRow]]
def authenticate(acountdata: AccountRow): Future[Option[AccountRow]]
}
class UserAccountService @Inject()(val accountDAO: AccountDAO, LoginForm:LoginForm)
extends UserAccountServiceLike {
import UserAccountService._
def findById(id: Int): Future[Option[AccountRow]] = {
accountDAO.findById(id)
}
def findByEmail(email: String): Future[Option[AccountRow]] = {
accountDAO.findByEmail(email)
}
def authenticate(acountdata: AccountRow): Future[Option[AccountRow]] = {
accountDAO.authenticate(acountdata.email, acountdata.password)
}
}
object UserAccountService {
val STRETCH_LOOP_COUNT = 1000
def hashAndStretch(plain: String, salt: String, loopCnt: Int): String = {
var hashed: String = ""
(1 to STRETCH_LOOP_COUNT).foreach(i =>
hashed = DigestUtils.sha256Hex(hashed + plain + salt)
)
hashed
}
def createPasswordSalt(): String = {
DigestUtils.sha256Hex(UUID.randomUUID().toString())
}
}
开发者ID:bananapianist,项目名称:playfw_sample,代码行数:55,代码来源:UserAccountService.scala
示例15: getUserInfo
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy, Inject, Singleton}
import org.apache.http.HttpStatus
import play.api.Logger
import play.api.libs.json.{JsError, JsSuccess, Json}
import play.api.libs.ws.WSClient
import services.endpoints.GOAuthEndpoints
import services.exceptions.ParseException
import services.models.UserInfo
import services.status.{AuthFailure, LoginStatus, LoginSuccess}
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
@ImplementedBy(classOf[GOAuthServicesImpl])
trait OAuthServices {
def getUserInfo(accessToken: String): Future[LoginStatus[UserInfo]]
}
@Singleton
class GOAuthServicesImpl @Inject()(gOAuthEndpoints: GOAuthEndpoints, wsClient: WSClient) extends OAuthServices {
override def getUserInfo(accessToken: String): Future[LoginStatus[UserInfo]] = {
wsClient.url(gOAuthEndpoints.userInfoURL(accessToken)).get().flatMap { wsResponse =>
val status = wsResponse.status
if (status == HttpStatus.SC_OK) {
Logger.info(s"""response body as string: ${wsResponse.body}""")
val payload = Json.parse(wsResponse.body)
payload.validate[UserInfo] match {
case JsSuccess(userInfo, _) => Future.successful(LoginSuccess(userInfo))
case [email protected](errors) => Future.failed(ParseException(s"Errors while parsing the json payload into user info object: ${errors.mkString(" ")}"))
}
} else if (status == HttpStatus.SC_UNAUTHORIZED) {
Future.successful(AuthFailure)
} else {
Future.failed(new Exception("Unknown http status: " + status))
}
}
}
}
开发者ID:pamu,项目名称:blog,代码行数:41,代码来源:OAuthServices.scala
示例16: sha1
//设置package包名称以及导入依赖的类
package services
import java.security.MessageDigest
import com.google.inject.{ImplementedBy, Inject, Singleton}
@ImplementedBy(classOf[Sha1ServicesImpl])
trait Sha1Services {
def sha1(msg: String): String
}
@Singleton
class Sha1ServicesImpl @Inject() () extends Sha1Services {
override def sha1(msg: String): String = {
val crypt = MessageDigest.getInstance("SHA-1")
crypt.reset()
crypt.update(msg.getBytes("UTF-8"))
String.valueOf(crypt.digest())
}
}
开发者ID:pamu,项目名称:blog,代码行数:21,代码来源:Sha1Services.scala
示例17: runAsync
//设置package包名称以及导入依赖的类
package services.db
import javax.inject.{ Inject, Singleton }
import com.google.inject.ImplementedBy
import play.api.db.slick.DatabaseConfigProvider
import slick.dbio.{ DBIOAction, NoStream }
import slick.driver.JdbcProfile
import scala.concurrent.duration.Duration
import scala.concurrent.{ Await, Future }
@ImplementedBy(classOf[DBServiceImpl])
trait DBService {
def runAsync[R](a: DBIOAction[R, NoStream, Nothing]): Future[R]
def run[R](a: DBIOAction[R, NoStream, Nothing]): R
}
@Singleton
class DBServiceImpl @Inject() (val dbConfigProvider: DatabaseConfigProvider) extends DBService {
private val db = dbConfigProvider.get[JdbcProfile].db
def runAsync[R](a: DBIOAction[R, NoStream, Nothing]): Future[R] = {
db.run(a)
}
def run[R](a: DBIOAction[R, NoStream, Nothing]): R = {
Await.result(runAsync(a), Duration.Inf)
}
}
开发者ID:workingDog,项目名称:SilverworkReact,代码行数:32,代码来源:DBService.scala
示例18: AmazonDynamoDbConnection
//设置package包名称以及导入依赖的类
package utils
import javax.inject.Inject
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsyncClient
import com.github.dwhjames.awswrap.dynamodb.{AmazonDynamoDBScalaClient, AmazonDynamoDBScalaMapper}
import com.google.inject.ImplementedBy
import play.api.Configuration
import play.api.libs.concurrent.Execution.Implicits._
@ImplementedBy(classOf[AmazonDynamoDbConnection])
trait DynamoDbConnection {
val db: AmazonDynamoDBScalaMapper
}
class AmazonDynamoDbConnection @Inject() (configuration: Configuration) extends DynamoDbConnection {
private val credentials = new BasicAWSCredentials(
configuration.getString("aws.accessKey").get,
configuration.getString("aws.secretKey").get
)
private val sdkClient = new AmazonDynamoDBAsyncClient(credentials)
private val client = new AmazonDynamoDBScalaClient(sdkClient)
val db = AmazonDynamoDBScalaMapper(client)
}
class InMemoryDynamoDbConnection extends DynamoDbConnection {
private val sdkClient = new AmazonDynamoDBAsyncClient(new BasicAWSCredentials("FAKE_ACCESS_KEY", "FAKE_SECRET_KEY"))
sdkClient.setEndpoint("http://localhost:8000")
private val client = new AmazonDynamoDBScalaClient(sdkClient)
val db = AmazonDynamoDBScalaMapper(client)
}
开发者ID:ArchDev,项目名称:dynamodb-rest-api,代码行数:35,代码来源:AmazonDynamoDBConnection.scala
示例19: create
//设置package包名称以及导入依赖的类
package data
import javax.inject.Singleton
import com.google.inject.{ImplementedBy, Inject}
import io.getquill.{CassandraAsyncContext, SnakeCase}
import models.User
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal
@ImplementedBy(classOf[UserDaoImpl])
trait UserDao {
def create(user: User): Future[Boolean]
def find(userName: String): Future[Option[User]]
}
@Singleton
class UserDaoImpl @Inject()(val ctx: CassandraAsyncContextImpl)(implicit ec: ExecutionContext) extends UserDao {
val db = ctx
import db._
val user = (userName: String) => quote {
query[User]
.filter(u => u.name == lift(userName))
}
def find(userName: String): Future[Option[User]] = {
db.run(user(userName)).collect {
case x :: xs => Some(x)
case Nil => None
} recover {
case NonFatal(e) => None
}
}
val insert = (user: User) => quote {
query[User].insert(lift(user))
}
def create(user: User): Future[Boolean] = {
db.run(insert(user)).map(_ => true)
}
}
开发者ID:DmytroOrlov,项目名称:devgym,代码行数:47,代码来源:UserDao.scala
示例20: apply
//设置package包名称以及导入依赖的类
package service.reflection
import javax.inject.Singleton
import com.google.inject.ImplementedBy
import monix.execution.Scheduler
import org.scalatest.Suite
@ImplementedBy(classOf[ScalaRuntimeRunner])
trait RuntimeSuiteExecutor {
def apply(suiteClass: Class[Suite], solutionTrait: Class[AnyRef], solution: String)
(channel: String => Unit)
(implicit s: Scheduler): Unit
}
@Singleton
class ScalaRuntimeRunner extends RuntimeSuiteExecutor with SuiteExecution with SuiteToolbox {
def apply(suiteClass: Class[Suite], solutionTrait: Class[AnyRef], solution: String)
(channel: String => Unit)
(implicit s: Scheduler): Unit = {
val solutionInstance = createSolutionInstance(solution, solutionTrait)
executionTestSuite(suiteClass.getConstructor(solutionTrait).newInstance(solutionInstance), channel)
}
def createSolutionInstance(solution: String, solutionTrait: Class[AnyRef]): AnyRef = {
val patchedSolution = classDefPattern.replaceFirstIn(solution, s"class $userClass extends ${solutionTrait.getSimpleName} ")
val dynamicCode = s"import ${solutionTrait.getName}; $patchedSolution; new $userClass"
tb.eval(tb.parse(dynamicCode)).asInstanceOf[AnyRef]
}
}
开发者ID:DmytroOrlov,项目名称:devgym,代码行数:33,代码来源:ScalaRuntimeRunner.scala
注:本文中的com.google.inject.ImplementedBy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论