Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding error messages to resource file for spatial datatype implementation #723

Merged
merged 4 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -393,5 +393,8 @@ protected Object[][] getContents() {
{"R_invalidSSLProtocol", "SSL Protocol {0} label is not valid. Only TLS, TLSv1, TLSv1.1, and TLSv1.2 are supported."},
{"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_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