667476 members! Sign up to stay informed.

Sponsored Links


Resources

Enterprise Java
Research Library

Get Java white papers, product information, case studies and webcasts

News News News Messages: 11 Messages: 11 Messages: 11 Printer friendly Printer friendly Printer friendly Post reply Post reply Post reply XML XML XML

LINQ for Java: Quaere

Posted by: Joseph Ottinger on September 13, 2007 DIGG
Dion Almaer: he met the author of Quaere, which is an implementation of LINQ for Java. It's functional; the MS examples work; it's a way of representing iterable data in a relational format, more or less. Interesting stuff.

From the introduction:
Examples To import the DSL into any Java class, simply add the following import to the class: import static org.quaere.DSL.*;

Below is an example of a simple query that selects the numbers less than five from an array of integers:
Integer[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
Iterable lowNums = from("n").in(numbers)
.where(lt("n", 5))
.select("n");
This query uses a projection expression to select the names of all products in the array:
List products = Arrays.asList(Product.getAllProducts());
Iterable productNames = from("p")
.in(products)
.select("p.getProductName()");
The following query creates a sequence anonymous class instances with two properties containing the upper and lower case versions of the words in an array. The classes in the upperLowerWords collection will have two strongly typed JavaBean properties:
String[] words = {"aPPLE", "BlUeBeRrY", "cHeRry"};
Iterable upperLowerWords = from("w")
.in(words)
.select( create( property("upper", "w.toUpperCase()"),
property("lower", "w.toLowerCase()") ) );
This is a great example of a DSL implemented with Java - and entirely usable from standard Java code.

Do you think you'd find a good use for it in your code?

Of course, on the subject of DSLs, Ola Bini weighs in with Concurrent DSLs:
With all the current talk of DSLs and concurrency, what I find lacking is discussions about how to combine the two. Of course, domain specific languages are incredibly important - they create a logical separation between the implementors of the business logic, and the people implementing the actual implementation of the DSL. Does it seem like a strange idea to want many DSLs to be able to run parallel to each other? I would imagine that in most cases a DSL that describes business rules and business logic is sequential in the particulars, but that there are also larger concurrency possibilities. This should be totally invisible for the business rule implementor in most cases - the runtime system should be able to run everything as efficient as possible.

Threaded replies

·  LINQ for Java: Quaere by Joseph Ottinger on Thu Sep 13 08:27:34 EDT 2007
  ·  Nice! by Karl Peterbauer on Thu Sep 13 09:41:15 EDT 2007
  ·  Awesome although it has a lame name by Dushyanth Inguva on Thu Sep 13 09:56:37 EDT 2007
  ·  Groovy equivalent by Time Passx on Thu Sep 13 11:08:02 EDT 2007
  ·  Considered response by Michael Bienstein on Thu Sep 13 11:25:50 EDT 2007
    ·  Re: Considered response by Anders Norås on Fri Sep 14 06:46:48 EDT 2007
  ·  Saffron by Mark Nuttall on Thu Sep 13 13:08:27 EDT 2007
    ·  John's Perforce server - Farrago, Mondrian etc by Michael Bienstein on Thu Sep 13 17:33:07 EDT 2007
  ·  joSQL by Carl Mueller on Mon Sep 17 11:01:33 EDT 2007
    ·  Re: joSQL by Anders Norås on Tue Sep 18 17:32:58 EDT 2007
      ·  Quaere: alternative syntax by Thomas Mueller on Tue Sep 25 10:04:19 EDT 2007
  ·  Saw it at JavaZone 2007 by Tor Iver Wilhelmsen on Tue Sep 18 03:58:17 EDT 2007
  Message #239644 Post reply Post reply Post reply Go to top Go to top Go to top

Nice!

Posted by: Karl Peterbauer on September 13, 2007 in response to Message #239632
A full LINQ-clone requires closures and support for inspecting the full expression tree at runtime. Otherwise we cannot get rid of those fragile, annoying string expressions...

  Message #239648 Post reply Post reply Post reply Go to top Go to top Go to top

Awesome although it has a lame name

Posted by: Dushyanth Inguva on September 13, 2007 in response to Message #239632
Its an Awesome news to hear LINQ coming to Java.
Although "I'm working on LINQ" sounds cool
"I'm working on Quaere" - I'm so sorry, why don't you call in sick?

  Message #239654 Post reply Post reply Post reply Go to top Go to top Go to top

Groovy equivalent

Posted by: Time Passx on September 13, 2007 in response to Message #239632
Here's the equivalent in Groovy:


Integer[] numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]
def lowNums = numbers.findAll { it < 5 }

List products = Arrays.asList(Product.getAllProducts())
def productNames = products.collect { it.productName }

