Skip to content

Commit 239be8e

Browse files
authored
Add support for layer read-only initialization and enforce write checks in EditableLayer methods (#443)
This commit introduces a `readOnly` flag throughout the layering and indexing APIs, updates all callers to propagate it, and enforces write protection on layers and indexes. - Added `readOnly` parameter to `LayerIndexReader.init`, `RTreeIndex.init`, `Layer.initialize`, and related factory methods. - Enforced write checks via `checkWritable()` in `EditableLayerImpl`, `RTreeIndex`, `DynamicLayer`, and others. - Updated all calls to `getLayer`/`getOrCreateLayer` in main code and tests to supply the appropriate `readOnly` boolean.
1 parent 9964547 commit 239be8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+758
-692
lines changed

server-plugin/src/main/java/org/geotools/data/neo4j/Neo4jSpatialDataStore.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@
6161
*/
6262
public class Neo4jSpatialDataStore extends ContentDataStore implements Constants {
6363

64-
private List<Name> typeNames;
6564
private final Map<String, SimpleFeatureType> simpleFeatureTypeIndex = Collections.synchronizedMap(new HashMap<>());
6665
private final Map<String, CoordinateReferenceSystem> crsIndex = Collections.synchronizedMap(new HashMap<>());
6766
private final Map<String, Style> styleIndex = Collections.synchronizedMap(new HashMap<>());
6867
private final Map<String, ReferencedEnvelope> boundsIndex = Collections.synchronizedMap(new HashMap<>());
6968
private final Map<String, SimpleFeatureSource> featureSourceIndex = Collections.synchronizedMap(new HashMap<>());
7069
private final GraphDatabaseService database;
7170
private final SpatialDatabaseService spatialDatabase;
71+
private List<Name> typeNames;
7272

7373
public Neo4jSpatialDataStore(GraphDatabaseService database) {
7474
this.database = database;
@@ -91,7 +91,7 @@ protected List<Name> createTypeNames() {
9191
for (String allTypeName : allTypeNames) {
9292
// discard empty layers
9393
System.out.print("loading layer " + allTypeName);
94-
Layer layer = spatialDatabase.getLayer(tx, allTypeName);
94+
Layer layer = spatialDatabase.getLayer(tx, allTypeName, true);
9595
if (!layer.getIndex().isEmpty(tx)) {
9696
notEmptyTypes.add(new NameImpl(allTypeName));
9797
}
@@ -111,7 +111,7 @@ public SimpleFeatureType buildFeatureType(String typeName) throws IOException {
111111
SimpleFeatureType result = simpleFeatureTypeIndex.get(typeName);
112112
if (result == null) {
113113
try (Transaction tx = database.beginTx()) {
114-
Layer layer = spatialDatabase.getLayer(tx, typeName);
114+
Layer layer = spatialDatabase.getLayer(tx, typeName, true);
115115
if (layer == null) {
116116
throw new IOException("Layer not found: " + typeName);
117117
}
@@ -129,7 +129,7 @@ public ReferencedEnvelope getBounds(String typeName) {
129129
ReferencedEnvelope result = boundsIndex.get(typeName);
130130
if (result == null) {
131131
try (Transaction tx = database.beginTx()) {
132-
Layer layer = spatialDatabase.getLayer(tx, typeName);
132+
Layer layer = spatialDatabase.getLayer(tx, typeName, true);
133133
if (layer != null) {
134134
Envelope bbox = Utilities.fromNeo4jToJts(layer.getIndex().getBoundingBox(tx));
135135
result = new ReferencedEnvelope(bbox, getCRS(tx, layer));
@@ -164,7 +164,7 @@ protected ContentFeatureSource createFeatureSource(ContentEntry contentEntry) th
164164
ArrayList<SpatialDatabaseRecord> records = new ArrayList<>();
165165
String[] extraPropertyNames;
166166
try (Transaction tx = database.beginTx()) {
167-
layer = spatialDatabase.getLayer(tx, contentEntry.getTypeName());
167+
layer = spatialDatabase.getLayer(tx, contentEntry.getTypeName(), false);
168168
SearchRecords results = layer.getIndex().search(tx, new SearchAll());
169169
// We need to pull all records during this transaction, so that later readers do not have a transaction violation
170170
// TODO: See if there is a more memory efficient way of doing this, perhaps create a transaction at read time in the reader?
@@ -194,7 +194,7 @@ private CoordinateReferenceSystem getCRS(Transaction tx, Layer layer) {
194194

195195
private Object getLayerStyle(String typeName) {
196196
try (Transaction tx = database.beginTx()) {
197-
Layer layer = spatialDatabase.getLayer(tx, typeName);
197+
Layer layer = spatialDatabase.getLayer(tx, typeName, true);
198198
tx.commit();
199199
if (layer == null) {
200200
return null;

0 commit comments

Comments
 (0)