or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

active-record.mdbootstrap-config.mdcrud-operations.mddatabase-support.mdindex.mdpagination.mdquery-builder.mdrow-operations.mdservice-layer.mdupdate-chain.md

crud-operations.mddocs/

0

# Universal CRUD Operations

1

2

Comprehensive CRUD interface that eliminates the need for custom mapper methods. The BaseMapper interface provides all standard database operations with support for batch processing, relationship loading, and advanced querying.

3

4

## Capabilities

5

6

### BaseMapper Interface

7

8

Universal CRUD interface that all entity mappers should extend. Provides complete database operations without requiring custom method definitions.

9

10

```java { .api }

11

/**

12

* Universal CRUD interface for all entity operations

13

* @param <T> Entity type

14

*/

15

public interface BaseMapper<T> {

16

// Insert operations

17

int insert(T entity);

18

int insert(T entity, boolean ignoreNulls);

19

int insertSelective(T entity);

20

int insertWithPk(T entity);

21

int insertSelectiveWithPk(T entity);

22

int insertWithPk(T entity, boolean ignoreNulls);

23

int insertBatch(Collection<T> entities);

24

int insertBatch(Collection<T> entities, int size);

25

int insertBatchSelective(Collection<T> entities);

26

int insertBatchSelective(Collection<T> entities, int size);

27

int insertOrUpdate(T entity);

28

int insertOrUpdateSelective(T entity);

29

int insertOrUpdate(T entity, boolean ignoreNulls);

30

31

// Select operations

32

T selectOneByEntityId(T entity);

33

T selectOneById(Serializable id);

34

T selectOneByMap(Map<String, Object> whereConditions);

35

T selectOneByCondition(QueryCondition whereConditions);

36

T selectOneByQuery(QueryWrapper queryWrapper);

37

<R> R selectOneByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

38

T selectOneWithRelationsByMap(Map<String, Object> whereConditions);

39

T selectOneWithRelationsByCondition(QueryCondition whereConditions);

40

T selectOneWithRelationsByQuery(QueryWrapper queryWrapper);

41

T selectOneWithRelationsById(Serializable id);

42

<R> R selectOneWithRelationsByIdAs(Serializable id, Class<R> asType);

43

<R> R selectOneWithRelationsByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

44

List<T> selectListByIds(Collection<? extends Serializable> ids);

45

List<T> selectListByMap(Map<String, Object> whereConditions);

46

List<T> selectListByMap(Map<String, Object> whereConditions, Long count);

47

List<T> selectListByCondition(QueryCondition whereConditions);

48

List<T> selectListByCondition(QueryCondition whereConditions, Long count);

49

List<T> selectListByQuery(QueryWrapper queryWrapper);

50

List<T> selectListByQuery(QueryWrapper queryWrapper, Consumer<FieldQueryBuilder<T>>... consumers);

51

Cursor<T> selectCursorByQuery(QueryWrapper queryWrapper);

52

<R> Cursor<R> selectCursorByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

53

List<Row> selectRowsByQuery(QueryWrapper queryWrapper);

54

<R> List<R> selectListByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

55

<R> List<R> selectListByQueryAs(QueryWrapper queryWrapper, Class<R> asType, Consumer<FieldQueryBuilder<R>>... consumers);

56

List<T> selectListWithRelationsByQuery(QueryWrapper queryWrapper);

57

<R> List<R> selectListWithRelationsByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

58

<R> List<R> selectListWithRelationsByQueryAs(QueryWrapper queryWrapper, Class<R> asType, Consumer<FieldQueryBuilder<R>>... consumers);

59

List<T> selectAll();

60

List<T> selectAllWithRelations();

61

Object selectObjectByQuery(QueryWrapper queryWrapper);

62

<R> R selectObjectByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

63

List<Object> selectObjectListByQuery(QueryWrapper queryWrapper);

64

<R> List<R> selectObjectListByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

65

long selectCountByQuery(QueryWrapper queryWrapper);

66

long selectCountByCondition(QueryCondition whereConditions);

67

68

// Update operations

69

int update(T entity);

70

int update(T entity, boolean ignoreNulls);

71

int updateByMap(T entity, Map<String, Object> whereConditions);

72

int updateByMap(T entity, boolean ignoreNulls, Map<String, Object> whereConditions);

73

int updateByCondition(T entity, QueryCondition whereConditions);

74

int updateByCondition(T entity, boolean ignoreNulls, QueryCondition whereConditions);

75

int updateByQuery(T entity, QueryWrapper queryWrapper);

76

int updateByQuery(T entity, boolean ignoreNulls, QueryWrapper queryWrapper);

77

78

// Delete operations

79

int delete(T entity);

80

int deleteById(Serializable id);

81

int deleteBatchByIds(Collection<? extends Serializable> ids);

82

int deleteBatchByIds(Collection<? extends Serializable> ids, int size);

83

int deleteByMap(Map<String, Object> whereConditions);

84

int deleteByCondition(QueryCondition whereConditions);

85

int deleteByQuery(QueryWrapper queryWrapper);

86

87

// Pagination operations

88

Page<T> paginate(Number pageNumber, Number pageSize, QueryWrapper queryWrapper);

89

Page<T> paginateWithRelations(Number pageNumber, Number pageSize, QueryWrapper queryWrapper);

90

Page<T> paginate(Number pageNumber, Number pageSize, QueryCondition whereConditions);

91

Page<T> paginateWithRelations(Number pageNumber, Number pageSize, QueryCondition whereConditions);

92

Page<T> paginate(Number pageNumber, Number pageSize, Number totalRow, QueryWrapper queryWrapper);

93

Page<T> paginateWithRelations(Number pageNumber, Number pageSize, Number totalRow, QueryWrapper queryWrapper);

94

Page<T> paginate(Number pageNumber, Number pageSize, Number totalRow, QueryCondition whereConditions);

95

Page<T> paginateWithRelations(Number pageNumber, Number pageSize, Number totalRow, QueryCondition whereConditions);

96

Page<T> paginate(Page<T> page, QueryWrapper queryWrapper);

97

Page<T> paginate(Page<T> page, QueryWrapper queryWrapper, Consumer<FieldQueryBuilder<T>>... consumers);

98

Page<T> paginateWithRelations(Page<T> page, QueryWrapper queryWrapper);

99

Page<T> paginateWithRelations(Page<T> page, QueryWrapper queryWrapper, Consumer<FieldQueryBuilder<T>>... consumers);

100

<R> Page<R> paginateAs(Number pageNumber, Number pageSize, QueryWrapper queryWrapper, Class<R> asType);

101

<R> Page<R> paginateAs(Number pageNumber, Number pageSize, Number totalRow, QueryWrapper queryWrapper, Class<R> asType);

102

<R> Page<R> paginateAs(Page<R> page, QueryWrapper queryWrapper, Class<R> asType);

103

<R> Page<R> paginateAs(Page<R> page, QueryWrapper queryWrapper, Class<R> asType, Consumer<FieldQueryBuilder<R>>... consumers);

104

<R> Page<R> paginateWithRelationsAs(Number pageNumber, Number pageSize, QueryWrapper queryWrapper, Class<R> asType);

105

<R> Page<R> paginateWithRelationsAs(Number pageNumber, Number pageSize, Number totalRow, QueryWrapper queryWrapper, Class<R> asType);

106

<R> Page<R> paginateWithRelationsAs(Page<R> page, QueryWrapper queryWrapper, Class<R> asType);

107

<R> Page<R> paginateWithRelationsAs(Page<R> page, QueryWrapper queryWrapper, Class<R> asType, Consumer<FieldQueryBuilder<R>>... consumers);

108

109

// XML operations

110

<E> Page<E> xmlPaginate(String dataSelectId, Page<E> page, QueryWrapper queryWrapper);

111

<E> Page<E> xmlPaginate(String dataSelectId, Page<E> page, Map<String, Object> otherParams);

112

<E> Page<E> xmlPaginate(String dataSelectId, Page<E> page, QueryWrapper queryWrapper, Map<String, Object> otherParams);

113

<E> Page<E> xmlPaginate(String dataSelectId, String countSelectId, Page<E> page, QueryWrapper queryWrapper, Map<String, Object> otherParams);

114

}

115

```

