Presentation

Speedment SQL Reflector
For Automatic Scale out of Existing SQL
Databases with Hazelcast
Per-Åke Minborg
www.speedment.com
Overview
INSERT
UPDATE
DELETE
Hazelcast
Node
Hazelcast
Node
RDBMS
Hazelcast
Node
Speedment
Hazelcast
Node
Reflects all Data with Hazelcast
Exising SQL data from start
System.out.println(hazelcastMap.size());
-> 300024
Inserts
sql> insert into employees (emp_no, birth_date, first_name, last_name, gender, hire_date)
values (10001, '1953-09-02', 'Georgi', 'Facello', 'M', '1986-06-26');
Employees emp = hazelcastMap.get("10001"); System.out.println(emp);
-> Employees { "emp_no": 10001, "birth_date": "1953-09-02", "first_name": "Georgi", "last_name":
"Facello", "gender": "M", "hire_date": "1986-06-26"}
Updates
sql> update employees set first_name="Georgi2" where emp_no=10001;
Employees emp = hazelcastMap.get("10001"); System.out.println(emp);
-> Employees { "emp_no": 10001, "birth_date": "1953-09-02", "first_name": "Georgi2", "last_name":
"Facello", "gender": "M", "hire_date": "1986-06-26"}
Deletes
sql> delete from employees where emp_no = 10001;
Employees emp = hazelcastMap.get("10001"); System.out.println(emp);
-> null
Works with transactions
SQL> START TRANSACTION;
update employees set first_name="Duangkaew"
where emp_no=10010;
update salaries set salary=salary+10 where
id=12322;
COMMIT;
// Backing hazelcast maps are updated atomically
Employees emp = employeesMap.get("10001");
Salaries sal = salaryMap.get("12322");
How do you use it?
“Easy as 1, 2, 3...”
1 Connect to your existing SQL DB…
…and it is Automatically Analyzed
2 Push play and….
… Java Classes are generated…







Java POJOs for each selected table
POJOs implements “IdentifiedDataSerializable”
Serialization factories
Hazelcast config support
Hazelcast Map creation and maintenance classes
SQL DB Metadata (Schema, Tables, Columns)
SQL DDL scripts (with table and triggers to harvest
DB changes)
3 Start Coding with Hazelcast
Work as you are used to, just add 4 lines of code in your startup class
Config hcConfig = new Config();
// Add optimized serialization Factories for Hazelcast that are generated automatically
SpeedmentHazelcastConfig.addTo(hcConfig);
HazelcastInstance hcInstance = Hazelcast.newHazelcastInstance(hcConfig);
// Tell Speedment what Hazelcast instance to use
ProjectManager.getInstance().putProperty(HazelcastInstance.class, hcInstance);
// Automatically build all Database metadata (e.g. Schema, Tables and Columns)
new TreeBuilder().build();
// Load selected data from the database into the Hazelcast maps and start tracking DB
ProjectManager.getInstance().init();
No change in how maps are used
// Get the Hazelcast map for the database table "employees"
IMap<String, Employees> employeesmap =
hcInstance.getMap(EmployeesMgr.getHazelcastMapName());
// Use the Hazelcast map just as you are used to
Employees emp = employeesmap.get("10001");
Conclusion
Now your Hazelcast maps will be synchronized with the underlying
database tables continuously.
Questions?
Per-Åke Minborg
[email protected]
http://minborgsjavapot.blogspot.com/
Twitter: @PMinborg