Skip to content

Commit

Permalink
Merge branch 'dev' into utf8Support
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra authored Jun 21, 2018
2 parents 0dac284 + c34e1a9 commit 72d3b9b
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 84 deletions.
27 changes: 18 additions & 9 deletions src/main/java/com/microsoft/sqlserver/jdbc/Geography.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ public class Geography extends SQLServerSpatialDatatype {

/**
* Private constructor used for creating a Geography object from WKT and srid.
* @throws SQLServerException
*/
private Geography(String WellKnownText, int srid) {
private Geography(String WellKnownText, int srid) throws SQLServerException {
this.wkt = WellKnownText;
this.srid = srid;

try {
parseWKTForSerialization(this, currentWktPos, -1, false);
}
catch (StringIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Reached unexpected end of WKT. Please make sure WKT is valid.");
String strError = SQLServerException.getErrString("R_illegalWKT");
throw new SQLServerException(strError, null, 0, null);
}

serializeToWkb(false);
Expand All @@ -33,8 +35,9 @@ private Geography(String WellKnownText, int srid) {

/**
* Private constructor used for creating a Geography object from WKB.
* @throws SQLServerException
*/
private Geography(byte[] wkb) {
private Geography(byte[] wkb) throws SQLServerException {
this.wkb = wkb;
buffer = ByteBuffer.wrap(wkb);
buffer.order(ByteOrder.LITTLE_ENDIAN);
Expand Down Expand Up @@ -62,8 +65,9 @@ public Geography() {
* @param wkt WKT
* @param srid SRID
* @return Geography instance
* @throws SQLServerException
*/
public static Geography STGeomFromText(String wkt, int srid) {
public static Geography STGeomFromText(String wkt, int srid) throws SQLServerException {
return new Geography(wkt, srid);
}

Expand All @@ -73,8 +77,9 @@ public static Geography STGeomFromText(String wkt, int srid) {
*
* @param wkb WKB
* @return Geography instance
* @throws SQLServerException
*/
public static Geography STGeomFromWKB(byte[] wkb) {
public static Geography STGeomFromWKB(byte[] wkb) throws SQLServerException {
return new Geography(wkb);
}

Expand All @@ -83,8 +88,9 @@ public static Geography STGeomFromWKB(byte[] wkb) {
*
* @param wkb WKB
* @return Geography instance
* @throws SQLServerException
*/
public static Geography deserialize(byte[] wkb) {
public static Geography deserialize(byte[] wkb) throws SQLServerException {
return new Geography(wkb);
}

Expand All @@ -94,8 +100,9 @@ public static Geography deserialize(byte[] wkb) {
*
* @param wkt WKt
* @return Geography instance
* @throws SQLServerException
*/
public static Geography parse(String wkt) {
public static Geography parse(String wkt) throws SQLServerException {
return new Geography(wkt, 4326);
}

Expand All @@ -106,8 +113,9 @@ public static Geography parse(String wkt) {
* @param y y coordinate
* @param srid SRID
* @return Geography instance
* @throws SQLServerException
*/
public static Geography point(double x, double y, int srid) {
public static Geography point(double x, double y, int srid) throws SQLServerException {
return new Geography("POINT (" + x + " " + y + ")", srid);
}

Expand All @@ -116,8 +124,9 @@ public static Geography point(double x, double y, int srid) {
* Geography instance. This text will not contain any Z (elevation) or M (measure) values carried by the instance.
*
* @return the WKT representation without the Z and M values.
* @throws SQLServerException
*/
public String STAsText() {
public String STAsText() throws SQLServerException {
if (null == wktNoZM) {
buffer = ByteBuffer.wrap(wkb);
buffer.order(ByteOrder.LITTLE_ENDIAN);
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ public class Geometry extends SQLServerSpatialDatatype {

/**
* Private constructor used for creating a Geometry object from WKT and srid.
* @throws SQLServerException
*/
private Geometry(String WellKnownText, int srid) {
private Geometry(String WellKnownText, int srid) throws SQLServerException {
this.wkt = WellKnownText;
this.srid = srid;

try {
parseWKTForSerialization(this, currentWktPos, -1, false);
}
catch (StringIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Reached unexpected end of WKT. Please make sure WKT is valid.");
String strError = SQLServerException.getErrString("R_illegalWKT");
throw new SQLServerException(strError, null, 0, null);
}

serializeToWkb(false);
Expand All @@ -33,8 +35,9 @@ private Geometry(String WellKnownText, int srid) {

/**
* Private constructor used for creating a Geometry object from WKB.
* @throws SQLServerException
*/
private Geometry(byte[] wkb) {
private Geometry(byte[] wkb) throws SQLServerException {
this.wkb = wkb;
buffer = ByteBuffer.wrap(wkb);
buffer.order(ByteOrder.LITTLE_ENDIAN);
Expand Down Expand Up @@ -62,8 +65,9 @@ public Geometry() {
* @param wkt WKT
* @param srid SRID
* @return Geometry instance
* @throws SQLServerException
*/
public static Geometry STGeomFromText(String wkt, int srid) {
public static Geometry STGeomFromText(String wkt, int srid) throws SQLServerException {
return new Geometry(wkt, srid);
}

Expand All @@ -73,8 +77,9 @@ public static Geometry STGeomFromText(String wkt, int srid) {
*
* @param wkb WKB
* @return Geometry instance
* @throws SQLServerException
*/
public static Geometry STGeomFromWKB(byte[] wkb) {
public static Geometry STGeomFromWKB(byte[] wkb) throws SQLServerException {
return new Geometry(wkb);
}

Expand All @@ -83,8 +88,9 @@ public static Geometry STGeomFromWKB(byte[] wkb) {
*
* @param wkb WKB
* @return Geometry instance
* @throws SQLServerException
*/
public static Geometry deserialize(byte[] wkb) {
public static Geometry deserialize(byte[] wkb) throws SQLServerException {
return new Geometry(wkb);
}

Expand All @@ -94,8 +100,9 @@ public static Geometry deserialize(byte[] wkb) {
*
* @param wkt WKT
* @return Geometry instance
* @throws SQLServerException
*/
public static Geometry parse(String wkt) {
public static Geometry parse(String wkt) throws SQLServerException {
return new Geometry(wkt, 0);
}

Expand All @@ -106,8 +113,9 @@ public static Geometry parse(String wkt) {
* @param y y coordinate
* @param srid SRID
* @return Geometry instance
* @throws SQLServerException
*/
public static Geometry point(double x, double y, int srid) {
public static Geometry point(double x, double y, int srid) throws SQLServerException {
return new Geometry("POINT (" + x + " " + y + ")", srid);
}

Expand All @@ -116,8 +124,9 @@ public static Geometry point(double x, double y, int srid) {
* Geometry instance. This text will not contain any Z (elevation) or M (measure) values carried by the instance.
*
* @return the WKT representation without the Z and M values.
* @throws SQLServerException
*/
public String STAsText() {
public String STAsText() throws SQLServerException {
if (null == wktNoZM) {
buffer = ByteBuffer.wrap(wkb);
buffer.order(ByteOrder.LITTLE_ENDIAN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,5 +394,8 @@ protected Object[][] getContents() {
{"R_cancelQueryTimeoutPropertyDescription", "The number of seconds to wait to cancel sending a query timeout."},
{"R_invalidCancelQueryTimeout", "The cancel timeout value {0} is not valid."},
{"R_unknownUTF8SupportValue", "Unknown value for UTF8 support."},
{"R_illegalWKT", "Illegal Well-Known text. Please make sure Well-Known text is valid."},
{"R_illegalTypeForGeometry", "{0} is not supported for Geometry."},
{"R_illegalWKTposition", "Illegal character in Well-Known text at position {0}."},
};
}
Loading

0 comments on commit 72d3b9b

Please sign in to comment.