116

117

**Basic Mapper Definition:**

118

119

```java

120

import com.mybatisflex.core.BaseMapper;

121

122

// Entity class

123

@Table("users")

124

public class User {

125

@Id

126

private Long id;

127

private String name;

128

private Integer age;

129

private String email;

130

131

// constructors, getters, setters...

132

}

133

134

// Mapper interface - no custom methods needed!

135

public interface UserMapper extends BaseMapper<User> {

136

// Inherits all CRUD operations from BaseMapper

137

}

138

```

139

140

### Insert Operations

141

142

Comprehensive insert capabilities including selective insertion, batch operations, and upsert functionality.

143

144

```java { .api }

145

/**

146

* Insert entity with all fields (including null values)

147

* @param entity entity to insert

148

* @return number of affected rows

149

*/

150

int insert(T entity);

151

152

/**

153

* Insert entity with control over null value handling

154

* @param entity entity to insert

155

* @param ignoreNulls whether to ignore null values

156

* @return number of affected rows

157

*/

158

int insert(T entity, boolean ignoreNulls);

159

160

/**

161

* Insert entity ignoring null fields (selective insert)

162

* Allows database default values to take effect for null fields

163

* @param entity entity to insert

164

* @return number of affected rows

165

*/

166

int insertSelective(T entity);

167

168

/**

169

* Insert entity with primary key value (bypasses primary key generator)

170

* @param entity entity to insert with pre-set primary key

171

* @return number of affected rows

172

*/

173

int insertWithPk(T entity);

174

175

/**

176

* Insert entity with primary key value, ignoring null fields

177

* @param entity entity to insert with pre-set primary key

178

* @return number of affected rows

179

*/

180

int insertSelectiveWithPk(T entity);

181

182

/**

183

* Insert entity with primary key value and null handling control

184

* @param entity entity to insert with pre-set primary key

185

* @param ignoreNulls whether to ignore null values

186

* @return number of affected rows

187

*/

188

int insertWithPk(T entity, boolean ignoreNulls);

189

190

/**

191

* Batch insert multiple entities (based on first entity's field structure)

192

* @param entities collection of entities to insert

193

* @return number of affected rows

194

*/

195

int insertBatch(Collection<T> entities);

196

197

/**

198

* Batch insert multiple entities with size chunking

199

* @param entities collection of entities to insert

200

* @param size chunk size for batching (0 or negative uses default size)

201

* @return number of affected rows

202

*/

203

int insertBatch(Collection<T> entities, int size);

204

205

/**

206

* Batch insert multiple entities ignoring null values

207

* Uses selective insertion strategy for each entity

208

* @param entities collection of entities to insert

209

* @return number of affected rows

210

*/

211

int insertBatchSelective(Collection<T> entities);

212

213

/**

214

* Batch insert multiple entities ignoring null values with size chunking

215

* @param entities collection of entities to insert

216

* @param size chunk size for batching (0 or negative uses default size)

217

* @return number of affected rows

218

*/

219

int insertBatchSelective(Collection<T> entities, int size);

220

221

/**

222

* Insert or update entity (upsert operation)

223

* Updates if primary key exists, inserts if not

224

* @param entity entity to insert or update

225

* @return number of affected rows

226

*/

227

int insertOrUpdate(T entity);

228

229

/**

230

* Insert or update entity with selective null handling (upsert operation)

231

* Updates if primary key exists, inserts if not, ignoring null fields

232

* @param entity entity to insert or update

233

* @return number of affected rows

234

*/

235

int insertOrUpdateSelective(T entity);

236

237

/**

238

* Insert or update entity with null handling control (upsert operation)

239

* @param entity entity to insert or update

240

* @param ignoreNulls whether to ignore null values

241

* @return number of affected rows

242

*/

243

int insertOrUpdate(T entity, boolean ignoreNulls);

244

```

245

246

**Insert Examples:**

247

248

```java

249

UserMapper userMapper = // ... get mapper instance

250

251

// Basic insert (includes null values)

252

User user = new User("Alice", 25, "alice@example.com");

253

int rows = userMapper.insert(user);

254

255

// Insert with null control

256

User userWithNulls = new User("Bob", null, "bob@example.com");

257

userMapper.insert(userWithNulls, false); // Include nulls

258

userMapper.insert(userWithNulls, true); // Ignore nulls

259

260

// Selective insert (ignores null fields)

261

User partialUser = new User();

262

partialUser.setName("Charlie");

263

partialUser.setAge(30);

264

// email remains null and won't be inserted

265

userMapper.insertSelective(partialUser);

266

267

// Insert with primary key (bypasses PK generator)

268

User userWithId = new User();

269

userWithId.setId(100L);

270

userWithId.setName("Diana");

271

userWithId.setAge(28);

272

userMapper.insertWithPk(userWithId);

273

274

// Insert with PK, ignoring nulls

275

userMapper.insertSelectiveWithPk(userWithId);

276

277

// Batch insert

278

List<User> users = Arrays.asList(

279

new User("Eve", 28, "eve@example.com"),

280

new User("Frank", 32, "frank@example.com")

281

);

282

userMapper.insertBatch(users);

283

284

// Batch insert with chunking

285

List<User> manyUsers = generateManyUsers();

286

userMapper.insertBatch(manyUsers, 500); // Insert in chunks of 500

287

288

// Batch selective insert (ignores nulls for all entities)

289

List<User> usersWithNulls = generateUsersWithNulls();

290

userMapper.insertBatchSelective(usersWithNulls);

291

292

// Upsert operations

293

User existingUser = new User();

294

existingUser.setId(1L);

295

existingUser.setName("Alice Updated");

296

existingUser.setAge(26);

297

userMapper.insertOrUpdate(existingUser); // Updates if ID exists, inserts if not

298

299

// Selective upsert (ignores nulls)

300

userMapper.insertOrUpdateSelective(existingUser);

301

302

// Upsert with null control

303

userMapper.insertOrUpdate(existingUser, true); // Ignore nulls

304

```

