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 -~----------~----~----~----~------~----~------~--~---