-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract the DataAccessingPlugin from BasePlugin, create some helper s…
…tuff.
- Loading branch information
Showing
5 changed files
with
49 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/scala/ru/org/codingteam/horta/plugins/DataAccessingPlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ru.org.codingteam.horta.plugins | ||
|
||
import akka.util.Timeout | ||
import ru.org.codingteam.horta.database.PersistentStore | ||
import scalikejdbc.DBSession | ||
|
||
import scala.concurrent.Future | ||
|
||
/** | ||
* Trait for the plugins that can access the database. | ||
*/ | ||
trait DataAccessingPlugin[Repository <: ru.org.codingteam.horta.database.Repository] extends BasePlugin { | ||
|
||
/** | ||
* A full plugin definition. | ||
* @return plugin definition. | ||
*/ | ||
override protected def pluginDefinition: PluginDefinition = super.pluginDefinition.copy(repository = Some(repository)) | ||
|
||
/** | ||
* Repository used for data access in this plugin. | ||
*/ | ||
protected abstract val repository: Repository | ||
|
||
/** | ||
* Execute repository action. Use with caution - do not mess with plugin data members within action; that is not | ||
* context-safe. | ||
* | ||
* @param action an action. | ||
* @tparam T type of action result. | ||
* @return future that will be resolved after action execution. | ||
*/ | ||
protected def withDatabase[T](action: (Repository, DBSession) => T)(implicit timeout: Timeout): Future[T] = { | ||
PersistentStore.execute[Repository, T](name, store) { case (r, s) => action(r, s) } | ||
} | ||
|
||
private val store = context.actorSelection("/user/core/store") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters