Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from codingteam/feature/storage-refactor
New storage API
- Loading branch information
Showing
23 changed files
with
386 additions
and
503 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
11 changes: 11 additions & 0 deletions
11
src/main/scala/ru/org/codingteam/horta/database/RepositoryFactory.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,11 @@ | ||
package ru.org.codingteam.horta.database | ||
|
||
import scalikejdbc.DBSession | ||
|
||
/** | ||
* A repository factory. Will be used to create the repository. | ||
* | ||
* @param schema schema name for current repository. | ||
* @param create a repository creation function. | ||
*/ | ||
case class RepositoryFactory(schema: String, create: (DBSession => Any)) |
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
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
package ru.org.codingteam.horta.plugins | ||
|
||
import akka.util.Timeout | ||
import ru.org.codingteam.horta.database.{RepositoryFactory, PersistentStore} | ||
import scalikejdbc.DBSession | ||
|
||
import scala.concurrent.Future | ||
import scala.reflect.ClassTag | ||
|
||
/** | ||
* Trait for the plugins that can access the database. | ||
*/ | ||
trait DataAccessingPlugin[Repository] extends BasePlugin { | ||
|
||
/** | ||
* A full plugin definition. | ||
* @return plugin definition. | ||
*/ | ||
override protected def pluginDefinition: PluginDefinition = | ||
super.pluginDefinition.copy(repositoryFactory = Some(RepositoryFactory(schema, createRepository))) | ||
|
||
/** | ||
* Schema name for database storage. | ||
*/ | ||
protected val schema: String | ||
|
||
/** | ||
* A function creating the repository for database access. | ||
*/ | ||
protected val createRepository: (DBSession) => 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: ClassTag](action: (Repository) => T) | ||
(implicit timeout: Timeout): Future[T] = { | ||
PersistentStore.execute[Repository, T](name, store)(action) | ||
} | ||
|
||
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
106 changes: 0 additions & 106 deletions
106
src/main/scala/ru/org/codingteam/horta/plugins/karma/KarmaDAO.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.