How to create multiple database connection in scala / lift?
Domanda
I want to configure my application to send & receive data from more than one DB. How do I configure my scala-lift application to do that ?
Soluzione
Create another connection Identifier ( in Boot.scala in case of lift application, otherwise in any other class where you are configure the Database Connections ). It's just a simple object creation.
....
object SecondaryConnectionIdentifier extends ConnectionIdentifier {
def jndiName: String = "Secondary"
}
Now, in the Mapper Classes , override the dbDefaultConnectionIdentifier for example.
.....
object Dummy extends Dummy with LongKeyedMetaMapper[Dummy] {
override def dbTableName="dummy_table"
override def dbDefaultConnectionIdentifier = SecondaryConnectionIdentifier
}
that's it.
To configure your Schemifier accordingly, you can add the name of the newly created connectionIdentifier (SecondaryConnectionIdentifier in this case )
Schemifier.schemify(true, Schemifier.infoF _, SecondaryConnectionIdentifier,
<mapper-name1>,<mapper-name2>,...)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow