Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelhoral committed Dec 21, 2023
1 parent 43b32a9 commit 43d8256
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 361 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,6 @@ protected Map<QueryDefinition, String> initializeQueryMap() {
return result;
}

/* (non-Javadoc)
* @see org.forgerock.openidm.repo.jdbc.impl.TableHandler#read(java.lang.String, java.lang.String, java.lang.String, java.sql.Connection)
*/
@Override
public ResourceResponse read(String fullId, String type, String localId, Connection connection)
throws ResourceException, SQLException, IOException {
Expand Down Expand Up @@ -231,9 +228,6 @@ public ResourceResponse read(String fullId, String type, String localId, Connect
}
}

/* (non-Javadoc)
* @see org.forgerock.openidm.repo.jdbc.impl.TableHandler#create(java.lang.String, java.lang.String, java.lang.String, java.util.Map, java.sql.Connection)
*/
@Override
public void create(String fullId, String type, String localId, Map<String, Object> obj, Connection connection)
throws SQLException, IOException, InternalServerErrorException {
Expand Down Expand Up @@ -499,9 +493,6 @@ public Map<String, Object> readForUpdate(String fullId, String type, String loca
}
}

/* (non-Javadoc)
* @see org.forgerock.openidm.repo.jdbc.impl.TableHandler#update(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Map, java.sql.Connection)
*/
@Override
public void update(String fullId, String type, String localId, String rev, Map<String, Object> obj, Connection connection)
throws SQLException, IOException, PreconditionFailedException, NotFoundException, InternalServerErrorException {
Expand Down Expand Up @@ -564,12 +555,9 @@ public void update(String fullId, String type, String localId, String rev, Map<S
}
}

