Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyc committed Jan 18, 2024
1 parent 3edcd83 commit d162dcc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 77 deletions.
8 changes: 3 additions & 5 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ private void writeInternal(byte[] b, int off, int len) throws IOException {
private final class ProxyInputStream extends InputStream {
private InputStream filteredStream;

private final transient Lock proxyInputStreamLock = new ReentrantLock();
private final Lock proxyInputStreamLock = new ReentrantLock();

/**
* Bytes that have been read by a poll(s).
Expand Down Expand Up @@ -3854,10 +3854,8 @@ void writeTime(java.sql.Timestamp value, int scale) throws SQLServerException {

void writeTime(java.sql.Timestamp value, int scale, Calendar cal) throws SQLServerException {
GregorianCalendar calendar = initializeCalender(TimeZone.getDefault());
long utcMillis; // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT)
int subSecondNanos;
utcMillis = value.getTime();
subSecondNanos = value.getNanos();
long utcMillis = value.getTime(); // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT)
int subSecondNanos = value.getNanos();

// Load the calendar with the desired value
calendar.setTimeInMillis(utcMillis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2480,13 +2480,10 @@ else if (4 >= bulkScale)
tdsWriter.writeByte((byte) 0x07);
else
tdsWriter.writeByte((byte) 0x08);
Timestamp ts = java.sql.Timestamp.valueOf(colValue.toString());
Timestamp ts = (Timestamp) colValue;
tdsWriter.writeTime(ts, bulkScale, cal);
// Send only the date part
tdsWriter.writeDate(ts.getTime(), cal);
//tdsWriter.writeRPCDateTime2(name,
// timestampNormalizedCalendar(calendar, javaType, conn.baseYear()),
// subSecondNanos, TDS.MAX_FRACTIONAL_SECONDS_SCALE, isOutParam);
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class BatchExecutionTest extends AbstractTest {
private static String timestampTable1 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("timestamptable1"));
private static String timestampTable2 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("timestampTableBatchInsert2"));
.escapeIdentifier(RandomUtil.getIdentifier("timestamptable2"));

/**
* This tests the updateCount when the error query does cause a SQL state HY008.
Expand Down Expand Up @@ -142,28 +142,27 @@ public void testValidTimezoneForTimestampBatchInsertWithBulkCopy() throws Except
}

// Compare Timestamp values inserted, should be the same
try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable1)) {
Timestamp ts0;
Timestamp ts1;
Time t0;
Time t1;
Date d0;
Date d1;

rs.next();
ts0 = rs.getTimestamp(1);
t0 = rs.getTime(1);
d0 = rs.getDate(1);
rs.next();
ts1 = rs.getTimestamp(1);
t1 = rs.getTime(1);
d1 = rs.getDate(1);

assertEquals(ts0, ts1);
assertEquals(t0, t1);
assertEquals(d0, d1);
}
try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable1)) {
Timestamp ts0;
Timestamp ts1;
Time t0;
Time t1;
Date d0;
Date d1;

rs.next();
ts0 = rs.getTimestamp(1);
t0 = rs.getTime(1);
d0 = rs.getDate(1);
rs.next();
ts1 = rs.getTimestamp(1);
t1 = rs.getTime(1);
d1 = rs.getDate(1);

assertEquals(ts0, ts1);
assertEquals(t0, t1);
assertEquals(d0, d1);
}
}

Expand Down Expand Up @@ -204,29 +203,28 @@ public void testValidTimezonesDstTimestampBatchInsertWithBulkCopy() throws Excep
}

// Compare Timestamp values inserted, should be the same
try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable1)) {
Timestamp ts0;
Timestamp ts1;
Time t0;
Time t1;
Date d0;
Date d1;

rs.next();
ts0 = rs.getTimestamp(1);
t0 = rs.getTime(1);
d0 = rs.getDate(1);
rs.next();
ts1 = rs.getTimestamp(1);
t1 = rs.getTime(1);
d1 = rs.getDate(1);

String failureMsg = "Failed for time zone: " + tzId;
assertEquals(ts0, ts1, failureMsg);
assertEquals(t0, t1, failureMsg);
assertEquals(d0, d1, failureMsg);
}
try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable1)) {
Timestamp ts0;
Timestamp ts1;
Time t0;
Time t1;
Date d0;
Date d1;

rs.next();
ts0 = rs.getTimestamp(1);
t0 = rs.getTime(1);
d0 = rs.getDate(1);
rs.next();
ts1 = rs.getTimestamp(1);
t1 = rs.getTime(1);
d1 = rs.getDate(1);

String failureMsg = "Failed for time zone: " + tzId;
assertEquals(ts0, ts1, failureMsg);
assertEquals(t0, t1, failureMsg);
assertEquals(d0, d1, failureMsg);
}
}
}
Expand Down Expand Up @@ -264,28 +262,27 @@ public void testBatchInsertTimestampNoTimezoneDoubleConversion() throws Exceptio
}

// Compare Timestamp values inserted, should be the same
try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable2)) {
Timestamp ts0;
Timestamp ts1;
Time t0;
Time t1;
Date d0;
Date d1;

rs.next();
ts0 = rs.getTimestamp(1);
t0 = rs.getTime(1);
d0 = rs.getDate(1);
rs.next();
ts1 = rs.getTimestamp(1);
t1 = rs.getTime(1);
d1 = rs.getDate(1);

assertEquals(ts0, ts1);
assertEquals(t0, t1);
assertEquals(d0, d1);
}
try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable2)) {
Timestamp ts0;
Timestamp ts1;
Time t0;
Time t1;
Date d0;
Date d1;

rs.next();
ts0 = rs.getTimestamp(1);
t0 = rs.getTime(1);
d0 = rs.getDate(1);
rs.next();
ts1 = rs.getTimestamp(1);
t1 = rs.getTime(1);
d1 = rs.getDate(1);

assertEquals(ts0, ts1);
assertEquals(t0, t1);
assertEquals(d0, d1);
}
}

Expand Down

0 comments on commit d162dcc

Please sign in to comment.