Skip to content

Commit

Permalink
#259 - add limit and offset
Browse files Browse the repository at this point in the history
  • Loading branch information
grabdoc committed Feb 7, 2024
1 parent 3e7773a commit 8d9e0f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
26 changes: 2 additions & 24 deletions src/main/java/com/homihq/db2rest/rest/read/ReadService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.homihq.db2rest.rest.read;

import com.homihq.db2rest.rest.read.dto.FindOneResponse;
import com.homihq.db2rest.rest.read.helper.*;
import com.homihq.db2rest.rest.read.dto.QueryRequest;
import com.homihq.db2rest.rest.read.v2.dto.ReadContextV2;
import com.homihq.db2rest.rest.read.v2.processor.QueryCreatorTemplate;
import com.homihq.db2rest.rest.read.v2.processor.ReadPreProcessor;
Expand All @@ -15,7 +13,7 @@

import java.util.List;
import java.util.Map;
import java.util.Objects;



@Service
Expand All @@ -42,7 +40,7 @@ public Object findAll(String schemaName, String tableName, String select, String
.tableName(tableName).select(select).filter(filter).build();

selectBuilder.build(ctx);
joinBuilder.build(ctx);
//joinBuilder.build(ctx);
whereBuilder.build(ctx);
limitPaginationBuilder.build(ctx);
sortBuilder.build(ctx);
Expand All @@ -59,32 +57,12 @@ public Object findAll(String schemaName, String tableName, String select, String

public Object findAll(ReadContextV2 readContextV2) {


for(ReadPreProcessor processor : processorList) {
processor.process(readContextV2);
}

queryCreatorTemplate.createQuery(readContextV2);

/*
selectBuilder.build(ctx);
joinBuilder.build(ctx);
whereBuilder.build(ctx);
limitPaginationBuilder.build(ctx);
sortBuilder.build(ctx);
String sql = ctx.prepareSQL();
Map<String,Object> bindValues = ctx.prepareParameters();
log.info("SQL - {}", sql);
log.info("Bind variables - {}", bindValues);
return namedParameterJdbcTemplate.queryForList(sql, bindValues);
*/

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,27 @@ public void createQuery(ReadContextV2 readContextV2) {
queryExpressionDSL.where(readContextV2.getWhereCondition());
}

addPagination(queryExpressionDSL, readContextV2.getOffset(), readContextV2.getLimit());

SelectStatementProvider selectStatementProvider = queryExpressionDSL.build().render(RenderingStrategies.SPRING_NAMED_PARAMETER);

log.info("SQL - {}", selectStatementProvider.getSelectStatement());
log.info("Bind Variables - {}", selectStatementProvider.getParameters());

}

protected void addPagination(QueryExpressionDSL<SelectModel> queryExpressionDSL, long offset, int limit) {

if(offset > -1) {
queryExpressionDSL.offset(offset);
}

if(limit > -1) {
queryExpressionDSL.limit(limit);
}

}

protected QueryExpressionDSL<SelectModel> createProjection(ReadContextV2 readContextV2) {
return
select(readContextV2.getColumns())
Expand Down

0 comments on commit 8d9e0f3

Please sign in to comment.