Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Purge database of removed state machines #19
Browse files Browse the repository at this point in the history
  • Loading branch information
tdauth committed Apr 10, 2019
1 parent f66688e commit 5bfbc10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.collection.concurrent.TrieMap

class GuiStateMachineApiNeo4J extends GuiStateMachineApi {
private val logger = Logger[GuiStateMachineApiNeo4J]
private val stateMachines = TrieMap[String, GuiStateMachine]()
private val stateMachines = TrieMap[String, GuiStateMachineNeo4J]()
// TODO #19 Load existing state machines from the disk.

override def createStateMachine(name: String): GuiStateMachine = {
Expand All @@ -22,15 +22,12 @@ class GuiStateMachineApiNeo4J extends GuiStateMachineApi {
guiStateMachine
}

override def removeStateMachine(name: String): Boolean = stateMachines.get(name) match {
case Some(_) =>
if (stateMachines.remove(name).isDefined) {
val uri = getUri(name)
Neo4jSessionFactory.getSessionFactory(uri).close() // TODO #19 Removes from disk?
true
} else {
false
}
override def removeStateMachine(name: String): Boolean = stateMachines.remove(name) match {
case Some(stateMachine) =>
stateMachine.session.purgeDatabase()
val uri = getUri(name)
Neo4jSessionFactory.getSessionFactory(uri).close()
true
case None => false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ class GuiStateMachineNeo4J(var uri: String) extends GuiStateMachine {
result
}

override def clear(): Unit =
Neo4jSessionFactory.transaction {
// Deletes all nodes and relationships.
session.deleteAll(classOf[SutStateEntity])
session.deleteAll(classOf[ActionTransitionEntity])
}
override def clear(): Unit = session.purgeDatabase()

override def assignFrom(other: GuiStateMachine): Unit = {
// TODO #19 Should we delete the old graph database?
Expand Down

0 comments on commit 5bfbc10

Please sign in to comment.