Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Something cool with 0.9.6
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post will appear after it is approved by moderators
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David Whittaker  
View profile  
 More options Oct 23 2012, 3:16 pm
From: David Whittaker <d...@iradix.com>
Date: Tue, 23 Oct 2012 15:15:43 -0400
Local: Tues, Oct 23 2012 3:15 pm
Subject: Something cool with 0.9.6

I'm just starting to play around with 0.9.6, and I found something I think
is pretty nifty that I wanted to share.  Getting rid of the reliance on
KeyedEntity is great, but I do use a field named id as a primary key in
most of my entities.... Type constructors and structural types to the
rescue!

  type WithId[A] = { def id: A }

 implicit def withIdDef[A, B <% WithId[A]] = new KeyedEntityDef[B,A] {

  def getId(b: B): A = b.id

  def idPropertyName: String = "id"

  def isPersisted(b: B): Boolean = bi.id > 0

  }

And just like that Squeryl knows that every entity that contains a val or
var named "id" should use that field as it's primary key.  No trait to mix
in or other change to the entity required.

P.S. If you're wondering why it's B <% WithId[A] rather than B <: WithId[A]
see here:
http://stackoverflow.com/questions/10343244/why-doesnt-type-inference...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Ryan-Brown  
View profile  
 More options Oct 25 2012, 8:11 pm
From: John Ryan-Brown <john.ryanbr...@gmail.com>
Date: Fri, 26 Oct 2012 10:11:54 +1000
Local: Thurs, Oct 25 2012 8:11 pm
Subject: Re: Something cool with 0.9.6

Small point - the isPersisted implementation depends on A being a numeric
type?

I'm still uncertain how isPersisted is meant to be implemented when primary
key values are not auto-generated. For example. our primary keys are UUIDs
that are generated by calling UUID.randomUUID.

On 24 October 2012 05:15, David Whittaker <d...@iradix.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Whittaker  
View profile  
 More options Oct 26 2012, 9:13 am
From: David Whittaker <d...@iradix.com>
Date: Fri, 26 Oct 2012 09:13:13 -0400
Local: Fri, Oct 26 2012 9:13 am
Subject: Re: Something cool with 0.9.6

Hi John,

Good point.  That's actually not what I was using..... I had a
sys.error("Unimplemented") as the body of my isPersisted and changed it
after copy / pasting because I thought that might confuse people.  You're
right though, it wouldn't compile.  As an alternative, you could use a
pattern match on A checking for 0 on numeric AnyVal(s) and null for AnyRef.

Personally, I don't see much use for isPersisted right with KeyedEntityDef,
given the current implementation.  It's only used by Squeryl in the
insertOrUpdate method, which I don't use.  Eventually I'd like to see it
reference a field so that Squeryl can properly set it for you.

On Thu, Oct 25, 2012 at 8:11 PM, John Ryan-Brown
<john.ryanbr...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Maxime Lévesque  
View profile  
 More options Oct 26 2012, 10:21 am
From: Maxime Lévesque <maxime.leves...@gmail.com>
Date: Fri, 26 Oct 2012 10:21:58 -0400
Local: Fri, Oct 26 2012 10:21 am
Subject: Re: Something cool with 0.9.6
You could have a canonical UUID to represent "the value was never
assigned", for example this :

 java.util.UUID.fromString("00000000-0000-0000-0000-000000000000")

2012/10/26 David Whittaker <d...@iradix.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »