Link Details

Link 1059365 thumbnail
User 1189573 avatar

By richigh82
via rick-hightower.blogspot.com
Published: Nov 04 2013 / 09:57

What if Java collections and Java hierarchies were easily searchable? They are with Boon! What if it were easy to query a complex set of Java objects at runtime? What if there were an API that kept your object indexes (really just TreeMaps, and HashMaps) in sync.? Well then you would have Boon's data repo. This article shows how to use Boon's data repo utilities to query Java objects. Boon comes with a simple criteria API that makes working with Java collections a snap.
  • 7
  • 0
  • 1582
  • 1207

Comments

Add your comment
User 1189573 avatar

richigh82 replied ago:

0 votes Vote down Vote up Reply

List results = userRepo.query ( eq ( EMAIL, "rick.hightower@foo.com") );

User 1189573 avatar

richigh82 replied ago:

0 votes Vote down Vote up Reply

It can be combined with the stream API. int sum = repo.query(eq("lastName", "Smith")).stream().filter(emp -> emp.getSalary()>50_000) .mapToInt(b -> b.getSalary()) .sum();

User 1189573 avatar

richigh82 replied ago:

0 votes Vote down Vote up Reply

Question: UPDATE QUESTION FROM A READER: On Saturday, November 2, 2013, Chris B wrote: "Very interesting, Rick - I only had time to do a quick read of the article, so forgive me if this is answered within your write up. But, I was curious as to the overhead of building the indexes when you wrap your collection in a query object... Say for the 200_000 employees in the example below. How long would it take to build the indexed structure ?" Thanks Chris. Good Question! It would be quite expensive so you would only use this construct if you plan on holding on to the collection for a while. There is also a repo object if you want to gradually update a collection's indexes. For a use case: Imagine you are pulling a list of employees from memcached every 20 minutes. You want to query against the employees so you need the indexes and you want something faster than storing every possible combination of a query in memcached (yes I have seen people do this to the tune of 12 GB... 20x more than the data in the DB. I have seen this more than once). So now you pull them down, query against the searchable collection. This avoids the call to memcached and the explosion of every possible query being cached. Anyway... Data repo was written to avoid many of the anti patterns that I have seen with caching. It allows you a way to query against Java objects.

User 1189573 avatar

richigh82 replied ago:

0 votes Vote down Vote up Reply

Using Java Indexed collections and querying collections (Treesets, TreeMaps) can help you with some common anti-patterns like cache explosion. 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 *1 times the number of common like statements. Don't let memcached be your hammer, and every query speed up a nail. Learn how to combine Memcached with Java collections to avoid the database hits and not store every possible combination of query results in Memcached. What if Java collections and Java hierarchies were easily searchable? They are with Boon! What if it were easy to query a complex set of Java objects at runtime? What if there were an API that kept your object indexes (really just TreeMaps, and... http://www.dzone.com/links/1059365.html

User 1189573 avatar

richigh82 replied ago:

0 votes Vote down Vote up Reply
User 1189573 avatar

richigh82 replied ago:

0 votes Vote down Vote up Reply

This and the last post are follow ups to this article. Java Boon filtering for Java Beans, JSON and Java Maps like JDK 8 streams but much faster http://www.dzone.com/links/java_boon_filtering_for_java_beans_json_and_java.html Java Boon filtering for Java Beans, JSON and Java Maps like JDK 8 streams but much faster. Many languages have support for querying objects and filtering objects easily. Java does in JDK 8, but Boon adds it as well, and it can compliment features of JDK 8 as well as work in Java 7 land. Boon adds filtering to to Java. You can filter JSON, Java, and Maps. You can also use indexed queries which are a lot faster than linear search queries that come with JDK 8.

User 1189573 avatar

richigh82 replied ago:

0 votes Vote down Vote up Reply

Which is faster serializing to JSON with Jackson or serializing to binary with ObjectOutputStream? Most people assume that Java object serialization is faster than Jackson JSON serialization because Jackson is using JSON and Java object serialization is binary. Is this true? Find out. http://www.dzone.com/links/which_is_faster_serializing_to_json_with_jackson.html

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (7)



Voters Against This Link (0)



    Play Framework
    Written by: Ryan Knight
    Featured Refcardz: Top Refcardz:
    1. Akka
    2. Design Patterns
    3. OO JS
    4. Cont. Delivery
    5. HTML5 Mobile
    1. Akka
    2. JUnit/EasyMock
    3. Java Performance
    4. REST
    5. Java