Skip to content

Commit

Permalink
OptionalKeyedEntityDef
Browse files Browse the repository at this point in the history
  • Loading branch information
max-l committed Jun 21, 2012
1 parent 2205acc commit 4eb4668
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/main/scala/org/squeryl/KeyedEntity.scala
Expand Up @@ -18,12 +18,17 @@ package org.squeryl
import annotations.Transient


trait KeyedEntityDef[A,K] {
trait KeyedEntityDef[A,K] extends OptionalKeyedEntityDef[A,K]{
def idF: A => K
def isPersisted: A => Boolean
def propertyName: String
def optimisticCounterPropertyName: Option[String] = None
def isOptimistic = optimisticCounterPropertyName.isDefined
def keyedEntityDef = Some(this)
}

trait OptionalKeyedEntityDef[A,K] {
def keyedEntityDef: Option[KeyedEntityDef[A,K]]
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/org/squeryl/Schema.scala
Expand Up @@ -332,20 +332,20 @@ class Schema(implicit val fieldMapper: FieldMapper) {
def tableNameFromClass(c: Class[_]):String =
c.getSimpleName

protected def table[T]()(implicit manifestT: Manifest[T], ked: Option[KeyedEntityDef[T,_]]): Table[T] =
protected def table[T]()(implicit manifestT: Manifest[T], ked: OptionalKeyedEntityDef[T,_]): Table[T] =
table(tableNameFromClass(manifestT.erasure))(manifestT, ked)

protected def table[T](name: String)(implicit manifestT: Manifest[T], ked: Option[KeyedEntityDef[T,_]]): Table[T] = {
protected def table[T](name: String)(implicit manifestT: Manifest[T], ked: OptionalKeyedEntityDef[T,_]): Table[T] = {
val typeT = manifestT.erasure.asInstanceOf[Class[T]]
val t = new Table[T](name, typeT, this, None, ked)
val t = new Table[T](name, typeT, this, None, ked.keyedEntityDef)
_addTable(t)
_addTableType(typeT, t)
t
}

protected def table[T](name: String, prefix: String)(implicit manifestT: Manifest[T], ked: Option[KeyedEntityDef[T,_]]): Table[T] = {
protected def table[T](name: String, prefix: String)(implicit manifestT: Manifest[T], ked: OptionalKeyedEntityDef[T,_]): Table[T] = {
val typeT = manifestT.erasure.asInstanceOf[Class[T]]
val t = new Table[T](name, typeT, this, Some(prefix), ked)
val t = new Table[T](name, typeT, this, Some(prefix), ked.keyedEntityDef)
_addTable(t)
_addTableType(typeT, t)
t
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/org/squeryl/dsl/QueryDsl.scala
Expand Up @@ -26,8 +26,9 @@ import scala.runtime.NonLocalReturnControl


trait BaseQueryDsl {
implicit def kedForKeyedEntitiesOptionZ[A,K]: Option[KeyedEntityDef[A,K]] = None

implicit def kedForKeyedEntitiesOptionZ[A,K]: OptionalKeyedEntityDef[A,K] = new OptionalKeyedEntityDef[A,K] {
override def keyedEntityDef: Option[KeyedEntityDef[A,K]] = None
}
}

trait QueryDsl
Expand Down
4 changes: 1 addition & 3 deletions src/test/scala/org/squeryl/test/schooldb/SchoolDb.scala
Expand Up @@ -124,9 +124,7 @@ class SchoolDb extends Schema {
def isPersisted = (a:Student) => a.id > 0
def propertyName = "id"
}

implicit val personKEDO = Some(personKED)


import org.squeryl.PrimitiveTypeMode._

// override val name = {
Expand Down

0 comments on commit 4eb4668

Please sign in to comment.