• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Named类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中com.google.inject.name.Named的典型用法代码示例。如果您正苦于以下问题:Scala Named类的具体用法?Scala Named怎么用?Scala Named使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Named类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: StoryServiceFactory

//设置package包名称以及导入依赖的类
package io.soheila.cms.services.stories

import com.google.inject.Inject
import com.google.inject.name.Named
import io.soheila.cms.daos.StoryDAO
import io.soheila.cms.services.stories.fsm.{ Edited, Published, StoryState }


class StoryServiceFactory @Inject() (@Named("storyDAO") val storyDAO: StoryDAO, @Named("publishedStoryDAO") val publishedStory: StoryDAO) {

  private val StoryServiceMap: Map[String, StoryService] = Map(
    Published.getClass.getSimpleName -> new StoryServiceImpl(publishedStory)
  ).withDefaultValue(new StoryServiceImpl(storyDAO))

  def getStoryService(storyState: StoryState): StoryService = {
    StoryServiceMap(storyState.getClass.getSimpleName)
  }

  def getStoryService(published: Boolean): StoryService = {
    if (published) getStoryService(Published)
    else getStoryService(Edited)
  }

  def getDefaultStoryService: StoryService = {
    getStoryService(Edited)
  }

  def getPublishedStoryService: StoryService = {
    getStoryService(Published)
  }
} 
开发者ID:esfand-r,项目名称:soheila-cm,代码行数:32,代码来源:StoryServiceFactory.scala


示例2: AppDependencyModule

//设置package包名称以及导入依赖的类
package modules

import com.google.inject.name.Named
import com.google.inject.{AbstractModule, Singleton, Provides}
import com.redis.RedisClientPool
import infrastructures.SomeModelDAO
import play.api.Configuration
import services.SomeModelStore


class AppDependencyModule extends AbstractModule {

  override def configure(): Unit = {
    bind(classOf[SomeModelStore]).to(classOf[SomeModelDAO])
  }

  @Provides
  @Singleton
  @Named("some_model")
  def provideStoreDetailRedisClientPool(
    configuration: Configuration
  ): RedisClientPool = new RedisClientPool(
    configuration.getString("redis.host").get,
    configuration.getInt("redis.port").get,
    database = 1
  )
} 
开发者ID:UsrNameu1,项目名称:RedisDISample,代码行数:28,代码来源:AppDependencyModule.scala


示例3: SSEDebug

//设置package包名称以及导入依赖的类
package jobs

import java.util.UUID

import akka.actor.Actor.Receive
import akka.actor.{ Actor, ActorRef }
import com.google.inject.Inject
import com.google.inject.name.Named
import utils.actors.SSEPublisher
import play.Logger

class SSEDebug @Inject() (
  @Named("sse-publisher") ssepublish: ActorRef
) extends Actor {
  override def receive: Receive = {
    case SSEDebug.OnStart => {
      Logger.info("Sending debug Classification Start")
      ssepublish ! SSEPublisher.ClassificationStart(UUID.fromString("1298ae9d-1b2b-4465-b81c-27e230091ff7"))
    }
  }
}
object SSEDebug {
  case object OnStart
} 
开发者ID:SwaggerTagger,项目名称:octo-tagger-backend,代码行数:25,代码来源:SSEDebug.scala


示例4: CoreActor

//设置package包名称以及导入依赖的类
package play.modules.io.joaovasques.playspark.core

import akka.actor.{Actor, ActorRef}
import play.modules.io.joaovasques.playspark.akkaguice.NamedActor
import com.google.inject.{BindingAnnotation, Inject}
import com.google.inject.name.Named
import play.modules.io.joaovasques.playspark.persistence.PersistenceMessages._
import play.modules.io.joaovasques.playspark.stats.StatsMessages._
import play.modules.io.joaovasques.playspark.persistence.{MyPersistenceActor}
import play.modules.io.joaovasques.playspark.stats.StatsActor
import play.modules.io.joaovasques.playspark.spark.SparkActor
import play.modules.io.joaovasques.playspark.spark.SparkMessages._

object CoreActor extends NamedActor {
  override final val name = "CoreActor"
}

