Skip to content

hugoltsp/havel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Havel

Havel is a simple library for JDBC batch processing, it's mainly written on top of builder classes and a few Java 8 API components (java.util.function and Streams)

Examples

Update
Connection connection = getMyConnection();
Stream<User> users = getMyUsers();

BulkUpdate<User> bulkUpdateOperation = new BulkUpdateBuilder<>()
		.withLogger(LoggerFactory.getLogger("myLogger")) //optional
		.withLoggerLevel(LogLevel.INFO) //optional
		.withConnection(connection)
		.withSqlStatement("INSERT INTO USER (NAME, EMAIL) VALUES (?, ?)")
		.withData(users)
		.withBulkSize(10_000)
		.withCommitBetweenExecutions(true) //optional
		.withStatementMapper((t, u) -> t.addParameter(u.getName()).addParameter(u.getEmail()))
		.build();

BulkUpdateSummary summary = bulkUpdateOperation.execute(); // returns info about executed batch update such as elapsed time

Select

Connection connection = getMyConnection();

BulkSelect<User> bulkSelect = new BulkSelectBuilder<>()
			.withLogger(LoggerFactory.getLogger("myLogger"))
			.withConnection(connection)
			.withSqlStatement("SELECT NAME, EMAIL FROM USER")
			.withOutputMapper(row -> {
				User u = new User();
				u.setEmail(row.getColumn("EMAIL", String.class));
				u.setName(row.getColumn("NAME", String.class));
				return u;
			}).build();
			
Stream<User> users = bulkSelect.select();

Trivia

Named after a Dark Souls character

Releases

No releases published

Packages

No packages published

Languages