本文整理汇总了Scala中com.google.inject.ImplementedBy类的典型用法代码示例。如果您正苦于以下问题:Scala ImplementedBy类的具体用法?Scala ImplementedBy怎么用?Scala ImplementedBy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImplementedBy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
}
示例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(())
}
}
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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()
}
}
示例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"
}
示例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)
}
}
}
示例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
}
示例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)
}
示例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())
}
}
示例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))
}
}
}
}