Skip to content

Instantly share code, notes, and snippets.

@j14159
Created July 27, 2014 23:19
Show Gist options
  • Save j14159/00b097487976b6486513 to your computer and use it in GitHub Desktop.
Save j14159/00b097487976b6486513 to your computer and use it in GitHub Desktop.
val databaseUrl = "postgresql://some-hostname:5432/db-name"
Class.forName("my.sql.database.driver.classname")
class BasicJdbcActor(connFac: () => Connection) extends Actor {
lazy val conn = connFac()
override def preRestart(why: Throwable, msg: Option[Any]): Unit =
try { conn.close() }
def receive = {
case anything => throw new Exception("Where's my implementation?")
}
}
def connFac = () => DriverManager.getConnection(databaseUrl)
def makeMeAnActor(sys: ActorSystem): ActorRef =
sys.actorOf(Props(new BasicJdbcActor(connFac)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment