This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/main by this push:
new ed067f26ac GH-3112: Add DatabaseMgr functions taking StoreParams
ed067f26ac is described below
commit ed067f26ac28796b8532f9a10581836521ecef66
Author: Andy Seaborne <[email protected]>
AuthorDate: Sun Apr 6 18:02:11 2025 +0100
GH-3112: Add DatabaseMgr functions taking StoreParams
---
.../java/org/apache/jena/tdb2/DatabaseMgr.java | 17 +++++++--
.../apache/jena/tdb2/sys/DatabaseConnection.java | 23 +++++++++---
.../java/org/apache/jena/tdb2/TestDatabaseMgr.java | 43 +++++++++++++++++-----
3 files changed, 64 insertions(+), 19 deletions(-)
diff --git a/jena-tdb2/src/main/java/org/apache/jena/tdb2/DatabaseMgr.java
b/jena-tdb2/src/main/java/org/apache/jena/tdb2/DatabaseMgr.java
index 2d60362193..92cfbb8908 100644
--- a/jena-tdb2/src/main/java/org/apache/jena/tdb2/DatabaseMgr.java
+++ b/jena-tdb2/src/main/java/org/apache/jena/tdb2/DatabaseMgr.java
@@ -21,6 +21,7 @@ package org.apache.jena.tdb2;
import org.apache.jena.dboe.base.file.Location;
import org.apache.jena.query.Dataset;
import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.tdb2.params.StoreParams;
import org.apache.jena.tdb2.store.DatasetGraphSwitchable;
import org.apache.jena.tdb2.store.DatasetGraphTDB;
import org.apache.jena.tdb2.sys.DatabaseConnection;
@@ -37,13 +38,13 @@ public class DatabaseMgr {
private DatabaseMgr() {}
// All creation of DatasetGraph for TDB2 goes through this method.
- private static DatasetGraph DB_ConnectCreate(Location location) {
- return DatabaseConnection.connectCreate(location).getDatasetGraph();
+ private static DatasetGraph DB_ConnectCreate(Location location,
StoreParams storeParams) {
+ return DatabaseConnection.connectCreate(location,
storeParams).getDatasetGraph();
}
/** Create or connect to a TDB2-backed dataset */
public static DatasetGraph connectDatasetGraph(Location location) {
- return DB_ConnectCreate(location);
+ return DB_ConnectCreate(location, null);
}
/** Create or connect to a TDB2-backed dataset */
@@ -51,6 +52,16 @@ public class DatabaseMgr {
return connectDatasetGraph(Location.create(location));
}
+ /** Create or connect to a TDB2-backed dataset with specific {@link
StoreParams}. */
+ public static DatasetGraph connectDatasetGraph(Location location,
StoreParams storeParams) {
+ return DB_ConnectCreate(location, storeParams);
+ }
+
+ /** Create or connect to a TDB2-backed dataset with specific {@link
StoreParams}. */
+ public static DatasetGraph connectDatasetGraph(String location,
StoreParams storeParams) {
+ return connectDatasetGraph(Location.create(location), storeParams);
+ }
+
/**
* Compact a dataset which must be a switchable TDB database.
* This is the normal dataset type for on-disk TDB2 databases.
diff --git
a/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/DatabaseConnection.java
b/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/DatabaseConnection.java
index 1bd87163eb..7b2a984978 100644
--- a/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/DatabaseConnection.java
+++ b/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/DatabaseConnection.java
@@ -50,16 +50,27 @@ public class DatabaseConnection {
* Get the {@code DatabaseConnection} to a location, creating the storage
* structures with default settings if it does not exist.
*/
- public synchronized static DatabaseConnection connectCreate(Location
location) {
+ public static DatabaseConnection connectCreate(Location location) {
return connectCreate(location, null, null);
}
- /** Get the {@code DatabaseConnection} to a location,
- * creating the storage structures if it does not exist.
- * Use the provided {@link StoreParams} - any persistent setting
- * already at the location take precedence.
+ /**
+ * Get the {@code DatabaseConnection} to a location,
+ * creating the storage structures if it does not exist.
+ * Use the provided {@link StoreParams} - any persistent setting
+ * already at the location take precedence.
+ */
+ public static DatabaseConnection connectCreate(Location location,
StoreParams params) {
+ return make(location, params, null);
+ }
+
+ /**
+ * Get the {@code DatabaseConnection} to a location,
+ * creating the storage structures if it does not exist.
+ * Use the provided {@link StoreParams} - any persistent setting
+ * already at the location take precedence.
*/
- public synchronized static DatabaseConnection connectCreate(Location
location, StoreParams params, ReorderTransformation reorderTransform) {
+ public static DatabaseConnection connectCreate(Location location,
StoreParams params, ReorderTransformation reorderTransform) {
return make(location, params, reorderTransform);
}
diff --git a/jena-tdb2/src/test/java/org/apache/jena/tdb2/TestDatabaseMgr.java
b/jena-tdb2/src/test/java/org/apache/jena/tdb2/TestDatabaseMgr.java
index f97fbf1991..db9256b9f8 100644
--- a/jena-tdb2/src/test/java/org/apache/jena/tdb2/TestDatabaseMgr.java
+++ b/jena-tdb2/src/test/java/org/apache/jena/tdb2/TestDatabaseMgr.java
@@ -18,17 +18,25 @@
package org.apache.jena.tdb2;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
import org.apache.jena.atlas.lib.FileOps;
import org.apache.jena.dboe.base.file.Location;
-import org.apache.jena.system.Txn;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.Quad;
import org.apache.jena.sparql.sse.SSE;
+import org.apache.jena.system.Txn;
+import org.apache.jena.tdb2.params.StoreParams;
+import org.apache.jena.tdb2.params.StoreParamsBuilder;
+import org.apache.jena.tdb2.sys.DatabaseConnection;
import org.apache.jena.tdb2.sys.TDBInternal;
-import org.junit.Test;
-/** Test of DatabaseMgr - the DatasetGraph level API to TDB2 **/
+/** Test of DatabaseMgr - the DatasetGraph level API to TDB2 */
public class TestDatabaseMgr
{
// String DIRx = ConfigTest.getCleanDir();
@@ -75,16 +83,31 @@ public class TestDatabaseMgr
DatasetGraph dg1 = DatabaseMgr.connectDatasetGraph(LOC);
DatasetGraph dg2 =
DatabaseMgr.connectDatasetGraph(Location.create(LOC.getDirectoryPath()));
assertSame(dg1, dg2);
- Txn.executeWrite(dg1, ()-> {
- dg1.add(quad1);
- });
- Txn.executeRead(dg2, ()-> {
- assertTrue(dg2.contains(quad1));
- });
+ Txn.executeWrite(dg1, ()-> dg1.add(quad1));
+ Txn.executeRead(dg2, ()-> assertTrue(dg2.contains(quad1)));
}
finally {
FileOps.clearDirectory(DIRx);
}
}
+
+ @Test
+ public void testDatabaseMgrStoreParams() {
+ TDBInternal.reset();
+ Location LOC = Location.mem();
+ // Not recommended for any real use!
+ int testBlockSize = 1024 ;
+ StoreParams storeParams1 =
StoreParamsBuilder.create("test").blockSize(testBlockSize).build();
+ DatasetGraph dg1 = DatabaseMgr.connectDatasetGraph(LOC, storeParams1);
+
+ Txn.executeWrite(dg1, ()-> dg1.add(quad1));
+ Txn.executeRead(dg1, () -> assertTrue(dg1.contains(quad1)));
+
+ DatabaseConnection conn = DatabaseConnection.connectCreate(LOC);
+ DatasetGraph dg2 = DatabaseMgr.connectDatasetGraph(LOC);
+
+ StoreParams storeParams2 =
TDBInternal.requireStorage(dg1).getStoreParams();
+ assertEquals(testBlockSize, storeParams2.getBlockSize().intValue());
+ }
}