class CoreActor @Inject()(
  @Named(MyPersistenceActor.name) persistenceActor: ActorRef,
  @Named(StatsActor.name) statsActor: ActorRef,
  @Named(SparkActor.name) sparkActor: ActorRef
) extends Actor {

  private def handlePersistenceRequest: Receive = {
    case m @ (Find(_,_,_,_) | Insert(_,_) | Update(_,_,_,_,_) | Delete(_,_,_)) => persistenceActor forward m
  }

  private def handleStatsRequest: Receive = {
    case m @ (GetJobsInExecution(_) | GetCompletedJobs(_) | GetFailedJobs(_)) => statsActor forward m
  }

  private def handleSparkRequest: Receive = {
    case m @ (GetContexts() | SaveContext(_) | DeleteContext(_) | StopContext() | StartSparkJob(_,_,_)) => {
      sparkActor forward m
    }
  }

  private def unhandled: Receive = {
    case m @ _ => sender ! akka.actor.Status.Failure(new MatchError(m))
  }

  def receive = handlePersistenceRequest orElse handleStatsRequest orElse handleSparkRequest orElse unhandled
  
} 
开发者ID:zqhxuyuan,项目名称:first-player,代码行数:45,代码来源:CoreActor.scala


示例5: DigitalElementIndexModule

//设置package包名称以及导入依赖的类
package utils

import java.io.{BufferedInputStream, InputStream}
import java.nio.file.{Files, Paths}

import com.amazonaws.services.s3.{AmazonS3, AmazonS3ClientBuilder}
import com.google.inject.name.Named
import com.google.inject.{AbstractModule, Provides, Singleton}
import play.api.Logger

class DigitalElementIndexModule extends AbstractModule {

  private[this] val fileUri = "^file:(.*)".r
  private[this] val s3Uri = "^s3://([^/]+)/(.*)".r

  override def configure(): Unit = ()

  @Provides
  @Named("DigitalElementIndex")
  @Singleton
  def getIndex(@javax.inject.Inject() environmentVariables: EnvironmentVariables): DigitalElementIndex = {
    val is: InputStream = environmentVariables.digitalElementFileUri match {
      case fileUri(path) => new BufferedInputStream(Files.newInputStream(Paths.get(path)))
      case s3Uri(bucket, key) => {
        val s3: AmazonS3 = AmazonS3ClientBuilder.standard().build()
        s3.getObject(bucket, key).getObjectContent()
      }
      case _ => throw new IllegalArgumentException("Invalid digitalElementFileUri.  Must use either s3:// or file:// protocol")
    }
    Logger.info(s"Building index from ${environmentVariables.digitalElementFileUri}")
    val start = System.currentTimeMillis()
    val index = DigitalElement.buildIndex(is, ';', '\n')
    is.close()
    Logger.info(s"Indexed ${index.size} records in ${(System.currentTimeMillis() - start) / 1000} seconds")
    index
  }

} 
开发者ID:flowcommerce,项目名称:location,代码行数:39,代码来源:DigitalElementIndexModule.scala


示例6: FoodCompositionServiceImpl

//设置package包名称以及导入依赖的类
package uk.ac.ncl.openlab.intake24.foodsql.user

import javax.sql.DataSource

import anorm.{Macro, SQL, SqlParser, sqlToSimple}
import com.google.inject.name.Named
import com.google.inject.{Inject, Singleton}
import org.slf4j.LoggerFactory
import uk.ac.ncl.openlab.intake24.errors.{FoodCompositionTableError, RecordNotFound, UnexpectedDatabaseError}
import uk.ac.ncl.openlab.intake24.services.nutrition.{FoodCompositionService, NutrientDescription}
import uk.ac.ncl.openlab.intake24.sql.{SqlDataService, SqlResourceLoader}


@Singleton
class FoodCompositionServiceImpl @Inject()(@Named("intake24_foods") val dataSource: DataSource) extends FoodCompositionService with SqlDataService with SqlResourceLoader {

  private val logger = LoggerFactory.getLogger(classOf[FoodCompositionServiceImpl])

  private case class NutrientDescriptionRow(id: Long, description: String, symbol: String)

  def getSupportedNutrients(): Either[UnexpectedDatabaseError, Seq[NutrientDescription]] = tryWithConnection {
    implicit conn =>
      Right(SQL("SELECT nutrient_types.id, nutrient_types.description, nutrient_units.symbol FROM nutrient_types INNER JOIN nutrient_units ON nutrient_types.unit_id = nutrient_units.id")
        .executeQuery()
        .as(Macro.namedParser[NutrientDescriptionRow].*)
        .map {
          row => NutrientDescription(row.id, row.description, row.symbol)
        })
  }