String[] words = ["aPPLE", "BlUeBeRrY", "cHeRry"];
def upperLowerWords = words.collect {
def val = new Expando()
val.upper = it.toUpperCase()
val.lower = it.toLowerCase()
val
}


If you ask me it's much easier to read, even compared to the .NET LINQ where they have closures.

  Message #239657 Post reply Post reply Post reply Go to top Go to top Go to top

Considered response

Posted by: Michael Bienstein on September 13, 2007 in response to Message #239632
It seems to me that LINQ has three major points that make it a useful technology, the first two being in common with SQL as well:
1) Separation of concern between the definition of the data request and its use.
2) Separation of concern between the definition of the data request and its implementation.
3) Integration of the definition of the data request into the 3GL being used to handle the results of the query.

Now the example given here is a well-worn idea and is nothing new. It is constructing an expression tree using java methods and a standard Java API. So there is no language-level integration. This only affects point 3 partially. The other two points are still perfectly valid but pose the following obvious questions:
a) The result is an Iterable. What happens if you want to be able to move back and forth in the list?
b) The Iterable is untyped, what happens with type-safety? (this is related to point 3).
c) When is the query plan created and when is it executed? On the initial call to the Iterable? How is the implementation chosen? One of the main reasons to push LINQ as a concept more is that we can move away from SQL only as a functional query language and have other types of data stores and have query engines that take advantage of the multi-core/massively parallel nature of the newer technologies. Can it do that? How can you set options to control this sort of query generation?

Not knowing anything more, this seems enough to get the ball rolling.

Michael

  Message #239668 Post reply Post reply Post reply Go to top Go to top Go to top

Saffron

Posted by: Mark Nuttall on September 13, 2007 in response to Message #239632
http://perforce.eigenbase.org:8080/@md=d&cd=//open/saffron/doc/&c=5tJ@//open/saffron/doc/index.html

  Message #239677 Post reply Post reply Post reply Go to top Go to top Go to top

John's Perforce server - Farrago, Mondrian etc

Posted by: Michael Bienstein on September 13, 2007 in response to Message #239668
Right Mark. Mondrian rocks too. It's also in that server and John contributes to it and yes Saffron pre-dates LINQ. Not really new technology.

  Message #239691 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Considered response

Posted by: Anders Norås on September 14, 2007 in response to Message #239657
Answers to you questions can be found in this blog post: http://andersnoras.com/blogs/anoras/archive/2007/09/13/answering-questions-about-quaere.aspx

Cheers,
Anders Norås

  Message #239782 Post reply Post reply Post reply Go to top Go to top Go to top

joSQL

Posted by: Carl Mueller on September 17, 2007 in response to Message #239632
Better/worse/same as joSQL?

http://josql.sourceforge.net/

doing chained api calls seems more obfuscated than josql, and not necessarily faster/more compact theoretically.

I haven't seen LINQ syntax other than "it's SQL for code", so maybe it's just matching the LINQ style in CSharpPokeInMyEye.

  Message #239812 Post reply Post reply Post reply Go to top Go to top Go to top

Saw it at JavaZone 2007

Posted by: Tor Iver Wilhelmsen on September 18, 2007 in response to Message #239632
... in Oslo. Looked very interesting.

What the presenter/author said was that LINQ in C# was implemented by having the compiler synthesize use of underlying classes etc. (I guess it's akin to how use of the "delegate" keyword is turned into a System.Delegate object for instance.) Perhaps the open-sourcing of Java will lead to something like "compiler plugins" that could support inline languages of the LINQ type, without having to resort to "tricks" like static import and Hibernate-like method chaining.

  Message #239874 Post reply Post reply Post reply Go to top Go to top Go to top

Re: joSQL

Posted by: Anders Norås on September 18, 2007 in response to Message #239782
Hi Carl.

First of all, JoSQL is a great framework that has brought many vitalizing ideas on working with POJOs. To clarify some of the confusion between Quaere and similar frameworks I've written a comparison of JoSQL and Quaere that shows some of the similarities and differences between the two. You'll find it one my here: http://andersnoras.com/blogs/anoras/archive/2007/09/18/what-s-the-difference-between-josql-quaere.aspx

Regards,
Anders Norås

  Message #240191 Post reply Post reply Post reply Go to top Go to top Go to top

Quaere: alternative syntax

Posted by: Thomas Mueller on September 25, 2007 in response to Message #239874
What do you think about this:
String[] cities = new String[]{"Auckland", "Oslo"};
Alias<String> city = alias(cities);
List<String> places = from(city)
.where(city.length().isBigger(5))
.orderBy(city.desc())
.select(city);
Customer c = db.alias(Customer.class);
List<Customer> list = db.from(c)
.where(c.city.is("London"))
.orderBy(c.name.asc(), c.city.desc())
.select();
public class Customer {
public Column<Integer> id;
public Column<String> name;
public Column<String> city;
}
Plain old Java classes can be supported as well:
Customer c = db.alias(Customer.class);
List<Customer> list = db.from(c)
.where(equal(c.city, "London"))
.orderBy(c.name, desc(c.id))
.select();
public class Customer {
public Integer id;
public String name;
public String city;
}
Soon to be available...