305

306

### Select Operations

307

308

Comprehensive query operations including single record retrieval, list queries, counting, and relationship loading.

309

310

```java { .api }

311

/**

312

* Select single entity by entity's primary key values

313

* @param entity entity containing primary key values

314

* @return entity or null if not found

315

*/

316

T selectOneByEntityId(T entity);

317

318

/**

319

* Select single entity by primary key

320

* @param id primary key value

321

* @return entity or null if not found

322

*/

323

T selectOneById(Serializable id);

324

325

/**

326

* Select single entity by Map conditions

327

* @param whereConditions key-value condition pairs

328

* @return entity or null if not found

329

*/

330

T selectOneByMap(Map<String, Object> whereConditions);

331

332

/**

333

* Select single entity by QueryCondition

334

* @param whereConditions query conditions

335

* @return entity or null if not found

336

*/

337

T selectOneByCondition(QueryCondition whereConditions);

338

339

/**

340

* Select single entity by query conditions

341

* @param queryWrapper query conditions

342

* @return single entity or null

343

*/

344

T selectOneByQuery(QueryWrapper queryWrapper);

345

346

/**

347

* Select single entity by query conditions with type conversion

348

* @param queryWrapper query conditions

349

* @param asType target type for conversion

350

* @return converted entity or null

351

*/

352

<R> R selectOneByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

353

354

/**

355

* Select single entity with relationships by Map conditions

356

* @param whereConditions key-value condition pairs

357

* @return entity with relationships or null

358

*/

359

T selectOneWithRelationsByMap(Map<String, Object> whereConditions);

360

361

/**

362

* Select single entity with relationships by QueryCondition

363

* @param whereConditions query conditions

364

* @return entity with relationships or null

365

*/

366

T selectOneWithRelationsByCondition(QueryCondition whereConditions);

367

368

/**

369

* Select single entity with relationships loaded

370

* @param queryWrapper query conditions

371

* @return entity with relationships

372

*/

373

T selectOneWithRelationsByQuery(QueryWrapper queryWrapper);

374

375

/**

376

* Select single entity with relationships by primary key

377

* @param id primary key value

378

* @return entity with relationships or null

379

*/

380

T selectOneWithRelationsById(Serializable id);

381

382

/**

383

* Select single entity with relationships by primary key with type conversion

384

* @param id primary key value

385

* @param asType target type for conversion

386

* @return converted entity with relationships or null

387

*/

388

<R> R selectOneWithRelationsByIdAs(Serializable id, Class<R> asType);

389

390

/**

391

* Select single entity with relationships by query with type conversion

392

* @param queryWrapper query conditions

393

* @param asType target type for conversion

394

* @return converted entity with relationships or null

395

*/

396

<R> R selectOneWithRelationsByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

397

398

/**

399

* Select multiple entities by primary keys

400

* @param ids collection of primary key values

401

* @return list of entities

402

*/

403

List<T> selectListByIds(Collection<? extends Serializable> ids);

404

405

/**

406

* Select entities by Map conditions

407

* @param whereConditions key-value condition pairs

408

* @return list of entities

409

*/

410

List<T> selectListByMap(Map<String, Object> whereConditions);

411

412

/**

413

* Select limited entities by Map conditions

414

* @param whereConditions key-value condition pairs

415

* @param count maximum number of records to return

416

* @return list of entities

417

*/

418

List<T> selectListByMap(Map<String, Object> whereConditions, Long count);

419

420

/**

421

* Select entities by QueryCondition

422

* @param whereConditions query conditions

423

* @return list of entities

424

*/

425

List<T> selectListByCondition(QueryCondition whereConditions);

426

427

/**

428

* Select limited entities by QueryCondition

429

* @param whereConditions query conditions

430

* @param count maximum number of records to return

431

* @return list of entities

432

*/

433

List<T> selectListByCondition(QueryCondition whereConditions, Long count);

434

435

/**

436

* Select entities by query conditions

437

* @param queryWrapper query conditions

438

* @return list of entities

439

*/

440

List<T> selectListByQuery(QueryWrapper queryWrapper);

441

442

/**

443

* Select entities by query conditions with field loading

444

* @param queryWrapper query conditions

445

* @param consumers field loading specifications

446

* @return list of entities

447

*/

448

List<T> selectListByQuery(QueryWrapper queryWrapper, Consumer<FieldQueryBuilder<T>>... consumers);

449

450

/**

451

* Select entities as cursor (requires transaction)

452

* @param queryWrapper query conditions

453

* @return cursor for streaming results

454

*/

455

Cursor<T> selectCursorByQuery(QueryWrapper queryWrapper);

456

457

/**

458

* Select entities as cursor with type conversion (requires transaction)

459

* @param queryWrapper query conditions

460

* @param asType target type for conversion

461

* @return cursor for streaming results

462

*/

463

<R> Cursor<R> selectCursorByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

464

465

/**

466

* Select entities as Row objects (Map-like structure)

467

* @param queryWrapper query conditions

468

* @return list of Row objects

469

*/

470

List<Row> selectRowsByQuery(QueryWrapper queryWrapper);

471

472

/**

473

* Select entities by query conditions with type conversion

474

* @param queryWrapper query conditions

475

* @param asType target type for conversion

476

* @return list of converted entities

477

*/

478

<R> List<R> selectListByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

479

480

/**

481

* Select entities with type conversion and field loading

482

* @param queryWrapper query conditions

483

* @param asType target type for conversion

484

* @param consumers field loading specifications

485

* @return list of converted entities

486

*/

487

<R> List<R> selectListByQueryAs(QueryWrapper queryWrapper, Class<R> asType, Consumer<FieldQueryBuilder<R>>... consumers);

488

489

/**

490

* Select entities with relationships loaded

491

* @param queryWrapper query conditions

492

* @return list of entities with relationships

493

*/

494

List<T> selectListWithRelationsByQuery(QueryWrapper queryWrapper);

495

496

/**

497

* Select entities with relationships and type conversion

498

* @param queryWrapper query conditions

499

* @param asType target type for conversion

500

* @return list of converted entities with relationships

501

*/

502

<R> List<R> selectListWithRelationsByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

503

504

/**

505

* Select entities with relationships, type conversion, and field loading

506

* @param queryWrapper query conditions

507

* @param asType target type for conversion

508

* @param consumers field loading specifications

509

* @return list of converted entities with relationships

510

*/

511

<R> List<R> selectListWithRelationsByQueryAs(QueryWrapper queryWrapper, Class<R> asType, Consumer<FieldQueryBuilder<R>>... consumers);

512

513

/**

514

* Select all entities from table

515

* @return list of all entities

516

*/

517

List<T> selectAll();

518

519

/**

520

* Select all entities with relationships loaded

521

* @return list of all entities with relationships

522

*/

523

List<T> selectAllWithRelations();

524

525

/**

526

* Select single object value from first column of query result

527

* @param queryWrapper query conditions (should select single column)

528

* @return object value or null

529

*/

530

Object selectObjectByQuery(QueryWrapper queryWrapper);

531

532

/**

533

* Select single object value with type conversion

534

* @param queryWrapper query conditions (should select single column)

535

* @param asType target type for conversion

536

* @return converted object value or null

537

*/

538

<R> R selectObjectByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

539

540

/**

541

* Select list of object values from first column of query result

542

* @param queryWrapper query conditions (should select single column)

543

* @return list of object values

544

*/

545

List<Object> selectObjectListByQuery(QueryWrapper queryWrapper);

546

547

/**

548

* Select list of object values with type conversion

549

* @param queryWrapper query conditions (should select single column)

550

* @param asType target type for conversion

551

* @return list of converted object values

552

*/

553

<R> List<R> selectObjectListByQueryAs(QueryWrapper queryWrapper, Class<R> asType);

554

555

/**

556

* Count entities matching query conditions

557

* @param queryWrapper query conditions

558

* @return count of matching entities

559

*/

560

long selectCountByQuery(QueryWrapper queryWrapper);

561

562

/**

563

* Count entities matching QueryCondition

564

* @param whereConditions query conditions

565

* @return count of matching entities

566

*/

567

long selectCountByCondition(QueryCondition whereConditions);

568

```

