Как получить имя таблицы динамически из значения столбца другой таблицы во время выполнения в PlaySlick3.0 - PullRequest
0 голосов
/ 21 февраля 2019

Я использую конфигурацию play slick 3.0.3 и ниже в файле build.sbt:

scalaVersion := "2.12.2"

val playPac4jVersion = "7.0.0-SNAPSHOT"
val pac4jVersion = "3.4.0"
val playVersion = "2.6.6"

libraryDependencies ++= Seq(
  guice,
  ehcache, // or cacheApi
  ws,
  ws % Test,
  filters,
  specs2 % Test,
  "org.pac4j" %% "play-pac4j" % playPac4jVersion,
  "org.pac4j" % "pac4j-http" % pac4jVersion,
  "org.pac4j" % "pac4j-cas" % pac4jVersion,
  "org.pac4j" % "pac4j-openid" % pac4jVersion exclude("xml-apis" , "xml-apis"),
  "org.pac4j" % "pac4j-oauth" % pac4jVersion,
  "org.pac4j" % "pac4j-saml" % pac4jVersion,
  "org.pac4j" % "pac4j-oidc" % pac4jVersion exclude("commons-io" , "commons-io"),
  "org.pac4j" % "pac4j-gae" % pac4jVersion,
  "org.pac4j" % "pac4j-jwt" % pac4jVersion exclude("commons-io" , "commons-io"),
  "org.pac4j" % "pac4j-ldap" % pac4jVersion,
  "org.pac4j" % "pac4j-sql" % pac4jVersion,
  "org.pac4j" % "pac4j-mongo" % pac4jVersion,
  "org.pac4j" % "pac4j-kerberos" % pac4jVersion,
  "org.pac4j" % "pac4j-couch" % pac4jVersion,
  "org.apache.shiro" % "shiro-core" % "1.4.0",
  "com.typesafe.play" % "play-cache_2.12" % playVersion,
  "commons-io" % "commons-io" % "2.5",
  "com.typesafe.play" %% "play-slick" % "3.0.3",
  "io.strongtyped"%% "active-slick" % "0.3.5",
  "org.postgresql" % "postgresql" % "9.3-1104-jdbc41",
  "com.typesafe.slick" %% "slick-hikaricp" % "3.1.0",
  "com.typesafe.play" %% "play-iteratees" % "2.6.1",

  "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test,
  "org.mockito" % "mockito-core" % "2.23.0" % Test,
  "com.typesafe.akka" %% "akka-testkit" % "2.5.16" % Test,
  "com.typesafe.akka" %% "akka-stream-testkit" % "2.5.16" % Test


)

Имя таблицы, т.е. genome_template_data_term_info_15d18d1def хранится в другом Term_info_index_pointer значение столбца таблицы.Поэтому я хочу, чтобы имя таблицы извлекалось динамически из таблицы Term_info_index_pointer во время выполнения приложения.

Файл генома Dao имеет следующий код:

  class AffinitiesDao extends  ProfileProvider {

  import jdbcProfile.api._    

  type EntityTable = AffinitiesDao.AffinitiesTable

  val tableQuery = AffinitiesDao.tableQuery


  def affinitiesList ()={
    tableQuery.result
  }
  def run[R](dbioAction: DBIOAction[R, NoStream, Nothing]) = db.run(dbioAction)


}


object AffinitiesDao extends ProfileProvider {
  import jdbcProfile.api._

  val tableQuery = TableQuery[AffinitiesTable]

  class AffinitiesTable(tag: Tag) extends Table[Affinities](tag, "genome_template_data_term_info_15d18d1def") {

    def * = (affinityType, name,totalAffinityScore,averageAffinityScore,customerCount,customerCoverage,productCount,productCoverage,tfIdf,cosine) <> ((Affinities.apply _).tupled, Affinities.unapply)

    val affinityType: Rep[String] = column[String]("type", O.Length(50, varying = true))
    val name: Rep[String] = column[String]("name", O.Length(50, varying = true),O.PrimaryKey)
    val totalAffinityScore: Rep[Double] = column[Double]("corpus_affinity_score")
    val averageAffinityScore: Rep[Double] = column[Double]("average_affinity_score")
    val customerCount: Rep[Int] = column[Int]("customer_count")
    val customerCoverage: Rep[Double] = column[Double]("customer_coverage")
    val productCount: Rep[Int] = column[Int]("product_count")
    val productCoverage: Rep[Double] = column[Double]("product_coverage")
    val tfIdf: Rep[Double] = column[Double]("importance_by_pairs_tf_idf")
    val cosine: Rep[Double] = column[Double]("importance_by_pairs_cosine")

  }
}

Указатель индексаТаблица Дао приводится ниже:

class TermInfoIndexPointerDao extends  ProfileProvider {

  import jdbcProfile.api._

val baseTypedType = implicitly[BaseTypedType[Id]]

  type Entity = TermInfoIndexPointer
  type Id = Int
  type EntityTable = TermInfoIndexPointerDao.TermInfoIndexPointerTable

  val tableQuery = TermInfoIndexPointerDao.tableQuery


  def $id(table: TermInfoIndexPointerDao.TermInfoIndexPointerTable): Rep[Id] = table.id

  val idLens = lens { t: TermInfoIndexPointer => t.id } { (tr, id) => tr.copy(id = id) }

   def findByAccountId(clientId:Int)={
      tableQuery.filter { row => row.clientId === clientId }

  }

  def run[R](dbioAction: DBIOAction[R, NoStream, Nothing]) = db.run(dbioAction)


}


object TermInfoIndexPointerDao extends ProfileProvider {
  import jdbcProfile.api._

  val tableQuery = TableQuery[TermInfoIndexPointerTable]

  class TermInfoIndexPointerTable(tag: Tag) extends Table[TermInfoIndexPointer](tag, "term_info_index_pointers") {

    def * = (Rep.Some(id),clientId,tableName) <> ((TermInfoIndexPointer.apply _).tupled, TermInfoIndexPointer.unapply)

    val id: Rep[Int] = column[Int]("id",O.AutoInc, O.PrimaryKey)
    val clientId: Rep[Int] = column[Int]("client_id")
    val tableName: Rep[String] = column[String]("table_name", O.Length(500, varying = true)) 

  }
}

Я понятия не имею, как этого добиться, любая помощь будет оценена.Благодаря.

...