All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tototoshi.fixture.SQLFixtureScript.scala Maven / Gradle / Ivy

There is a newer version: 0.4.1
Show newest version
package com.github.tototoshi.fixture

import java.sql.Connection

// Almost taken from scalikejdbc-play-fixture
private[fixture] case class SQLFixtureScript(override val name: String, content: String) extends FixtureScript {

  private def isSetUpMarker(s: String): Boolean = s.matches("""^#.*!(SetUp|Ups).*$""")

  private def isTearDownMarker(s: String): Boolean = s.matches("""^#.*!(TearDown|Downs).*$""")

  def setUpScript: String =
    content
      .linesIterator
      .dropWhile { line => !isSetUpMarker(line) }
      .dropWhile { line => isSetUpMarker(line) }
      .takeWhile { line => !isTearDownMarker(line) }
      .mkString("\n")

  def tearDownScript: String =
    content
      .linesIterator
      .dropWhile { line => !isTearDownMarker(line) }
      .dropWhile { line => isTearDownMarker(line) }
      .mkString("\n")

  override def setUp(connection: Connection): Unit = {
    connection.prepareStatement(setUpScript).execute()
  }

  override def tearDown(connection: Connection): Unit = {
    connection.prepareStatement(tearDownScript).execute()
  }

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy