-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30d3fb0
commit 61f876a
Showing
16 changed files
with
147 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,7 @@ benchmark/data/ | |
/backup/ | ||
backup.zip | ||
db/ | ||
backups/ | ||
backups/ | ||
metals.sbt | ||
derby.log | ||
*report-*.json |
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
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,25 @@ | ||
package lightdb.doc | ||
|
||
import lightdb.collection.Collection | ||
import lightdb.transaction.Transaction | ||
import lightdb.trigger.BasicCollectionTrigger | ||
|
||
trait MaterializedModel[Doc <: Document[Doc], MaterialDoc <: Document[MaterialDoc], MaterialModel <: DocumentModel[MaterialDoc]] extends DocumentModel[Doc] { mm => | ||
def materialCollection: Collection[MaterialDoc, MaterialModel] | ||
|
||
protected def adding(doc: MaterialDoc)(implicit transaction: Transaction[MaterialDoc]): Unit | ||
protected def modifying(oldDoc: MaterialDoc, newDoc: MaterialDoc)(implicit transaction: Transaction[MaterialDoc]): Unit | ||
protected def removing(doc: MaterialDoc)(implicit transaction: Transaction[MaterialDoc]): Unit | ||
|
||
override def init[Model <: DocumentModel[Doc]](collection: Collection[Doc, Model]): Unit = { | ||
super.init(collection) | ||
|
||
materialCollection.trigger += new BasicCollectionTrigger[MaterialDoc, MaterialModel] { | ||
override def collection: Collection[MaterialDoc, MaterialModel] = materialCollection | ||
|
||
override protected def adding(doc: MaterialDoc)(implicit transaction: Transaction[MaterialDoc]): Unit = mm.adding(doc) | ||
override protected def modifying(oldDoc: MaterialDoc, newDoc: MaterialDoc)(implicit transaction: Transaction[MaterialDoc]): Unit = mm.modifying(oldDoc, newDoc) | ||
override protected def removing(doc: MaterialDoc)(implicit transaction: Transaction[MaterialDoc]): Unit = mm.removing(doc) | ||
} | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
core/src/main/scala/lightdb/trigger/BasicCollectionTrigger.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,33 @@ | ||
package lightdb.trigger | ||
|
||
import lightdb.UniqueIndex | ||
import lightdb.collection.Collection | ||
import lightdb.doc.{Document, DocumentModel} | ||
import lightdb.transaction.Transaction | ||
|
||
trait BasicCollectionTrigger[Doc <: Document[Doc], Model <: DocumentModel[Doc]] extends CollectionTrigger[Doc] { | ||
def collection: Collection[Doc, Model] | ||
|
||
protected def adding(doc: Doc)(implicit transaction: Transaction[Doc]): Unit | ||
|
||
protected def modifying(oldDoc: Doc, newDoc: Doc)(implicit transaction: Transaction[Doc]): Unit | ||
|
||
protected def removing(doc: Doc)(implicit transaction: Transaction[Doc]): Unit | ||
|
||
override final def insert(doc: Doc)(implicit transaction: Transaction[Doc]): Unit = adding(doc) | ||
|
||
override final def upsert(doc: Doc)(implicit transaction: Transaction[Doc]): Unit = { | ||
collection.get(doc._id) match { | ||
case Some(current) => modifying(current, doc) | ||
case None => adding(doc) | ||
} | ||
} | ||
|
||
override final def delete[V](index: UniqueIndex[Doc, V], value: V)(implicit transaction: Transaction[Doc]): Unit = { | ||
collection.query.filter(_ => index === value).iterator.foreach(removing) | ||
} | ||
|
||
override final def truncate(): Unit = collection.transaction { implicit transaction => | ||
collection.iterator.foreach(removing) | ||
} | ||
} |
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
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
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