Speedment is a Java Tool to Create Database Applications for Existing Databases.
Why should you need to use SQL when the same semantics can be derived directly from Java 8 streams? If you take a closer look at this objective, it turns out there is a remarkable resemblance between the verbs of Java 8 streams
and SQL commands. Streams and SQL queries have similar syntax in part because both are declarative constructs, meaning they describe a result rather than state instructions on how to compute the result. The open source project Speedment capitalizes on this similarity to enable you to perform database actions using Java 8 stream syntax instead of SQL.
|SQL COMMAND||JAVA 8 STREAM OPERATIONS|
|WHERE||filter() (BEFORE COLLECTING)|
|HAVING||filter() (AFTER COLLECTING)|
|JOIN||flatMap() OR map()|
Speedment allows you to write pure Java code for entire database applications. It uses lazy evaluation of streams, meaning that only a minimum set of data is actually pulled from the database into your application and only as the elements are needed.
How It Works:- Because a Java 8 Stream is an interface, there can be many different implementations of streams. Speedment comes with its own Stream implementations that connect seamlessly to database
tables and lazily pull in rows as the streams are being consumed. Furthermore, a Speedment stream introspects its own pipeline before it starts. This means stream operations such as filter() and sorted() can be moved from the stream’s pipeline into a SQL query (more specifically, into its WHERE and ORDER BY clauses, respectively), effectively eliminating the need for writing SQL code altogether.
Why Speedment:- 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. Speedment is a solution to this. The Speedment Java stream ORM leverages standard Java 8 streams to allow fast development of relational database applications.
Stream Based API:-
Speedment Java toolkit and runtime is a Java Stream ORM (Object Relational Mapping). It generates Java object relational mapper classes and API from SQL database metadata. The generated API is stream based and lets users use standard Java streams for querying databases. The generated API is stream based and lets user use standard Java streams for querying databases. By leveraging automatic code generation, the code will be free from manual errors and is quickly generated and can greatly reduce development time and improve application quality. Essentially relational databases are made up of huge chunks of data organized in table-like structures. These structures are ideal for filtering and mapping operations, as can be seen in the SELECT, WHERE and AS statements of the SQL language. Speedment integrates perfectly with the Java 8 Stream API to query databases using lambdas without writing a single line of SQL. The streams are optimized to reduce database load, latency and network load. Speedment uses a custom delegator for the Stream API to manipulate a stream in the background, optimizing the resulting SQL queries.
Parallelism and Transaction Safety:-
Speedment supports parallelism using standard Java Stream semantics. This way, it is possible to easily work with database content in parallel and produce results much faster than if processed sequentially. Speedment provide full transaction safety, Full ACID (Atomicity, Consistency, Isolation, Durability), with selectable isolation levels.
Eliminates Null Pointer Exception:-
Speedment analyzes if null values are allowed for a column in the database and wraps the values as appropriate in Java 8 Optionals. This protects your application for one of the most common Java error manifestations historically: the NullPointerException.
In Memory Acceleration:-
Speedment automatically analyses the SQL relational database structure and creates corresponding in memory data. The Data is structured using a column oriented scheme, allowing data to be retrieved in O(1) or O(log(n)) time using any of the columns. For many operations (e.g. <, >, in, >=, <=, startWith() and sort()), rows can be obtained in sub-millisecond time, even for data sets in the terabytes. Thus, Speedment offers several magnitudes performance increase over standard JDBC “SELECT” code. This means that the original database can be retained in a traditional safe RDBMS environment and that legacy tools can still be used while it is, at the same time, possible to benefit from the advantages of the Speedment technology.
Conclusion:- Under the hood, Speedment converts a ResultSet to a Stream. The raw conversion overhead compared to reading the ResultSet with custom JDBC code and then converting each row to an entity is in every practical aspect negligible. Open source Speedment makes life easier for Java developers and allows them to express database queries in pure Java while using well-known APIs (such as java.util.Stream) that
are interoperable with a large number of other libraries. Using introspection, Speedment is able to render a Java 8 stream pipeline to SQL and lazily pull in relevant elements only as the application needs them.