Skip to content

Commit 05713f3

Browse files
Addressed comments
1 parent 668be97 commit 05713f3

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClientImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ class DatabaseClientImpl implements DatabaseClient {
4646
@VisibleForTesting final boolean useMultiplexedSessionPartitionedOps;
4747
@VisibleForTesting final boolean useMultiplexedSessionForRW;
4848

49-
private StatementFactory statementFactory = null;
50-
5149
final boolean useMultiplexedSessionBlindWrite;
5250

5351
@VisibleForTesting

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerTypeConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static <T> Value createUntypedIterableValue(
9898
}
9999

100100
static ZonedDateTime atUTC(LocalDateTime localDateTime) {
101-
return localDateTime.atZone(UTC_ZONE);
101+
return atUTC(localDateTime.atZone(ZoneId.systemDefault()));
102102
}
103103

104104
static ZonedDateTime atUTC(OffsetDateTime localDateTime) {

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Statement.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,34 @@ StringBuilder toString(StringBuilder b) {
249249
return b;
250250
}
251251

252+
/**
253+
* Factory for creating {@link Statement}.
254+
*
255+
* <p>This factory class supports creating {@link Statement} with positional(or unnamed)
256+
* parameters.
257+
*
258+
* <p>
259+
*
260+
* <h2>Usage Example</h2>
261+
*
262+
* Simple SQL query
263+
*
264+
* <pre>{@code
265+
* Statement statement = databaseClient.getStatementFactory()
266+
* .withUnnamedParameters("SELECT * FROM TABLE WHERE ID = ?", 10L)
267+
* }</pre>
268+
*
269+
* How to use SQL queries with IN command
270+
*
271+
* <pre>{@code
272+
* long[] ids = {10L, 12L, 1483L};
273+
* Statement statement = databaseClient.getStatementFactory()
274+
* .withUnnamedParameters("SELECT * FROM TABLE WHERE ID = UNNEST(?)", ids)
275+
* }</pre>
276+
*
277+
* @see DatabaseClient#getStatementFactory()
278+
* @see StatementFactory#withUnnamedParameters(String, Object...)
279+
*/
252280
public static final class StatementFactory {
253281
private final Dialect dialect;
254282

@@ -262,7 +290,7 @@ public Statement of(String sql) {
262290

263291
/**
264292
* This function accepts the SQL statement with unnamed parameters(?) and accepts the list of
265-
* objects to replace unnamed parameters. Primitive types are supported
293+
* objects to replace unnamed parameters. Primitive types are supported.
266294
*
267295
* <p>For Date column, following types are supported
268296
*

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import java.time.LocalDate;
5151
import java.time.LocalDateTime;
5252
import java.time.OffsetDateTime;
53-
import java.time.ZoneId;
5453
import java.time.ZonedDateTime;
5554
import java.util.ArrayList;
5655
import java.util.Arrays;
@@ -871,13 +870,10 @@ static Value toValue(Object value) {
871870
return Value.date(convertLocalDateToSpannerDate((LocalDate) value));
872871
}
873872
if (value instanceof LocalDateTime) {
874-
return createUntypedStringValue(
875-
convertToISO8601(
876-
SpannerTypeConverter.atUTC(((LocalDateTime) value).atZone(ZoneId.systemDefault()))));
873+
return createUntypedStringValue(convertToISO8601(atUTC((LocalDateTime) value)));
877874
}
878875
if (value instanceof OffsetDateTime) {
879-
return createUntypedStringValue(
880-
convertToISO8601(SpannerTypeConverter.atUTC((OffsetDateTime) value)));
876+
return createUntypedStringValue(convertToISO8601(atUTC((OffsetDateTime) value)));
881877
}
882878
if (value instanceof ZonedDateTime) {
883879
return createUntypedStringValue(convertToISO8601(atUTC((ZonedDateTime) value)));
@@ -945,16 +941,11 @@ static Value toValue(Object value) {
945941
}
946942
if (object instanceof LocalDateTime) {
947943
return createUntypedIterableValue(
948-
(LocalDateTime) object,
949-
iterator,
950-
val ->
951-
convertToISO8601(SpannerTypeConverter.atUTC(val.atZone(ZoneId.systemDefault()))));
944+
(LocalDateTime) object, iterator, val -> convertToISO8601(atUTC(val)));
952945
}
953946
if (object instanceof OffsetDateTime) {
954947
return createUntypedIterableValue(
955-
(OffsetDateTime) object,
956-
iterator,
957-
val -> convertToISO8601(SpannerTypeConverter.atUTC(val)));
948+
(OffsetDateTime) object, iterator, val -> convertToISO8601(atUTC(val)));
958949
}
959950
if (object instanceof ZonedDateTime) {
960951
return createUntypedIterableValue(

0 commit comments

Comments
 (0)