SlideShare a Scribd company logo
Meetup Gothenburg Dec
28 2015
Per-Åke Minborg
minborg@speedment.com
Palo Alto Office Speedment Java One
Presentation
Background
Before Speedment
Connector
JDBC
ORM
JPA
Application
PROS
Widely spread standard
• Many providers
• Many developers
You can work with a
relational database as if it
were object oriented
 Increased productivity
 Provides a certain
degree of abstraction
(you can replace your
DBMS)
CONS
 Slows down the application
and gives unpredictable
performance
 You can not access all
Java 8 features
Time consuming to write
applications for existing
databases, You must still
write SQL, HQL, et. Al
Higher the risk for errors
Java
ORM
JPA
Speedment- a Java
Development Tool
Connector
JDBC
Application
Object Oriented functional programming
 Fast to develop
 Fast Execution
 Easy to test
 Secure
 Make use of all Java 8 features
Domain Model reflects your existing
datasource
Automatic generation of Code (”error
free”)
Java
Speedment
Java 8
Application
Speedment- a Java
Development Tool
Code Examples
• Embrace Java 8 paradigms with stream(), filter(), sort(), limit() etc.
• Forget about SQL, JQL et. al
Database Table “hare”
mysql> explain hare;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(45) | NO | | NULL | |
| color | varchar(45) | NO | | NULL | |
| age | int(11) | NO | | NU | |
+-------+-------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)
Code Generation
public interface Hare extends Entity<Hare> {
public final static ReferenceComparableField<Hare, Integer> ID = …
public final static ReferenceComparableStringField<Hare> NAME = …
public final static ReferenceComparableStringField<Hare> COLOR = …
public final static ReferenceComparableField<Hare, Integer> AGE = …
Integer getId();
String getName();
String getColor();
Integer getAge();
Hare setId(Integer id);
Hare setName(String name);
Hare setColor(String color);
Hare setAge(Integer age);
/** Graph-like traversal methods eliminating JOINs */
Stream<Carrot> findCarrotsByOwner();
Stream<Carrot> findCarrotsByRival();
Stream<Carrot> findCarrots();
}
DZone Java 8 Block Buster: Query Databases Using Streams
Querying using Java 8
Streams
List<Hare> oldHares = hares.stream()
.filter(Hare.AGE.greaterThan(4))
.collect(toList());
SELECT * from `hare`
WHERE
`age` > 4;
Stream Fundamentals
Detailed description Slide 35-45
Depends on Terminating
Operation
Optional<Hare> oldHare = hares.stream()
.filter(Hare.AGE.greaterThan(4))
.findAny();
SELECT * from `hare`
WHERE
`age` > 4 LIMIT 1;
Depends on Terminating
Operation
long noOldHares = hares.stream()
.filter(Hare.AGE.greaterThan(4))
.count();
SELECT count(*) from `hare`
WHERE
`age` > 4;
Entities are linked
Optional<Carrot> carrot = hares.stream()
.filter(Hare.NAME.equal(”Spire”))
// Carrot is a foreign key.
.flatmap(Hare::findCarrots)
.findAny();
Multi-threading
hares.stream()
.parallel()
.forEach(doExpensiveOperation());
Persistence
Hare harry = hares.newInstance()
.setName("Harry")
.setColor("Gray")
.setAge(3)
.persist();
// OR JPA-style
entityManager.persist(harry);
Delete Using Streams
users.stream()
.filter(User.ID.greaterThan(4))
.forEach(User::delete);
DELETE FROM `user`
WHERE `id` > 4;
Initialization
Speedment speedment = new HareApplication().build();
Manager<Hare> hares = speedment.managerOf(Hare.class);
Speedment Insane Mode
•Extreme Performance, real time big Data
•Convert large databases into In-JVM-memory Java Objects
•Scales Linearly -More CPUs, More Insane
In Memory Initialization
Speedment speedment = new HareApplication()
.with(OnHeapReadOnlyCacheComponent.class)
.build();
DZone Java 8 Block Buster: Query Databases Using Streams
How does it Work?
23
1 In-JVM-memory cache
2 Java Objects in Graph View
3 Separates Reads and Writes
Reflection in
real time
Application
JVM
Read
Write
Why will in-JVM-Memory give
Insane Speed?
Database In JVM Memory
Compare latencies using the Speed of Light
Why will in-JVM Memory give
Insane Speed?
• Keep everything in-JVM
• No need to check if an object is in cache
• We can organize objects knowing that we have them all
• We do not even have to look at individual objects -> O(1)
• Everything is Java
Size
Time
O(1)
O(n)
Speedment – OSS and
Enterprise
Cloud Deployment
RDBMS
Speedment
Speedment
Speedment
Speedment
Speedment
• Spin up nodes as you
grow
• Partition data over nodes
How can I fit my full Database
in JVM Memory?
~24 GB
>1 TB
>4 TB
∞
On-Heap
Off-Heap
SSD
SQL
Database Size
(After Compression)
Scale out with our partner
Hazelcast
• Set up a cluster in the Cloud
• Scale out your existing database
• Set up Terabytes of RAM
Properties:
• The API will remain the same regardless of selected Storage Engine
• Massively concurrent and lock free
• Scale with CPU performance and number of cores
• Eventually consistent
• Transaction safe, if you want
Configuration
• Groovy script like Gradle
• Config file is placed at the same location as the POM
dbms {
schema {
table {
name = ”hare";
column {
name = "name";
}
}
}
}
Ease of use:
• Single Maven dependency in POM
• Maven targets
• Works with Gradle
• GUI to automatically derive the groovy config file from existing databases
Properties:
• The database ”owns” the data
• Data is reflected into Materialized Object Views (MOVs)
• MOVs and application resides in the same JVM
• Most operations are O(1)
• persons.byName(“Bob") -> Map<PK,Person> with 1000 persons in 100 ns
(30 m)
• TCP/IP RTT 100 us -> +1000 "finds" per TCP RT.
• In-memory DBs with zero query latency are snails by definition
http://localhost:4567/trades/1001/200?
from=0&to=1441147840000&callback=Ext.data.JsonP.callback1
Ext.data.JsonP.callback1([
{'start':1420131600000,'stop':1420236681000,'average':100876,'open':100000,'close':102209,'high':104060,'low':98714},
{'start':1420236682000,'stop':1420243199000,'average':102339,'open':102224,'close':103348,'high':103366,'low':101603},
{'start':1420477200000,'stop':1420502399000,'average':102272,'open':103353,'close':103316,'high':103608,'low':100819},
{'start':1420563600000,'stop':1420657005000,'average':101682,'open':103315,'close':102292,'high':103755,'low':99241},
… (200 rows in total) ...
{'start':1441147839000,'stop':1441147839000,'average':142165,'open':142165,'close':142165,'high':142165,'low':142165}
]);
Objectives:
Stream Fundamentals Per-Åke Minborg
minborg@speedment.com
Setup
36
DB App
Pwd ?
In-JVM
Cache
Stream<Trade>stream= trades.stream();
37
DB
Data
Source
Trade5 Trade4 Trade3 Trade2 Trade1
trades.stream().parallel();
38
TradeN
Trade4
Trade3
Trade2
Trade1
TradeX
Thread 1
Thread 2
Thread N
DB
Data
Source
trades.stream().filter(Predicate<Trade> predicate);
39
Trade2 Trade1
predicate.
test(trade)Trade5 Trade4
Trade3
false
true
trades.stream().map(Function<Trade,String>mapper);
40
Json2 Json1Trade5 Trade4
mapper.
apply(trade)
e.g.Trade::toJson
trades.stream().collect(Collectorcollector);
41
TradeN
Trade4
Trade3
Trade2
Trade1
TradeX
apply(trade)
apply(trade)
apply(trade)
Complete Stream
42
DB
Data
Source
Finding first and last date/time in an interval
43
from to
selected
trades.stream().parallel()
.filter(DATE.between(from, to))
.filter(STOCK.equal(stock))
.mapToLong(Trade::getDate)
.summaryStatistics();
44
2 3 4
2 3 4
2 3 4
5
1
2
3
4
5
DB
Data
Source
45
DB
Data
Source 1
4
4
4
5
2
3
trades.stream().parallel()
.filter(DATE.between(from, to))
.filter(STOCK.equal(stock))
.mapToLong(Trade::getDate)
.summaryStatistics();
1
2
3
4
5
Generating a REST API
Introduction to Speedment and Sencha
Emil Forslund
emil@speedment.com
Outline
●The Speedment + Sencha Software Stack
●Using the Pivotgrid Plugin for Speedment
Overview of the Software
Stack
DB
Javascript Framework
Server
Framework
DB Abstraction Layer
Database Layer
●Holds all the data collected from various sources
●High Level of Normalization
Sale
Product
Salesperson
Customer
Country
Region
Office
Cost Price
Count
Database Abstraction Layer
●Presents an Object-Oriented view of the database
●Write expressive and powerful queries
●Optimize reading by using in-memory caching
●Better testability and higher productivity
speedment.managerOf(Sale.class)
.stream()
.filter(Sale.PRODUCT.equal(105))
.collect(toList());
Server Framework
●A lightweight webserver
●Separates client/server-responsabilitys
●Execute selected business logic as response to REST commands
●Low Level of Abstraction
http://localhost:8123/salesinfo/
?c=callback
&filter=[{...}]
Javascript Framework
●Presents data in user-friendly components
●User can navigate the data in the browser
●Automatically requests additional data from the server
Introduction to the Pivot Grid
for Speedment
●Generate a full-fledged server application from your database
●Select exactly which data to expose in the API
●Define aliases for columns and tables
●Map between different data types
●Create virtual columns calculated in real-time
Step 1 – Create a New Project
Step 2 – Find Pivotgrid
Archetype
Step 3 – Name Project
Step 4 – Run Speedment GUI
Step 5 – Press Generate
Step 6 – Run Application
Example Application:
Salesinfo
Thanks!

More Related Content

PDF
Speedment - Reactive programming for Java8
PPT
NYJavaSIG - Big Data Microservices w/ Speedment
PDF
Building a near real time search engine & analytics for logs using solr
PDF
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...
PDF
Data Analytics Service Company and Its Ruby Usage
PDF
Presto At Treasure Data
PPTX
Performance Tuning and Optimization
PDF
Groovy concurrency
Speedment - Reactive programming for Java8
NYJavaSIG - Big Data Microservices w/ Speedment
Building a near real time search engine & analytics for logs using solr
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...
Data Analytics Service Company and Its Ruby Usage
Presto At Treasure Data
Performance Tuning and Optimization
Groovy concurrency

What's hot (20)

PDF
Introduction to Apache ZooKeeper
PDF
Integrate Solr with real-time stream processing applications
PDF
使用ZooKeeper打造軟體式負載平衡
PDF
Scaling Hibernate with Terracotta
PDF
Structured Streaming for Columnar Data Warehouses with Jack Gudenkauf
PPTX
Distributed Applications with Apache Zookeeper
PPTX
Real-Time Integration Between MongoDB and SQL Databases
PPT
Real-Time Streaming with Apache Spark Streaming and Apache Storm
PDF
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
PDF
Distributed real time stream processing- why and how
PDF
Logging for Production Systems in The Container Era
PDF
Beyond the Query – Bringing Complex Access Patterns to NoSQL with DataStax - ...
PDF
Treasure Data and AWS - Developers.io 2015
PPTX
How to ensure Presto scalability 
in multi use case
PDF
Spark on Mesos-A Deep Dive-(Dean Wampler and Tim Chen, Typesafe and Mesosphere)
PDF
Hive dirty/beautiful hacks in TD
PDF
Fortify aws aurora_proxy
PPTX
NYC Lucene/Solr Meetup: Spark / Solr
PDF
Call me maybe: Jepsen and flaky networks
PPTX
To scale or not to scale: Key/Value, Document, SQL, JPA – What’s right for my...
Introduction to Apache ZooKeeper
Integrate Solr with real-time stream processing applications
使用ZooKeeper打造軟體式負載平衡
Scaling Hibernate with Terracotta
Structured Streaming for Columnar Data Warehouses with Jack Gudenkauf
Distributed Applications with Apache Zookeeper
Real-Time Integration Between MongoDB and SQL Databases
Real-Time Streaming with Apache Spark Streaming and Apache Storm
High Performance Solr and JVM Tuning Strategies used for MapQuest’s Search Ah...
Distributed real time stream processing- why and how
Logging for Production Systems in The Container Era
Beyond the Query – Bringing Complex Access Patterns to NoSQL with DataStax - ...
Treasure Data and AWS - Developers.io 2015
How to ensure Presto scalability 
in multi use case
Spark on Mesos-A Deep Dive-(Dean Wampler and Tim Chen, Typesafe and Mesosphere)
Hive dirty/beautiful hacks in TD
Fortify aws aurora_proxy
NYC Lucene/Solr Meetup: Spark / Solr
Call me maybe: Jepsen and flaky networks
To scale or not to scale: Key/Value, Document, SQL, JPA – What’s right for my...
Ad

Similar to DZone Java 8 Block Buster: Query Databases Using Streams (20)

PPTX
Java days gbg online
PPTX
eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015
PDF
SAP Open Source meetup/Speedment - Palo Alto 2015
PDF
Migrating Speedment to Java 9
PPTX
How to generate customized java 8 code from your database
PPTX
Silicon Valley JUG - How to generate customized java 8 code from your database
PPTX
Work with hundred of hot terabytes in JVMs
PPTX
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
PPTX
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
PDF
In-Memory Computing - The Big Picture
PDF
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
PDF
WebObjects Optimization
PDF
Building Realtime Access Data Apps with Speedment (TCF ITPC 2017)
KEY
Appengine Nljug
PPTX
Modern software design in Big data era
PPTX
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
PDF
Apache Con Us2007 Apachei Batis
 
PPTX
In memory databases presentation
PDF
Scalable IoT platform
PPT
Wmware NoSQL
Java days gbg online
eXtreme Tuesday Club at Pivotal Labs ft. Speemdnet / San Francisco - SEP 2015
SAP Open Source meetup/Speedment - Palo Alto 2015
Migrating Speedment to Java 9
How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your database
Work with hundred of hot terabytes in JVMs
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
In-Memory Computing - The Big Picture
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
WebObjects Optimization
Building Realtime Access Data Apps with Speedment (TCF ITPC 2017)
Appengine Nljug
Modern software design in Big data era
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
Apache Con Us2007 Apachei Batis
 
In memory databases presentation
Scalable IoT platform
Wmware NoSQL
Ad

More from Speedment, Inc. (6)

PPTX
SenchaCon Roadshow Irvine 2017
PPTX
SenchaCon 2016 - How to Auto Generate a Back-end in Minutes
PPTX
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
PPTX
Speed-up Your Big Data Applications with Sencha and Speedment
PPTX
Speedment & Sencha at Oracle Open World 2015
PPTX
Java one2015 - Work With Hundreds of Hot Terabytes in JVMs
SenchaCon Roadshow Irvine 2017
SenchaCon 2016 - How to Auto Generate a Back-end in Minutes
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
Speed-up Your Big Data Applications with Sencha and Speedment
Speedment & Sencha at Oracle Open World 2015
Java one2015 - Work With Hundreds of Hot Terabytes in JVMs

Recently uploaded (20)

PDF
Understanding Forklifts - TECH EHS Solution
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Introduction to Artificial Intelligence
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
AI in Product Development-omnex systems
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
L1 - Introduction to python Backend.pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Understanding Forklifts - TECH EHS Solution
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Which alternative to Crystal Reports is best for small or large businesses.pdf
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
Introduction to Artificial Intelligence
Design an Analysis of Algorithms II-SECS-1021-03
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
AI in Product Development-omnex systems
VVF-Customer-Presentation2025-Ver1.9.pptx
L1 - Introduction to python Backend.pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
Softaken Excel to vCard Converter Software.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Odoo Companies in India – Driving Business Transformation.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
How to Choose the Right IT Partner for Your Business in Malaysia
Lecture 3: Operating Systems Introduction to Computer Hardware Systems

DZone Java 8 Block Buster: Query Databases Using Streams