Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-14454 Add SpatialDialect for CockroachDB
- Loading branch information
Showing
26 changed files
with
629 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachDB202SpatialDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
|
||
package org.hibernate.spatial.dialect.cockroachdb; | ||
|
||
import java.util.Map; | ||
|
||
import org.hibernate.boot.model.TypeContributions; | ||
import org.hibernate.dialect.CockroachDB201Dialect; | ||
import org.hibernate.dialect.function.SQLFunction; | ||
import org.hibernate.service.ServiceRegistry; | ||
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor; | ||
|
||
/** | ||
* An @{code SpatialDialect} for CockroachDB 20.2 and later. CockroachDB's spatial features where introduced in | ||
* that version. | ||
*/ | ||
public class CockroachDB202SpatialDialect extends CockroachDB201Dialect implements CockroachSpatialDialectTrait { | ||
|
||
|
||
public CockroachDB202SpatialDialect() { | ||
super(); | ||
registerColumnType( | ||
PGGeometryTypeDescriptor.INSTANCE_WKB_2.getSqlType(), | ||
"GEOMETRY" | ||
); | ||
for ( Map.Entry<String, SQLFunction> entry : functionsToRegister() ) { | ||
registerFunction( entry.getKey(), entry.getValue() ); | ||
} | ||
} | ||
|
||
@Override | ||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { | ||
super.contributeTypes( | ||
typeContributions, | ||
serviceRegistry | ||
); | ||
delegateContributeTypes( typeContributions, serviceRegistry ); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...al/src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachDBSpatialSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
|
||
package org.hibernate.spatial.dialect.cockroachdb; | ||
|
||
import org.hibernate.boot.model.TypeContributions; | ||
import org.hibernate.service.ServiceRegistry; | ||
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor; | ||
import org.hibernate.spatial.GeolatteGeometryType; | ||
import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor; | ||
import org.hibernate.spatial.JTSGeometryType; | ||
import org.hibernate.spatial.SpatialDialect; | ||
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor; | ||
import org.hibernate.spatial.dialect.postgis.PostgisFunctions; | ||
import org.hibernate.spatial.dialect.postgis.PostgisSupport; | ||
|
||
public class CockroachDBSpatialSupport extends PostgisSupport implements SpatialDialect { | ||
|
||
CockroachDBSpatialSupport() { | ||
super( new CockroachDBSpatialFunctions() ); | ||
} | ||
|
||
@Override | ||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { | ||
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) ); | ||
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) ); | ||
|
||
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE ); | ||
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE ); | ||
} | ||
|
||
} | ||
|
||
class CockroachDBSpatialFunctions extends PostgisFunctions { | ||
|
||
CockroachDBSpatialFunctions() { | ||
super(); | ||
this.functionMap.remove( "geomunion" ); | ||
} | ||
|
||
} | ||
|
77 changes: 77 additions & 0 deletions
77
...src/main/java/org/hibernate/spatial/dialect/cockroachdb/CockroachSpatialDialectTrait.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
|
||
package org.hibernate.spatial.dialect.cockroachdb; | ||
|
||
import org.hibernate.boot.model.TypeContributions; | ||
import org.hibernate.service.ServiceRegistry; | ||
import org.hibernate.spatial.SpatialDialect; | ||
import org.hibernate.spatial.SpatialFunction; | ||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry; | ||
|
||
public interface CockroachSpatialDialectTrait extends SpatialDialect { | ||
|
||
CockroachDBSpatialSupport DELEGATE = new CockroachDBSpatialSupport(); | ||
|
||
default SpatialFunctionsRegistry functionsToRegister() { | ||
return DELEGATE.functionsToRegister(); | ||
|
||
} | ||
|
||
default String getSpatialRelateSQL(String columnName, int spatialRelation) { | ||
return DELEGATE.getSpatialRelateSQL( columnName, spatialRelation ); | ||
} | ||
|
||
default void delegateContributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { | ||
DELEGATE.contributeTypes( typeContributions, serviceRegistry ); | ||
} | ||
|
||
/** | ||
* Returns the SQL fragment for the SQL WHERE-expression when parsing | ||
* <code>org.hibernate.spatial.criterion.SpatialFilterExpression</code>s | ||
* into prepared statements. | ||
* | ||
* @param columnName The name of the geometry-typed column to which the filter is | ||
* be applied | ||
* | ||
* @return Rhe SQL fragment for the {@code SpatialFilterExpression} | ||
*/ | ||
default String getSpatialFilterExpression(String columnName) { | ||
return DELEGATE.getSpatialFilterExpression( columnName ); | ||
} | ||
|
||
@Override | ||
default String getSpatialAggregateSQL(String columnName, int aggregation) { | ||
return DELEGATE.getSpatialAggregateSQL( columnName, aggregation ); | ||
} | ||
|
||
@Override | ||
default String getDWithinSQL(String columnName) { | ||
return DELEGATE.getDWithinSQL( columnName ); | ||
} | ||
|
||
@Override | ||
default String getHavingSridSQL(String columnName) { | ||
return DELEGATE.getHavingSridSQL( columnName ); | ||
} | ||
|
||
@Override | ||
default String getIsEmptySQL(String columnName, boolean isEmpty) { | ||
return DELEGATE.getIsEmptySQL( columnName, isEmpty ); | ||
} | ||
|
||
@Override | ||
default boolean supportsFiltering() { | ||
return DELEGATE.supportsFiltering(); | ||
} | ||
|
||
@Override | ||
default boolean supports(SpatialFunction function) { | ||
return DELEGATE.supports( function ); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/cockroachdb/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
|
||
/** | ||
* {@code SpatialDialect}s for CockroachDB | ||
*/ | ||
package org.hibernate.spatial.dialect.cockroachdb; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.