Permalink
Browse files

Merge pull request #19 from lift/jon-nosafe-1196

use dynamic "safe_#" instead of random long
  • Loading branch information...
2 parents 8f1698a + c006de9 commit d35d7da0ca67da0d71f6a112a9dccdf603c2f0ce @dpp dpp committed Feb 11, 2012
@@ -17,30 +17,22 @@
package net.liftweb
package util
-import java.security.{SecureRandom, MessageDigest}
-import org.apache.commons.codec.binary.Base64
-
/**
* Manage the current "safety" state of the stack
*/
object Safe {
- private val rand = new SecureRandom
- /**
- * Get the next "safe" number
- */
- def next = rand.synchronized{rand.nextLong}
- private val threadLocal = new ThreadGlobal[Long]
+ private val threadLocal = new ThreadGlobal[Int]
/**
* Is the current context "safe" for the object with the
* given safety code?
*/
- def safe_?(test : Long) : Boolean = test == threadLocal.value
+ def safe_?(test : Int) : Boolean = test == threadLocal.value
/**
* Marks access to a given object as safe for the duration of the function
*/
- def runSafe[T](x : Long)(f : => T) : T = {
+ def runSafe[T](x : Int)(f : => T) : T = {
threadLocal.doWith(x)(f)
}
@@ -37,23 +37,22 @@ trait Mapper[A<:Mapper[A]] extends BaseMapper {
self: A =>
type MapperType = A
- private val secure_# = Safe.next
private var was_deleted_? = false
private var dbConnectionIdentifier: Box[ConnectionIdentifier] = Empty
private[mapper] var addedPostCommit = false
@volatile private[mapper] var persisted_? = false
def getSingleton : MetaMapper[A];
final def safe_? : Boolean = {
- Safe.safe_?(secure_#)
+ Safe.safe_?(System.identityHashCode(this))
}
def dbName:String = getSingleton.dbName
implicit def thisToMappee(in: Mapper[A]): A = this.asInstanceOf[A]
def runSafe[T](f : => T) : T = {
- Safe.runSafe(secure_#)(f)
+ Safe.runSafe(System.identityHashCode(this))(f)
}
def connectionIdentifier(id: ConnectionIdentifier): A = {
@@ -31,11 +31,6 @@ trait Record[MyType <: Record[MyType]] extends FieldContainer {
self: MyType =>
/**
- * A unique identifier for this record... used for access control
- */
- private val secure_# = Safe.next
-
- /**
* Get the fields defined on the meta object for this record instance
*/
def fields() = meta.fields(this)
@@ -51,11 +46,11 @@ trait Record[MyType <: Record[MyType]] extends FieldContainer {
* Is it safe to make changes to the record (or should we check access control?)
*/
final def safe_? : Boolean = {
- Safe.safe_?(secure_#)
+ Safe.safe_?(System.identityHashCode(this))
}
def runSafe[T](f : => T) : T = {
- Safe.runSafe(secure_#)(f)
+ Safe.runSafe(System.identityHashCode(this))(f)
}
/**

0 comments on commit d35d7da

Please sign in to comment.