Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#259 - add limit and offset #260

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading