Easy Java 8 App Development
How do you bridge between the two fundamentally different worlds of an object oriented language like Java and a relational database? Until now, you could take the time to write your own mapping layer, or use an Object Relational Mapper (ORM) like Hibernate. It can be convenient to use an ORM, but it can slow down your application, and configuration may be challenging.
Luckily, Speedment has found an alternative, by solving this problem for our own projects. We are sharing our technology in the hopes that it will make life easier for all Java database application developers.
Open Source Speedment supports MySQL and MariaDB. For Java 7 users and other databases we provide further options in the Enterprise version, please see Open Source details on Github and Enterprise version for further features.
What is Speedment Open Source?
Speedment Open Source project is written entirely in Java 8. Speedment uses standard streams for querying a database so you do not have to learn any new query API. You do not have to think at all about JDBC, ResultSet nor other database specific things!
Speedment generates code automatically by analysing an existing database (i.e. the “domain model”). That way, you do not have to write a single line of code for database entities. The generated code even contains auto-generated JavaDocs!
Query with Smart Streams
Here is an example how it could look like when you are querying a table named “hare” :
List<Hare> oldHares = hares.stream() .filter(AGE.greaterThan(8)) .collect(toList());
Now, it looks like the code above will stream over all rows in the “hare” database table, but it is actually not. The
Stream is “smart” and will, upon reaching its Terminal Operation
collect(), analyze the filter
Predicate “AGE.greaterThan(8)” and conclude that it is actually the “hare.age” column that is compared to 8 and thus, it will be able to reduce the stream of hares to something corresponding to:
SELECT * FROM `hare` WHERE `hare`.`age` > 8;
If you are using several filters, they are of course further combined to reduce the stream even more. Just to show the principle, here is a stream with more operations:
long noOldHares = hares.stream() .filter(AGE.greaterThan(8)) .mapToInt(Hare::getAge) .sorted() .count();
When this <code”>Stream reaches its Terminal Operation
count(), it will inspect its own pipeline. It will then conclude that it can reduce the AGE
Predicate just like in the previous example. It will furthermore conclude that the operations
sorted() does not change the outcome of <code”>count() and thus, these operations can be eliminated all together. So the statement is reduced to:
SELECT COUNT(*) FROM `hare` WHERE `hare`.`age` > 8;
This means that you can use Java 8 streams while you do not have to care so much about how the streams are translated to SQL.
Try It Out!
If you are curious and like Java8, you can try Speedment as an alternative to traditional ORMs.