-
Notifications
You must be signed in to change notification settings - Fork 425
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
API and JavaDoc changes for Spatial Datatypes #752
Changes from 8 commits
73edf05
a09c247
3f694ff
243f294
537959f
862d71d
d86b237
eac074f
79c7e59
81a065f
7ec6fcc
272a729
54c5297
a3eb552
0de6184
b4fca56
3135521
2dfb95b
6f4af3d
8aba9e6
589c1c0
a61a58b
1d7800d
1f3e437
35d99a8
e156263
5ca2a83
2f886a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,16 @@ | |
|
||
package com.microsoft.sqlserver.jdbc; | ||
|
||
import java.nio.BufferUnderflowException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
import java.text.MessageFormat; | ||
|
||
|
||
/** | ||
* Geography datatype represents data in a round-earth coordinate system. | ||
*/ | ||
|
||
public class Geography extends SQLServerSpatialDatatype { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs class description |
||
|
||
/** | ||
|
@@ -49,7 +55,13 @@ private Geography(byte[] wkb) throws SQLServerException { | |
buffer = ByteBuffer.wrap(wkb); | ||
buffer.order(ByteOrder.LITTLE_ENDIAN); | ||
|
||
parseWkb(); | ||
try { | ||
parseWkb(); | ||
} catch (BufferUnderflowException e) { | ||
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ParsingError")); | ||
Object[] msgArgs = {JDBCType.VARBINARY}; | ||
throw new SQLServerException(this, form.format(msgArgs), null, 0, false); | ||
} | ||
|
||
WKTsb = new StringBuffer(); | ||
WKTsbNoZM = new StringBuffer(); | ||
|
@@ -62,8 +74,8 @@ private Geography(byte[] wkb) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Returns a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation | ||
* augmented with any Z (elevation) and M (measure) values carried by the instance. | ||
* Constructor for a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) | ||
* representation augmented with any Z (elevation) and M (measure) values carried by the instance. | ||
* | ||
* @param wkt | ||
* Well-Known Text (WKT) provided by the user. | ||
|
@@ -78,7 +90,8 @@ public static Geography STGeomFromText(String wkt, int srid) throws SQLServerExc | |
} | ||
|
||
/** | ||
* Returns a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation. | ||
* Constructor for a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) | ||
* representation. | ||
* | ||
* @param wkb | ||
* Well-Known Binary (WKB) provided by the user. | ||
|
@@ -91,7 +104,7 @@ public static Geography STGeomFromWKB(byte[] wkb) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Returns a constructed Geography from an internal SQL Server format for spatial data. | ||
* Constructor for a Geography instance from an internal SQL Server format for spatial data. | ||
* | ||
* @param wkb | ||
* Well-Known Binary (WKB) provided by the user. | ||
|
@@ -104,8 +117,8 @@ public static Geography deserialize(byte[] wkb) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Returns a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation. SRID | ||
* is defaulted to 4326. | ||
* Constructor for a Geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) | ||
* representation. SRID is defaulted to 4326. | ||
* | ||
* @param wkt | ||
* Well-Known Text (WKT) provided by the user. | ||
|
@@ -118,7 +131,7 @@ public static Geography parse(String wkt) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Constructs a Geography instance that represents a Point instance from its X and Y values and an SRID. | ||
* Constructor for a Geography instance that represents a Point instance from its X and Y values and an SRID. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SRID = Spatial Reference System Identifier |
||
* | ||
* @param x | ||
* x coordinate | ||
|
@@ -203,8 +216,8 @@ public boolean hasZ() { | |
* @return double value that represents the X coordinate. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix Javadocs too. Also for getY() function |
||
*/ | ||
public Double getX() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename getX() and getY() to getLatitude() and getLongitude() for Geography. |
||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && points.length == 2) { | ||
return points[0]; | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && xpoints.length == 1) { | ||
return xpoints[0]; | ||
} | ||
return null; | ||
} | ||
|
@@ -215,8 +228,8 @@ public Double getX() { | |
* @return double value that represents the Y coordinate. | ||
*/ | ||
public Double getY() { | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && points.length == 2) { | ||
return points[1]; | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && ypoints.length == 1) { | ||
return ypoints[0]; | ||
} | ||
return null; | ||
} | ||
|
@@ -317,8 +330,8 @@ protected void serializeToWkb(boolean noZM) { | |
} | ||
|
||
for (int i = 0; i < numberOfPoints; i++) { | ||
buf.putDouble(points[2 * i + 1]); | ||
buf.putDouble(points[2 * i]); | ||
buf.putDouble(ypoints[i]); | ||
buf.putDouble(xpoints[i]); | ||
} | ||
|
||
if (!noZM) { | ||
|
@@ -368,7 +381,7 @@ protected void serializeToWkb(boolean noZM) { | |
return; | ||
} | ||
|
||
protected void parseWkb() { | ||
protected void parseWkb() throws SQLServerException { | ||
srid = buffer.getInt(); | ||
version = buffer.get(); | ||
serializationProperties = buffer.get(); | ||
|
@@ -403,10 +416,11 @@ protected void parseWkb() { | |
} | ||
|
||
private void readPoints() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a few methods are duplicated in both Geometry/Geography classes and they should be moved to SQLServerSpatialDatatype.
|
||
points = new double[2 * numberOfPoints]; | ||
xpoints = new double[numberOfPoints]; | ||
ypoints = new double[numberOfPoints]; | ||
for (int i = 0; i < numberOfPoints; i++) { | ||
points[2 * i + 1] = buffer.getDouble(); | ||
points[2 * i] = buffer.getDouble(); | ||
ypoints[i] = buffer.getDouble(); | ||
xpoints[i] = buffer.getDouble(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,16 @@ | |
|
||
package com.microsoft.sqlserver.jdbc; | ||
|
||
import java.nio.BufferUnderflowException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
import java.text.MessageFormat; | ||
|
||
|
||
/** | ||
* Geometry datatype represents data in a Euclidean (flat) coordinate system. | ||
*/ | ||
|
||
public class Geometry extends SQLServerSpatialDatatype { | ||
|
||
/** | ||
|
@@ -49,7 +55,13 @@ private Geometry(byte[] wkb) throws SQLServerException { | |
buffer = ByteBuffer.wrap(wkb); | ||
buffer.order(ByteOrder.LITTLE_ENDIAN); | ||
|
||
parseWkb(); | ||
try { | ||
parseWkb(); | ||
} catch (BufferUnderflowException e) { | ||
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ParsingError")); | ||
Object[] msgArgs = {JDBCType.VARBINARY}; | ||
throw new SQLServerException(this, form.format(msgArgs), null, 0, false); | ||
} | ||
|
||
WKTsb = new StringBuffer(); | ||
WKTsbNoZM = new StringBuffer(); | ||
|
@@ -62,7 +74,7 @@ private Geometry(byte[] wkb) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Returns a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation | ||
* Constructor for a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation | ||
* augmented with any Z (elevation) and M (measure) values carried by the instance. | ||
* | ||
* @param wkt | ||
|
@@ -78,7 +90,8 @@ public static Geometry STGeomFromText(String wkt, int srid) throws SQLServerExce | |
} | ||
|
||
/** | ||
* Returns a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) representation. | ||
* Constructor for a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Binary (WKB) | ||
* representation. | ||
* | ||
* @param wkb | ||
* Well-Known Binary (WKB) provided by the user. | ||
|
@@ -91,7 +104,7 @@ public static Geometry STGeomFromWKB(byte[] wkb) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Returns a constructed Geometry from an internal SQL Server format for spatial data. | ||
* Constructor for a Geometry instance from an internal SQL Server format for spatial data. | ||
* | ||
* @param wkb | ||
* Well-Known Binary (WKB) provided by the user. | ||
|
@@ -104,8 +117,8 @@ public static Geometry deserialize(byte[] wkb) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Returns a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation. SRID | ||
* is defaulted to 0. | ||
* Constructor for a Geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) | ||
* representation. SRID is defaulted to 0. | ||
* | ||
* @param wkt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method has param name as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
* Well-Known Text (WKT) provided by the user. | ||
|
@@ -118,7 +131,7 @@ public static Geometry parse(String wkt) throws SQLServerException { | |
} | ||
|
||
/** | ||
* Constructs a Geometry instance that represents a Point instance from its X and Y values and an SRID. | ||
* Constructor for a Geometry instance that represents a Point instance from its X and Y values and an SRID. | ||
* | ||
* @param x | ||
* x coordinate | ||
|
@@ -203,8 +216,8 @@ public boolean hasZ() { | |
* @return double value that represents the X coordinate. | ||
*/ | ||
public Double getX() { | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && points.length == 2) { | ||
return points[0]; | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && xpoints.length == 1) { | ||
return xpoints[0]; | ||
} | ||
return null; | ||
} | ||
|
@@ -215,8 +228,8 @@ public Double getX() { | |
* @return double value that represents the Y coordinate. | ||
*/ | ||
public Double getY() { | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && points.length == 2) { | ||
return points[1]; | ||
if (null != internalType && internalType == InternalSpatialDatatype.POINT && ypoints.length == 1) { | ||
return ypoints[0]; | ||
} | ||
return null; | ||
} | ||
|
@@ -317,8 +330,8 @@ protected void serializeToWkb(boolean noZM) { | |
} | ||
|
||
for (int i = 0; i < numberOfPoints; i++) { | ||
buf.putDouble(points[2 * i]); | ||
buf.putDouble(points[2 * i + 1]); | ||
buf.putDouble(xpoints[i]); | ||
buf.putDouble(ypoints[i]); | ||
} | ||
|
||
if (!noZM) { | ||
|
@@ -369,7 +382,7 @@ protected void serializeToWkb(boolean noZM) { | |
return; | ||
} | ||
|
||
protected void parseWkb() { | ||
protected void parseWkb() throws SQLServerException { | ||
srid = buffer.getInt(); | ||
version = buffer.get(); | ||
serializationProperties = buffer.get(); | ||
|
@@ -404,10 +417,11 @@ protected void parseWkb() { | |
} | ||
|
||
private void readPoints() { | ||
points = new double[2 * numberOfPoints]; | ||
xpoints = new double[numberOfPoints]; | ||
ypoints = new double[numberOfPoints]; | ||
for (int i = 0; i < numberOfPoints; i++) { | ||
points[2 * i] = buffer.getDouble(); | ||
points[2 * i + 1] = buffer.getDouble(); | ||
xpoints[i] = buffer.getDouble(); | ||
ypoints[i] = buffer.getDouble(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2010,7 +2010,8 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL | |
} catch (SQLException e) { | ||
// throw a BatchUpdateException with the given error message, and return null for the updateCounts. | ||
throw new BatchUpdateException(e.getMessage(), null, 0, null); | ||
} catch (IllegalArgumentException e) { | ||
} | ||
catch (IllegalArgumentException | StringIndexOutOfBoundsException e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this change is not related to Spatial types? You probably need to update the comment below too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this change out of this PR as we already have another active PR to track useBulkCopyWithBatchInsert API changes. It will be easier to track changes there. |
||
// If we fail with IllegalArgumentException, fall back to the original batch insert logic. | ||
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE)) { | ||
getStatementLogger().fine("Parsing user's Batch Insert SQL Query failed: " + e.toString()); | ||
|
@@ -2154,7 +2155,8 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio | |
} catch (SQLException e) { | ||
// throw a BatchUpdateException with the given error message, and return null for the updateCounts. | ||
throw new BatchUpdateException(e.getMessage(), null, 0, null); | ||
} catch (IllegalArgumentException e) { | ||
} | ||
catch (IllegalArgumentException | StringIndexOutOfBoundsException e) { | ||
// If we fail with IllegalArgumentException, fall back to the original batch insert logic. | ||
if (getStatementLogger().isLoggable(java.util.logging.Level.FINE)) { | ||
getStatementLogger().fine("Parsing user's Batch Insert SQL Query failed: " + e.toString()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to import this?