All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.powerscala.property.TransactionProperty.scala Maven / Gradle / Ivy

The newest version!
package org.powerscala.property

import org.powerscala.Unique
import org.powerscala.transactional.{TransactionAction, transaction}

/**
 * @author Matt Hicks 
 */
trait TransactionProperty[T] extends Property[T] {
  private val transactionId = Unique()

  override def apply(): T = transaction.actionById[TransactionChange](transactionId) match {
    case Some(tc) => tc.newValue
    case None => super.apply()
  }

  override def apply(value: T, handling: EventHandling) = transaction.action(TransactionChange(apply(), value, handling))

  case class TransactionChange(oldValue: T, newValue: T, handling: EventHandling) extends TransactionAction {
    override def id = transactionId

    override def localized = true

    override def commit() = TransactionProperty.super.apply(newValue, handling)

    override def rollback() = {}

    override def toString = s"TransactionChange($id, $oldValue, $newValue)"
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy