forked from databricks/databricks-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractDatabricksGeospatial.java
More file actions
119 lines (105 loc) · 3.31 KB
/
AbstractDatabricksGeospatial.java
File metadata and controls
119 lines (105 loc) · 3.31 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.databricks.jdbc.api.impl;
import com.databricks.jdbc.api.IDatabricksGeospatial;
import com.databricks.jdbc.api.impl.converters.WKTConverter;
import com.databricks.jdbc.exception.DatabricksValidationException;
import com.databricks.jdbc.log.JdbcLogger;
import com.databricks.jdbc.log.JdbcLoggerFactory;
import java.util.Objects;
/**
* Abstract base class for geospatial data types in Databricks JDBC driver.
*
* <p>This class provides common functionality for both GEOMETRY and GEOGRAPHY types, including
* storage of WKT (Well-Known Text) format data and access to both WKT and WKB representations.
*/
public abstract class AbstractDatabricksGeospatial implements IDatabricksGeospatial {
private static final JdbcLogger LOGGER =
JdbcLoggerFactory.getLogger(AbstractDatabricksGeospatial.class);
private final String wkt;
private final int srid; // Spatial Reference System Identifier
/**
* Constructs an AbstractDatabricksGeospatial with the specified WKT and SRID.
*
* @param wkt the Well-Known Text representation of the geospatial object
* @param srid the Spatial Reference System Identifier
* @throws DatabricksValidationException if the WKT is invalid
*/
protected AbstractDatabricksGeospatial(String wkt, int srid)
throws DatabricksValidationException {
if (wkt == null || wkt.trim().isEmpty()) {
LOGGER.error("WKT string cannot be null or empty");
throw new DatabricksValidationException("WKT string cannot be null or empty");
}
this.wkt = wkt.trim();
this.srid = srid;
}
/**
* Returns the Well-Known Binary (WKB) representation of the geospatial object.
*
* @return the WKB representation as a byte array
* @throws DatabricksValidationException if WKT to WKB conversion fails
*/
@Override
public byte[] getWKB() throws DatabricksValidationException {
return WKTConverter.toWKB(wkt);
}
/**
* Returns the Spatial Reference System Identifier (SRID) of the geospatial object.
*
* @return the SRID value
*/
@Override
public int getSRID() {
return srid;
}
/**
* Returns the Well-Known Text (WKT) representation of the geospatial object.
*
* @return the WKT string
*/
@Override
public String getWKT() {
return wkt;
}
/**
* Returns a string representation of the geospatial object in EWKT format.
*
* @return the EWKT string representation
*/
@Override
public String toString() {
return String.format("SRID=%d;%s", srid, wkt);
}
/**
* Checks if this geospatial object is equal to another object.
*
* @param obj the object to compare
* @return true if the objects are equal, false otherwise
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
AbstractDatabricksGeospatial that = (AbstractDatabricksGeospatial) obj;
return srid == that.srid && wkt.equals(that.wkt);
}
/**
* Returns the hash code for this geospatial object.
*
* @return the hash code
*/
@Override
public int hashCode() {
return Objects.hash(wkt, srid);
}
/**
* Returns the data type of the geospatial object.
*
* @return the type as a string, either "GEOMETRY" or "GEOGRAPHY"
*/
@Override
public abstract String getType();
}