569

570

**Select Examples:**

571

572

```java

573

// Select by primary key

574

User user = userMapper.selectOneById(1L);

575

576

// Select by entity's primary key

577

User searchUser = new User();

578

searchUser.setId(1L);

579

User foundUser = userMapper.selectOneByEntityId(searchUser);

580

581

// Select by Map conditions

582

Map<String, Object> conditions = Map.of("age", 25, "status", "ACTIVE");

583

User userByMap = userMapper.selectOneByMap(conditions);

584

585

// Select by QueryCondition

586

User userByCondition = userMapper.selectOneByCondition(USER.AGE.eq(25));

587

588

// Select multiple by IDs

589

List<Long> ids = Arrays.asList(1L, 2L, 3L);

590

List<User> users = userMapper.selectListByIds(ids);

591

592

// Select with QueryWrapper

593

List<User> adults = userMapper.selectListByQuery(

594

QueryWrapper.create()

595

.select()

596

.from(User.class)

597

.where(USER.AGE.ge(18))

598

.orderBy(USER.NAME.asc())

599

);

600

601

// Select with limited count by Map

602

List<User> limitedUsers = userMapper.selectListByMap(

603

Map.of("status", "ACTIVE"), 10L

604

);

605

606

// Select with type conversion

607

List<UserDto> userDtos = userMapper.selectListByQueryAs(

608

QueryWrapper.create()

609

.select(USER.ID, USER.NAME, USER.AGE)

610

.from(User.class),

611

UserDto.class

612

);

613

614

// Select as cursor (streaming, requires transaction)

615

try (Cursor<User> cursor = userMapper.selectCursorByQuery(

616

QueryWrapper.create().from(User.class)

617

)) {

618

for (User u : cursor) {

619

// Process one by one

620

}

621

}

622

623

// Select as Row objects (Map-like)

624

List<Row> rows = userMapper.selectRowsByQuery(

625

QueryWrapper.create()

626

.select(USER.NAME, USER.AGE)

627

.from(User.class)

628

);

629

630

// Select all entities

631

List<User> allUsers = userMapper.selectAll();

632

633

// Select all with relationships

634

List<User> allUsersWithRelations = userMapper.selectAllWithRelations();

635

636

// Select single object (for aggregate functions)

637

Long maxAge = userMapper.selectObjectByQueryAs(

638

QueryWrapper.create()

639

.select(USER.AGE.max())

640

.from(User.class),

641

Long.class

642

);

643

644

// Select object list (for single column results)

645

List<String> names = userMapper.selectObjectListByQueryAs(

646

QueryWrapper.create()

647

.select(USER.NAME)

648

.from(User.class),

649

String.class

650

);

651

652

// Count records

653

long adultCount = userMapper.selectCountByQuery(

654

QueryWrapper.create()

655

.from(User.class)

656

.where(USER.AGE.ge(18))

657

);

658

659

// Count by condition

660

long activeCount = userMapper.selectCountByCondition(USER.STATUS.eq("ACTIVE"));

661

662

// Select with relationships

663

User userWithRelations = userMapper.selectOneWithRelationsById(1L);

664

665

// Select with relationships and type conversion

666

UserDto userDtoWithRelations = userMapper.selectOneWithRelationsByIdAs(1L, UserDto.class);

667

668

// Select with field loading

669

List<User> usersWithFields = userMapper.selectListByQuery(

670

QueryWrapper.create().from(User.class),

671

fieldQuery -> fieldQuery.load(USER.ORDERS)

672

);

673

```

674

675

### Update Operations

676

677

Flexible update operations supporting full updates, selective updates, and condition-based updates.

678

679

