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

Consider pros and cons of moving generic sql to hakunapi-sql to enable other db implementations #86

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.classpath
.project
.settings/
.vscode

# Intellij
.idea/
Expand All @@ -20,4 +21,4 @@ bin/

hakuna.log
pom.xml.versionsBackup
**/pom.xml.versionsBackup
**/pom.xml.versionsBackup
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
<artifactId>hakunapi-simple-webapp-test-javax</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fi.nls.hakunapi</groupId>
<artifactId>hakunapi-sql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fi.nls.hakunapi</groupId>
<artifactId>hakunapi-source-postgis</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions src/hakunapi-source-postgis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<artifactId>hakunapi-source-postgis</artifactId>

<dependencies>
<dependency>
<groupId>fi.nls.hakunapi</groupId>
<artifactId>hakunapi-sql</artifactId>
</dependency>
<dependency>
<groupId>fi.nls.hakunapi</groupId>
<artifactId>hakunapi-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fi.nls.hakunapi.simple.postgis;

import fi.nls.hakunapi.core.FeatureProducer;
import fi.nls.hakunapi.sql.SQLFeatureType;

public class PostGISFeatureType extends SQLFeatureType {

@Override
public FeatureProducer getFeatureProducer() {
return new SimplePostGIS(ds);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import fi.nls.hakunapi.core.property.simple.HakunaPropertyString;
import fi.nls.hakunapi.core.property.simple.HakunaPropertyUUID;
import fi.nls.hakunapi.core.transformer.ValueTransformer;
import fi.nls.hakunapi.sql.SQLFeatureType;

public class PostGISSimpleSource implements SimpleSource {

Expand Down Expand Up @@ -169,7 +170,7 @@ public void close() throws IOException {
public SimpleFeatureType parse(HakunaConfigParser cfg, Path path, String collectionId, int[] srids) throws Exception {
// Current prefix for properties
String p = "collections." + collectionId + ".";
SQLFeatureType ft = new SQLFeatureType();
SQLFeatureType ft = new PostGISFeatureType();
ft.setName(collectionId);

String db = cfg.get(p + "db");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@
import fi.nls.hakunapi.simple.postgis.filter.PostGISTouches;
import fi.nls.hakunapi.simple.postgis.filter.PostGISWithin;
import fi.nls.hakunapi.simple.postgis.filter.PostgresArrayOverlaps;
import fi.nls.hakunapi.simple.postgis.filter.SQLAnd;
import fi.nls.hakunapi.simple.postgis.filter.SQLEqualTo;
import fi.nls.hakunapi.simple.postgis.filter.SQLFilter;
import fi.nls.hakunapi.simple.postgis.filter.SQLGreaterThan;
import fi.nls.hakunapi.simple.postgis.filter.SQLGreaterThanOrEqualTo;
import fi.nls.hakunapi.simple.postgis.filter.SQLIsNotNull;
import fi.nls.hakunapi.simple.postgis.filter.SQLIsNull;
import fi.nls.hakunapi.simple.postgis.filter.SQLLessThan;
import fi.nls.hakunapi.simple.postgis.filter.SQLLessThanOrEqualTo;
import fi.nls.hakunapi.simple.postgis.filter.SQLLike;
import fi.nls.hakunapi.simple.postgis.filter.SQLNot;
import fi.nls.hakunapi.simple.postgis.filter.SQLNotEqualTo;
import fi.nls.hakunapi.simple.postgis.filter.SQLOr;
import fi.nls.hakunapi.sql.SQLUtil;
import fi.nls.hakunapi.sql.filter.SQLAnd;
import fi.nls.hakunapi.sql.filter.SQLEqualTo;
import fi.nls.hakunapi.sql.filter.SQLFilter;
import fi.nls.hakunapi.sql.filter.SQLGreaterThan;
import fi.nls.hakunapi.sql.filter.SQLGreaterThanOrEqualTo;
import fi.nls.hakunapi.sql.filter.SQLIsNotNull;
import fi.nls.hakunapi.sql.filter.SQLIsNull;
import fi.nls.hakunapi.sql.filter.SQLLessThan;
import fi.nls.hakunapi.sql.filter.SQLLessThanOrEqualTo;
import fi.nls.hakunapi.sql.filter.SQLLike;
import fi.nls.hakunapi.sql.filter.SQLNot;
import fi.nls.hakunapi.sql.filter.SQLNotEqualTo;
import fi.nls.hakunapi.sql.filter.SQLOr;

public class PostGISUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import fi.nls.hakunapi.core.request.GetFeatureRequest;
import fi.nls.hakunapi.core.util.EmptyFeatureStream;
import fi.nls.hakunapi.core.util.U;
import fi.nls.hakunapi.sql.BufferedResultSet;
import fi.nls.hakunapi.sql.SQLFeatureType;

/**
* Streaming implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import fi.nls.hakunapi.core.projection.ProjectionHelper;
import fi.nls.hakunapi.core.property.HakunaProperty;
import fi.nls.hakunapi.core.property.simple.HakunaPropertyGeometry;
import fi.nls.hakunapi.sql.filter.SQLFilter;

public abstract class PostGISGeometryFunction implements SQLFilter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import fi.nls.hakunapi.core.projection.ProjectionHelper;
import fi.nls.hakunapi.core.property.HakunaProperty;
import fi.nls.hakunapi.core.property.simple.HakunaPropertyGeometry;
import fi.nls.hakunapi.sql.filter.SQLFilter;

public class PostGISIntersectsIndex implements SQLFilter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import fi.nls.hakunapi.core.filter.Filter;
import fi.nls.hakunapi.core.property.HakunaProperty;
import fi.nls.hakunapi.core.property.HakunaPropertyArray;
import fi.nls.hakunapi.sql.filter.SQLFilter;

public class PostgresArrayOverlaps implements SQLFilter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import fi.nls.hakunapi.core.join.Join;
import fi.nls.hakunapi.core.join.OneToOneJoin;
import fi.nls.hakunapi.sql.SimpleJoinGraph;

public class SimpleJoinGraphTest {

Expand Down
26 changes: 26 additions & 0 deletions src/hakunapi-sql/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fi.nls.hakunapi</groupId>
<artifactId>src</artifactId>
<version>1.3.0-SNAPSHOT</version>
</parent>
<artifactId>hakunapi-sql</artifactId>

<dependencies>

<dependency>
<groupId>fi.nls.hakunapi</groupId>
<artifactId>hakunapi-core</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fi.nls.hakunapi.simple.postgis;
package fi.nls.hakunapi.sql;

import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -38,6 +38,14 @@ public BufferedResultSet(Connection c, PreparedStatement ps, ResultSet rs, int n
this.mappers = mappers;
this.buffer = new ValueContainer[bufSize];
}
public BufferedResultSet(Connection c, PreparedStatement ps, ResultSetValueProvider vp, ResultSet rs, List<ValueMapper> mappers, int bufSize) {
this.c = c;
this.ps = ps;
this.rs = rs;
this.valueProvider = vp;
this.mappers = mappers;
this.buffer = new ValueContainer[bufSize];
}

@Override
public boolean hasNext() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fi.nls.hakunapi.simple.postgis;
package fi.nls.hakunapi.sql;

import java.nio.charset.StandardCharsets;
import java.sql.Array;
Expand All @@ -16,8 +16,8 @@

public class ResultSetValueProvider implements ValueProvider {

private final ResultSet rs;
private final int numCols;
protected final ResultSet rs;
protected final int numCols;

public ResultSetValueProvider(ResultSet rs, int numCols) {
this.rs = rs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fi.nls.hakunapi.simple.postgis;
package fi.nls.hakunapi.sql;

import java.util.List;

Expand All @@ -8,12 +8,12 @@
import fi.nls.hakunapi.core.SimpleFeatureType;
import fi.nls.hakunapi.core.join.Join;

public class SQLFeatureType extends SimpleFeatureType {
public abstract class SQLFeatureType extends SimpleFeatureType {

private String dbSchema;
private String primaryTable;
private List<Join> joins;
private DataSource ds;
protected String dbSchema;
protected String primaryTable;
protected List<Join> joins;
protected DataSource ds;

public String getDbSchema() {
return dbSchema;
Expand Down Expand Up @@ -47,9 +47,7 @@ public void setDatabase(DataSource ds) {
this.ds = ds;
}

@Override
public FeatureProducer getFeatureProducer() {
return new SimplePostGIS(ds);
}

public abstract FeatureProducer getFeatureProducer() ;

}