5. The idea
u -> ( u.firstName.equals("john") && u.lastName.equals("doe"))
|| u.userName.equals("jdoe"))
final List<User> users = userCollection.filter(
u -> ( u.firstName.equals("john") && u.lastName.equals("doe"))
|| u.userName.equals("jdoe")).toList();
13. final List<User> users = userCollection.filter(
u -> ( u.firstName.equals("john") && u.lastName.equals("doe"))
|| u.userName.equals("jdoe")).toList();
Metamodel in action
public class UserCollection extends
LambdamaticMongoCollectionImpl<User, QUser> {
...
}
package com.example.domain;
@Generated(value="LambdamaticAnnotationsProcessor")
public class QUser implements QueryMetadata<User> {
@DocumentField(name="_id")
public StringField firstName;
@DocumentField(name="firstName")
public StringField firstName;
...
}
25. Lambda Expression
Analysis
Boolean algebra to the rescue !
a.(b.c) = a.b.c
a + (b + c) = a + b + c
a.(!a + b).(!a + c) = a.b.c
a + (!a.b) + (!a.c) = a + b + c
a.(a + b).(a + c) = a
a + (a.b) + (a.c) = a
(a.b) + (a.c) + (a.d) = a.(b + c + d)
(a + b).(a + c).(a + d) = a + (b.c.d)
a + a = a
a.a = a
a.!a = O
a + !a = I
O + a = a
O.a = O
1 + a = 1
1.a = a
a.(b + c + d) = (a.b) + (a.c) + (a.d)
a + (b.c.d) = (a + b).(a + c).(a + d)
26.
27. Lambda Expression
Analysis
Step#6 : further simplify the statement tree
(u.firstName.equals("john")
&& u.lastName.equals("doe"))
|| (u.firstName.equals("john")
&& !u.lastName.equals("doe")
&& u.userName.equals("jdoe"))
|| (!u.firstName.equals("john")
&& u.userName.equals("jdoe"))
(u.firstName.equals("john") && u.lastName.equals("doe")) || u.userName.equals("jdoe")
28.
29. Performances ?
• Byte code is analyzed on first access to Lambda
Expression ( <100ms)
• "Raw" AST is cached for subsequent calls
• Placeholders in AST for captured arguments
31. Managing Data on
MongoDB
• Providing Codecs for Lambda Expressions and
Documents
• Skipping the "DBObject" DTOs layer
MongoDB Java Driver Integration
37. Query on Arrays
final List<BlogEntry> blogEntries =
blogEntryCollection.filter(
e -> e.comments.elementMatch(
c -> c.author.equals("anonymous") && c.date.greaterOrEquals(twoDaysAgo)))
.toList();
final List<BlogEntry> blogEntries =
blogEntryCollection.filter(
e -> e.comments.author.equals("anonymous") &&
e.comments.date.greaterOrEquals(twoDaysAgo))
.toList();
43. Update Operations
@Document(collection="blog")
public class BlogEntry {
@DocumentId
private String id;
/** Name of author of the blog entry. */
private String authorName;
/** Title of the Blog Entry */
private String title;
/** list of comments. */
private List<BlogEntryComment> comments;
...
}
Update Metadata class generation
@Generated(value="o.l.m.a.DocumentAnnotationProcessor")
public abstract class UBlogEntry implements UpdateMetadata<BlogEntry> {
@DocumentField(name="_id")
public String id;
@DocumentField(name="authorName")
public String authorName;
@DocumentField(name="title")
public String title;
@DocumentField(name="comments")
public UBlogEntryCommentArray comments;
...
}
44. Update Operations
BlogEntryComment comment = ... ;
blogEntries.filter(e -> e.id.equals("1")).
forEach(e -> {
e.lastUpdate = new Date();
e.commentsNumber++;
e.comments.push(comment);});
@Document(collection="blog")
public class BlogEntry {
@DocumentId
private String id;
/** date of last update. */
private Date lastUpdate;
/** Number of comments */
private int commentsNumber;
/** list of comments. */
private List<BlogEntryComment> comments;
@EmbeddedDocument
public class BlogEntryComment {
/** comment author. */
private String author;
/** comment date. */
private Date date;
/** comment content. */
private String content;