Gain SQL SELECT functionality in Java

Select, filter, and sort collections or arrays of objects with a simple mechanism

1 2 Page 2
Page 2 of 2

As you can see, constructing a simple SELECT statement in Java is almost as simple as constructing a simple SELECT statement in SQL. The more features you want to use, the more complicated it gets. But, you can also do more with your invokers, conditions, and comparators then you can with a SQL SELECT. After all, that's why you became a programmer and not a database designer!

Some missing features

The solution presented only allows you to apply SELECT functionality to a single array or collection. What if we want to select data from multiple arrays or collections? What about INSERT, UPDATE, and DELETE? And how about writing a parser that takes a simple SQL statement as input, creates the objects described, and applies them to one or multiple datasources? If we had a complete SQL API in Java, we could treat a cache of database objects the same way we treat the database itself using simple SQL statements! These and other issues are, for now, left as an exercise for the reader.

David Rappoport has worked for IBM Global Services and Credit Suisse Application Development for the past five years, where he has been developing software in the J2EE area. He is a Sun Certified Java 2 Programmer, Sun Certified Java 2 Developer, Sun Certified J2EE Architect, and Sun Certified Business Component Developer. He lives with his wife and two children in Switzerland.

Learn more about this topic

This story, "Gain SQL SELECT functionality in Java" was originally published by JavaWorld.

Copyright © 2004 IDG Communications, Inc.

1 2 Page 2
Page 2 of 2