diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/Geography.java b/src/main/java/com/microsoft/sqlserver/jdbc/Geography.java index 0790a0691..a565d5084 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/Geography.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/Geography.java @@ -15,8 +15,9 @@ 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; @@ -24,7 +25,8 @@ private Geography(String WellKnownText, int srid) { 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); @@ -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); @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java b/src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java index 90f4427a5..196f6a0ad 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java @@ -15,8 +15,9 @@ 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; @@ -24,7 +25,8 @@ private Geometry(String WellKnownText, int srid) { 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); @@ -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); @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java index 884be5c93..3cea768e6 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java @@ -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}."}, }; } \ No newline at end of file diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java index a5256aa10..3fe57e8dd 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java @@ -10,6 +10,7 @@ import java.math.BigDecimal; import java.nio.ByteBuffer; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -107,13 +108,15 @@ abstract class SQLServerSpatialDatatype { * @param figureIndexEnd upper bound for reading figures * @param segmentIndexEnd upper bound for reading segments * @param shapeIndexEnd upper bound for reading shapes + * @throws SQLServerException */ protected void constructWKT(SQLServerSpatialDatatype sd, InternalSpatialDatatype isd, int pointIndexEnd, int figureIndexEnd, - int segmentIndexEnd, int shapeIndexEnd) { + int segmentIndexEnd, int shapeIndexEnd) throws SQLServerException { if (null == points || numberOfPoints == 0) { if (isd.getTypeCode() == 11) { // FULLGLOBE if (sd instanceof Geometry) { - throw new IllegalArgumentException("Fullglobe is not supported for Geometry."); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalTypeForGeometry")); + throw new SQLServerException(form.format(new Object[]{"Fullglobe"}), null, 0, null); } else { appendToWKTBuffers("FULLGLOBE"); return; @@ -163,7 +166,8 @@ protected void constructWKT(SQLServerSpatialDatatype sd, InternalSpatialDatatype constructCurvepolygonWKT(currentFigureIndex, figureIndexEnd, currentSegmentIndex, segmentIndexEnd); break; default: - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } appendToWKTBuffers(")"); @@ -176,8 +180,9 @@ protected void constructWKT(SQLServerSpatialDatatype sd, InternalSpatialDatatype * @param startPos The index to start from from the WKT. * @param parentShapeIndex The index of the parent's Shape in the shapes array. Used to determine this shape's parent. * @param isGeoCollection flag to indicate if this is part of a GeometryCollection. + * @throws SQLServerException */ - protected void parseWKTForSerialization(SQLServerSpatialDatatype sd, int startPos, int parentShapeIndex, boolean isGeoCollection) { + protected void parseWKTForSerialization(SQLServerSpatialDatatype sd, int startPos, int parentShapeIndex, boolean isGeoCollection) throws SQLServerException { //after every iteration of this while loop, the currentWktPosition will be set to the //end of the geometry/geography shape, except for the very first iteration of it. //This means that there has to be comma (that separates the previous shape with the next shape), @@ -199,7 +204,8 @@ protected void parseWKTForSerialization(SQLServerSpatialDatatype sd, int startPo isd = InternalSpatialDatatype.valueOf(nextToken); } catch (Exception e) { - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } byte fa = 0; @@ -211,11 +217,13 @@ protected void parseWKTForSerialization(SQLServerSpatialDatatype sd, int startPo // check for FULLGLOBE before reading the first open bracket, since FULLGLOBE doesn't have one. if (nextToken.equals("FULLGLOBE")) { if (sd instanceof Geometry) { - throw new IllegalArgumentException("Fullglobe is not supported for Geometry."); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalTypeForGeometry")); + throw new SQLServerException(form.format(new Object[]{"Fullglobe"}), null, 0, null); } if (startPos != 0) { - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } shapeList.add(new Shape(parentShapeIndex, -1, isd.getTypeCode())); @@ -293,7 +301,8 @@ protected void parseWKTForSerialization(SQLServerSpatialDatatype sd, int startPo break; default: - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } readCloseBracket(); } @@ -668,8 +677,9 @@ protected void constructSegmentWKT(int currentSegment, byte segment, int pointEn * The starting point for constructing a GeometryCollection type in WKT form. * * @param shapeEndIndex . + * @throws SQLServerException */ - protected void constructGeometryCollectionWKT(int shapeEndIndex) { + protected void constructGeometryCollectionWKT(int shapeEndIndex) throws SQLServerException { currentShapeIndex++; constructGeometryCollectionWKThelper(shapeEndIndex); } @@ -677,8 +687,9 @@ protected void constructGeometryCollectionWKT(int shapeEndIndex) { /** * Reads Point WKT and adds it to the list of points. * This method will read up until and including the comma that may come at the end of the Point WKT. + * @throws SQLServerException */ - protected void readPointWkt() { + protected void readPointWkt() throws SQLServerException { int numOfCoordinates = 0; double sign; double coords[] = new double[4]; @@ -708,7 +719,8 @@ protected void readPointWkt() { coords[numOfCoordinates] = sign * new BigDecimal(wkt.substring(startPos, currentWktPos)).doubleValue(); } catch (Exception e) { //modify to conversion exception - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } numOfCoordinates++; @@ -719,14 +731,16 @@ protected void readPointWkt() { // character has to be either a , or ), or the WKT is invalid. if (numOfCoordinates == 4) { if (wkt.charAt(currentWktPos) != ',' && wkt.charAt(currentWktPos) != ')') { - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } } if (wkt.charAt(currentWktPos) == ',') { // need at least 2 coordinates if (numOfCoordinates == 1) { - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } currentWktPos++; skipWhiteSpaces(); @@ -747,8 +761,9 @@ protected void readPointWkt() { /** * Reads a series of Point types. + * @throws SQLServerException */ - protected void readLineWkt() { + protected void readLineWkt() throws SQLServerException { while (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') { readPointWkt(); } @@ -759,8 +774,9 @@ protected void readLineWkt() { * * @param parentShapeIndex shape index of the parent shape that called this method * @param nextToken next string token + * @throws SQLServerException */ - protected void readShapeWkt(int parentShapeIndex, String nextToken) { + protected void readShapeWkt(int parentShapeIndex, String nextToken) throws SQLServerException { byte fa = FA_POINT; while (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') { @@ -803,15 +819,17 @@ protected void readShapeWkt(int parentShapeIndex, String nextToken) { } else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop continue; } else { // unexpected input - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } } } /** * Reads a CurvePolygon WKT + * @throws SQLServerException */ - protected void readCurvePolygon() { + protected void readCurvePolygon() throws SQLServerException { while (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') { String nextPotentialToken = getNextStringToken().toUpperCase(Locale.US); if (nextPotentialToken.equals("CIRCULARSTRING")) { @@ -830,7 +848,8 @@ protected void readCurvePolygon() { readLineWkt(); readCloseBracket(); } else { - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } if (wkt.charAt(currentWktPos) == ',') { // more polygons to follow @@ -838,7 +857,8 @@ protected void readCurvePolygon() { } else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop continue; } else { // unexpected input - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } } } @@ -848,8 +868,9 @@ protected void readCurvePolygon() { * * @param thisShapeIndex shape index of current shape * @param nextToken next string token + * @throws SQLServerException */ - protected void readMultiPolygonWkt(int thisShapeIndex, String nextToken) { + protected void readMultiPolygonWkt(int thisShapeIndex, String nextToken) throws SQLServerException { while (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') { if (checkEmptyKeyword(thisShapeIndex, InternalSpatialDatatype.valueOf(nextToken), true)) { continue; @@ -864,7 +885,8 @@ protected void readMultiPolygonWkt(int thisShapeIndex, String nextToken) { } else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop continue; } else { // unexpected input - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } } } @@ -874,8 +896,9 @@ protected void readMultiPolygonWkt(int thisShapeIndex, String nextToken) { * * @param segmentType segment type * @param isFirstIteration flag that indicates if this is the first iteration from the loop outside + * @throws SQLServerException */ - protected void readSegmentWkt(int segmentType, boolean isFirstIteration) { + protected void readSegmentWkt(int segmentType, boolean isFirstIteration) throws SQLServerException { segmentList.add(new Segment((byte) segmentType)); int segmentLength = segmentType; @@ -908,8 +931,9 @@ protected void readSegmentWkt(int segmentType, boolean isFirstIteration) { * Reads a CompoundCurve WKT * * @param isFirstIteration flag that indicates if this is the first iteration from the loop outside + * @throws SQLServerException */ - protected void readCompoundCurveWkt(boolean isFirstIteration) { + protected void readCompoundCurveWkt(boolean isFirstIteration) throws SQLServerException { while (currentWktPos < wkt.length() && wkt.charAt(currentWktPos) != ')') { String nextPotentialToken = getNextStringToken().toUpperCase(Locale.US); if (nextPotentialToken.equals("CIRCULARSTRING")) { @@ -921,7 +945,8 @@ protected void readCompoundCurveWkt(boolean isFirstIteration) { readSegmentWkt(SEGMENT_FIRST_LINE, isFirstIteration); readCloseBracket(); } else { - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } isFirstIteration = false; @@ -931,7 +956,8 @@ protected void readCompoundCurveWkt(boolean isFirstIteration) { } else if (wkt.charAt(currentWktPos) == ')') { // about to exit while loop continue; } else { // unexpected input - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } } } @@ -1029,23 +1055,25 @@ protected void populateStructures() { numberOfSegments = segmentList.size(); } - protected void readOpenBracket() { + protected void readOpenBracket() throws SQLServerException { skipWhiteSpaces(); if (wkt.charAt(currentWktPos) == '(') { currentWktPos++; skipWhiteSpaces(); } else { - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } } - protected void readCloseBracket() { + protected void readCloseBracket() throws SQLServerException { skipWhiteSpaces(); if (wkt.charAt(currentWktPos) == ')') { currentWktPos++; skipWhiteSpaces(); } else { - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } } @@ -1221,7 +1249,7 @@ protected void determineInternalType() { } } - protected boolean checkEmptyKeyword(int parentShapeIndex, InternalSpatialDatatype isd, boolean isInsideAnotherShape) { + protected boolean checkEmptyKeyword(int parentShapeIndex, InternalSpatialDatatype isd, boolean isInsideAnotherShape) throws SQLServerException { String potentialEmptyKeyword = getNextStringToken().toUpperCase(Locale.US); if (potentialEmptyKeyword.equals("EMPTY")) { @@ -1238,7 +1266,8 @@ protected boolean checkEmptyKeyword(int parentShapeIndex, InternalSpatialDatatyp } else if (parentTypeCode == 7) { // GeometryCollection typeCode = InternalSpatialDatatype.GEOMETRYCOLLECTION.getTypeCode(); } else { - throw new IllegalArgumentException("Illegal parentTypeCode."); + String strError = SQLServerException.getErrString("R_illegalWKT"); + throw new SQLServerException(strError, null, 0, null); } } else { typeCode = isd.getTypeCode(); @@ -1254,7 +1283,8 @@ protected boolean checkEmptyKeyword(int parentShapeIndex, InternalSpatialDatatyp } if (!potentialEmptyKeyword.equals("")) { - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } return false; } @@ -1271,8 +1301,9 @@ private void incrementPointNumStartIfPointNotReused(int pointEndIndex) { * Helper used for resurcive iteration for constructing GeometryCollection in WKT form. * * @param shapeEndIndex . + * @throws SQLServerException */ - private void constructGeometryCollectionWKThelper(int shapeEndIndex) { + private void constructGeometryCollectionWKThelper(int shapeEndIndex) throws SQLServerException { //phase 1: assume that there is no multi - stuff and no geometrycollection while (currentShapeIndex < shapeEndIndex) { InternalSpatialDatatype isd = InternalSpatialDatatype.valueOf(shapes[currentShapeIndex].getOpenGISType()); @@ -1531,13 +1562,14 @@ private void skipFirstPointWkt() { } } - private void readComma() { + private void readComma() throws SQLServerException { skipWhiteSpaces(); if (wkt.charAt(currentWktPos) == ',') { currentWktPos++; skipWhiteSpaces(); } else { - throw new IllegalArgumentException("Illegal character at wkt position " + currentWktPos); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_illegalWKTposition")); + throw new SQLServerException(form.format(new Object[]{currentWktPos}), null, 0, null); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java index 4d6e59dc4..b67b49871 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java @@ -42,7 +42,8 @@ protected Object[][] getContents() { {"R_invalidErrorMessage", "Invalid Error Message: "}, {"R_expectedFailPassed", "Expected failure did not fail"}, {"R_dataTypeNotFound", "Cannot find data type"}, - {"R_illegalCharWkt", "Illegal character at wkt position "}, + {"R_illegalCharWktPosition", "Illegal character in Well-Known text at position {0}."}, + {"R_illegalCharWkt", "Illegal Well-Known text. Please make sure Well-Known text is valid."}, {"R_errorMessage", " Error message: "}, {"R_createDropViewFailed", "Create/drop view with preparedStatement failed!"}, {"R_createDropSchemaFailed", "Create/drop schema with preparedStatement failed!"}, diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java index 886cb36cc..21d0e0624 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java @@ -8,6 +8,7 @@ package com.microsoft.sqlserver.jdbc.datatypes; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.sql.DriverManager; @@ -15,6 +16,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; @@ -29,6 +31,7 @@ import com.microsoft.sqlserver.jdbc.Geography; import com.microsoft.sqlserver.jdbc.Geometry; import com.microsoft.sqlserver.jdbc.SQLServerConnection; +import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.jdbc.TestResource; @@ -53,7 +56,7 @@ public class SQLServerSpatialDatatypeTest extends AbstractTest { static boolean isDenaliOrLater = false; @Test - public void testPointWkb() throws DecoderException { + public void testPointWkb() throws DecoderException, SQLException { String geoWKT = "POINT(3 40 5 6)"; byte[] geomWKB = Hex.decodeHex("00000000010F0000000000000840000000000000444000000000000014400000000000001840".toCharArray()); byte[] geogWKB = Hex.decodeHex("E6100000010F0000000000004440000000000000084000000000000014400000000000001840".toCharArray()); @@ -64,7 +67,7 @@ public void testPointWkb() throws DecoderException { } @Test - public void testLineStringWkb() throws DecoderException { + public void testLineStringWkb() throws DecoderException, SQLException { String geoWKT = "LINESTRING(1 0, 0 1, -1 0)"; byte[] geomWKB = Hex.decodeHex("00000000010403000000000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F0BF000000000000000001000000010000000001000000FFFFFFFF0000000002".toCharArray()); byte[] geogWKB = Hex.decodeHex("E61000000104030000000000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F0BF01000000010000000001000000FFFFFFFF0000000002".toCharArray()); @@ -75,7 +78,7 @@ public void testLineStringWkb() throws DecoderException { } @Test - public void testPolygonWkb() throws DecoderException { + public void testPolygonWkb() throws DecoderException, SQLException { String geoWKT = "POLYGON((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1))"; byte[] geomWKB = Hex.decodeHex("000000000104090000000000000000000000000000000000000000000000000000000000000000000840000000000000084000000000000008400000000000000840000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F00000000000000400000000000000040000000000000F03F000000000000F03F000000000000F03F020000000200000000000500000001000000FFFFFFFF0000000003".toCharArray()); byte[] geogWKB = Hex.decodeHex("E61000000200090000000000000000000000000000000000000000000000000008400000000000000000000000000000084000000000000008400000000000000000000000000000084000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000F03F000000000000F03F0000000000000040000000000000F03F000000000000F03F020000000100000000010500000001000000FFFFFFFF0000000003".toCharArray()); @@ -86,7 +89,7 @@ public void testPolygonWkb() throws DecoderException { } @Test - public void testMultiPointWkb() throws DecoderException { + public void testMultiPointWkb() throws DecoderException, SQLException { String geoWKT = "MULTIPOINT((2 3), (7 8 9.5))"; byte[] geomWKB = Hex.decodeHex("00000000010502000000000000000000004000000000000008400000000000001C400000000000002040000000000000F8FF0000000000002340020000000100000000010100000003000000FFFFFFFF0000000004000000000000000001000000000100000001".toCharArray()); byte[] geogWKB = Hex.decodeHex("E61000000105020000000000000000000840000000000000004000000000000020400000000000001C40000000000000F8FF0000000000002340020000000100000000010100000003000000FFFFFFFF0000000004000000000000000001000000000100000001".toCharArray()); @@ -97,7 +100,7 @@ public void testMultiPointWkb() throws DecoderException { } @Test - public void testMultiLineStringWkb() throws DecoderException { + public void testMultiLineStringWkb() throws DecoderException, SQLException { String geoWKT = "MULTILINESTRING((0 2, 1 1), (1 0, 1 1))"; byte[] geomWKB = Hex.decodeHex("0000000001040400000000000000000000000000000000000040000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F020000000100000000010200000003000000FFFFFFFF0000000005000000000000000002000000000100000002".toCharArray()); byte[] geogWKB = Hex.decodeHex("E610000001040400000000000000000000400000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F000000000000F03F020000000100000000010200000003000000FFFFFFFF0000000005000000000000000002000000000100000002".toCharArray()); @@ -108,7 +111,7 @@ public void testMultiLineStringWkb() throws DecoderException { } @Test - public void testMultiPolygonWkb() throws DecoderException { + public void testMultiPolygonWkb() throws DecoderException, SQLException { String geoWKT = "MULTIPOLYGON(((1 1, 1 2, 2 1, 1 1), (0 0, 0 3, 3 3, 3 0, 0 0 7)), ((9 9, 9 10, 10 9, 9 9)))"; byte[] geomWKB = Hex.decodeHex("0000000001010D000000000000000000F03F000000000000F03F000000000000F03F00000000000000400000000000000040000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000000000000000084000000000000008400000000000000840000000000000084000000000000000000000000000000000000000000000000000000000000022400000000000002240000000000000224000000000000024400000000000002440000000000000224000000000000022400000000000002240000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF0000000000001C40000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF0300000002000000000004000000020900000003000000FFFFFFFF0000000006000000000000000003000000000200000003".toCharArray()); byte[] geogWKB = Hex.decodeHex("E610000002010D000000000000000000F03F000000000000F03F0000000000000040000000000000F03F000000000000F03F0000000000000040000000000000F03F000000000000F03F000000000000000000000000000000000000000000000840000000000000000000000000000008400000000000000840000000000000000000000000000008400000000000000000000000000000000000000000000022400000000000002240000000000000244000000000000022400000000000002240000000000000244000000000000022400000000000002240000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF0000000000001C40000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF0300000001000000000104000000010900000003000000FFFFFFFF0000000006000000000000000003000000000200000003".toCharArray()); @@ -119,7 +122,7 @@ public void testMultiPolygonWkb() throws DecoderException { } @Test - public void testGeometryCollectionWkb() throws DecoderException { + public void testGeometryCollectionWkb() throws DecoderException, SQLException { String geoWKT = "GEOMETRYCOLLECTION(POINT(3 3 1), LINESTRING(1 0, 0 1, -1 0), CIRCULARSTRING(1 3, 3 5, 4 7, 7 3, 1 3), POLYGON((0 0 2, 1 10 3, 1 0 4, 0 0 2), (0 0 2, 1 10 3, 1 0 4, 0 0 2), (0 0 2, 1 10 3, 1 0 4, 0 0 2)), MULTIPOINT((2 3), (7 8 9.5)), MULTILINESTRING((0 2, 1 1), (1 0, 1 1)), MULTIPOLYGON(((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1)), ((9 9, 9 10, 10 9, 9 9))), COMPOUNDCURVE(CIRCULARSTRING(1 0 3, 0 1 3, 9 6 3, 8 7 3, -1 0 3), CIRCULARSTRING(-1 0 3, 7 9 3, -10 2 3), (-10 2 3, 77 77 77, 88 88 88, 2 6 4), (2 6 4, 3 3 6, 7 7 1)), CURVEPOLYGON((0 0, 0 0, 0 0, 0 0), COMPOUNDCURVE((0 -23.43778, 0 23.43778), CIRCULARSTRING(0 23.43778, -45 -23.43778, 0 -23.43778)), COMPOUNDCURVE((0 -23.43778, 7 7, 0 23.43778), CIRCULARSTRING(0 23.43778, 8 8, 8 8, -45 23.43778, -90 23.43778), (-90 23.43778, -90 -23.43778), CIRCULARSTRING(-90 -23.43778, -45 -23.43778, 0 -23.43778))), POLYGON((0 0 2, 1 10 3, 1 0 4, 0 0 2)))"; byte[] geomWKB = Hex.decodeHex("0100000002014A00000000000000000008400000000000000840000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F0BF0000000000000000000000000000F03F00000000000008400000000000000840000000000000144000000000000010400000000000001C400000000000001C400000000000000840000000000000F03F000000000000084000000000000000000000000000000000000000000000F03F0000000000002440000000000000F03F00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000002440000000000000F03F00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000002440000000000000F03F000000000000000000000000000000000000000000000000000000000000004000000000000008400000000000001C40000000000000204000000000000000000000000000000040000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000000000000000000000000000000000000840000000000000084000000000000008400000000000000840000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F00000000000000400000000000000040000000000000F03F000000000000F03F000000000000F03F00000000000022400000000000002240000000000000224000000000000024400000000000002440000000000000224000000000000022400000000000002240000000000000F03F00000000000000000000000000000000000000000000F03F0000000000002240000000000000184000000000000020400000000000001C40000000000000F0BF00000000000000000000000000001C40000000000000224000000000000024C00000000000000040000000000040534000000000004053400000000000005640000000000000564000000000000000400000000000001840000000000000084000000000000008400000000000001C400000000000001C40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C7D79E59127037C00000000000000000C7D79E591270374000000000008046C0C7D79E59127037C00000000000000000C7D79E59127037C00000000000000000C7D79E59127037C00000000000001C400000000000001C400000000000000000C7D79E5912703740000000000000204000000000000020400000000000002040000000000000204000000000008046C0C7D79E591270374000000000008056C0C7D79E591270374000000000008056C0C7D79E59127037C000000000008046C0C7D79E59127037C00000000000000000C7D79E59127037C000000000000000000000000000000000000000000000F03F0000000000002440000000000000F03F000000000000000000000000000000000000000000000000000000000000F03F000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000004000000000000008400000000000001040000000000000004000000000000000400000000000000840000000000000104000000000000000400000000000000040000000000000084000000000000010400000000000000040000000000000F8FF0000000000002340000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF00000000000008400000000000000840000000000000084000000000000008400000000000000840000000000000084000000000000008400000000000405340000000000000564000000000000010400000000000001840000000000000F03F000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF0000000000000040000000000000084000000000000010400000000000000040120000000100000000010100000002040000000109000000010D00000001110000000115000000011600000001170000000119000000011B00000001200000000124000000032800000001340000000338000000033C000000014600000011000000FFFFFFFF0000000007000000000000000001000000000100000002000000000200000008000000000300000003000000000600000004050000000600000001050000000700000001000000000800000005080000000800000002080000000900000002000000000A000000060B0000000A000000030B0000000C00000003000000000D00000009000000000E0000000A0000000011000000031000000003010302000002000203020003010203".toCharArray()); byte[] geogWKB = Hex.decodeHex("E610000002214A000000000000000000084000000000000008400000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F0BF0000000000000840000000000000F03F000000000000144000000000000008400000000000001C40000000000000104000000000000008400000000000001C400000000000000840000000000000F03F000000000000000000000000000000000000000000002440000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000000000000000000000000000000000000000000000002440000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000000000000000000000000000000000000000000000002440000000000000F03F0000000000000000000000000000F03F000000000000000000000000000000000000000000000840000000000000004000000000000020400000000000001C4000000000000000400000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000000000000000000008400000000000000000000000000000084000000000000008400000000000000000000000000000084000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000F03F000000000000F03F0000000000000040000000000000F03F000000000000F03F000000000000224000000000000022400000000000002440000000000000224000000000000022400000000000002440000000000000224000000000000022400000000000000000000000000000F03F000000000000F03F0000000000000000000000000000184000000000000022400000000000001C4000000000000020400000000000000000000000000000F0BF00000000000022400000000000001C40000000000000004000000000000024C0000000000040534000000000004053400000000000005640000000000000564000000000000018400000000000000040000000000000084000000000000008400000000000001C400000000000001C4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C7D79E59127037C00000000000000000C7D79E59127037400000000000000000C7D79E59127037C000000000008046C0C7D79E59127037C00000000000000000C7D79E59127037C000000000000000000000000000001C400000000000001C40C7D79E591270374000000000000000000000000000002040000000000000204000000000000020400000000000002040C7D79E591270374000000000008046C0C7D79E591270374000000000008056C0C7D79E59127037C000000000008056C0C7D79E59127037C000000000008046C0C7D79E59127037C00000000000000000000000000000000000000000000000000000000000002440000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000004000000000000008400000000000001040000000000000004000000000000000400000000000000840000000000000104000000000000000400000000000000040000000000000084000000000000010400000000000000040000000000000F8FF0000000000002340000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF00000000000008400000000000000840000000000000084000000000000008400000000000000840000000000000084000000000000008400000000000405340000000000000564000000000000010400000000000001840000000000000F03F000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF0000000000000040000000000000084000000000000010400000000000000040120000000100000000010100000002040000000109000000010D00000001110000000115000000011600000001170000000119000000011B00000001200000000124000000032800000001340000000338000000033C000000014600000011000000FFFFFFFF0000000007000000000000000001000000000100000002000000000200000008000000000300000003000000000600000004050000000600000001050000000700000001000000000800000005080000000800000002080000000900000002000000000A000000060B0000000A000000030B0000000C00000003000000000D00000009000000000E0000000A0000000011000000031000000003010302000002000203020003010203".toCharArray()); @@ -130,7 +133,7 @@ public void testGeometryCollectionWkb() throws DecoderException { } @Test - public void testCircularStringWkb() throws DecoderException { + public void testCircularStringWkb() throws DecoderException, SQLException { String geoWKT = "CIRCULARSTRING(2 1 3 4, 1 2 3, 0 7 3, 1 0 3, 2 1 3)"; byte[] geomWKB = Hex.decodeHex("000000000207050000000000000000000040000000000000F03F000000000000F03F000000000000004000000000000000000000000000001C40000000000000F03F00000000000000000000000000000040000000000000F03F000000000000084000000000000008400000000000000840000000000000084000000000000008400000000000001040000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF01000000020000000001000000FFFFFFFF0000000008".toCharArray()); byte[] geogWKB = Hex.decodeHex("E6100000020705000000000000000000F03F00000000000000400000000000000040000000000000F03F0000000000001C4000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000084000000000000008400000000000000840000000000000084000000000000008400000000000001040000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF01000000020000000001000000FFFFFFFF0000000008".toCharArray()); @@ -141,7 +144,7 @@ public void testCircularStringWkb() throws DecoderException { } @Test - public void testCompoundCurveWkb() throws DecoderException { + public void testCompoundCurveWkb() throws DecoderException, SQLException { String geoWKT = "COMPOUNDCURVE(CIRCULARSTRING(1 0 3, 0 1 3, 9 6 3, 8 7 3, -1 0 3), CIRCULARSTRING(-1 0 3, 7 9 3, -10 2 3), (-10 2 3, 77 77 77, 88 88 88, 2 6 4), (2 6 4, 3 3 6, 7 7 1))"; byte[] geomWKB = Hex.decodeHex("0000000002050C000000000000000000F03F00000000000000000000000000000000000000000000F03F0000000000002240000000000000184000000000000020400000000000001C40000000000000F0BF00000000000000000000000000001C40000000000000224000000000000024C00000000000000040000000000040534000000000004053400000000000005640000000000000564000000000000000400000000000001840000000000000084000000000000008400000000000001C400000000000001C4000000000000008400000000000000840000000000000084000000000000008400000000000000840000000000000084000000000000008400000000000405340000000000000564000000000000010400000000000001840000000000000F03F01000000030000000001000000FFFFFFFF0000000009080000000301030200000200".toCharArray()); byte[] geogWKB = Hex.decodeHex("E610000002050C0000000000000000000000000000000000F03F000000000000F03F0000000000000000000000000000184000000000000022400000000000001C4000000000000020400000000000000000000000000000F0BF00000000000022400000000000001C40000000000000004000000000000024C0000000000040534000000000004053400000000000005640000000000000564000000000000018400000000000000040000000000000084000000000000008400000000000001C400000000000001C4000000000000008400000000000000840000000000000084000000000000008400000000000000840000000000000084000000000000008400000000000405340000000000000564000000000000010400000000000001840000000000000F03F01000000030000000001000000FFFFFFFF0000000009080000000301030200000200".toCharArray()); @@ -152,7 +155,7 @@ public void testCompoundCurveWkb() throws DecoderException { } @Test - public void testCurvePolygonWkb() throws DecoderException { + public void testCurvePolygonWkb() throws DecoderException, SQLException { String geoWKT = "CURVEPOLYGON((0 0, 0 0, 0 0, 0 0), CIRCULARSTRING(1 3, 3 5, 4 7, 7 3, 1 3), COMPOUNDCURVE((0 -23.43778, 0 23.43778), CIRCULARSTRING(0 23.43778, -45 -23.43778, 0 -23.43778)), COMPOUNDCURVE((0 -23.43778, 7 7, 0 23.43778), CIRCULARSTRING(0 23.43778, 8 8, 8 8, -45 23.43778, -90 23.43778), (-90 23.43778, -90 -23.43778), CIRCULARSTRING(-90 -23.43778, -45 -23.43778, 0 -23.43778)))"; byte[] geomWKB = Hex.decodeHex("0A00000002001700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000008400000000000000840000000000000144000000000000010400000000000001C400000000000001C400000000000000840000000000000F03F00000000000008400000000000000000C7D79E59127037C00000000000000000C7D79E591270374000000000008046C0C7D79E59127037C00000000000000000C7D79E59127037C00000000000000000C7D79E59127037C00000000000001C400000000000001C400000000000000000C7D79E5912703740000000000000204000000000000020400000000000002040000000000000204000000000008046C0C7D79E591270374000000000008056C0C7D79E591270374000000000008056C0C7D79E59127037C000000000008046C0C7D79E59127037C00000000000000000C7D79E59127037C004000000010000000002040000000309000000030D00000001000000FFFFFFFF000000000A080000000203020003010203".toCharArray()); byte[] geogWKB = Hex.decodeHex("E6100000020017000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000000000000F03F000000000000144000000000000008400000000000001C40000000000000104000000000000008400000000000001C400000000000000840000000000000F03FC7D79E59127037C00000000000000000C7D79E59127037400000000000000000C7D79E59127037C000000000008046C0C7D79E59127037C00000000000000000C7D79E59127037C000000000000000000000000000001C400000000000001C40C7D79E591270374000000000000000000000000000002040000000000000204000000000000020400000000000002040C7D79E591270374000000000008046C0C7D79E591270374000000000008056C0C7D79E59127037C000000000008056C0C7D79E59127037C000000000008046C0C7D79E59127037C0000000000000000004000000010000000002040000000309000000030D00000001000000FFFFFFFF000000000A080000000203020003010203".toCharArray()); @@ -163,7 +166,7 @@ public void testCurvePolygonWkb() throws DecoderException { } @Test - public void testFullGlobeWkb() throws DecoderException { + public void testFullGlobeWkb() throws DecoderException, SQLException { String geoWKT = "FULLGLOBE"; byte[] geogWKB = Hex.decodeHex("E61000000224000000000000000001000000FFFFFFFFFFFFFFFF0B".toCharArray()); Geography geogWKT = Geography.deserialize(geogWKB); @@ -296,7 +299,7 @@ public void testFullGlobeWkt() throws SQLException { try { Geometry.STGeomFromText(geoWKT, 0); } - catch (IllegalArgumentException e) { + catch (SQLServerException e) { assertEquals(e.getMessage(), "Fullglobe is not supported for Geometry."); } @@ -329,8 +332,8 @@ public void testIllegalCases() throws SQLException { try { testWkt(geoWKT); } - catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), "Reached unexpected end of WKT. Please make sure WKT is valid."); + catch (SQLServerException e) { + assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")); } //Not enough closing and opening bracket case @@ -339,8 +342,10 @@ public void testIllegalCases() throws SQLException { try { testWkt(geoWKT); } - catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"14"); + catch (SQLServerException e) { + MessageFormat form = new MessageFormat(TestResource.getResource("R_illegalCharWktPosition")); + Object[] msgArgs1 = {"14"}; + assertEquals(e.getMessage(), form.format(msgArgs1)); } //Too many closing bracket @@ -349,8 +354,10 @@ public void testIllegalCases() throws SQLException { try { testWkt(geoWKT); } - catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"91"); + catch (SQLServerException e) { + MessageFormat form = new MessageFormat(TestResource.getResource("R_illegalCharWktPosition")); + Object[] msgArgs1 = {"91"}; + assertEquals(e.getMessage(), form.format(msgArgs1)); } //Too many opening bracket @@ -359,8 +366,10 @@ public void testIllegalCases() throws SQLException { try { testWkt(geoWKT); } - catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"15"); + catch (SQLServerException e) { + MessageFormat form = new MessageFormat(TestResource.getResource("R_illegalCharWktPosition")); + Object[] msgArgs1 = {"15"}; + assertEquals(e.getMessage(), form.format(msgArgs1)); } //Too many coordinates @@ -369,8 +378,10 @@ public void testIllegalCases() throws SQLException { try { testWkt(geoWKT); } - catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"23"); + catch (SQLServerException e) { + MessageFormat form = new MessageFormat(TestResource.getResource("R_illegalCharWktPosition")); + Object[] msgArgs1 = {"23"}; + assertEquals(e.getMessage(), form.format(msgArgs1)); } //Too little coordinates @@ -379,8 +390,10 @@ public void testIllegalCases() throws SQLException { try { testWkt(geoWKT); } - catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"17"); + catch (SQLServerException e) { + MessageFormat form = new MessageFormat(TestResource.getResource("R_illegalCharWktPosition")); + Object[] msgArgs1 = {"17"}; + assertEquals(e.getMessage(), form.format(msgArgs1)); } //Incorrect data type @@ -389,8 +402,10 @@ public void testIllegalCases() throws SQLException { try { testWkt(geoWKT); } - catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"14"); + catch (SQLServerException e) { + MessageFormat form = new MessageFormat(TestResource.getResource("R_illegalCharWktPosition")); + Object[] msgArgs1 = {"14"}; + assertEquals(e.getMessage(), form.format(msgArgs1)); } // too many commas @@ -399,8 +414,10 @@ public void testIllegalCases() throws SQLException { try { testWkt(geoWKT); } - catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"35"); + catch (SQLServerException e) { + MessageFormat form = new MessageFormat(TestResource.getResource("R_illegalCharWktPosition")); + Object[] msgArgs1 = {"35"}; + assertEquals(e.getMessage(), form.format(msgArgs1)); } // too little commas @@ -409,8 +426,10 @@ public void testIllegalCases() throws SQLException { try { testWkt(geoWKT); } - catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"35"); + catch (SQLServerException e) { + MessageFormat form = new MessageFormat(TestResource.getResource("R_illegalCharWktPosition")); + Object[] msgArgs1 = {"35"}; + assertEquals(e.getMessage(), form.format(msgArgs1)); } }