Skip to content

Commit

Permalink
Adding OSLC4JConstants#LYO_STORE_PAGING_UNSAFE to disable/enable orde…
Browse files Browse the repository at this point in the history
…ring (#240)

* Adding OSLC4JConstants#LYO_STORE_PAGING_UNSAFE to disable/enable
ordering

Signed-off-by: Jad El-khoury <jad.el.khoury@scania.com>

* changelog change

Co-authored-by: Jad El-khoury <jad.el.khoury@scania.com>
  • Loading branch information
jadelkhoury and jad-elkhoury committed Feb 9, 2022
1 parent e46d315 commit e5c1dc9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- 🧨 Lyo is now built using JDK 11
- 🧨 Jena is upgraded to 4.1.0
- Jena renamed `RDFReader/RDFWriter` to `RDFReaderI/RDFWriterI`
- LyoStore: Ordering resources by their subject IDs when doing a query to store.
- LyoStore: Ordering resources by their subject IDs when doing a query to store. This ordering can be disabled with a call to `OSLC4JUtils.setLyoStorePagingUnsafe(true)`


### Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ public interface OSLC4JConstants {
* properties.
*/
String OSLC4J_STRICT_DATATYPES = OSLC4J + "strictDatatypes";

/**
* System property {@value} : When "false" (default), add an OrderBy clause to the queries in LyoStore that involve paging.
* When "true", do not add such an OrderBy clause, in the hope that the triplestore sorting algorithm is stable-
* properties.
*/
String LYO_STORE_PAGING_UNSAFE = OSLC4J + "unsafePaging";

}
Original file line number Diff line number Diff line change
Expand Up @@ -738,4 +738,18 @@ public static RDFDatatype getDataTypeBasedOnResourceShapeType(final HashSet<Stri
}
return null;
}

/**
* @see OSLC4JConstants#LYO_STORE_PAGING_UNSAFE
* @return the boolean value of org.eclipse.lyo.oslc4j.unsafePaging
* Default is false if not set.
*/
public static boolean isLyoStorePagingUnsafe() {
return parseBooleanPropertyOrDefault(OSLC4JConstants.LYO_STORE_PAGING_UNSAFE, false);
}

public static void setLyoStorePagingUnsafe(boolean value) {
System.setProperty(OSLC4JConstants.LYO_STORE_PAGING_UNSAFE, Boolean.toString(value));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.eclipse.lyo.core.query.StringValue;
import org.eclipse.lyo.core.query.UriRefValue;
import org.eclipse.lyo.core.query.Value;
import org.eclipse.lyo.oslc4j.core.OSLC4JUtils;
import org.eclipse.lyo.oslc4j.core.annotation.OslcName;
import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace;
import org.eclipse.lyo.oslc4j.core.exception.OslcCoreApplicationException;
Expand Down Expand Up @@ -610,8 +611,10 @@ private SelectBuilder constructSparqlWhere(final String prefixes, final String w
distinctResourcesQuery.addFilter(regex);
}

//Order the response by the subject, to ensure stable responses when using limit and offset below.
distinctResourcesQuery.addOrderBy("?s", Order.ASCENDING);

if ((limit > 0 || offset > 0) && (! OSLC4JUtils.isLyoStorePagingUnsafe())) {
distinctResourcesQuery.addOrderBy("?s", Order.ASCENDING);
}

if (limit > 0) {
distinctResourcesQuery.setLimit(limit);
Expand Down

0 comments on commit e5c1dc9

Please sign in to comment.