/**
* @see org.forgerock.openidm.repo.jdbc.impl.GenericTableHandler#delete(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.sql.Connection)
*/
@Override
public void delete(String fullId, String type, String localId, String rev, Connection connection)
throws PreconditionFailedException, InternalServerErrorException, NotFoundException, SQLException, IOException {
throws PreconditionFailedException, InternalServerErrorException, NotFoundException, SQLException{
logger.debug("Delete with fullid {}", fullId);

PreparedStatement deleteStatement = null;
Expand Down Expand Up @@ -609,9 +597,6 @@ public void delete(String fullId, String type, String localId, String rev, Conne
}
}

/* (non-Javadoc)
* @see org.forgerock.openidm.repo.jdbc.impl.TableHandler#delete(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.sql.Connection)
*/
@Override
public List<Map<String, Object>> query(String type, Map<String, Object> params, Connection connection)
throws ResourceException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ public Promise<ResourceResponse, ResourceException> handlePatch(Context context,

@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
// TODO XXX FIXME bordel nize
try {

// If paged results are requested then decode the cookie in order to determine
Expand Down Expand Up @@ -622,31 +623,32 @@ public Promise<QueryResponse, ResourceException> handleQuery(Context context, Qu
switch (request.getTotalPagedResultsPolicy()) {
case ESTIMATE:
case EXACT:
if (request.getQueryId() != null) {
// Get total if -count query is available
final String countQueryId = request.getQueryId() + "-count";
if (tableHandler.queryIdExists(countQueryId)) {
QueryRequest countRequest = Requests.copyOfQueryRequest(request);
countRequest.setQueryId(countQueryId);

// Strip pagination parameters
countRequest.setPageSize(0);
countRequest.setPagedResultsOffset(0);
countRequest.setPagedResultsCookie(null);

List<ResourceResponse> countResult = query(countRequest);

if (countResult != null && !countResult.isEmpty()) {
resultCount = countResult.get(0).getContent().get("total").asInteger();
} else {
logger.debug("Count query {} failed", countQueryId);
resultCount = NO_COUNT;
}
} else {
logger.debug("Count query with id {} not found", countQueryId);
resultCount = NO_COUNT;
}
} else if (request.getQueryFilter() != null) {
if (request.getQueryId() != null) {
// Get total if -count query is available
final String countQueryId = request.getQueryId() + "-count";
if (tableHandler.queryIdExists(countQueryId)) {
QueryRequest countRequest = Requests.copyOfQueryRequest(request);
countRequest.setQueryId(countQueryId);

// Strip pagination parameters
countRequest.setPageSize(0);
countRequest.setPagedResultsOffset(0);
countRequest.setPagedResultsCookie(null);

List<ResourceResponse> countResult = query(countRequest);

if (countResult != null && !countResult.isEmpty()) {
resultCount = countResult.get(0).getContent().get("total").asInteger();
} else {
logger.debug("Count query {} failed", countQueryId);
resultCount = NO_COUNT;
}
} else {
logger.debug("Count query with id {} not found", countQueryId);
resultCount = NO_COUNT;
}
} else if (request.getQueryFilter() != null) {
// TODO XXX pouzit COUNT POLICY jako parametr
Map<String, Object> params = new HashMap<>();
params.putAll(request.getAdditionalParameters());
params.put(QUERY_FILTER, request.getQueryFilter());
Expand All @@ -657,7 +659,7 @@ public Promise<QueryResponse, ResourceException> handleQuery(Context context, Qu
logger.debug("Count query {} failed", QUERY_FILTER);
resultCount = NO_COUNT;
}
}
}
break;
case NONE:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ protected void initializeQueries() {

}

/**
* @see org.forgerock.openidm.repo.jdbc.TableHandler#read(java.lang.String,
* java.lang.String, java.lang.String, java.sql.Connection)
*/
@Override
public ResourceResponse read(String fullId, String type, String localId, Connection connection)
throws NotFoundException, SQLException, InternalServerErrorException {
Expand Down Expand Up @@ -247,11 +243,6 @@ Map<String, Object> readForUpdate(String fullId, String type, String localId, Co
}
}

/**
* @see org.forgerock.openidm.repo.jdbc.TableHandler#create(java.lang.String,
* java.lang.String, java.lang.String, java.util.Map,
* java.sql.Connection)
*/
@Override
public void create(String fullId, String type, String localId, Map<String, Object> obj,
Connection connection) throws SQLException, IOException {
Expand Down Expand Up @@ -356,11 +347,6 @@ int populatePrepStatementColumns(String type, PreparedStatement prepStatement, J
return colPos;
}

/**
* @see org.forgerock.openidm.repo.jdbc.TableHandler#update(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, java.util.Map,
* java.sql.Connection)
*/
@Override
public void update(String fullId, String type, String localId, String rev,
Map<String, Object> obj, Connection connection) throws SQLException, IOException,
Expand Down Expand Up @@ -415,11 +401,6 @@ public void update(String fullId, String type, String localId, String rev,
}
}

/**
* @see org.forgerock.openidm.repo.jdbc.TableHandler#delete(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String,
* java.sql.Connection)
*/
@Override
public void delete(String fullId, String type, String localId, String rev, Connection connection)
throws PreconditionFailedException, InternalServerErrorException, NotFoundException,
Expand Down Expand Up @@ -463,11 +444,6 @@ public void delete(String fullId, String type, String localId, String rev, Conne
}
}

/**
* @see org.forgerock.openidm.repo.jdbc.TableHandler#delete(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String,
* java.sql.Connection)
*/
@Override
public List<Map<String, Object>> query(String type, Map<String, Object> params,
Connection connection) throws ResourceException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,6 @@ Clause buildNumericValueClause(String propTable, String operand, String placehol
builder.orderBy("obj.id", false);
}

return builder.toSQL(count);
return count ? builder.toCountSQL() : builder.toSQL();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private class Column implements SQLRenderer<String> {
this.column = column;
}

@Override
public String toSQL() {
return column;
}
Expand All @@ -82,6 +83,7 @@ private class Table implements SQLRenderer<String> {
this.alias = alias;
}

@Override
public String toSQL() {
return table + (alias != null ? " " + alias : "");
}
Expand Down Expand Up @@ -178,6 +180,7 @@ private class OrderBy implements SQLRenderer<String> {
this.ascending = ascending;
}

@Override
public String toSQL() {
return order + " " + (ascending ? "ASC" : "DESC");
}
Expand Down Expand Up @@ -429,19 +432,17 @@ public String toSQL() {
public abstract String toSQL();

/**
* Render the SQL string.
*
* @param count whether the query should return row count only
* @return rendered SQL string
* Render the SQL string for counting number of matched rows.
*
* @return rendered COUNT SQL string
*/
public String toSQL(boolean count) {
return !count ? toSQL() :
"SELECT COUNT(*) as total "
+ getFromClause()
+ getJoinClause()
+ getWhereClause();
public String toCountSQL() {
return "SELECT COUNT(*) as total "
+ getFromClause()
+ getJoinClause()
+ getWhereClause();
}

/**
* Return a string representation of this builder.
*
Expand Down
Loading

0 comments on commit 43d8256

Please sign in to comment.