Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make spatial query procedures read only #403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Andy2003
Copy link
Collaborator

@Andy2003 Andy2003 commented May 29, 2024

This PR changes the following procedure to be read-only:

  • spatial.layers
  • spatial.bbox
  • spatial.closest
  • spatial.withinDistance
  • spatial.intersects

@Andy2003 Andy2003 requested a review from jexp May 29, 2024 16:40
@Andy2003 Andy2003 force-pushed the feature/make-spatial-query-procedures-read-only branch from d730ddd to 083dafe Compare May 30, 2024 11:27
Copy link
Contributor

@craigtaverner craigtaverner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice fix. I do wonder if we should think of a better word than close for the method that flushes the count to the index?

@@ -521,21 +522,27 @@ public void removeLayer(@Name("name") String name) {
@Description("Adds the given node to the layer, returns the geometry-node")
public Stream<NodeResult> addNodeToLayer(@Name("layerName") String name, @Name("node") Node node) {
EditableLayer layer = getEditableLayerOrThrow(tx, spatial(), name);
return streamNode(layer.add(tx, node).getGeomNode());
Node geomNode = layer.add(tx, node).getGeomNode();
layer.close(tx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of the word close and in particular close(tx) almost makes it feel like the transaction is being closed. It also makes me look for a matching open(tx) statement. I wonder if it would not be better to use a word like finalize(tx)? Although that also has connotations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea behind the close was to implement java.io.Closeable so one can use try-with-resource. The problem here is that the index itself is not aware of the transaction, so the tx must be passed to each method as param- also to the close method. And so, with the additional parameter, it can no longer implement java.io.Closeable.

What do you think about having a Transaction-Aware Facade that can be Closable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks sounds nice. Worth a try, as long as the transaction does not leak anywhere.

@@ -606,7 +621,8 @@ public Stream<NodeResult> addGeometryWKTsToLayer(@Name("layerName") String name,
EditableLayer layer = getEditableLayerOrThrow(tx, spatial(), name);
WKTReader reader = new WKTReader(layer.getGeometryFactory());
return geometryWKTs.stream().map(geometryWKT -> addGeometryWkt(layer, reader, geometryWKT))
.map(NodeResult::new);
.map(NodeResult::new)
.onClose(() -> layer.close(tx));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice trick. Perhaps we could add a lambda for this to the streamNode() method?

@@ -1528,4 +1528,9 @@ public int compare(NodeWithEnvelope o1, NodeWithEnvelope o2) {
return Double.compare(o1.envelope.getArea(), o2.envelope.getArea());
}
}

@Override
public void close(Transaction tx) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, I wonder if there is a better choice of word than close?

@Andy2003 Andy2003 force-pushed the feature/make-spatial-query-procedures-read-only branch from 083dafe to 0be5527 Compare May 31, 2024 14:45
@Andy2003 Andy2003 force-pushed the master branch 5 times, most recently from 6844765 to bee28a4 Compare June 20, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants