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

Minor version updates and code polishes #395

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<skinGroupId>org.neo4j.maven.skins</skinGroupId>
<skinArtifactId>default-skin</skinArtifactId>
<skinVersion>2</skinVersion>
<geotools.version>30.0</geotools.version>
<geotools.version>30.1</geotools.version>
<spatial.test.osm.version>20100819</spatial.test.osm.version>
<spatial.test.shp.version>20100819</spatial.test.shp.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bundle.namespace>org.neo4j.gis</bundle.namespace>
<github.global.server>github</github.global.server>
<junit.version>5.10.0</junit.version>
<maven-surefire-plugin.version>3.2.1</maven-surefire-plugin.version>
<junit.version>5.10.2</junit.version>
<maven-surefire-plugin.version>3.2.2</maven-surefire-plugin.version>
</properties>

<modelVersion>4.0.0</modelVersion>
Expand All @@ -37,7 +37,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.12.1</version>
<configuration>
<source>${neo4j.java.version}</source>
<target>${neo4j.java.version}</target>
Expand Down
21 changes: 2 additions & 19 deletions src/main/java/org/geotools/data/neo4j/Neo4jSpatialDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ protected ContentFeatureSource createFeatureSource(ContentEntry contentEntry) th
Neo4jSpatialFeatureSource source = new Neo4jSpatialFeatureSource(contentEntry, database, layer, buildFeatureType(contentEntry.getTypeName()), records, extraPropertyNames);
if (layer instanceof EditableLayer) {
return new Neo4jSpatialFeatureStore(contentEntry, database, (EditableLayer) layer, source);
} else {
return source;
}
return source;
Andy2003 marked this conversation as resolved.
Show resolved Hide resolved
}

private CoordinateReferenceSystem getCRS(Transaction tx, Layer layer) {
Expand All @@ -187,7 +186,7 @@ private Object getLayerStyle(String typeName) {
Layer layer = spatialDatabase.getLayer(tx, typeName);
tx.commit();
if (layer == null) return null;
else return layer.getStyle();
return layer.getStyle();
}
}

Expand Down Expand Up @@ -217,20 +216,4 @@ public Style getStyle(String typeName) {
}
return result;
}

