Skip to main content

5.3 Builder API

LambdaTemplate is the core class of dbVisitor's Builder API, building SQL statements programmatically and automatically handling database dialect differences.

Choose a Mode First​

ModeRequires object mappingBest for
Entity modeYesEntity classes and method references such as User::getName.
Mapped Map ModeYesTable mapping exists, but row data is carried by Map.
Freedom Map ModeNoDirect table names, column names, and Map values.

Entity mode and Mapped Map Mode require Object Mapping. Freedom Map Mode does not need entity mapping.

Entity class mapping
@Table("users")
public class User {
@Column(value = "id", primary = true, keyType = KeyType.Auto)
private Long id;
@Column("name")
private String name;

public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
Creation and usage
LambdaTemplate lambda = new LambdaTemplate(dataSource);

// Query example
List<User> users = lambda.query(User.class)
.eq(User::getName, "alice")
.queryForList();
Hint

How to obtain a LambdaTemplate depends on your project architecture. See Framework Integration for details.

Principle​

Build operations through the insert, update, delete, query, and freedom series of methods. Developers describe SQL logic programmatically; at runtime, dialect-specific SQL is generated automatically and executed via JdbcTemplate.

User Guide​

Data Writes​

  • Insert: insert entities or multiple records; see Write Conflicts for duplicate handling.
  • Update: update selected fields, use a sample, or overwrite a row.
  • Delete: delete records matching the conditions.

Updates and deletes reject empty conditions by default. Call allowEmptyWhere() explicitly to operate on all records. See Builder API Differences for affected counts and readback behavior by data source.