88 *
99 * SPDX-License-Identifier: BSD-3-Clause
1010 *******************************************************************************/
11+ // Some portions generated by Codex
1112package org .eclipse .rdf4j .sail .lmdb .config ;
1213
1314import java .time .Duration ;
15+ import java .util .function .Consumer ;
16+ import java .util .function .IntConsumer ;
17+ import java .util .function .LongConsumer ;
1418
19+ import org .eclipse .rdf4j .model .IRI ;
1520import org .eclipse .rdf4j .model .Model ;
1621import org .eclipse .rdf4j .model .Resource ;
1722import org .eclipse .rdf4j .model .ValueFactory ;
@@ -75,6 +80,8 @@ public class LmdbStoreConfig extends BaseSailConfig {
7580
7681 private long valueEvictionInterval = Duration .ofSeconds (60 ).toMillis ();
7782
83+ private boolean pageCardinalityEstimator = true ;
84+
7885 /*--------------*
7986 * Constructors *
8087 *--------------*/
@@ -190,6 +197,15 @@ public LmdbStoreConfig setValueEvictionInterval(long valueEvictionInterval) {
190197 return this ;
191198 }
192199
200+ public boolean getPageCardinalityEstimator () {
201+ return pageCardinalityEstimator ;
202+ }
203+
204+ public LmdbStoreConfig setPageCardinalityEstimator (boolean pageCardinalityEstimator ) {
205+ this .pageCardinalityEstimator = pageCardinalityEstimator ;
206+ return this ;
207+ }
208+
193209 @ Override
194210 public Resource export (Model m ) {
195211 Resource implNode = super .export (m );
@@ -226,6 +242,9 @@ public Resource export(Model m) {
226242 if (valueEvictionInterval != Duration .ofSeconds (60 ).toMillis ()) {
227243 m .add (implNode , LmdbStoreSchema .VALUE_EVICTION_INTERVAL , vf .createLiteral (valueEvictionInterval ));
228244 }
245+ if (!pageCardinalityEstimator ) {
246+ m .add (implNode , LmdbStoreSchema .PAGE_CARDINALITY_ESTIMATOR , vf .createLiteral (false ));
247+ }
229248 return implNode ;
230249 }
231250
@@ -234,104 +253,61 @@ public void parse(Model m, Resource implNode) throws SailConfigException {
234253 super .parse (m , implNode );
235254
236255 try {
237- Models .objectLiteral (m .getStatements (implNode , LmdbStoreSchema .TRIPLE_INDEXES , null ))
238- .ifPresent (lit -> setTripleIndexes (lit .getLabel ()));
239-
240- Models .objectLiteral (m .getStatements (implNode , LmdbStoreSchema .TRIPLE_DB_SIZE , null ))
241- .ifPresent (lit -> {
242- try {
243- setTripleDBSize (lit .longValue ());
244- } catch (NumberFormatException e ) {
245- throw new SailConfigException (
246- "Long value required for " + LmdbStoreSchema .TRIPLE_DB_SIZE
247- + " property, found " + lit );
248- }
249- });
250-
251- Models .objectLiteral (m .getStatements (implNode , LmdbStoreSchema .VALUE_DB_SIZE , null ))
252- .ifPresent (lit -> {
253- try {
254- setValueDBSize (lit .longValue ());
255- } catch (NumberFormatException e ) {
256- throw new SailConfigException (
257- "Long value required for " + LmdbStoreSchema .VALUE_DB_SIZE
258- + " property, found " + lit );
259- }
260- });
261-
262- Models .objectLiteral (m .getStatements (implNode , LmdbStoreSchema .FORCE_SYNC , null )).ifPresent (lit -> {
263- try {
264- setForceSync (lit .booleanValue ());
265- } catch (IllegalArgumentException e ) {
266- throw new SailConfigException (
267- "Boolean value required for " + LmdbStoreSchema .FORCE_SYNC + " property, found " + lit );
268- }
269- });
270-
271- Models .objectLiteral (m .getStatements (implNode , LmdbStoreSchema .VALUE_CACHE_SIZE , null )).ifPresent (lit -> {
272- try {
273- setValueCacheSize (lit .intValue ());
274- } catch (NumberFormatException e ) {
275- throw new SailConfigException (
276- "Integer value required for " + LmdbStoreSchema .VALUE_CACHE_SIZE + " property, found "
277- + lit );
278- }
279- });
280-
281- Models .objectLiteral (m .getStatements (implNode , LmdbStoreSchema .VALUE_ID_CACHE_SIZE , null ))
282- .ifPresent (lit -> {
283- try {
284- setValueIDCacheSize (lit .intValue ());
285- } catch (NumberFormatException e ) {
286- throw new SailConfigException (
287- "Integer value required for " + LmdbStoreSchema .VALUE_ID_CACHE_SIZE
288- + " property, found " + lit );
289- }
290- });
291-
292- Models .objectLiteral (m .getStatements (implNode , LmdbStoreSchema .NAMESPACE_CACHE_SIZE , null ))
293- .ifPresent (lit -> {
294- try {
295- setNamespaceCacheSize (lit .intValue ());
296- } catch (NumberFormatException e ) {
297- throw new SailConfigException (
298- "Integer value required for " + LmdbStoreSchema .NAMESPACE_CACHE_SIZE
299- + " property, found " + lit );
300- }
301- });
302-
303- Models .objectLiteral (m .getStatements (implNode , LmdbStoreSchema .NAMESPACE_ID_CACHE_SIZE , null ))
304- .ifPresent (lit -> {
305- try {
306- setNamespaceIDCacheSize (lit .intValue ());
307- } catch (NumberFormatException e ) {
308- throw new SailConfigException (
309- "Integer value required for " + LmdbStoreSchema .NAMESPACE_ID_CACHE_SIZE
310- + " property, found " + lit );
311- }
312- });
313-
314- Models .objectLiteral (m .getStatements (implNode , LmdbStoreSchema .AUTO_GROW , null )).ifPresent (lit -> {
315- try {
316- setAutoGrow (lit .booleanValue ());
317- } catch (IllegalArgumentException e ) {
318- throw new SailConfigException (
319- "Boolean value required for " + LmdbStoreSchema .AUTO_GROW + " property, found " + lit );
320- }
321- });
322-
323- Models .objectLiteral (m .getStatements (implNode , LmdbStoreSchema .VALUE_EVICTION_INTERVAL , null ))
324- .ifPresent (lit -> {
325- try {
326- setValueEvictionInterval (lit .longValue ());
327- } catch (NumberFormatException e ) {
328- throw new SailConfigException (
329- "Long value required for " + LmdbStoreSchema .VALUE_EVICTION_INTERVAL
330- + " property, found " + lit );
331- }
332- });
256+ parseStringLiteral (m , implNode , LmdbStoreSchema .TRIPLE_INDEXES , this ::setTripleIndexes );
257+ parseLongLiteral (m , implNode , LmdbStoreSchema .TRIPLE_DB_SIZE , this ::setTripleDBSize );
258+ parseLongLiteral (m , implNode , LmdbStoreSchema .VALUE_DB_SIZE , this ::setValueDBSize );
259+ parseBooleanLiteral (m , implNode , LmdbStoreSchema .FORCE_SYNC , this ::setForceSync );
260+ parseIntegerLiteral (m , implNode , LmdbStoreSchema .VALUE_CACHE_SIZE , this ::setValueCacheSize );
261+ parseIntegerLiteral (m , implNode , LmdbStoreSchema .VALUE_ID_CACHE_SIZE , this ::setValueIDCacheSize );
262+ parseIntegerLiteral (m , implNode , LmdbStoreSchema .NAMESPACE_CACHE_SIZE , this ::setNamespaceCacheSize );
263+ parseIntegerLiteral (m , implNode , LmdbStoreSchema .NAMESPACE_ID_CACHE_SIZE , this ::setNamespaceIDCacheSize );
264+ parseBooleanLiteral (m , implNode , LmdbStoreSchema .AUTO_GROW , this ::setAutoGrow );
265+ parseLongLiteral (m , implNode , LmdbStoreSchema .VALUE_EVICTION_INTERVAL , this ::setValueEvictionInterval );
266+ parseBooleanLiteral (m , implNode , LmdbStoreSchema .PAGE_CARDINALITY_ESTIMATOR ,
267+ this ::setPageCardinalityEstimator );
333268 } catch (ModelException e ) {
334269 throw new SailConfigException (e .getMessage (), e );
335270 }
336271 }
272+
273+ private void parseStringLiteral (Model m , Resource implNode , IRI property , Consumer <String > setter ) {
274+ Models .objectLiteral (m .getStatements (implNode , property , null ))
275+ .ifPresent (lit -> setter .accept (lit .getLabel ()));
276+ }
277+
278+ private void parseIntegerLiteral (Model m , Resource implNode , IRI property , IntConsumer setter ) {
279+ Models .objectLiteral (m .getStatements (implNode , property , null ))
280+ .ifPresent (lit -> {
281+ try {
282+ setter .accept (lit .intValue ());
283+ } catch (NumberFormatException e ) {
284+ throw new SailConfigException (
285+ "Integer value required for " + property + " property, found " + lit );
286+ }
287+ });
288+ }
289+
290+ private void parseLongLiteral (Model m , Resource implNode , IRI property , LongConsumer setter ) {
291+ Models .objectLiteral (m .getStatements (implNode , property , null ))
292+ .ifPresent (lit -> {
293+ try {
294+ setter .accept (lit .longValue ());
295+ } catch (NumberFormatException e ) {
296+ throw new SailConfigException (
297+ "Long value required for " + property + " property, found " + lit );
298+ }
299+ });
300+ }
301+
302+ private void parseBooleanLiteral (Model m , Resource implNode , IRI property , Consumer <Boolean > setter ) {
303+ Models .objectLiteral (m .getStatements (implNode , property , null ))
304+ .ifPresent (lit -> {
305+ try {
306+ setter .accept (lit .booleanValue ());
307+ } catch (IllegalArgumentException e ) {
308+ throw new SailConfigException (
309+ "Boolean value required for " + property + " property, found " + lit );
310+ }
311+ });
312+ }
337313}
0 commit comments