Skip to main content

Posts

Showing posts from February, 2019

How to build your own SQLBuilder from scartch

Hibernate is used widely for data access. It is great to release developer from tons of sql scripts. However, the performance is about 50% less than pure jdbc access. For core function, my current project is still using the pure jdbc to access. The pain part is the current code is all write down by stringbuilder which is easy to make a mistake in syntax and missing space between key sql words. My purpose is trying to create simple java class which help build sql prepared statement. The class should be working in the following feature as the first version: 1. Support select, Update, delete sql generation. 2.  Code usage should go with the flow feature 3. Support where, join, and, or key words. 4. support parameters for prepared statement. Let's start from simple simple select/delete statement, the unit test will be as following at first: The implementation will be simple as well: After that, we add support of "WHERE" "UPDATE" as well as al...

The performance of non-blocking jdbc

The JDK 9+ provided incubator to support non-blocking jdbc. The idea is trying to process data when reading or updating the database.  The code support most existing jdbc driver and just need minimal change of incubator code. With the non-blocking jdbc code, the performance increased significantly for updating operations. But just hit slightly change on selection. It make sense since updating will cost on database side and our code will wait longer time to database IO response. The chart clearly show performance comparison between block jdbc and non-block jdbc. Overview, all of them hit the similar query time by access 10000 rows simple data. When using just one thread, the non-block api just took half time of block api to update the database. However, multiple thread increase the performance block api a lot. It should be like it since multiple thread used more system resources to process services. See the table before for detail data: Although multiple thead...