Skip to content

Commit 0a7594c

Browse files
Addressed comments
1 parent 05713f3 commit 0a7594c

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,20 @@ ServerStream<BatchWriteResponse> batchWriteAtLeastOnce(
609609
long executePartitionedUpdate(Statement stmt, UpdateOption... options);
610610

611611
/**
612-
* Returns StatementFactory for the given dialect.
612+
* Returns a {@link StatementFactory} for the given dialect.
613613
*
614-
* <p>A {@link StatementFactory}, can be used to create statements with unnamed parameters.
614+
* <p>A {@link StatementFactory} can be used to create statements with unnamed parameters. This is
615+
* primarily intended for framework developers who want to integrate the Spanner client with
616+
* frameworks that use unnamed parameters. Developers who just want to use the Spanner client in
617+
* their application, should use named parameters.
615618
*
616619
* <p>Examples using {@link StatementFactory}
617620
*
618-
* <p>databaseClient.getStatementFactory().of("SELECT NAME FROM TABLE WHERE ID = ?", 10)
621+
* <pre>{@code
622+
* Statement statement = databaseClient
623+
* .getStatementFactory()
624+
* .withUnnamedParameters("SELECT NAME FROM TABLE WHERE ID = ?", 10);
625+
* }</pre>
619626
*/
620627
default StatementFactory getStatementFactory() {
621628
throw new UnsupportedOperationException("method should be overwritten");

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,11 @@ StringBuilder toString(StringBuilder b) {
250250
}
251251

252252
/**
253-
* Factory for creating {@link Statement}.
253+
* Factory for creating {@link Statement}s with unnamed parameters.
254254
*
255-
* <p>This factory class supports creating {@link Statement} with positional(or unnamed)
256-
* parameters.
255+
* <p>This class is primarily intended for framework developers who want to integrate the Spanner
256+
* client with a framework that uses unnamed parameters. Developers who want to use the Spanner
257+
* client in their application, should use named parameters.
257258
*
258259
* <p>
259260
*
@@ -266,7 +267,18 @@ StringBuilder toString(StringBuilder b) {
266267
* .withUnnamedParameters("SELECT * FROM TABLE WHERE ID = ?", 10L)
267268
* }</pre>
268269
*
269-
* How to use SQL queries with IN command
270+
* SQL query with multiple parameters
271+
*
272+
* <pre>{@code
273+
* long id = 10L;
274+
* String name = "google";
275+
* List<String> phoneNumbers = Arrays.asList("1234567890", "0987654321");
276+
* Statement statement = databaseClient.getStatementFactory()
277+
* * .withUnnamedParameters("INSERT INTO TABLE (ID, name, phonenumbers)
278+
* // VALUES(?, ?, ?)", id, name, phoneNumbers)
279+
* }</pre>
280+
*
281+
* How to use arrays with the IN operator
270282
*
271283
* <pre>{@code
272284
* long[] ids = {10L, 12L, 1483L};
@@ -289,25 +301,27 @@ public Statement of(String sql) {
289301
}
290302

291303
/**
292-
* This function accepts the SQL statement with unnamed parameters(?) and accepts the list of
293-
* objects to replace unnamed parameters. Primitive types are supported.
304+
* This function accepts a SQL statement with unnamed parameters (?) and accepts a list of
305+
* objects that should be used as the values for those parameters. Primitive types are
306+
* supported.
294307
*
295-
* <p>For Date column, following types are supported
308+
* <p>For parameters of type DATE, the following types are supported
296309
*
297310
* <ul>
298-
* <li>java.util.Date
299-
* <li>LocalDate
300-
* <li>com.google.cloud.Date
311+
* <li>{@link java.time.LocalDate}
312+
* <li>{@link com.google.cloud.Date}
301313
* </ul>
302314
*
303-
* <p>For Timestamp column, following types are supported. All the dates should be in UTC
304-
* format. Incase if the timezone is not in UTC, spanner client will convert that to UTC
305-
* automatically
315+
* <p>For parameters of type TIMESTAMP, the following types are supported. Note that Spanner
316+
* stores all timestamps in UTC. Instances of ZonedDateTime and OffsetDateTime that use other
317+
* timezones than UTC, will be converted to the corresponding UTC values before being sent to
318+
* Spanner. Instances of LocalDateTime will be converted to a ZonedDateTime using the system
319+
* default timezone, and then converted to UTC before being sent to Spanner.
306320
*
307321
* <ul>
308-
* <li>LocalDateTime
309-
* <li>OffsetDateTime
310-
* <li>ZonedDateTime
322+
* <li>{@link java.time.LocalDateTime}
323+
* <li>{@link java.time.OffsetDateTime}
324+
* <li>{@link java.time.ZonedDateTime}
311325
* </ul>
312326
*
313327
* <p>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ public static Value structArray(Type elementType, @Nullable Iterable<Struct> v)
839839
private Value() {}
840840

841841
static Value toValue(Object value) {
842+
if (value == null) {
843+
return Value.untyped(NULL_PROTO);
844+
}
842845
if (value instanceof Value) {
843846
return (Value) value;
844847
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2510,8 +2510,12 @@ public void verifyBrokenSerialization() {
25102510

25112511
@Test
25122512
public void testToValue() {
2513+
Value value = Value.toValue(null);
2514+
assertNull(value.getType());
2515+
assertEquals("NULL", value.getAsString());
2516+
25132517
int i = 10;
2514-
Value value = Value.toValue(i);
2518+
value = Value.toValue(i);
25152519
assertNull(value.getType());
25162520
assertEquals("10", value.getAsString());
25172521

0 commit comments

Comments
 (0)