```java { .api }

680

/**

681

* Update entity by primary key (ignores null fields by default)

682

* @param entity entity with updated values and primary key

683

* @return number of affected rows

684

*/

685

int update(T entity);

686

687

/**

688

* Update entity by primary key with null handling control

689

* @param entity entity with updated values and primary key

690

* @param ignoreNulls whether to ignore null fields

691

* @return number of affected rows

692

*/

693

int update(T entity, boolean ignoreNulls);

694

695

/**

696

* Update entity by Map conditions

697

* @param entity entity with updated values

698

* @param whereConditions key-value condition pairs

699

* @return number of affected rows

700

*/

701

int updateByMap(T entity, Map<String, Object> whereConditions);

702

703

/**

704

* Update entity by Map conditions with null handling control

705

* @param entity entity with updated values

706

* @param ignoreNulls whether to ignore null fields

707

* @param whereConditions key-value condition pairs

708

* @return number of affected rows

709

*/

710

int updateByMap(T entity, boolean ignoreNulls, Map<String, Object> whereConditions);

711

712

/**

713

* Update entity by QueryCondition

714

* @param entity entity with updated values

715

* @param whereConditions query conditions

716

* @return number of affected rows

717

*/

718

int updateByCondition(T entity, QueryCondition whereConditions);

719

720

/**

721

* Update entity by QueryCondition with null handling control

722

* @param entity entity with updated values

723

* @param ignoreNulls whether to ignore null fields

724

* @param whereConditions query conditions

725

* @return number of affected rows

726

*/

727

int updateByCondition(T entity, boolean ignoreNulls, QueryCondition whereConditions);

728

729

/**

730

* Update entities matching query conditions (ignores nulls by default)

731

* @param entity entity with updated values

732

* @param queryWrapper conditions for which records to update

733

* @return number of affected rows

734

*/

735

int updateByQuery(T entity, QueryWrapper queryWrapper);

736

737

/**

738

* Update entities matching query conditions with null handling control

739

* @param entity entity with updated values

740

* @param ignoreNulls whether to ignore null fields

741

* @param queryWrapper conditions for which records to update

742

* @return number of affected rows

743

*/

744

int updateByQuery(T entity, boolean ignoreNulls, QueryWrapper queryWrapper);

745

```

746

747

**Update Examples:**

748

749

```java

750

// Update by primary key (ignores nulls by default)

751

User user = userMapper.selectOneById(1L);

752

user.setAge(26);

753

user.setEmail("alice.updated@example.com");

754

userMapper.update(user);

755

756

// Update with null control

757

User userWithNulls = new User();

758

userWithNulls.setId(1L);

759

userWithNulls.setAge(27);

760

userWithNulls.setEmail(null); // Will be ignored

761

userMapper.update(userWithNulls, true); // Ignore nulls

762

763

userWithNulls.setEmail(null);

764

userMapper.update(userWithNulls, false); // Include nulls (sets email to NULL)

765

766

// Update by Map conditions

767

User updates = new User();

768

updates.setStatus("INACTIVE");

769

updates.setUpdatedAt(LocalDateTime.now());

770

Map<String, Object> conditions = Map.of("age", 25);

771

userMapper.updateByMap(updates, conditions);

772

773

// Update by Map conditions with null control

774

userMapper.updateByMap(updates, true, conditions); // Ignore nulls

775

776

// Update by QueryCondition

777

userMapper.updateByCondition(updates, USER.AGE.lt(18));

778

779

// Update by QueryCondition with null control

780

userMapper.updateByCondition(updates, false, USER.AGE.lt(18)); // Include nulls

781

782

// Update by QueryWrapper (ignores nulls by default)

783

User statusUpdate = new User();

784

statusUpdate.setStatus("VERIFIED");

785

userMapper.updateByQuery(statusUpdate,

786

QueryWrapper.create()

787

.from(User.class)

788

.where(USER.EMAIL.isNotNull())

789

.and(USER.STATUS.eq("PENDING"))

790

);

791

792

// Update by QueryWrapper with null control

793

User nullUpdate = new User();

794

nullUpdate.setLastLoginTime(null); // Will set to NULL

795

userMapper.updateByQuery(nullUpdate, false,

796

QueryWrapper.create()

797

.from(User.class)

798

.where(USER.STATUS.eq("INACTIVE"))

799

);

800

```

801

802

### Delete Operations

803

804

Comprehensive delete operations supporting single deletion, batch deletion, and condition-based deletion.

805

806

```java { .api }

807

/**

808

* Delete entity by entity's primary key values

809

* @param entity entity containing primary key values

810

* @return number of affected rows

811

*/

812

int delete(T entity);

813

814

/**

815

* Delete entity by primary key

816

* @param id primary key value

817

* @return number of affected rows

818

*/

819

int deleteById(Serializable id);

820

821

/**

822

* Delete multiple entities by primary keys

823

* @param ids collection of primary key values

824

* @return number of affected rows

825

*/

826

int deleteBatchByIds(Collection<? extends Serializable> ids);

827

828

/**

829

* Delete multiple entities by primary keys with size chunking

830

* @param ids collection of primary key values

831

* @param size chunk size for batching (0 or negative uses default size)

832

* @return number of affected rows

833

*/

834

int deleteBatchByIds(Collection<? extends Serializable> ids, int size);

835

836

/**

837

* Delete entities by Map conditions

838

* @param whereConditions key-value condition pairs

839

* @return number of affected rows

840

*/

841

int deleteByMap(Map<String, Object> whereConditions);

842

843

/**

844

* Delete entities by QueryCondition

845

* @param whereConditions query conditions

846

* @return number of affected rows

847

*/

848

int deleteByCondition(QueryCondition whereConditions);

849

850

/**

851

* Delete entities matching query conditions

852

* @param queryWrapper conditions for which records to delete

853

* @return number of affected rows

854

*/

855

int deleteByQuery(QueryWrapper queryWrapper);

856

```

857

858

**Delete Examples:**

859

860

```java

861

// Delete by entity's primary key

862

User userToDelete = new User();

863

userToDelete.setId(1L);

864

int deleted = userMapper.delete(userToDelete);

865

866

// Delete by primary key

867

int deletedById = userMapper.deleteById(1L);

868

869

// Batch delete by IDs

870

List<Long> idsToDelete = Arrays.asList(2L, 3L, 4L);

871

int batchDeleted = userMapper.deleteBatchByIds(idsToDelete);

872

873

// Batch delete with chunking

874

List<Long> manyIds = generateManyIds();

875

int chunkedDeleted = userMapper.deleteBatchByIds(manyIds, 500); // Delete in chunks of 500

876

877

// Delete by Map conditions

878

Map<String, Object> conditions = Map.of("status", "INACTIVE", "age", 0);

879

int deletedByMap = userMapper.deleteByMap(conditions);

880

881

// Delete by QueryCondition

882

int deletedByCondition = userMapper.deleteByCondition(USER.STATUS.eq("DELETED"));

883

884

// Delete by QueryWrapper

885

int conditionalDeleted = userMapper.deleteByQuery(

886

QueryWrapper.create()

887

.from(User.class)

888

.where(USER.AGE.lt(18))

889

.and(USER.STATUS.eq("INACTIVE"))

890

);

891

892

// Complex conditional delete

893

int complexDelete = userMapper.deleteByQuery(

894

QueryWrapper.create()

895

.from(User.class)

896

.where(USER.CREATED_AT.lt(LocalDateTime.now().minusYears(1)))

897

.and(USER.LAST_LOGIN_TIME.isNull())

898

);

899

```