New content on TheServerSide.comNew content on TheServerSide.comNew content on TheServerSide.com

Dependency Injection in Java EE 6 - Part 1

Reza Rahman explores the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6. (November 2, Article)

SAML: It's Not just for Web services

SAML is an XML-based standard for exchanging authentication and authorization data between security domains. The single most important problem that SAML was created to solve is the Web browser Single Sign-On problem. Many organizations are debating whether to stay with version 1.1 or move to 2.0. This article makes observations about both options. (September 28, Article)

Programming is Also Teaching Your Team

Joe Ottinger takes a look at how people learn, and applies it to the practice of programming. He notes that understanding how people learn is an essential part of working in a programming team. (September 22, Article)

Can Java EE Deliver The Asynchronous Web?

Stephen Maryka gave us an article about the Asynchronous Web and posed a number of questions that get examined like an approach to delivering Asynchronous Web capabilities through extensions to existing Java EE technologies. (July 14, Article)

JSF Flex

JavaServer Faces Flex goal is to provide users capability in creating standard Flex components, part of flexSDK which is open sourced through MPL license, as normal JSF components. This article by Ji Hoon Kim will provide an overview of creating a simple multilingual JSF page consisting of JSF Flex tags. (June 29, Article)

The Rules of SOA - A Road to a Successful SOA Implementation

In this session Jeff explores the key characteristics of successful SOA projects. He covers some of the patterns, and anti-patterns, tool sets, and strategies that he himself learned the hard way. Last, he provides a strategy and blueprint for achieving a high likelihood of success in your SOA project. (June 23, Tech Talk)

Ari Zilka Talks About Terracotta 3.1

Ari Zilka, CTO of Terracotta, Inc., talks about the new features in Terracotta 3.1, announced during JavaOne and available now. (June 15, Tech Talk)

Enterprise Application Integration, and Spring

In this Tech Talk, Josh Long explores an integration challenge using Spring Integration and walks through the implementation, employing and expanding on the basic patterns of Enterprise Application Integration to tie together components into a function integration solution, and then demonstrates how Spring Integration helps address the integration requirements. (June 15, Tech Talk)

Google Web Toolkit: An Introduction

In this Tech Talk, David Geary teaches you: The basics of Google Web Toolkit; How to implement Ajax-enabled applications in Java; Internationalization; Hooking into the browser history mechanism; Remote procedure calls. (June 4, Tech Talk)

Just Enough Early Architecture to Guide Development

Jon Kern discusses the best architecture/technical solutions and ensure that they are repeated by all developers. By tackling the architecture up-front in a serial manner, subsequent parallel development will be much more manageable and predictable. (May 28, Tech Talk)

Productive Programmer: On the Lam from the Furniture Police

This keynote describes the frustrations of modern knowledge workers in their quest to actually get some work done, and solutions for how to guard yourself against all those distractions. Neal Ford talks about environments, coding, acceleration, automation, and avoiding repetition as ways to defeat the misguided attempts to sap your ability to produce good work. (May 26, Tech Talk)

Auto-Scaling Your Existing Web Application

Gil demonstrates how new, aggressive uses of already abundant compute capacity by common applications offer competitive value for application designers. (May 21, Tech Talk)

Automating Hibernate Mapping and Queries For Java Web Development

Chris Keene introduces WaveMaker as a new way to automate the ability to generate Hibernate classes in order to more quickly bring OR mapping into an application. (May 19, Article)

Auto-Scaling Your Existing Web Application

In this session Nati Shalom demonstrates how to take a standard Java EE web application and scale it out or down dynamically without changes to the application code. Seeing as most web applications are over-provisioned to meet infrequent peak loads, this is a dramatic change because it enables growing your application as needed, when needed, without paying for unutilized resources. (May 19, Tech Talk)

Free Book PDF Download: Mastering EJB Third Edition

Mastering EJB was one of the original and most influential EJB books in the industry. Mastering EJB III now returns with two new expert co-authors, updated for EJB 2.1 and 30% new chapters including security, integration, best practices, open source, and more.
(Book PDF Download)

Application Server Matrix

The Application Server Matrix is a detailed listing of J2EE vendors and their application server products, with information on latest version numbers, J2EE spec support and licensing, pricing, platform support, and links to product downloads and reviews.
(Application Server Comparison Matrix)

News | Blogs | Discussions | Tech talks | Patterns | Reviews | White Papers | Downloads | Articles | Media kit | About
Java Solutions
All Content Copyright ©2007 TheServerSide Privacy Policy
Site Map