|
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
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.
|
|
Message #239644
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Nice!
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
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
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
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 #239677
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
John's Perforce server - Farrago, Mondrian etc
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 #239782
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
joSQL
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
... 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 #240191
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Quaere: alternative syntax
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 |
 |
 |
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 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)
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)
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)
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)
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, CTO of Terracotta, Inc., talks about the new features in Terracotta 3.1, announced during JavaOne and available now.
(June 15, Tech Talk)
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)
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)
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)
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)
Gil demonstrates how new, aggressive uses of already abundant compute capacity by common applications offer competitive value for application designers.
(May 21, Tech Talk)
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)
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)
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)
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)
|
|