900

901

### Pagination Operations

902

903

Built-in pagination support with count optimization, type conversion, and relationship loading.

904

905

```java { .api }

906

/**

907

* Paginate query results with page number and size

908

* @param pageNumber current page number (1-based)

909

* @param pageSize number of records per page

910

* @param queryWrapper query conditions

911

* @return page of results with total count

912

*/

913

Page<T> paginate(Number pageNumber, Number pageSize, QueryWrapper queryWrapper);

914

915

/**

916

* Paginate query results with relationships loaded

917

* @param pageNumber current page number (1-based)

918

* @param pageSize number of records per page

919

* @param queryWrapper query conditions

920

* @return page of results with relationships and total count

921

*/

922

Page<T> paginateWithRelations(Number pageNumber, Number pageSize, QueryWrapper queryWrapper);

923

924

/**

925

* Paginate query results by QueryCondition

926

* @param pageNumber current page number (1-based)

927

* @param pageSize number of records per page

928

* @param whereConditions query conditions

929

* @return page of results with total count

930

*/

931

Page<T> paginate(Number pageNumber, Number pageSize, QueryCondition whereConditions);

932

933

/**

934

* Paginate query results by QueryCondition with relationships

935

* @param pageNumber current page number (1-based)

936

* @param pageSize number of records per page

937

* @param whereConditions query conditions

938

* @return page of results with relationships and total count

939

*/

940

Page<T> paginateWithRelations(Number pageNumber, Number pageSize, QueryCondition whereConditions);

941

942

/**

943

* Paginate query results with known total row count

944

* @param pageNumber current page number (1-based)

945

* @param pageSize number of records per page

946

* @param totalRow total number of records (skips count query)

947

* @param queryWrapper query conditions

948

* @return page of results

949

*/

950

Page<T> paginate(Number pageNumber, Number pageSize, Number totalRow, QueryWrapper queryWrapper);

951

952

/**

953

* Paginate query results with known total row count and relationships

954

* @param pageNumber current page number (1-based)

955

* @param pageSize number of records per page

956

* @param totalRow total number of records (skips count query)

957

* @param queryWrapper query conditions

958

* @return page of results with relationships

959

*/

960

Page<T> paginateWithRelations(Number pageNumber, Number pageSize, Number totalRow, QueryWrapper queryWrapper);

961

962

/**

963

* Paginate query results by QueryCondition with known total row count

964

* @param pageNumber current page number (1-based)

965

* @param pageSize number of records per page

966

* @param totalRow total number of records (skips count query)

967

* @param whereConditions query conditions

968

* @return page of results

969

*/

970

Page<T> paginate(Number pageNumber, Number pageSize, Number totalRow, QueryCondition whereConditions);

971

972

/**

973

* Paginate query results by QueryCondition with known total row count and relationships

974

* @param pageNumber current page number (1-based)

975

* @param pageSize number of records per page

976

* @param totalRow total number of records (skips count query)

977

* @param whereConditions query conditions

978

* @return page of results with relationships

979

*/

980

Page<T> paginateWithRelations(Number pageNumber, Number pageSize, Number totalRow, QueryCondition whereConditions);

981

982

/**

983

* Paginate query results using Page object

984

* @param page pagination parameters (page number, size, optional total count)

985

* @param queryWrapper query conditions

986

* @return page of results with total count

987

*/

988

Page<T> paginate(Page<T> page, QueryWrapper queryWrapper);

989

990

/**

991

* Paginate query results with field loading

992

* @param page pagination parameters

993

* @param queryWrapper query conditions

994

* @param consumers field loading specifications

995

* @return page of results with loaded fields

996

*/

997

Page<T> paginate(Page<T> page, QueryWrapper queryWrapper, Consumer<FieldQueryBuilder<T>>... consumers);

998

999

/**

1000

* Paginate query results with relationships loaded

1001

* @param page pagination parameters

1002

* @param queryWrapper query conditions

1003

* @return page of results with relationships

1004

*/

1005

Page<T> paginateWithRelations(Page<T> page, QueryWrapper queryWrapper);

1006

1007

/**

1008

* Paginate query results with relationships and field loading

1009

* @param page pagination parameters

1010

* @param queryWrapper query conditions

1011

* @param consumers field loading specifications

1012

* @return page of results with relationships and loaded fields

1013

*/

1014

Page<T> paginateWithRelations(Page<T> page, QueryWrapper queryWrapper, Consumer<FieldQueryBuilder<T>>... consumers);

1015

1016

/**

1017

* Paginate query results with type conversion

1018

* @param pageNumber current page number (1-based)

1019

* @param pageSize number of records per page

1020

* @param queryWrapper query conditions

1021

* @param asType target type for conversion

1022

* @return page of converted results

1023

*/

1024

<R> Page<R> paginateAs(Number pageNumber, Number pageSize, QueryWrapper queryWrapper, Class<R> asType);

1025

1026

/**

1027

* Paginate query results with type conversion and known total count

1028

* @param pageNumber current page number (1-based)

1029

* @param pageSize number of records per page

1030

* @param totalRow total number of records

1031

* @param queryWrapper query conditions

1032

* @param asType target type for conversion

1033

* @return page of converted results

1034

*/

1035

<R> Page<R> paginateAs(Number pageNumber, Number pageSize, Number totalRow, QueryWrapper queryWrapper, Class<R> asType);

1036

1037

/**

1038

* Paginate query results with type conversion using Page object

1039

* @param page pagination parameters

1040

* @param queryWrapper query conditions

1041

* @param asType target type for conversion

1042

* @return page of converted results

1043

*/

1044

<R> Page<R> paginateAs(Page<R> page, QueryWrapper queryWrapper, Class<R> asType);

1045

1046

/**

1047

* Paginate query results with type conversion and field loading

1048

* @param page pagination parameters

1049

* @param queryWrapper query conditions

1050

* @param asType target type for conversion

1051

* @param consumers field loading specifications

1052

* @return page of converted results with loaded fields

1053

*/

1054

<R> Page<R> paginateAs(Page<R> page, QueryWrapper queryWrapper, Class<R> asType, Consumer<FieldQueryBuilder<R>>... consumers);

1055

1056

/**

1057

* Paginate query results with relationships and type conversion

1058

* @param pageNumber current page number (1-based)

1059

* @param pageSize number of records per page

1060

* @param queryWrapper query conditions

1061

* @param asType target type for conversion

1062

* @return page of converted results with relationships

1063

*/

1064

<R> Page<R> paginateWithRelationsAs(Number pageNumber, Number pageSize, QueryWrapper queryWrapper, Class<R> asType);

1065

1066

/**

1067

* Paginate query results with relationships, type conversion, and known total count

1068

* @param pageNumber current page number (1-based)

1069

* @param pageSize number of records per page

1070

* @param totalRow total number of records

1071

* @param queryWrapper query conditions

1072

* @param asType target type for conversion

1073

* @return page of converted results with relationships

1074

*/

1075

<R> Page<R> paginateWithRelationsAs(Number pageNumber, Number pageSize, Number totalRow, QueryWrapper queryWrapper, Class<R> asType);

1076

1077

/**

1078

* Paginate query results with relationships and type conversion using Page object

1079

* @param page pagination parameters

1080

* @param queryWrapper query conditions

1081

* @param asType target type for conversion

1082

* @return page of converted results with relationships

1083

*/

1084

<R> Page<R> paginateWithRelationsAs(Page<R> page, QueryWrapper queryWrapper, Class<R> asType);

1085

1086

/**

1087

* Paginate query results with relationships, type conversion, and field loading

1088

* @param page pagination parameters

1089

* @param queryWrapper query conditions

1090

* @param asType target type for conversion

1091

* @param consumers field loading specifications

1092

* @return page of converted results with relationships and loaded fields

1093

*/

1094

<R> Page<R> paginateWithRelationsAs(Page<R> page, QueryWrapper queryWrapper, Class<R> asType, Consumer<FieldQueryBuilder<R>>... consumers);

1095

```

