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

inner.Optimistic.scala Maven / Gradle / Ivy

There is a newer version: 0.5.1
Show newest version
package com.github.aselab.activerecord.inner

import com.github.aselab.activerecord._
import dsl._
import aliases._
import reflections.ReflectionUtil._

trait Optimistic extends CRUDable { self: AR =>
  protected val occVersionNumber = 0
  private def occVersion = occVersionNumber

  /** update with lock */
  abstract override protected def doUpdate = try {
    val result = super.doUpdate
    if (result) {
      this.setValue("occVersionNumber", occVersion + 1)
    }
    result
  } catch {
    case e: StaleUpdateException => throw ActiveRecordException.staleUpdate(e)
  }

  /** destroy with lock */
  abstract override protected def doDelete = self.recordInDatabase match {
    case Some(m) if m.occVersion != occVersion =>
      throw ActiveRecordException.staleDelete(self.getClass.getName)
    case _ => super.doDelete
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy