Scala subjects and context of persistence

Is it possible to introduce a persistence context into a scala actor every time he acts? I have a dual Java / Scala spring application and I use spring annotations to mark my Java services and methods as transactional. I would like to use similar features in my scala actors. That is, the actor must act within the framework of one transaction every time he answers the message. Has anyone tried something similar or are there examples of this kind of thing?

+3
source share
1 answer

Why not encapsulate the constant access through Dao traitthat which is introduced into the actor himself. Thus, you can have an actor of perseverance that is separate from the preservation mechanism itself:

class DaoActor(val dao: Dao) extends Actor {

   def act() = {
     loop {
       react {
         case SaveTrade(trade) => dao.save(trade)
         case ReadTrades(date) => dao.lookup(date)           }
     }
   }
}

What's more, yours Daocan be encoded in Java, so you can add annotation there @Transactional.

+6
source

Source: https://habr.com/ru/post/1719817/


All Articles