1096

1097

**Pagination Examples:**

1098

1099

```java

1100

// Basic pagination with page number and size

1101

Page<User> result1 = userMapper.paginate(1, 10,

1102

QueryWrapper.create()

1103

.select()

1104

.from(User.class)

1105

.where(USER.AGE.ge(18))

1106

.orderBy(USER.NAME.asc())

1107

);

1108

1109

// Pagination with relationships loaded

1110

Page<User> resultWithRelations = userMapper.paginateWithRelations(1, 10,

1111

QueryWrapper.create()

1112

.from(User.class)

1113

.where(USER.STATUS.eq("ACTIVE"))

1114

);

1115

1116

// Pagination by QueryCondition

1117

Page<User> resultByCondition = userMapper.paginate(1, 20, USER.AGE.ge(25));

1118

1119

// Pagination with known total count (optimized - skips count query)

1120

Page<User> optimizedResult = userMapper.paginate(1, 10, 1000L,

1121

QueryWrapper.create().from(User.class)

1122

);

1123

1124

// Using Page object

1125

Page<User> page = new Page<>(1, 10);

1126

Page<User> result2 = userMapper.paginate(page,

1127

QueryWrapper.create()

1128

.from(User.class)

1129

.where(USER.AGE.ge(18))

1130

.orderBy(USER.NAME.asc())

1131

);

1132

1133

// Pagination with field loading

1134

Page<User> resultWithFields = userMapper.paginate(page,

1135

QueryWrapper.create().from(User.class),

1136

fieldQuery -> fieldQuery.load(USER.ORDERS).load(USER.PROFILE)

1137

);

1138

1139

// Pagination with type conversion

1140

Page<UserDto> dtoResult = userMapper.paginateAs(1, 10,

1141

QueryWrapper.create()

1142

.select(USER.ID, USER.NAME, USER.EMAIL)

1143

.from(User.class),

1144

UserDto.class

1145

);

1146

1147

// Pagination with relationships and type conversion

1148

Page<UserDto> dtoWithRelations = userMapper.paginateWithRelationsAs(1, 10,

1149

QueryWrapper.create().from(User.class),

1150

UserDto.class

1151

);

1152

1153

// Complex pagination with all features

1154

Page<UserDto> complexResult = userMapper.paginateWithRelationsAs(

1155

new Page<>(2, 20), // Page 2, 20 records per page

1156

QueryWrapper.create()

1157

.from(User.class)

1158

.where(USER.STATUS.eq("ACTIVE"))

1159

.orderBy(USER.CREATED_AT.desc()),

1160

UserDto.class,

1161

fieldQuery -> fieldQuery.load(USER.ORDERS).load(USER.PROFILE)

1162

);

1163

1164

System.out.println("Total records: " + complexResult.getTotalRow());

1165

System.out.println("Total pages: " + complexResult.getTotalPage());

1166

System.out.println("Current page: " + complexResult.getPageNumber());

1167

List<UserDto> users = complexResult.getRecords();

1168

```

1169

1170

### XML Operations

1171

1172

Support for custom XML-based queries with pagination, allowing integration with existing MyBatis XML mappers.

1173

1174

```java { .api }

1175

/**

1176

* Paginate using XML mapper method with automatic count query

1177

* @param dataSelectId XML select statement ID for data

1178

* @param page pagination parameters

1179

* @param queryWrapper query conditions passed to XML mapper

1180

* @return page of results

1181

*/

1182

<E> Page<E> xmlPaginate(String dataSelectId, Page<E> page, QueryWrapper queryWrapper);

1183

1184

/**

1185

* Paginate using XML mapper method with parameters

1186

* @param dataSelectId XML select statement ID for data

1187

* @param page pagination parameters

1188

* @param otherParams additional parameters passed to XML mapper

1189

* @return page of results

1190

*/

1191

<E> Page<E> xmlPaginate(String dataSelectId, Page<E> page, Map<String, Object> otherParams);

1192

1193

/**

1194

* Paginate using XML mapper method with query wrapper and parameters

1195

* @param dataSelectId XML select statement ID for data

1196

* @param page pagination parameters

1197

* @param queryWrapper query conditions passed to XML mapper

1198

* @param otherParams additional parameters passed to XML mapper

1199

* @return page of results

1200

*/

1201

<E> Page<E> xmlPaginate(String dataSelectId, Page<E> page, QueryWrapper queryWrapper, Map<String, Object> otherParams);

1202

1203

/**

1204

* Paginate using XML mapper method with custom count query

1205

* @param dataSelectId XML select statement ID for data

1206

* @param countSelectId XML select statement ID for count query

1207

* @param page pagination parameters

1208

* @param queryWrapper query conditions passed to XML mapper

1209

* @param otherParams additional parameters passed to XML mapper

1210

* @return page of results

1211

*/

1212

<E> Page<E> xmlPaginate(String dataSelectId, String countSelectId, Page<E> page, QueryWrapper queryWrapper, Map<String, Object> otherParams);

1213

```

1214

1215

**XML Pagination Examples:**

1216

1217

```java

1218

// Basic XML pagination (uses dataSelectId + "_COUNT" for count query)

1219

Page<User> xmlResult1 = userMapper.xmlPaginate("selectUsersByCondition",

1220

new Page<>(1, 10),

1221

QueryWrapper.create().where(USER.STATUS.eq("ACTIVE"))

1222

);

1223

1224

// XML pagination with additional parameters

1225

Map<String, Object> params = Map.of(

1226

"minAge", 18,

1227

"status", "ACTIVE",

1228

"orderBy", "created_at DESC"

1229

);

1230

Page<User> xmlResult2 = userMapper.xmlPaginate("selectUsersWithParams",

1231

new Page<>(1, 20),

1232

params

1233

);

1234

1235

// XML pagination with QueryWrapper and parameters

1236

Page<User> xmlResult3 = userMapper.xmlPaginate("selectComplexUsers",

1237

new Page<>(1, 15),

1238

QueryWrapper.create().where(USER.AGE.between(18, 65)),

1239

Map.of("includeDeleted", false)

1240

);

1241

1242

// XML pagination with custom count query

1243

Page<User> xmlResult4 = userMapper.xmlPaginate(

1244

"selectUsersSummary", // Data select statement

1245

"countUsersSummary", // Count select statement

1246

new Page<>(1, 10),

1247

QueryWrapper.create().where(USER.DEPARTMENT.eq("IT")),

1248

Map.of("year", 2024)

1249

);

1250

```

1251

1252

**Example XML Mapper:**

1253

1254

```xml

1255

<!-- UserMapper.xml -->

1256

<select id="selectUsersByCondition" resultType="User">

1257

SELECT * FROM users

1258

<where>

1259

<if test="query != null">

1260

${query.whereSql}

1261

</if>

1262

</where>

1263

ORDER BY created_at DESC

1264

</select>

1265

1266

<select id="selectUsersByCondition_COUNT" resultType="long">

1267

SELECT COUNT(*) FROM users

1268

<where>

1269

<if test="query != null">

1270

${query.whereSql}

1271

</if>

1272

</where>

1273

</select>

1274

1275

<select id="selectUsersWithParams" resultType="User">

1276

SELECT * FROM users

1277

WHERE age >= #{minAge}

1278

AND status = #{status}

1279

${orderBy}

1280

</select>

1281

```

1282

1283

## Types

1284

1285

```java { .api }

1286

// Pagination

1287

public class Page<T> {

1288

public Page(int pageNumber, int pageSize);

1289

public Page(int pageNumber, int pageSize, boolean optimizeCountQuery);

1290

public Page(Number pageNumber, Number pageSize);

1291

public Page(Number pageNumber, Number pageSize, Number totalRow);

1292

1293

public List<T> getRecords();

1294

public void setRecords(List<T> records);

1295

public long getTotalRow();

1296

public void setTotalRow(long totalRow);

1297

public int getTotalPage();

1298

public int getPageNumber();

1299

public int getPageSize();

1300

public boolean isOptimizeCountQuery();

1301

public boolean hasRecords();

1302

}

1303

1304

// Query conditions

1305

public class QueryWrapper {

1306

public static QueryWrapper create();

1307

public QueryWrapper select(QueryColumn... columns);

1308

public QueryWrapper from(Class<?> entityClass);

1309

public QueryWrapper where(QueryCondition condition);

1310

public QueryWrapper where(Map<String, Object> conditions);

1311

public QueryWrapper and(QueryCondition condition);

1312

public QueryWrapper or(QueryCondition condition);

1313

public QueryWrapper orderBy(QueryColumn... columns);

1314

public QueryWrapper limit(Number rows);

1315

public QueryWrapper limit(Number offset, Number rows);

1316

}

1317

1318

public class QueryCondition {

1319

// Comparison conditions

1320

public QueryCondition eq(Object value);

1321

public QueryCondition ne(Object value);

1322

public QueryCondition gt(Object value);

1323

public QueryCondition ge(Object value);

1324

public QueryCondition lt(Object value);

1325

public QueryCondition le(Object value);

1326

public QueryCondition like(String value);

1327

public QueryCondition between(Object start, Object end);

1328

public QueryCondition in(Object... values);

1329

public QueryCondition in(Collection<?> values);

1330

public QueryCondition isNull();

1331

public QueryCondition isNotNull();

1332

}

1333

1334

// Row operations (Map-like structure)

1335

public class Row implements Map<String, Object> {

1336

public static Row create();

1337

public Row set(String key, Object value);

1338

public <T> T get(String key, Class<T> type);

1339

public String getString(String key);

1340

public Integer getInt(String key);

1341

public Long getLong(String key);

1342

public Boolean getBoolean(String key);

1343

public Date getDate(String key);

1344

// ... implements Map<String, Object> methods

1345

}

1346

1347

// Cursor for streaming results

1348

public interface Cursor<T> extends Closeable, Iterable<T> {

1349

boolean isOpen();

1350

boolean isConsumed();

1351

int getCurrentIndex();

1352

}

1353

1354

// Field query builder for lazy loading

1355

public interface FieldQueryBuilder<T> {

1356

FieldQueryBuilder<T> load(QueryColumn field);

1357

FieldQueryBuilder<T> load(String fieldName);

1358

}

1359

1360

// Consumer interface for functional programming

1361

public interface Consumer<T> {

1362

void accept(T t);

1363

}

1364

1365

// Collection types

1366

public interface Collection<E> extends Iterable<E> {

1367

int size();

1368

boolean isEmpty();

1369

boolean contains(Object o);

1370

Object[] toArray();

1371

boolean add(E e);

1372

boolean remove(Object o);

1373

// ... other collection methods

1374

}

1375

1376

// Serializable for primary keys

1377

public interface Serializable {

1378

// Marker interface for primary key types

1379

}

1380

1381

// Map for conditions and parameters

1382

public interface Map<K, V> {

1383

V get(Object key);

1384

V put(K key, V value);

1385

V remove(Object key);

1386

boolean containsKey(Object key);

1387

boolean containsValue(Object value);

1388

Set<K> keySet();

1389

Collection<V> values();

1390

Set<Entry<K, V>> entrySet();

1391

// ... other map methods

1392

}

1393

```