  private case class NutrientsRow(nutrient_type_id: Long, units_per_100g: Double)

  def getFoodCompositionRecord(table_id: String, record_id: String): Either[FoodCompositionTableError, Map[Long, Double]] = tryWithConnection {
    implicit conn =>
      val validation = SQL("SELECT 1 FROM nutrient_table_records WHERE id={record_id} AND nutrient_table_id={table_id}")
        .on('record_id -> record_id, 'table_id -> table_id)
        .executeQuery().as(SqlParser.long(1).singleOpt).isDefined

      if (!validation)
        Left(RecordNotFound(new RuntimeException(s"table_id: $table_id, record_id: $record_id")))
      else {
        val rows = SQL("SELECT nutrient_type_id, units_per_100g FROM nutrient_table_records_nutrients WHERE nutrient_table_record_id={record_id} and nutrient_table_id={table_id}")
          .on('record_id -> record_id, 'table_id -> table_id)
          .as(Macro.namedParser[NutrientsRow].*)

        val result = rows.map(row => (row.nutrient_type_id -> row.units_per_100g)).toMap

        Right(result)
      }
  }

  def getEnergyKcalNutrientId(): Long = 1
} 
开发者ID:digitalinteraction,项目名称:intake24,代码行数:54,代码来源:FoodCompositionServiceImpl.scala


示例7: ImageMapServiceImpl

//设置package包名称以及导入依赖的类
package uk.ac.ncl.openlab.intake24.foodsql.user

import javax.inject.Inject
import javax.sql.DataSource

import anorm.NamedParameter.symbol
import anorm.{Macro, SQL, sqlToSimple}
import com.google.inject.Singleton
import com.google.inject.name.Named
import uk.ac.ncl.openlab.intake24.errors.{LookupError, RecordNotFound}
import uk.ac.ncl.openlab.intake24.services.fooddb.user.{ImageMapService, UserImageMap, UserImageMapObject}
import uk.ac.ncl.openlab.intake24.sql.{SqlDataService, SqlResourceLoader}

@Singleton
class ImageMapServiceImpl @Inject()(@Named("intake24_foods") val dataSource: DataSource) extends ImageMapService with SqlDataService with SqlResourceLoader {

  private case class ResultRow(id: String, base_image_path: String, object_id: Long, description: String, outline: Array[Double], overlay_image_path: String)

  private lazy val imageMapObjectsQuery = sqlFromResource("user/get_image_map_objects.sql")

  def getImageMaps(ids: Seq[String]): Either[LookupError, Seq[UserImageMap]] = tryWithConnection {
    implicit conn =>
      val result = SQL(imageMapObjectsQuery).on('ids -> ids).as(Macro.namedParser[ResultRow].*).groupBy(_.id).map {
        case (id, rows) =>
          val objects = rows.map {
            row => UserImageMapObject(row.object_id.toInt, row.description, row.overlay_image_path, row.outline)
          }
          id -> UserImageMap(rows.head.base_image_path, objects)
      }

      val missing = ids.filterNot(result.contains(_))

      if (missing.nonEmpty)
        Left(RecordNotFound(new RuntimeException(s"Missing image maps: ${missing.mkString(", ")}")))
      else
        Right(ids.map(result(_)))
  }

  def getImageMap(id: String): Either[LookupError, UserImageMap] = getImageMaps(Seq(id)).right.map {
    _.head
  }
} 
开发者ID:digitalinteraction,项目名称:intake24,代码行数:43,代码来源:ImageMapServiceImpl.scala


示例8: DrinkwareServiceImpl

//设置package包名称以及导入依赖的类
package uk.ac.ncl.openlab.intake24.foodsql.user

import java.sql.Connection
import javax.inject.Inject
import javax.sql.DataSource

import anorm.NamedParameter.symbol
import anorm.{Macro, SQL, SqlParser, sqlToSimple}
import com.google.inject.Singleton
import com.google.inject.name.Named
import uk.ac.ncl.openlab.intake24.errors.{LookupError, RecordNotFound}
import uk.ac.ncl.openlab.intake24.services.fooddb.user.DrinkwareService
import uk.ac.ncl.openlab.intake24.sql.{SqlDataService, SqlResourceLoader}
import uk.ac.ncl.openlab.intake24.{DrinkScale, DrinkwareSet, VolumeFunction, VolumeSample}

