DEV Community

ts5432
ts5432

Posted on

Load a single record using JooqTemplate

1. load

Load a single record matching the condition and map it to the specified entity class. Automatically appends LIMIT 1.

public <E> E load(String table, Class<E> cls, Condition condition)
public <E> E load(String table, Class<E> cls, Condition condition, List<? extends OrderField> orderBy)
public <E> E load(String table, Class<E> cls, List<Condition> conditions)
public <E> E load(String table, Class<E> cls, List<Condition> conditions, List<? extends OrderField> orderBy)
Enter fullscreen mode Exit fullscreen mode

Returns: Entity object, or null if not found.
Example:

// Single condition
User user = jt.load("user_table", User.class, F("id").eq(id));

// Multiple conditions + order
User user = jt.load("user_table", User.class,
    Arrays.asList(F("name").eq("John"), F("birthday").isNotNull()),
    Arrays.asList(F("create_time").desc()));
Enter fullscreen mode Exit fullscreen mode

2. loadv (varargs conditions)

Load a single record using varargs for conditions. Supports embedding operators and ordering in field names.

public <E> E loadv(String table, Class<E> cls, Object... conditions)
public <E> E loadv(TableLike table, Class<E> cls, Object... conditions)
Enter fullscreen mode Exit fullscreen mode

Example:

// Simple equality
User user = jt.loadv("user_table", User.class, "id", id);

// Combined conditions + sort
User user = jt.loadv("user_table", User.class,
    "name", name, "name:isnotnull", "birthday:desc");

// Mix with Condition object
User user = jt.loadv("user_table", User.class,
    "id", id, F("name").isNotNull());
Enter fullscreen mode Exit fullscreen mode

3. loadRecord

public Record loadRecord(String table, Condition condition)
public Record loadRecord(String table, List<Condition> conditions)
public Record loadRecord(String table, Condition condition, List<? extends OrderField> orderBy)
public Record loadRecord(String table, List<Condition> conditions, List<? extends OrderField> orderBy)
public Record loadRecordv(String table, Object... conditions)
Enter fullscreen mode Exit fullscreen mode

4. loadLowerCaseRecord

public LowerCaseRecord loadLowerCaseRecord(String table, Condition condition)
public LowerCaseRecord loadLowerCaseRecord(String table, List<Condition> conditions)
public LowerCaseRecord loadLowerCaseRecordv(String table, Object... conditions)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)