Here is the solution to the complex domain modeling problem with Mapper

import net.liftweb.mapper._

trait Position extends BaseLongKeyedMapper {
  type ContentType <: LongKeyedMapper[ContentType] with Positionable
  def foreign: LongKeyedMetaMapper[ContentType]
  def isMoving():Boolean = scheduled.obj.map(_ => true).openOr(false) || 
content.obj.map(_.isMoving()).openOr(false)
  object role extends MappedString(this.asInstanceOf[MapperType],18)
  object content extends MappedLongForeignKey(this
.asInstanceOf[MapperType],foreign)
  object scheduled extends MappedLongForeignKey(this
.asInstanceOf[MapperType],foreign)
}

trait Positionable extends BaseLongKeyedMapper {
  type ContainerType <: LongKeyedMapper[ContainerType] with Position 
  def foreign: LongKeyedMetaMapper[ContainerType]
  def isMoving(): Boolean = dest.obj.map(_ => true).openOr(false) || 
container.obj.map(_.isMoving()).openOr(false)
  object name extends MappedString(this.asInstanceOf[MapperType],32)
  object container extends MappedLongForeignKey(this.asInstanceOf[
MapperType],foreign)
  object dest extends MappedLongForeignKey(this.asInstanceOf[MapperType],
foreign)

}

class Pallet extends LongKeyedMapper[Pallet] with Positionable with IdPK {
  type ContainerType = PalletPosition
  def getSingleton = PalletMeta
  def foreign = PalletPositionMeta
}

object PalletMeta extends Pallet with LongKeyedMetaMapper[Pallet]

class PalletPosition extends LongKeyedMapper[PalletPosition] with Position 
with IdPK {
  type ContentType = Pallet
  def getSingleton = PalletPositionMeta
  def foreign = PalletMeta
}

object PalletPositionMeta extends PalletPosition with LongKeyedMetaMapper[
PalletPosition]

Scala programming is too fun. 

Regards
Giuseppe Fogliazza



beppe61 <[email protected]> 
26/02/2009 20.08
Per favore, rispondere a
[email protected]


Per
Lift <[email protected]>
CC

Oggetto
[Lift] Using Traits in complex domain models







In a new project to support Manufacturing Operations, using Lift, I
want to code a common pattern for my application and hence I
introduced two traits implementing the basic relationship between a
Position and its content assumed as a Positionable. Concrete classes
will be persisted using Mapper.
Here my try:

trait Position extends BaseLongKeyedMapper {
  type ContentType <: Positionable
  def foreign: LongKeyedMetaMapper[ContentType]
  def isMoving():Boolean = scheduled.obj.map(_ => true).openOr(false)
||  content.obj.map(_.isMoving()).openOr(false)
  object role extends MappedString(this.asInstanceOf[MapperType],18)
  object content extends MappedLongForeignKey(this.asInstanceOf
[MapperType],foreign) // type mismatch
  object scheduled extends MappedLongForeignKey(this.asInstanceOf
[MapperType],foreign) // type mismatch
}

trait Positionable extends BaseLongKeyedMapper {
  type ContainerType <: Position
  def foreign: LongKeyedMetaMapper[ContainerType]
  def isMoving(): Boolean = dest.obj.map(_=>true).openOr(false)
  object name extends MappedString(this.asInstanceOf[MapperType],32)
  object position extends MappedLongForeignKey(this.asInstanceOf
[MapperType],foreign) // type mismatch
  object dest extends MappedLongForeignKey(this.asInstanceOf
[MapperType],foreign) // type mismatch
}

I would like to declare a concrete class this way:

class Pallet extends LongKeyedMapper[Pallet] with Positionable with
IdPK {
  type ContainerType = PalletPosition
  def getSingleton = PalletMeta
  def foreign = PalletPositionMeta
}

object PalletMeta extends Pallet with LongKeyedMetaMapper[Pallet]

class PalletPosition extends LongKeyedMapper[PalletPosition] with
Position with IdPK {
  type ContentType = Pallet
  def getSingleton = PalletPositionMeta
  def foreign = PalletMeta
}

object PalletPositionMeta extends PalletPosition with
LongKeyedMetaMapper[PalletPosition]

Unfortunately there is a type mismatch in parameters passed to
MappedLongForeignKey in the Position and Positionable traits.

Do you have any suggestion?







Chi riceve il presente messaggio e' tenuto a verificare se lo stesso non gli 
sia  pervenuto per errore. In tal caso e' pregato di avvisare immediatamente il 
 mittente e, tenuto conto delle responsabilita' connesse all'indebito utilizzo 
e/o divulgazione del messaggio e/o delle informazioni in esso contenute, voglia 
cancellare l'originale e distruggere le varie copie o stampe.

The  receiver of this message is required to check if he/she has received it 
erroneously. If so, the receiver is requested to immediately inform the sender 
and - in condideration of the responsibilities arising from undue use and/or 
disclosure of the message and/or the information contained therein destroy the 
original message and any copy or printout thereof.

Die Information dieses e-mails ist vertraulich und ausschließlich für den 
Adressaten bestimmt.
Der Empfänger dieses e-mails der nicht der Adressat ist (sowie einer seiner 
Mitarbeiter oder sein Empfangsberechtigter), darf den Inhalt nicht verwenden, 
weitergeben oder reproduzieren.
Sollten Sie dieses e-mail irrtümlich erhalten haben, benachrichtigen Sie bitte 
den Absender und vernichten Sie dieses e-mail.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to