@Singleton
class DrinkwareServiceImpl @Inject()(@Named("intake24_foods") val dataSource: DataSource) extends DrinkwareService with SqlDataService with SqlResourceLoader {

  protected case class DrinkwareResultRow(id: String, scale_id: Long, description: String, guide_image_id: String,
                                          width: Int, height: Int, empty_level: Int, full_level: Int, choice_id: Int, base_image_url: String,
                                          overlay_image_url: String)

  protected case class VolumeSampleResultRow(scale_id: Long, fill: Double, volume: Double)

  private lazy val drinkwareScalesQuery = sqlFromResource("user/drinkware_scales.sql")

  private lazy val drinkwareVolumeSamplesQuery = sqlFromResource("user/drinkware_volume_samples.sql")

  def getDrinkwareSet(id: String): Either[LookupError, DrinkwareSet] = tryWithConnection {
    implicit conn =>

      conn.setAutoCommit(false)
      conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ)

      val validation = SQL("SELECT true AS v FROM drinkware_sets WHERE id={drinkware_id}").on('drinkware_id -> id).executeQuery().as(SqlParser.bool("v").singleOpt)

      if (validation.isEmpty) {
        conn.commit()
        Left(RecordNotFound(new RuntimeException(id)))
      } else {
        val result = SQL(drinkwareScalesQuery).on('drinkware_id -> id).executeQuery().as(Macro.namedParser[DrinkwareResultRow].*)

        val scale_ids = result.map(_.scale_id)

        val volume_sample_results = SQL(drinkwareVolumeSamplesQuery).on('scale_ids -> scale_ids).executeQuery().as(Macro.namedParser[VolumeSampleResultRow].*)

        val scales = result.map(r => DrinkScale(r.choice_id, r.base_image_url, r.overlay_image_url, r.width, r.height, r.empty_level, r.full_level,
          volume_sample_results.filter(_.scale_id == r.scale_id).map(s => VolumeSample(s.fill, s.volume))))

        conn.commit()
        Right(DrinkwareSet(id, result.head.description, result.head.guide_image_id, scales))
      }
  }
} 
开发者ID:digitalinteraction,项目名称:intake24,代码行数:55,代码来源:DrinkwareServiceImpl.scala


示例9: BrandNamesServiceImpl

//设置package包名称以及导入依赖的类
package uk.ac.ncl.openlab.intake24.foodsql.user

import javax.inject.Inject
import javax.sql.DataSource

import anorm._
import com.google.inject.Singleton
import com.google.inject.name.Named
import uk.ac.ncl.openlab.intake24.errors.LocalLookupError
import uk.ac.ncl.openlab.intake24.foodsql.{FirstRowValidation, FirstRowValidationClause}
import uk.ac.ncl.openlab.intake24.services.fooddb.user.BrandNamesService
import uk.ac.ncl.openlab.intake24.sql.{SqlDataService, SqlResourceLoader}

@Singleton
class BrandNamesServiceImpl @Inject()(@Named("intake24_foods") val dataSource: DataSource) extends BrandNamesService with SqlDataService with FirstRowValidation with SqlResourceLoader {

  private lazy val getBrandNamesQuery = sqlFromResource("user/get_brand_names_frv.sql")

  protected def getBrandNamesComposable(foodCode: String, locale: String)(implicit conn: java.sql.Connection): Either[LocalLookupError, Seq[String]] = {
    val result = SQL(getBrandNamesQuery).on('food_code -> foodCode, 'locale_id -> locale).executeQuery()

    parseWithLocaleAndFoodValidation(foodCode, result, SqlParser.str("name").+)(Seq(FirstRowValidationClause("name", () => Right(List()))))
  }

  def getBrandNames(foodCode: String, locale: String): Either[LocalLookupError, Seq[String]] = tryWithConnection {
    implicit conn =>
      getBrandNamesComposable(foodCode, locale)
  }
} 
开发者ID:digitalinteraction,项目名称:intake24,代码行数:30,代码来源:BrandNamesServiceImpl.scala


示例10: GuideImageServiceImpl

//设置package包名称以及导入依赖的类
package uk.ac.ncl.openlab.intake24.foodsql.user

import javax.inject.Inject
import javax.sql.DataSource

import anorm.NamedParameter.symbol
import anorm.{Macro, SQL, sqlToSimple}
import com.google.inject.Singleton
import com.google.inject.name.Named
import uk.ac.ncl.openlab.intake24.errors.{LookupError, RecordNotFound}
import uk.ac.ncl.openlab.intake24.services.fooddb.user.{GuideImageService, UserGuideImage}
import uk.ac.ncl.openlab.intake24.sql.{SqlDataService, SqlResourceLoader}

@Singleton
class GuideImageServiceImpl @Inject()(@Named("intake24_foods") val dataSource: DataSource) extends GuideImageService with SqlDataService with SqlResourceLoader {

  private case class GuideResultRow(description: String, image_map_id: String, object_id: Array[Long], object_weight: Array[Double])

  private lazy val guideImageQuery = sqlFromResource("user/get_guide_image.sql")

  def getGuideImage(id: String): Either[LookupError, UserGuideImage] = tryWithConnection {
    implicit conn =>
      withTransaction {
        val imageResult = SQL(guideImageQuery).on('id -> id).executeQuery().as(Macro.namedParser[GuideResultRow].singleOpt)

        imageResult match {
          case Some(row) => {
            Right(UserGuideImage(row.description, row.image_map_id, row.object_id.map(_.toInt).zip(row.object_weight).toMap))
          }
          case None => Left(RecordNotFound(new RuntimeException(s"Guide image $id not found")))
        }
      }
  }
} 
开发者ID:digitalinteraction,项目名称:intake24,代码行数:35,代码来源:GuideImageServiceImpl.scala


示例11: AssociatedFoodsServiceImpl

//设置package包名称以及导入依赖的类
package uk.ac.ncl.openlab.intake24.foodsql.user

import javax.inject.Inject
import javax.sql.DataSource

import anorm.{Macro, SQL, sqlToSimple}
import com.google.inject.Singleton
import com.google.inject.name.Named
import uk.ac.ncl.openlab.intake24.AssociatedFood
import uk.ac.ncl.openlab.intake24.errors.LocalLookupError
import uk.ac.ncl.openlab.intake24.foodsql.{FirstRowValidation, FirstRowValidationClause}
import uk.ac.ncl.openlab.intake24.services.fooddb.user.AssociatedFoodsService
import uk.ac.ncl.openlab.intake24.sql.{SqlDataService, SqlResourceLoader}

@Singleton
class AssociatedFoodsServiceImpl @Inject()(@Named("intake24_foods") val dataSource: DataSource) extends AssociatedFoodsService with SqlDataService with SqlResourceLoader with FirstRowValidation {

  private case class AssociatedFoodPromptsRow(associated_food_code: Option[String], associated_category_code: Option[String],
                                              text: String, link_as_main: Boolean, generic_name: String, locale_id: String, af_locale_id: String)

  private val getAssociatedFoodsQuery = sqlFromResource("user/get_associated_foods_frv.sql")

  def getAssociatedFoods(foodCode: String, locale: String): Either[LocalLookupError, Seq[AssociatedFood]] = tryWithConnection {
    implicit conn =>

      val result = SQL(getAssociatedFoodsQuery).on('food_code -> foodCode, 'locale_id -> locale).executeQuery()

      val parser = Macro.namedParser[AssociatedFoodPromptsRow].+

      def mkPrompt(row: AssociatedFoodPromptsRow) = {

        val foodOrCategory: Either[String, String] = (row.associated_food_code, row.associated_category_code) match {
          case (Some(foodCode), None) => Left(foodCode)
          case (None, Some(categoryCode)) => Right(categoryCode)
          case _ => throw new RuntimeException(s"Unexpected associated food row format: ${row.toString()}")
        }

        AssociatedFood(foodOrCategory, row.text, row.link_as_main, row.generic_name)
      }

      parseWithLocaleAndFoodValidation(foodCode, result, parser)(Seq(FirstRowValidationClause("id", () => Right(List())))).right.map {
        rows =>
          val (local, prototype) = rows.partition(_.af_locale_id == locale)

          if (local.nonEmpty)
            local.map(mkPrompt)
          else
            prototype.map(mkPrompt)
      }
  }
} 
开发者ID:digitalinteraction,项目名称:intake24,代码行数:52,代码来源:AssociatedFoodsServiceImpl.scala


示例12: AsServedSetsServiceImpl

//设置package包名称以及导入依赖的类
package uk.ac.ncl.openlab.intake24.foodsql.user

import javax.inject.Inject
import javax.sql.DataSource

import anorm.NamedParameter.symbol
import anorm.{Macro, SQL, sqlToSimple}
import com.google.inject.Singleton
import com.google.inject.name.Named
import uk.ac.ncl.openlab.intake24.errors.{LookupError, RecordNotFound}
import uk.ac.ncl.openlab.intake24.services.fooddb.user.{AsServedSetsService, UserAsServedImage, UserAsServedSet}
import uk.ac.ncl.openlab.intake24.sql.{SqlDataService, SqlResourceLoader}

@Singleton
class AsServedSetsServiceImpl @Inject()(@Named("intake24_foods") val dataSource: DataSource) extends AsServedSetsService with SqlDataService with SqlResourceLoader {

  private case class AsServedImageRow(image_path: String, thumbnail_path: String, weight: Double)

  private case class AsServedSetRow(selection_image_path: String)

  private lazy val setQuery = sqlFromResource("user/get_as_served_set.sql")

  private lazy val imagesQuery = sqlFromResource("user/get_as_served_images.sql")

  def getAsServedSet(id: String): Either[LookupError, UserAsServedSet] = tryWithConnection {
    implicit conn =>
      withTransaction {
        SQL(setQuery).on('id -> id).executeQuery().as(Macro.namedParser[AsServedSetRow].singleOpt) match {
          case Some(set) => {
            val result = SQL(imagesQuery).on('as_served_set_id -> id).executeQuery().as(Macro.namedParser[AsServedImageRow].*)
            val images = result.map(row => UserAsServedImage(row.image_path, row.thumbnail_path, row.weight))
            Right(UserAsServedSet(set.selection_image_path, images))
          }
          case None => Left(RecordNotFound(new RuntimeException(id)))
        }
      }
  }
} 
开发者ID:digitalinteraction,项目名称:intake24,代码行数:39,代码来源:AsServedSetsServiceImpl.scala


示例13: BrandNamesAdminImpl

//设置package包名称以及导入依赖的类
package uk.ac.ncl.openlab.intake24.foodsql.admin

import javax.sql.DataSource

import anorm.{SQL, sqlToSimple}
import com.google.inject.Inject
import com.google.inject.name.Named
import org.slf4j.LoggerFactory
import uk.ac.ncl.openlab.intake24.errors.{LocalLookupError, LocaleError, LocaleOrParentError}
import uk.ac.ncl.openlab.intake24.foodsql.SimpleValidation
import uk.ac.ncl.openlab.intake24.foodsql.modular.BrandNamesAdminQueries
import uk.ac.ncl.openlab.intake24.services.fooddb.admin.BrandNamesAdminService
import uk.ac.ncl.openlab.intake24.services.fooddb.user.BrandNamesService
import uk.ac.ncl.openlab.intake24.sql.SqlDataService


class BrandNamesAdminImpl @Inject()(@Named("intake24_foods") val dataSource: DataSource, brandNamesService: BrandNamesService) extends BrandNamesAdminService with BrandNamesAdminQueries with SqlDataService with SimpleValidation {
  private val logger = LoggerFactory.getLogger(classOf[BrandNamesAdminImpl])

  def deleteAllBrandNames(locale: String): Either[LocaleError, Unit] = tryWithConnection {
    implicit conn =>
      logger.debug(s"Deleting all brand definitions for locale $locale")

      withTransaction {
        validateLocale(locale).right.flatMap {
          _ =>
            SQL("DELETE FROM brands WHERE locale_id={locale_id}").on('locale_id -> locale).execute()
            Right(())
        }
      }
  }

  def createBrandNames(brandNames: Map[String, Seq[String]], locale: String): Either[LocaleOrParentError, Unit] = tryWithConnection {
    implicit conn =>
      withTransaction {
        createBrandNamesQuery(brandNames, locale)
      }
  }

  override def getBrandNames(foodCode: String, locale: String): Either[LocalLookupError, Seq[String]] =
    brandNamesService.getBrandNames(foodCode, locale)
} 
开发者ID:digitalinteraction,项目名称:intake24,代码行数:43,代码来源:BrandNamesAdminImpl.scala


示例14: AssociatedFoodsAdminImpl

//设置package包名称以及导入依赖的类
package uk.ac.ncl.openlab.intake24.foodsql.admin

import javax.sql.DataSource

import com.google.inject.name.Named
import com.google.inject.{Inject, Singleton}
import org.slf4j.LoggerFactory
import uk.ac.ncl.openlab.intake24.errors.{LocalLookupError, LocaleOrParentError, UnexpectedDatabaseError}
import uk.ac.ncl.openlab.intake24.foodsql.SimpleValidation
import uk.ac.ncl.openlab.intake24.foodsql.modular.AssociatedFoodsAdminQueries
import uk.ac.ncl.openlab.intake24.services.fooddb.admin.AssociatedFoodsAdminService
import uk.ac.ncl.openlab.intake24.services.fooddb.user.AssociatedFoodsService
import uk.ac.ncl.openlab.intake24.sql.SqlDataService
import uk.ac.ncl.openlab.intake24.{AssociatedFood, AssociatedFoodWithHeader}

@Singleton
class AssociatedFoodsAdminImpl @Inject()(@Named("intake24_foods") val dataSource: DataSource, associatedFoodsService: AssociatedFoodsService) extends AssociatedFoodsAdminService with AssociatedFoodsAdminQueries with SimpleValidation with SqlDataService {

  private val logger = LoggerFactory.getLogger(classOf[AssociatedFoodsAdminImpl])

  def getAssociatedFoodsWithHeaders(foodCode: String, locale: String): Either[LocalLookupError, Seq[AssociatedFoodWithHeader]] = tryWithConnection {
    implicit conn =>
      withTransaction {
        for (
          _ <- validateFoodAndLocale(foodCode, locale).right;
          result <- getAssociatedFoodsWithHeadersQuery(foodCode, locale).right
        ) yield result
      }
  }

  def createAssociatedFoods(assocFoods: Map[String, Seq[AssociatedFood]], locale: String): Either[LocaleOrParentError, Unit] = tryWithConnection {
    implicit conn =>
      withTransaction {
        createAssociatedFoodsQuery(assocFoods, locale)
      }
  }

  def deleteAllAssociatedFoods(locale: String): Either[UnexpectedDatabaseError, Unit] = tryWithConnection {
    implicit conn =>
      deleteAllAssociatedFoodsQuery(locale)
  }

  def updateAssociatedFoods(foodCode: String, assocFoods: Seq[AssociatedFood], locale: String): Either[LocaleOrParentError, Unit] = tryWithConnection {
    implicit conn =>
      withTransaction {
        for (
          _ <- deleteAssociatedFoodsQuery(foodCode, locale).right;
          _ <- createAssociatedFoodsQuery(Map(foodCode -> assocFoods), locale).right
        ) yield ()
      }
  }

  def getAssociatedFoods(foodCode: String, locale: String): Either[LocalLookupError, Seq[AssociatedFood]] =
    associatedFoodsService.getAssociatedFoods(foodCode, locale)
} 
开发者ID:digitalinteraction,项目名称:intake24,代码行数:56,代码来源:AssociatedFoodsAdminImpl.scala


示例15: AchievementTimerScheduler

//设置package包名称以及导入依赖的类
package achievements

import achievements.actors.TimingAchievementActor
import achievements.actors.TimingAchievementActor.ProcessTimingAchievement
import akka.actor.ActorRef
import com.google.inject.Inject
import com.google.inject.name.Named
import com.markatta.akron.{CronExpression, CronTab}
import play.api.Logger

class AchievementTimerScheduler @Inject()(
    @Named("crontab") crontab: ActorRef,
    @Named(TimingAchievementActor.name) timingAchievementActor: ActorRef
) {
  val logger = Logger(this.getClass)
  logger.info("Initializing timeing achievements...")
  AchievementDefinitionsTiming.achievements
    .foreach { achievementDefinition =>
      crontab ! CronTab.Schedule(
        timingAchievementActor,
        ProcessTimingAchievement(achievementDefinition),
        CronExpression(achievementDefinition.pattern))
    }
} 
开发者ID:partysalat,项目名称:overjizzle-bra-backend,代码行数:25,代码来源:AchievementTimerScheduler.scala


示例16: AchievementModule

//设置package包名称以及导入依赖的类
package achievements

import achievements.actors.TimingAchievementActor
import akka.actor.{ActorRef, ActorSystem}
import com.google.inject.name.Named
import com.google.inject.{AbstractModule, Provides, Singleton}
import com.markatta.akron.CronTab
import play.api.libs.concurrent.AkkaGuiceSupport

class AchievementModule extends AbstractModule with AkkaGuiceSupport{

  protected def configure: Unit =  {
    bind(classOf[AchievementTimerScheduler]).asEagerSingleton()
    bindActor[TimingAchievementActor](TimingAchievementActor.name)
  }

  @Provides
  @Singleton
  @Named("crontab")
  def getScheduler(system: ActorSystem): ActorRef = {
   system.actorOf(CronTab.props, "crontab")
  }

} 
开发者ID:partysalat,项目名称:overjizzle-bra-backend,代码行数:25,代码来源:AchievementModule.scala


示例17: CameraController

//设置package包名称以及导入依赖的类
package camera

import akka.actor.{ActorRef, ActorSystem}
import camera.TakePhotoActor.{StartSchedulingPhotos, StopSchedulingPhotos, TakePhotoForNewsFeed, TakePhotoForStream}
import com.google.inject.name.Named
import com.google.inject.{Inject, Singleton}
import play.api.mvc._

import scala.concurrent.ExecutionContext


@Singleton
class CameraController @Inject()(val system: ActorSystem, @Named("takePhotoActor") val takePhotoActor: ActorRef)(implicit exec: ExecutionContext) extends Controller {
  def takePhoto = Action {
    takePhotoActor ! TakePhotoForNewsFeed()
    Ok("Photo shoot!")
  }
  def startSchedule = Action {
    takePhotoActor ! StartSchedulingPhotos()
    Ok("start photos")
  }
  def stopSchedule = Action {
    takePhotoActor ! StopSchedulingPhotos()
    Ok("stop photos")
  }
} 
开发者ID:partysalat,项目名称:overjizzle-bra-backend,代码行数:27,代码来源:CameraController.scala


示例18: PhotoScheduler

//设置package包名称以及导入依赖的类
package camera

import akka.actor.{ActorRef, ActorSystem}
import camera.TakePhotoActor.TakePhotoForStream
import com.google.inject.Inject
import com.google.inject.name.Named
import com.typesafe.config.Config

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

class PhotoScheduler @Inject() (
                                 val system: ActorSystem,
                                 @Named(TakePhotoActor.name) val takePhotoActor: ActorRef,
                                 @Named("streamTimeout") interval:Int,
                                 config:Config
                               )(implicit ec: ExecutionContext)
{
  system.scheduler.schedule(
    0.microseconds, interval.milliseconds, takePhotoActor, TakePhotoForStream())
} 
开发者ID:partysalat,项目名称:overjizzle-bra-backend,代码行数:22,代码来源:PhotoScheduler.scala


示例19: CameraModule

//设置package包名称以及导入依赖的类
package camera

import com.google.inject.name.Named
import com.google.inject.{AbstractModule, Provides, Singleton}
import com.hopding.jrpicam.RPiCamera
import com.typesafe.config.Config
import play.api.Logger
import play.api.libs.concurrent.AkkaGuiceSupport

class CameraModule extends AbstractModule with AkkaGuiceSupport{

  protected def configure: Unit = {
    bindActor[TakePhotoActor]("takePhotoActor")
    bind(classOf[PhotoScheduler]).asEagerSingleton()
  }

  @Provides
  @Singleton
  def getCamera(config:Config): Option[RPiCamera] = {
    try {
      val camera = new RPiCamera(config.getString("camera.path"))
      camera.setWidth(500)
      camera.setHeight(281)
      camera.setTimeout(1)
      camera.turnOffThumbnail()
      camera.enableBurst()
      camera.setQuality(75)
      camera.turnOffPreview()
      Some(camera)
    } catch {
      case e: Throwable =>
        Logger.warn(s"Camera could not be initialized due to ${e.toString}")
        None
    }
  }

  @Provides
  @Named("streamFileName")
  def getStreamFileName(config:Config):String = {
    config.getString("camera.filename")
  }
 @Provides
  @Named("streamTimeout")
  def getStreamInterval(config:Config):Int = {
    config.getInt("camera.streamTimeout")
  }

} 
开发者ID:partysalat,项目名称:overjizzle-bra-backend,代码行数:49,代码来源:CameraModule.scala



注:本文中的com.google.inject.name.Named类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala SQLConf类代码示例发布时间:2022-05-23
下一篇:
Scala Silhouette类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap