Did you try to override def dirty_? and def dirty_?(b: Boolean), and in the 
latter set your own private variable and read it in dirty_? (the getter)?

-------------------------------------
Peter Robinett<pe...@bubblefoundry.com> wrote:


Hi Derek,

I'm afraid I'm not sure how to do this, since _dirty_? is a private
var in MappedField:
/**
 * Is the field dirty
 */
private var _dirty_? = false

/**
 * Is the field dirty (has it been changed since the record was loaded
from the database
 */
def dirty_? = !dbPrimaryKey_? && _dirty_?

/**
 * Make the field dirty
 */
protected def dirty_?(b: Boolean) = _dirty_? = b


Trying various things I still cannot get it to work:
override def dirty_? = _dirty_? leads to the compiler error 'not
found: value _dirty_?'
override def dirty_? = super._dirty_? leads to the compiler error
'variable _dirty_? cannot be accessed in
net.liftweb.mapper.MappedStringIndex[com.equalnetworks.model.Node]
with ScalaObject'

If I redefine _dirty_?:
private var _dirty_? = false
override def dirty_? = _dirty_?
I am able to compile but I still get blank rows being created in the
database.

What do you suggest?

David, I'll have some sample code soon.

Peter

On Jul 28, 4:19 pm, Derek Chen-Becker <dchenbec...@gmail.com> wrote:
> Did you override the dirty_? def?
>
> Derek
>
> On Tue, Jul 28, 2009 at 3:09 PM, Peter Robinett 
> <pe...@bubblefoundry.com>wrote:
>
>
>
> > Sorry to bump this, but does anyone have any idea why my mac column is
> > not being saved to the database, despite the save method returning
> > true?
>
> > On Jul 22, 9:19 am, Peter Robinett <pe...@bubblefoundry.com> wrote:
> > > Because it's unique across systems and maps directly to hardware I'm
> > > tracking. But thanks for the equations!
>
> > > Peter
>
> > > On Jul 21, 7:20 pm, jon <jonhoff...@gmail.com> wrote:
>
> > > > This doesn't address your question, so I'll apologize in advance, but
> > > > why do you want to use a mac address as a primary key?   Also, a mac
> > > > address represents six bytes, why not pack into a long?  This probably
> > > > isn't the most efficient or prettiest way:
>
> > > >   def macToLong(mac: String) = java.lang.Long.parseLong(mac.replace
> > > > (":",""),16)
>
> > > >   def longToMac(mac: Long) = (0 to 5).reverse.map( i => (mac & ((0xff)
> > > > << (i * 8).asInstanceOf[Long])) >> (i * 8)).
> > > >     map( l => String.format("%02x",l.asInstanceOf[Object])).mkString
> > > > (":")
>
> > > >   println( longToMac(macToLong("00:1d:c9:00:04:9f")))
>
> > > > On Jul 21, 4:19 pm, Peter Robinett <pe...@bubblefoundry.com> wrote:
>
> > > > > I should add that I believe this is because the field isn't being
> > > > > marked as dirty and so isn't saved. This is in MappedField:
> > > > > def dirty_? = !dbPrimaryKey_? && _dirty_?
>
> > > > > How would I overload it in my object mac definition?
>
> > > > > Thanks,
> > > > > Peter
>
> > > > > On Jul 21, 12:30 pm, Peter Robinett <pe...@bubblefoundry.com> wrote:
>
> > > > > > Thanks Derek, but unfortunately it only works halfway: I am able to
> > > > > > set MAC address of my new Node and save it (returning true) and my
> > > > > > MySQL database row is created, but the mac column is null.
>
> > > > > > Peter
>
> > > > > > On Jul 21, 7:58 am, Derek Chen-Becker <dchenbec...@gmail.com>
> > wrote:
>
> > > > > > > I think that this should work, but I haven't tested it:
>
> > > > > > > class Node extends KeyedMapper[String, Node] {
> > > > > > >  def getSingleton = Node
> > > > > > >  /* MAC address as primary key */
> > > > > > >  def primaryKeyField = mac
> > > > > > >  object mac extends MappedStringIndex(this, 17) {
> > > > > > >         override def writePermission_? = true
> > > > > > >         override def dbDisplay_? = true
> > > > > > >  }
>
> > > > > > > }
>
> > > > > > > Note that primaryKey_? is already set to true in
> > MappedStringIndex.
> > > > > > > writePermission_? is set to false by default...
>
> > > > > > > Derek
>
> > > > > > > On Mon, Jul 20, 2009 at 7:30 PM, Peter Robinett <
> > pe...@bubblefoundry.com>wrote:
>
> > > > > > > > Hi all,
>
> > > > > > > > I'm using Mapper with MAC addresses as my primary keys:
> > > > > > > > class Node extends KeyedMapper[String, Node] {
> > > > > > > >  def getSingleton = Node
> > > > > > > >  /* MAC address as primary key */
> > > > > > > >  def primaryKeyField = mac
> > > > > > > >  object mac extends MappedStringIndex(this, 17) {
> > > > > > > >         override def dbPrimaryKey_? = true
> > > > > > > >         override def dbDisplay_? = true
> > > > > > > >  }
> > > > > > > > }
>
> > > > > > > > Unfortunately, if I try to create a new Node and assign a MAC
> > address,
> > > > > > > > I get an error saying that I don't have permission:
> > > > > > > > scala> Node.create.mac("00:1d:c9:00:04:9f")
> > > > > > > > java.lang.Exception: Do not have permissions to set this field
> > > > > > > >        at
> > net.liftweb.mapper.MappedField$class.set(MappedField.scala:425)
> > > > > > > >        at
> > net.liftweb.mapper.MappedString.set(MappedString.scala:38)
> > > > > > > >        at
> > net.liftweb.mapper.MappedString$$anonfun$apply$6.apply
> > > > > > > > (MappedString.scala:121)
> > > > > > > >        at
> > net.liftweb.mapper.MappedString$$anonfun$apply$6.apply
> > > > > > > > (MappedString.scala:121)
> > > > > > > >        at net.liftweb.util.Full.f...
>
> > > > > > > > How do I go about creating a new Node with the mac address –
> > the
> > > > > > > > primary key – of my choosing?
>
> > > > > > > > Thanks,
> > > > > > > > Peter Robinett


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

Reply via email to