PageRenderTime 54ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/sqlserver/SqlServerFunctions.java

https://github.com/sebersole/hibernate-core
Java | 66 lines | 38 code | 9 blank | 19 comment | 0 complexity | b8270d08a8002a3699a007230ea61485 MD5 | raw file
  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. package org.hibernate.spatial.dialect.sqlserver;
  8. import org.hibernate.dialect.function.SQLFunctionTemplate;
  9. import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
  10. import org.hibernate.type.StandardBasicTypes;
  11. /**
  12. * Created by Karel Maesen, Geovise BVBA on 19/09/2018.
  13. */
  14. class SqlServerFunctions extends SpatialFunctionsRegistry {
  15. public SqlServerFunctions() {
  16. put( "dimension", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "?1.STDimension()" ) );
  17. put( "geometrytype", new SQLFunctionTemplate( StandardBasicTypes.STRING, "?1.STGeometryType()" ) );
  18. put( "srid", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "?1.STSrid" ) );
  19. put( "envelope", new SqlServerMethod( "STEnvelope" ) );
  20. put( "astext", new SQLFunctionTemplate( StandardBasicTypes.STRING, "?1.STAsText()" ) );
  21. put( "asbinary", new SQLFunctionTemplate( StandardBasicTypes.BINARY, "?1.STAsBinary()" ) );
  22. put( "isempty", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STIsEmpty()" ) );
  23. put( "issimple", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STIsSimple()" ) );
  24. put( "boundary", new SqlServerMethod( "STBoundary" ) );
  25. // section 2.1.1.2
  26. // Register functions for spatial relation constructs
  27. put( "contains", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STContains(?2)" ) );
  28. put( "crosses", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STCrosses(?2)" ) );
  29. put( "disjoint", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STDisjoint(?2)" ) );
  30. put( "equals", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STEquals(?2)" ) );
  31. put( "intersects", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STIntersects(?2)" ) );
  32. put( "overlaps", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STOverlaps(?2)" ) );
  33. put( "touches", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STTouches(?2)" ) );
  34. put( "within", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STWithin(?2)" ) );
  35. put( "relate", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STRelate(?2,?3)" ) );
  36. // section 2.1.1.3
  37. // Register spatial analysis functions.
  38. put( "distance", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "?1.STDistance(?2)" ) );
  39. put( "buffer", new SqlServerMethod( "STBuffer" ) );
  40. put( "convexhull", new SqlServerMethod( "STConvexHull" ) );
  41. put( "difference", new SqlServerMethod( "STDifference" ) );
  42. put( "intersection", new SqlServerMethod( "STIntersection" ) );
  43. put( "symdifference", new SqlServerMethod( "STSymDifference" ) );
  44. put( "geomunion", new SqlServerMethod( "STUnion" ) );
  45. // we rename OGC union to geomunion because union is a reserved SQL keyword.
  46. // (See also postgis documentation).
  47. // portable spatial aggregate functions
  48. // no aggregatefunctions implemented in sql-server2000
  49. //put("extent", new SQLFunctionTemplate(geomType, "?1.STExtent()"));
  50. // section 2.1.9.1 methods on surfaces
  51. put( "area", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "?1.STArea()" ) );
  52. put( "centroid", new SqlServerMethod( "STCentroid" ) );
  53. put(
  54. "pointonsurface", new SqlServerMethod( "STPointOnSurface" )
  55. );
  56. }
  57. }