Skip to content

Commit b9fb1b1

Browse files
maesenkadreab8
authored andcommitted
HHH-14037 Add PostgisPG10Dialect
1 parent ffc43aa commit b9fb1b1

File tree

3 files changed

+169
-113
lines changed

3 files changed

+169
-113
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
8+
package org.hibernate.spatial.dialect.postgis;
9+
10+
import org.hibernate.spatial.SpatialDialect;
11+
import org.hibernate.spatial.SpatialFunction;
12+
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
13+
14+
interface PGSpatialDialectTrait extends SpatialDialect {
15+
16+
PostgisSupport support = new PostgisSupport();
17+
18+
19+
default SpatialFunctionsRegistry functionsToRegister() {
20+
return support.functionsToRegister();
21+
}
22+
/**
23+
* Returns the SQL fragment for the SQL WHERE-clause when parsing
24+
* <code>org.hibernatespatial.criterion.SpatialRelateExpression</code>s
25+
* into prepared statements.
26+
* <p/>
27+
*
28+
* @param columnName The name of the geometry-typed column to which the relation is
29+
* applied
30+
* @param spatialRelation The type of spatial relation (as defined in
31+
* <code>SpatialRelation</code>).
32+
*
33+
* @return SQL fragment {@code SpatialRelateExpression}
34+
*/
35+
@Override
36+
default String getSpatialRelateSQL(String columnName, int spatialRelation) {
37+
return support.getSpatialRelateSQL( columnName, spatialRelation );
38+
}
39+
40+
/**
41+
* Returns the SQL fragment for the SQL WHERE-expression when parsing
42+
* <code>org.hibernate.spatial.criterion.SpatialFilterExpression</code>s
43+
* into prepared statements.
44+
*
45+
* @param columnName The name of the geometry-typed column to which the filter is
46+
* be applied
47+
*
48+
* @return Rhe SQL fragment for the {@code SpatialFilterExpression}
49+
*/
50+
@Override
51+
default String getSpatialFilterExpression(String columnName) {
52+
return support.getSpatialFilterExpression( columnName );
53+
}
54+
55+
/**
56+
* Returns the SQL fragment for the specfied Spatial aggregate expression.
57+
*
58+
* @param columnName The name of the Geometry property
59+
* @param aggregation The type of <code>SpatialAggregate</code>
60+
*
61+
* @return The SQL fragment for the projection
62+
*/
63+
@Override
64+
default String getSpatialAggregateSQL(String columnName, int aggregation) {
65+
return support.getSpatialAggregateSQL( columnName, aggregation );
66+
}
67+
68+
/**
69+
* Returns The SQL fragment when parsing a <code>DWithinExpression</code>.
70+
*
71+
* @param columnName The geometry column to test against
72+
*
73+
* @return The SQL fragment when parsing a <code>DWithinExpression</code>.
74+
*/
75+
@Override
76+
default String getDWithinSQL(String columnName) {
77+
return support.getDWithinSQL( columnName );
78+
}
79+
80+
/**
81+
* Returns the SQL fragment when parsing a <code>HavingSridExpression</code>.
82+
*
83+
* @param columnName The geometry column to test against
84+
*
85+
* @return The SQL fragment for a <code>HavingSridExpression</code>.
86+
*/
87+
@Override
88+
default String getHavingSridSQL(String columnName) {
89+
return support.getHavingSridSQL( columnName );
90+
}
91+
92+
/**
93+
* Returns the SQL fragment when parsing a <code>IsEmptyExpression</code> or
94+
* <code>IsNotEmpty</code> expression.
95+
*
96+
* @param columnName The geometry column
97+
* @param isEmpty Whether the geometry is tested for empty or non-empty
98+
*
99+
* @return The SQL fragment for the isempty function
100+
*/
101+
@Override
102+
default String getIsEmptySQL(String columnName, boolean isEmpty) {
103+
return support.getIsEmptySQL( columnName, isEmpty );
104+
}
105+
106+
/**
107+
* Returns true if this <code>SpatialDialect</code> supports a specific filtering function.
108+
* <p> This is intended to signal DB-support for fast window queries, or MBR-overlap queries.</p>
109+
*
110+
* @return True if filtering is supported
111+
*/
112+
@Override
113+
default boolean supportsFiltering() {
114+
return support.supportsFiltering();
115+
}
116+
117+
/**
118+
* Does this dialect supports the specified <code>SpatialFunction</code>.
119+
*
120+
* @param function <code>SpatialFunction</code>
121+
*
122+
* @return True if this <code>SpatialDialect</code> supports the spatial function specified by the function parameter.
123+
*/
124+
@Override
125+
default boolean supports(SpatialFunction function) {
126+
return support.supports( function );
127+
}
128+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
8+
package org.hibernate.spatial.dialect.postgis;
9+
10+
import java.util.Map;
11+
12+
import org.hibernate.boot.model.TypeContributions;
13+
import org.hibernate.dialect.PostgreSQL10Dialect;
14+
import org.hibernate.dialect.function.SQLFunction;
15+
import org.hibernate.service.ServiceRegistry;
16+
17+
public class PostgisPG10Dialect extends PostgreSQL10Dialect implements PGSpatialDialectTrait {
18+
19+
public PostgisPG10Dialect() {
20+
super();
21+
registerColumnType(
22+
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
23+
"GEOMETRY"
24+
);
25+
for ( Map.Entry<String, SQLFunction> entry : functionsToRegister() ) {
26+
registerFunction( entry.getKey(), entry.getValue() );
27+
}
28+
}
29+
30+
@Override
31+
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
32+
super.contributeTypes(
33+
typeContributions,
34+
serviceRegistry
35+
);
36+
support.contributeTypes( typeContributions, serviceRegistry );
37+
}
38+
39+
}

hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG95Dialect.java

Lines changed: 2 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,12 @@
1212
import org.hibernate.dialect.PostgreSQL95Dialect;
1313
import org.hibernate.dialect.function.SQLFunction;
1414
import org.hibernate.service.ServiceRegistry;
15-
import org.hibernate.spatial.SpatialDialect;
16-
import org.hibernate.spatial.SpatialFunction;
1715

1816
/**
1917
* Extends the {@code PostgreSQL95Dialect} to add support for the Postgis spatial types, functions and operators .
2018
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
2119
*/
22-
public class PostgisPG95Dialect extends PostgreSQL95Dialect implements SpatialDialect {
23-
24-
25-
transient private PostgisSupport support = new PostgisSupport();
20+
public class PostgisPG95Dialect extends PostgreSQL95Dialect implements PGSpatialDialectTrait {
2621

2722
/**
2823
* Creates an instance
@@ -33,7 +28,7 @@ public PostgisPG95Dialect() {
3328
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
3429
"GEOMETRY"
3530
);
36-
for ( Map.Entry<String, SQLFunction> entry : support.functionsToRegister() ) {
31+
for ( Map.Entry<String, SQLFunction> entry : functionsToRegister() ) {
3732
registerFunction( entry.getKey(), entry.getValue() );
3833
}
3934
}
@@ -47,110 +42,4 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
4742
support.contributeTypes( typeContributions, serviceRegistry );
4843
}
4944

50-
/**
51-
* Returns the SQL fragment for the SQL WHERE-clause when parsing
52-
* <code>org.hibernatespatial.criterion.SpatialRelateExpression</code>s
53-
* into prepared statements.
54-
* <p/>
55-
*
56-
* @param columnName The name of the geometry-typed column to which the relation is
57-
* applied
58-
* @param spatialRelation The type of spatial relation (as defined in
59-
* <code>SpatialRelation</code>).
60-
*
61-
* @return SQL fragment {@code SpatialRelateExpression}
62-
*/
63-
@Override
64-
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
65-
return support.getSpatialRelateSQL( columnName, spatialRelation );
66-
}
67-
68-
/**
69-
* Returns the SQL fragment for the SQL WHERE-expression when parsing
70-
* <code>org.hibernate.spatial.criterion.SpatialFilterExpression</code>s
71-
* into prepared statements.
72-
*
73-
* @param columnName The name of the geometry-typed column to which the filter is
74-
* be applied
75-
*
76-
* @return Rhe SQL fragment for the {@code SpatialFilterExpression}
77-
*/
78-
@Override
79-
public String getSpatialFilterExpression(String columnName) {
80-
return support.getSpatialFilterExpression( columnName );
81-
}
82-
83-
/**
84-
* Returns the SQL fragment for the specfied Spatial aggregate expression.
85-
*
86-
* @param columnName The name of the Geometry property
87-
* @param aggregation The type of <code>SpatialAggregate</code>
88-
*
89-
* @return The SQL fragment for the projection
90-
*/
91-
@Override
92-
public String getSpatialAggregateSQL(String columnName, int aggregation) {
93-
return support.getSpatialAggregateSQL( columnName, aggregation );
94-
}
95-
96-
/**
97-
* Returns The SQL fragment when parsing a <code>DWithinExpression</code>.
98-
*
99-
* @param columnName The geometry column to test against
100-
*
101-
* @return The SQL fragment when parsing a <code>DWithinExpression</code>.
102-
*/
103-
@Override
104-
public String getDWithinSQL(String columnName) {
105-
return support.getDWithinSQL( columnName );
106-
}
107-
108-
/**
109-
* Returns the SQL fragment when parsing a <code>HavingSridExpression</code>.
110-
*
111-
* @param columnName The geometry column to test against
112-
*
113-
* @return The SQL fragment for a <code>HavingSridExpression</code>.
114-
*/
115-
@Override
116-
public String getHavingSridSQL(String columnName) {
117-
return support.getHavingSridSQL( columnName );
118-
}
119-
120-
/**
121-
* Returns the SQL fragment when parsing a <code>IsEmptyExpression</code> or
122-
* <code>IsNotEmpty</code> expression.
123-
*
124-
* @param columnName The geometry column
125-
* @param isEmpty Whether the geometry is tested for empty or non-empty
126-
*
127-
* @return The SQL fragment for the isempty function
128-
*/
129-
@Override
130-
public String getIsEmptySQL(String columnName, boolean isEmpty) {
131-
return support.getIsEmptySQL( columnName, isEmpty );
132-
}
133-
134-
/**
135-
* Returns true if this <code>SpatialDialect</code> supports a specific filtering function.
136-
* <p> This is intended to signal DB-support for fast window queries, or MBR-overlap queries.</p>
137-
*
138-
* @return True if filtering is supported
139-
*/
140-
@Override
141-
public boolean supportsFiltering() {
142-
return support.supportsFiltering();
143-
}
144-
145-
/**
146-
* Does this dialect supports the specified <code>SpatialFunction</code>.
147-
*
148-
* @param function <code>SpatialFunction</code>
149-
*
150-
* @return True if this <code>SpatialDialect</code> supports the spatial function specified by the function parameter.
151-
*/
152-
@Override
153-
public boolean supports(SpatialFunction function) {
154-
return support.supports( function );
155-
}
15645
}

0 commit comments

Comments
 (0)