object slick_generate {
def main(args: Array[String]) {
slick.codegen.SourceCodeGenerator.main(
Array("slick.driver.H2Driver", "org.postgresql.Driver", "jdbc:postgresql://localhost/journal", "src/main/scala", "journal"))
}
}
import scala.collection.JavaConversions._ // important for 'foreach'
import org.apache.commons.io.FileUtils
import java.io.File
import scala.xml._
import common._
import journal.Tables
import slick._
import slick.backend.DatabasePublisher
import slick.driver.H2Driver.api._
object journal2db2 {
def main(args: Array[String]) {
val db = Database.forURL(
"jdbc:postgresql://localhost/journal",
driver = "org.postgresql.Driver")
val roller = TableQuery[journal.Tables.Roller]
db.run(roller.map(r => (r.rollId, r.namn)) += (1, "Utfärdare"))
db.run(roller.map(r => (r.rollId, r.namn)) += (2, "Användare"))
db.close()
}
}
16:54:06.183 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Select namn16:54:06.232 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path @98394724.namn16:54:06.259 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path @98394724.roll_id16:54:06.274 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path @550668305.namn16:54:06.274 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path @550668305.roll_id16:54:06.337 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s4.namn16:54:06.337 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s4.roll_id16:54:06.352 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s3.namn16:54:06.352 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s2.namn16:54:06.352 [main] DEBUG slick.compiler.QueryCompiler - Source:| Bind| from s2: TableExpansion| table s3: Table Journal.roller : Vector[@(H2Driver.Journal.roller)<UnassignedStructuralType(@(H2Driver.Journal.roller))>]| columns: TypeMapping| 0: ProductNode| 1: Path s3.roll_id : Short'| 2: Path s3.namn : String'| select: Pure t5| value: ProductNode| 1: Path s2.roll_id : Short'| 2: Path s2.namn : String'
16:54:06.383 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s7.namn16:54:06.383 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s7.roll_id16:54:06.383 [main] DEBUG slick.compiler.QueryCompiler - After phase assignUniqueSymbols:| Bind| from s2: TableExpansion| table s3: Table Journal.roller : Vector[@t6<UnassignedStructuralType(@t6)>]| columns: TypeMapping| 0: ProductNode| 1: Path s3.roll_id : Short'| 2: Path s3.namn : String'| select: Pure t5| value: ProductNode| 1: Path s2.roll_id : Short'| 2: Path s2.namn : String'
16:54:06.383 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s3.roll_id16:54:06.383 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s3.roll_id16:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s3.namn16:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s3.namn16:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s8.roll_id16:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s9._116:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s8.namn16:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s9._216:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node ProductNode16:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node ProductNode16:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node Insert16:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type Vector[(Short', String')] to node ResultSetMapping16:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s10.namn16:54:06.399 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s10.roll_id16:54:06.399 [main] DEBUG slick.compiler.QueryCompiler - After phase insertCompiler:| ResultSetMapping : Vector[(Short', String')]| from s9: Insert : (Short', String')| table s8: Table Journal.roller : Vector[@t6<UnassignedStructuralType(@t6)>]| linear: ProductNode : (Short', String')| 1: Path s8.roll_id : Short'| 2: Path s8.namn : String'| map: ProductNode : (Short', String')| 1: InsertColumn roll_id : Short'| 0: Path s9._1 : Short'| 2: InsertColumn namn : String'| 0: Path s9._2 : String'
16:54:06.446 [main] DEBUG s.relational.ResultConverterCompiler - Compiled ResultConverter| ProductResultConverter| 1: BaseResultConverter$mcS$sp idx=1, name=roll_id : Short'| 2: SpecializedJdbcResultConverter$$anon$1 idx=2, name=namn : String'
16:54:06.446 [main] DEBUG slick.ast.Node$ - Assigned type Vector[(Short', String')] to node ResultSetMapping16:54:06.446 [main] DEBUG slick.compiler.QueryCompiler - After phase codeGen:| ResultSetMapping : Vector[(Short', String')]| from s9: CompiledStatement "merge into "Journal"."roller" ("roll_id","namn") values (?,?)" : (Short', String')| map: CompiledMapping : (Short', String')| converter: ProductResultConverter| 1: BaseResultConverter$mcS$sp idx=1, name=roll_id : Short'| 2: SpecializedJdbcResultConverter$$anon$1 idx=2, name=namn : String'
16:54:06.446 [main] DEBUG s.compiler.QueryCompilerBenchmark - ------------------- Phase: Time ---------16:54:06.461 [main] DEBUG s.compiler.QueryCompilerBenchmark - assignUniqueSymbols: 29,943800 ms16:54:06.461 [main] DEBUG s.compiler.QueryCompilerBenchmark - insertCompiler: 22,554200 ms16:54:06.461 [main] DEBUG s.compiler.QueryCompilerBenchmark - codeGen: 41,260800 ms16:54:06.461 [main] DEBUG s.compiler.QueryCompilerBenchmark - TOTAL: 93,758800 ms16:54:06.461 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s4.namn16:54:06.461 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s4.roll_id16:54:06.461 [main] DEBUG slick.compiler.QueryCompiler - Source:| Bind| from s2: TableExpansion| table s3: Table Journal.roller : Vector[@(H2Driver.Journal.roller)<UnassignedStructuralType(@(H2Driver.Journal.roller))>]| columns: TypeMapping| 0: ProductNode| 1: Path s3.roll_id : Short'| 2: Path s3.namn : String'| select: Pure t5| value: ProductNode| 1: Path s2.roll_id : Short'| 2: Path s2.namn : String'
16:54:06.461 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s7.namn16:54:06.461 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s7.roll_id16:54:06.477 [main] DEBUG slick.compiler.QueryCompiler - After phase assignUniqueSymbols:| Bind| from s2: TableExpansion| table s3: Table Journal.roller : Vector[@t6<UnassignedStructuralType(@t6)>]| columns: TypeMapping| 0: ProductNode| 1: Path s3.roll_id : Short'| 2: Path s3.namn : String'| select: Pure t5| value: ProductNode| 1: Path s2.roll_id : Short'| 2: Path s2.namn : String'
16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s3.roll_id16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s3.roll_id16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s3.namn16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s3.namn16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s8.roll_id16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s9._116:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s8.namn16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s9._216:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node ProductNode16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node ProductNode16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node Insert16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type Vector[(Short', String')] to node ResultSetMapping16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s10.namn16:54:06.477 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s10.roll_id16:54:06.477 [main] DEBUG slick.compiler.QueryCompiler - After phase insertCompiler:| ResultSetMapping : Vector[(Short', String')]| from s9: Insert : (Short', String')| table s8: Table Journal.roller : Vector[@t6<UnassignedStructuralType(@t6)>]| linear: ProductNode : (Short', String')| 1: Path s8.roll_id : Short'| 2: Path s8.namn : String'| map: ProductNode : (Short', String')| 1: InsertColumn roll_id : Short'| 0: Path s9._1 : Short'| 2: InsertColumn namn : String'| 0: Path s9._2 : String'
16:54:06.477 [main] DEBUG s.relational.ResultConverterCompiler - Compiled ResultConverter| ProductResultConverter| 1: BaseResultConverter$mcS$sp idx=1, name=roll_id : Short'| 2: SpecializedJdbcResultConverter$$anon$1 idx=2, name=namn : String'
16:54:06.493 [main] DEBUG slick.ast.Node$ - Assigned type Vector[(Short', String')] to node ResultSetMapping16:54:06.493 [main] DEBUG slick.compiler.QueryCompiler - After phase codeGen:| ResultSetMapping : Vector[(Short', String')]| from s9: CompiledStatement "insert into "Journal"."roller" ("roll_id","namn") values (?,?)" : (Short', String')| map: CompiledMapping : (Short', String')| converter: ProductResultConverter| 1: BaseResultConverter$mcS$sp idx=1, name=roll_id : Short'| 2: SpecializedJdbcResultConverter$$anon$1 idx=2, name=namn : String'
16:54:06.493 [main] DEBUG s.compiler.QueryCompilerBenchmark - ------------------- Phase: Time ---------16:54:06.493 [main] DEBUG s.compiler.QueryCompilerBenchmark - assignUniqueSymbols: 5,422500 ms16:54:06.493 [main] DEBUG s.compiler.QueryCompilerBenchmark - insertCompiler: 11,216900 ms16:54:06.493 [main] DEBUG s.compiler.QueryCompilerBenchmark - codeGen: 13,980800 ms16:54:06.493 [main] DEBUG s.compiler.QueryCompilerBenchmark - TOTAL: 30,620200 ms16:54:06.508 [main] DEBUG s.backend.DatabaseComponent.action - #1: += [insert into "Journal"."roller" ("roll_id","namn") values (?,?)]
16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path @257513673.namn16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path @257513673.roll_id16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s4.namn16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s4.roll_id16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s2.namn16:54:06.524 [main] DEBUG slick.compiler.QueryCompiler - Source:| Bind| from s2: TableExpansion| table s3: Table Journal.roller : Vector[@(H2Driver.Journal.roller)<UnassignedStructuralType(@(H2Driver.Journal.roller))>]| columns: TypeMapping| 0: ProductNode| 1: Path s3.roll_id : Short'| 2: Path s3.namn : String'| select: Pure t5| value: ProductNode| 1: Path s2.roll_id : Short'| 2: Path s2.namn : String'
16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s7.namn16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s7.roll_id16:54:06.524 [main] DEBUG slick.compiler.QueryCompiler - After phase assignUniqueSymbols:| Bind| from s2: TableExpansion| table s3: Table Journal.roller : Vector[@t6<UnassignedStructuralType(@t6)>]| columns: TypeMapping| 0: ProductNode| 1: Path s3.roll_id : Short'| 2: Path s3.namn : String'| select: Pure t5| value: ProductNode| 1: Path s2.roll_id : Short'| 2: Path s2.namn : String'
16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s3.roll_id16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s3.roll_id16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s3.namn16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s3.namn16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s8.roll_id16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s9._116:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s8.namn16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s9._216:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node ProductNode16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node ProductNode16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node Insert16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type Vector[(Short', String')] to node ResultSetMapping16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s10.namn16:54:06.524 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s10.roll_id16:54:06.555 [main] DEBUG slick.compiler.QueryCompiler - After phase insertCompiler:| ResultSetMapping : Vector[(Short', String')]| from s9: Insert : (Short', String')| table s8: Table Journal.roller : Vector[@t6<UnassignedStructuralType(@t6)>]| linear: ProductNode : (Short', String')| 1: Path s8.roll_id : Short'| 2: Path s8.namn : String'| map: ProductNode : (Short', String')| 1: InsertColumn roll_id : Short'| 0: Path s9._1 : Short'| 2: InsertColumn namn : String'| 0: Path s9._2 : String'
16:54:06.555 [main] DEBUG s.relational.ResultConverterCompiler - Compiled ResultConverter| ProductResultConverter| 1: BaseResultConverter$mcS$sp idx=1, name=roll_id : Short'| 2: SpecializedJdbcResultConverter$$anon$1 idx=2, name=namn : String'
16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type Vector[(Short', String')] to node ResultSetMapping16:54:06.555 [main] DEBUG slick.compiler.QueryCompiler - After phase codeGen:| ResultSetMapping : Vector[(Short', String')]| from s9: CompiledStatement "merge into "Journal"."roller" ("roll_id","namn") values (?,?)" : (Short', String')| map: CompiledMapping : (Short', String')| converter: ProductResultConverter| 1: BaseResultConverter$mcS$sp idx=1, name=roll_id : Short'| 2: SpecializedJdbcResultConverter$$anon$1 idx=2, name=namn : String'
16:54:06.555 [main] DEBUG s.compiler.QueryCompilerBenchmark - ------------------- Phase: Time ---------16:54:06.555 [main] DEBUG s.compiler.QueryCompilerBenchmark - assignUniqueSymbols: 3,258900 ms16:54:06.555 [main] DEBUG s.compiler.QueryCompilerBenchmark - insertCompiler: 20,123300 ms16:54:06.555 [main] DEBUG s.compiler.QueryCompilerBenchmark - codeGen: 6,788000 ms16:54:06.555 [main] DEBUG s.compiler.QueryCompilerBenchmark - TOTAL: 30,170200 ms16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s4.namn16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s4.roll_id16:54:06.555 [main] DEBUG slick.compiler.QueryCompiler - Source:| Bind| from s2: TableExpansion| table s3: Table Journal.roller : Vector[@(H2Driver.Journal.roller)<UnassignedStructuralType(@(H2Driver.Journal.roller))>]| columns: TypeMapping| 0: ProductNode| 1: Path s3.roll_id : Short'| 2: Path s3.namn : String'| select: Pure t5| value: ProductNode| 1: Path s2.roll_id : Short'| 2: Path s2.namn : String'
16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s7.namn16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s7.roll_id16:54:06.555 [main] DEBUG slick.compiler.QueryCompiler - After phase assignUniqueSymbols:| Bind| from s2: TableExpansion| table s3: Table Journal.roller : Vector[@t6<UnassignedStructuralType(@t6)>]| columns: TypeMapping| 0: ProductNode| 1: Path s3.roll_id : Short'| 2: Path s3.namn : String'| select: Pure t5| value: ProductNode| 1: Path s2.roll_id : Short'| 2: Path s2.namn : String'
16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s3.roll_id16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s3.roll_id16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s3.namn16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s3.namn16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s8.roll_id16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s9._116:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s8.namn16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s9._216:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node ProductNode16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node ProductNode16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type (Short', String') to node Insert16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type Vector[(Short', String')] to node ResultSetMapping16:54:06.555 [main] DEBUG slick.ast.Node$ - Assigned type String' to node Path s10.namn16:54:06.571 [main] DEBUG slick.ast.Node$ - Assigned type Short' to node Path s10.roll_id16:54:06.571 [main] DEBUG slick.compiler.QueryCompiler - After phase insertCompiler:| ResultSetMapping : Vector[(Short', String')]| from s9: Insert : (Short', String')| table s8: Table Journal.roller : Vector[@t6<UnassignedStructuralType(@t6)>]| linear: ProductNode : (Short', String')| 1: Path s8.roll_id : Short'| 2: Path s8.namn : String'| map: ProductNode : (Short', String')| 1: InsertColumn roll_id : Short'| 0: Path s9._1 : Short'| 2: InsertColumn namn : String'| 0: Path s9._2 : String'
16:54:06.571 [main] DEBUG s.relational.ResultConverterCompiler - Compiled ResultConverter| ProductResultConverter| 1: BaseResultConverter$mcS$sp idx=1, name=roll_id : Short'| 2: SpecializedJdbcResultConverter$$anon$1 idx=2, name=namn : String'
16:54:06.571 [main] DEBUG slick.ast.Node$ - Assigned type Vector[(Short', String')] to node ResultSetMapping16:54:06.586 [main] DEBUG slick.compiler.QueryCompiler - After phase codeGen:| ResultSetMapping : Vector[(Short', String')]| from s9: CompiledStatement "insert into "Journal"."roller" ("roll_id","namn") values (?,?)" : (Short', String')| map: CompiledMapping : (Short', String')| converter: ProductResultConverter| 1: BaseResultConverter$mcS$sp idx=1, name=roll_id : Short'| 2: SpecializedJdbcResultConverter$$anon$1 idx=2, name=namn : String'
16:54:06.586 [main] DEBUG s.compiler.QueryCompilerBenchmark - ------------------- Phase: Time ---------16:54:06.586 [main] DEBUG s.compiler.QueryCompilerBenchmark - assignUniqueSymbols: 1,938700 ms16:54:06.586 [main] DEBUG s.compiler.QueryCompilerBenchmark - insertCompiler: 14,267000 ms16:54:06.586 [main] DEBUG s.compiler.QueryCompilerBenchmark - codeGen: 5,892700 ms16:54:06.586 [main] DEBUG s.compiler.QueryCompilerBenchmark - TOTAL: 22,098400 ms16:54:06.586 [main] DEBUG s.backend.DatabaseComponent.action - #1: += [insert into "Journal"."roller" ("roll_id","namn") values (?,?)]
16:54:06.602 [AsyncExecutor.default-2] DEBUG slick.jdbc.JdbcBackend.statement - Preparing statement: insert into "Journal"."roller" ("roll_id","namn") values (?,?)16:54:06.617 [AsyncExecutor.default-1] DEBUG slick.jdbc.JdbcBackend.statement - Preparing statement: insert into "Journal"."roller" ("roll_id","namn") values (?,?)
db.run returns a Future without waiting for it to run. I'm not sure how db.close works but it may be closing the database before the Futures compete. You need to use Await.result (or .ready).
--
---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/c9bdc2a8-8625-4773-a2e4-a15d7065d744%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import scala.collection.JavaConversions._ // important for 'foreach'
import org.apache.commons.io.FileUtils
import java.io.File
import scala.xml._
import common._
import journal.Tables
import slick._
import slick.backend.DatabasePublisher
import slick.driver.H2Driver.api._
import scala.concurrent.{ Future, Await }
import scala.concurrent.duration.Duration
object journal2db2 {
def main(args: Array[String]) {
val db = Database.forURL(
"jdbc:postgresql://localhost/journal",
driver = "org.postgresql.Driver")
val roller = TableQuery[journal.Tables.Roller]
try {
val rollerQuery = roller.countDistinct
val cnt = Query(rollerQuery)
if (cnt == 0) {
val setupAction: DBIO[Unit] = DBIO.seq(
roller.map(r => (r.rollId, r.namn)) += (1, "Utfärdare"),
roller.map(r => (r.rollId, r.namn)) += (2, "Användare"))
val setupFuture: Future[Unit] = db.run(setupAction)
Await.result(setupFuture, Duration.Inf)
}
} finally {
db.close()
}
}
}