private EditableLayer getEditableLayer(String typeName) throws IOException {
try (Transaction tx = database.beginTx()) {
Layer layer = spatialDatabase.getLayer(tx, typeName);
if (layer == null) {
throw new IOException("Layer not found: " + typeName);
}

if (!(layer instanceof EditableLayer)) {
throw new IOException("Cannot create a FeatureWriter on a read-only layer: " + layer);
}
tx.commit();

return (EditableLayer) layer;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.geotools.api.data.DataStore;
import org.geotools.api.data.DataStoreFactorySpi;
import org.geotools.api.data.Parameter;
import org.geotools.util.KVP;
import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.dbms.api.DatabaseManagementServiceBuilder;
Expand All @@ -46,7 +47,7 @@ public class Neo4jSpatialDataStoreFactory implements DataStoreFactorySpi {
"db", true);

public static final Param DBTYPE = new Param("dbtype", String.class,
"must be 'neo4j'", true, "neo4j", new KVP(Param.LEVEL, "program"));
"must be 'neo4j'", true, "neo4j", new KVP(Parameter.LEVEL, "program"));

/**
* Creates a new instance of Neo4jSpatialDataStoreFactory
Expand Down
74 changes: 46 additions & 28 deletions src/main/java/org/neo4j/gis/spatial/DefaultLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,26 @@ public class DefaultLayer implements Constants, Layer, SpatialDataset {

// Public methods

public String getName() {
@Override
public String getName() {
return name;
}

public LayerIndexReader getIndex() {
@Override
public LayerIndexReader getIndex() {
return indexReader;
}

public String getSignature() {
@Override
public String getSignature() {
return "Layer(name='" + getName() + "', encoder=" + getGeometryEncoder().getSignature() + ")";
}

/**
* Add the geometry encoded in the given Node. This causes the geometry to appear in the index.
*/
public SpatialDatabaseRecord add(Transaction tx, Node geomNode) {
@Override
public SpatialDatabaseRecord add(Transaction tx, Node geomNode) {
Geometry geometry = getGeometryEncoder().decodeGeometry(geomNode);

// add BBOX to Node if it's missing
Expand All @@ -91,7 +95,8 @@ public int addAll(Transaction tx, List<Node> geomNodes) {
return geomNodes.size();
}

public GeometryFactory getGeometryFactory() {
@Override
public GeometryFactory getGeometryFactory() {
return geometryFactory;
}

Expand All @@ -100,13 +105,13 @@ public void setCoordinateReferenceSystem(Transaction tx, CoordinateReferenceSyst
layerNode.setProperty(PROP_CRS, crs.toWKT());
}

public CoordinateReferenceSystem getCoordinateReferenceSystem(Transaction tx) {
@Override
public CoordinateReferenceSystem getCoordinateReferenceSystem(Transaction tx) {
Node layerNode = getLayerNode(tx);
if (layerNode.hasProperty(PROP_CRS)) {
return GeotoolsAdapter.getCRS((String) layerNode.getProperty(PROP_CRS));
} else {
return null;
}
return null;
}

public void setGeometryType(Transaction tx, int geometryType) {
Expand All @@ -118,17 +123,17 @@ public void setGeometryType(Transaction tx, int geometryType) {
layerNode.setProperty(PROP_TYPE, geometryType);
}

public Integer getGeometryType(Transaction tx) {
@Override
public Integer getGeometryType(Transaction tx) {
Node layerNode = getLayerNode(tx);
if (layerNode.hasProperty(PROP_TYPE)) {
return (Integer) layerNode.getProperty(PROP_TYPE);
} else {
GuessGeometryTypeSearch geomTypeSearch = new GuessGeometryTypeSearch();
indexReader.searchIndex(tx, geomTypeSearch).count();

// returns null for an empty layer!
return geomTypeSearch.firstFoundType;
}
GuessGeometryTypeSearch geomTypeSearch = new GuessGeometryTypeSearch();
indexReader.searchIndex(tx, geomTypeSearch).count();

// returns null for an empty layer!
return geomTypeSearch.firstFoundType;
}

private static class GuessGeometryTypeSearch implements SearchFilter {
Expand All @@ -150,7 +155,8 @@ public boolean geometryMatches(Transaction tx, Node geomNode) {
}
}

public String[] getExtraPropertyNames(Transaction tx) {
@Override
public String[] getExtraPropertyNames(Transaction tx) {
Node layerNode = getLayerNode(tx);
String[] extraPropertyNames;
if (layerNode.hasProperty(PROP_LAYERNODEEXTRAPROPS)) {
Expand Down Expand Up @@ -248,14 +254,16 @@ public void initialize(Transaction tx, IndexManager indexManager, String name, N
* All layers are associated with a single node in the database. This node will have properties,
* relationships (sub-graph) or both to describe the contents of the layer
*/
public Node getLayerNode(Transaction tx) {
@Override
public Node getLayerNode(Transaction tx) {
return tx.getNodeByElementId(layerNodeId);
}

/**
* Delete Layer
*/
public void delete(Transaction tx, Listener monitor) {
@Override
public void delete(Transaction tx, Listener monitor) {
indexWriter.removeAll(tx, true, monitor);
Node layerNode = getLayerNode(tx);
layerNode.delete();
Expand All @@ -279,11 +287,13 @@ public void delete(Transaction tx, Listener monitor) {
protected LayerIndexReader indexReader;
protected SpatialIndexWriter indexWriter;

public SpatialDataset getDataset() {
@Override
public SpatialDataset getDataset() {
return this;
}

public Iterable<Node> getAllGeometryNodes(Transaction tx) {
@Override
public Iterable<Node> getAllGeometryNodes(Transaction tx) {
return indexReader.getAllIndexedNodes(tx);
}

Expand All @@ -298,7 +308,8 @@ public boolean containsGeometryNode(Transaction tx, Node geomNode) {
*
* @return iterable over geometries in the dataset
*/
public Iterable<? extends Geometry> getAllGeometries(Transaction tx) {
@Override
public Iterable<? extends Geometry> getAllGeometries(Transaction tx) {
return new NodeToGeometryIterable(getAllGeometryNodes(tx));
}

Expand All @@ -312,15 +323,18 @@ private class NodeToGeometryIterable implements Iterable<Geometry> {

private class GeometryIterator implements Iterator<Geometry> {

public boolean hasNext() {
@Override
public boolean hasNext() {
return NodeToGeometryIterable.this.allGeometryNodeIterator.hasNext();
}

public Geometry next() {
@Override
public Geometry next() {
return geometryEncoder.decodeGeometry(NodeToGeometryIterable.this.allGeometryNodeIterator.next());
}

public void remove() {
@Override
public void remove() {
}

}
Expand All @@ -329,7 +343,8 @@ public void remove() {
this.allGeometryNodeIterator = allGeometryNodes.iterator();
}

public Iterator<Geometry> iterator() {
@Override
public Iterator<Geometry> iterator() {
return new GeometryIterator();
}

Expand All @@ -341,7 +356,8 @@ public Iterator<Geometry> iterator() {
*
* @return GeometryEncoder for this dataset
*/
public GeometryEncoder getGeometryEncoder() {
@Override
public GeometryEncoder getGeometryEncoder() {
return geometryEncoder;
}

Expand All @@ -350,7 +366,8 @@ public GeometryEncoder getGeometryEncoder() {
*
* @return iterable over all Layers that can be viewed from this dataset
*/
public Iterable<? extends Layer> getLayers() {
@Override
public Iterable<? extends Layer> getLayers() {
return Collections.singletonList(this);
}

Expand All @@ -362,7 +379,8 @@ public Iterable<? extends Layer> getLayers() {
*
* @return null
*/
public Object getStyle() {
@Override
public Object getStyle() {
return null;
}

Expand Down
75 changes: 35 additions & 40 deletions src/main/java/org/neo4j/gis/spatial/DynamicLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,41 +102,39 @@ public DynamicLayerConfig addCQLDynamicLayerOnGeometryType(Transaction tx, int g
public DynamicLayerConfig addCQLDynamicLayerOnAttribute(Transaction tx, String key, String value, int gtype) {
if (value == null) {
return addLayerConfig(tx, "CQL:" + key, gtype, key + " IS NOT NULL AND " + makeGeometryCQL(gtype));
} else {
// TODO: Better escaping here
//return addLayerConfig("CQL:" + key + "-" + value, gtype, key + " = '" + value + "' AND " + makeGeometryCQL(gtype));
return addCQLDynamicLayerOnAttributes(tx, new String[]{key, value}, gtype);
}
// TODO: Better escaping here
//return addLayerConfig("CQL:" + key + "-" + value, gtype, key + " = '" + value + "' AND " + makeGeometryCQL(gtype));
return addCQLDynamicLayerOnAttributes(tx, new String[]{key, value}, gtype);
}

public DynamicLayerConfig addCQLDynamicLayerOnAttributes(Transaction tx, String[] attributes, int gtype) {
if (attributes == null) {
return addCQLDynamicLayerOnGeometryType(tx, gtype);
} else {
StringBuilder name = new StringBuilder();
StringBuilder query = new StringBuilder();
if (gtype != GTYPE_GEOMETRY) {
query.append(makeGeometryCQL(gtype));
}
for (int i = 0; i < attributes.length; i += 2) {
String key = attributes[i];
if (name.length() > 0) {
name.append("-");
}
if (query.length() > 0) {
query.append(" AND ");
}
if (attributes.length > i + 1) {
String value = attributes[i + 1];
name.append(key).append("-").append(value);
query.append(key).append(" = '").append(value).append("'");
} else {
name.append(key);
query.append(key).append(" IS NOT NULL");
}
}
return addLayerConfig(tx, "CQL:" + name.toString(), gtype, query.toString());
}
StringBuilder name = new StringBuilder();
StringBuilder query = new StringBuilder();
if (gtype != GTYPE_GEOMETRY) {
query.append(makeGeometryCQL(gtype));
}
for (int i = 0; i < attributes.length; i += 2) {
String key = attributes[i];
if (name.length() > 0) {
name.append("-");
}
if (query.length() > 0) {
query.append(" AND ");
}
if (attributes.length > i + 1) {
String value = attributes[i + 1];
name.append(key).append("-").append(value);
query.append(key).append(" = '").append(value).append("'");
} else {
name.append(key);
query.append(key).append(" IS NOT NULL");
}
}
return addLayerConfig(tx, "CQL:" + name.toString(), gtype, query.toString());
}

public DynamicLayerConfig addLayerConfig(Transaction tx, String name, int type, String query) {
Expand All @@ -156,14 +154,13 @@ public DynamicLayerConfig addLayerConfig(Transaction tx, String name, int type,
if (config.getGeometryType(tx) != type || !config.getQuery().equals(query)) {
System.err.println("Existing LayerConfig with different geometry type or query: " + config);
return null;
} else {
return config;
}
} else {
System.err.println("Existing Layer has same name as requested LayerConfig: " + layer.getName());
return null;
return config;
}
} else synchronized (this) {
System.err.println("Existing Layer has same name as requested LayerConfig: " + layer.getName());
return null;
}
synchronized (this) {
DynamicLayerConfig config = new DynamicLayerConfig(tx, this, name, type, query);
layers = null; // force recalculation of layers cache
return config;
Expand Down Expand Up @@ -191,14 +188,12 @@ public DynamicLayerConfig restrictLayerProperties(Transaction tx, String name, S
config.setExtraPropertyNames(tx, names);
}
return config;
} else {
System.err.println("Existing Layer has same name as requested LayerConfig: " + layer.getName());
return null;
}
} else {
System.err.println("No such layer: " + name);
return null;
System.err.println("Existing Layer has same name as requested LayerConfig: " + layer.getName());
return null;
}
System.err.println("No such layer: " + name);
return null;
}

/**
Expand Down
Loading