Created
February 10, 2010 16:14
-
-
Save hlship/300480 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void contributeValueEncoderSource( | |
MappedConfiguration<Class, ValueEncoderFactory> configuration, | |
final Session session) | |
{ | |
ValueEncoder<Posting> postingValueEncoder = new ValueEncoder<Posting>() | |
{ | |
@Override | |
public String toClient(Posting value) | |
{ | |
return String.format("%s:%s", value.getBlog().getName(), value | |
.getExternalId()); | |
} | |
@Override | |
public Posting toValue(String clientValue) | |
{ | |
int colon = clientValue.indexOf(':'); | |
String blogName = clientValue.substring(0, colon); | |
String externalId = clientValue.substring(colon + 1); | |
Query query = session | |
.createQuery("from Posting where blog.name = :blogName and externalId = :externalId"); | |
query.setString("blogName", blogName).setString("externalId", | |
externalId); | |
return (Posting) query.uniqueResult(); | |
} | |
}; | |
configuration.override(Posting.class, GenericValueEncoderFactory.create(postingValueEncoder)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment