-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
CockroachDbContributor.java
62 lines (52 loc) · 2.2 KB
/
CockroachDbContributor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* 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.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.spatial.FunctionKey;
import org.hibernate.spatial.GeolatteGeometryType;
import org.hibernate.spatial.HSMessageLogger;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.contributor.ContributorImplementor;
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
import org.hibernate.spatial.dialect.postgis.PostgisSqmFunctionDescriptors;
public class CockroachDbContributor implements ContributorImplementor {
private final ServiceRegistry serviceRegistry;
public CockroachDbContributor(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
@Override
public void contributeTypes(TypeContributions typeContributions) {
HSMessageLogger.LOGGER.typeContributions( this.getClass().getCanonicalName() );
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) );
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) );
}
@Override
public void contributeFunctions(SqmFunctionRegistry functionRegistry) {
HSMessageLogger.LOGGER.functionContributions( this.getClass().getCanonicalName() );
PostgisSqmFunctionDescriptors postgisFunctions = new PostgisSqmFunctionDescriptors( getServiceRegistry() );
postgisFunctions.asMap()
.forEach( (key, desc) -> {
if ( isUnsupported( key ) ) {
return;
}
functionRegistry.register( key.getName(), desc );
key.getAltName().ifPresent( altName -> functionRegistry.registerAlternateKey(
altName,
key.getName()
) );
} );
}
private boolean isUnsupported(FunctionKey key) {
return key.getName().equalsIgnoreCase( "st_union" );
}
@Override
public ServiceRegistry getServiceRegistry() {
return this.serviceRegistry;
}
}