Created
January 3, 2012 09:42
-
-
Save makotan/1554280 to your computer and use it in GitHub Desktop.
Scala版Buri構想・・・第一版 rev10
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
@RunWith(classOf[JUnitRunner]) | |
class Sample01 extends FunSuite { | |
import sburi._ | |
import scala.reflect.BeanInfo | |
@BeanInfo | |
class Sample01Entity( | |
var id:Long = 0 , | |
var name : String = "" , | |
var status : String = "") | |
class Sample01EntityPersistentPlugin extends PersistentPlugin[Sample01Entity,Long] { | |
import scala.collection.mutable.HashMap | |
val repo = new HashMap[Long,Sample01Entity] | |
var idGen = 0; | |
def setStatus(e :Sample01Entity , state : String) { | |
e.status = state | |
} | |
def save(e :Sample01Entity) = { | |
if(e.id == 0) { | |
idGen += 1 | |
e.id = idGen | |
} | |
repo += ((e.id,e)) | |
} | |
def getStatus(e :Sample01Entity) :Option[String] = { | |
e.status match { | |
case null => None | |
case "" => None | |
case status => Some(status) | |
} | |
} | |
def get(id:Long) : Option[Sample01Entity] = { | |
repo.get(id) | |
} | |
} | |
class Process01 extends BuriBuilder("process01") { | |
type IdType = Long | |
type Entity = Sample01Entity | |
val persistent = new Sample01EntityPersistentPlugin() | |
import sburi.TransitBuilder._ | |
val actStart = StartActivity("Start") | |
val processAct = new Activity("Process") with Procedure[Entity] { | |
override def process(entity: Entity) = { | |
// any process | |
} | |
} | |
val statusAct = new Activity("保存済み") with Status with UseUpdate with UseDelete | |
this += actStart -> List(processAct,statusAct) >> | |
{(e:Entity,act:Option[String]) => | |
act match { | |
case None => statusAct | |
case Some("pass") => statusAct | |
case _ => processAct | |
} | |
} | |
this += processAct -> statusAct | |
} | |
object Process01 { | |
val procecss01 = new Process01 buildBuri | |
def apply() : Buri[Sample01Entity,Long] = procecss01 | |
} | |
test("flow test 01") { | |
val entity = new Sample01Entity(1,"","") | |
Process01().entry(entity) | |
assert(entity.status == "保存済み" , "status eq 保存済み") | |
Process01().update(entity) | |
assert(entity.status == "保存済み" , "status eq 保存済み") | |
Process01().delete(entity) | |
assert(entity.status == "Delete" , "status eq Delete") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment