5757import java .sql .Time ;
5858import java .sql .Timestamp ;
5959import java .sql .Types ;
60+ import java .time .Instant ;
61+ import java .time .LocalDate ;
62+ import java .time .LocalDateTime ;
63+ import java .time .LocalTime ;
64+ import java .time .OffsetDateTime ;
65+ import java .time .ZonedDateTime ;
6066import java .util .ArrayList ;
6167import java .util .Arrays ;
6268import java .util .Calendar ;
@@ -70,7 +76,7 @@ class BigQueryPreparedStatement extends BigQueryStatement implements PreparedSta
7076 protected int parameterCount = 0 ;
7177 protected String currentQuery ;
7278 private Queue <ArrayList <BigQueryJdbcParameter >> batchParameters = new LinkedList <>();
73- private Schema insertSchema = null ;
79+ Schema insertSchema = null ;
7480 private TableName insertTableName = null ;
7581
7682 BigQueryPreparedStatement (BigQueryConnection connection , String query ) {
@@ -207,20 +213,20 @@ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
207213 }
208214
209215 @ Override
210- public void setAsciiStream (int parameterIndex , InputStream x , int length ) {
211- // TODO :NOT IMPLEMENTED
216+ public void setAsciiStream (int parameterIndex , InputStream x , int length ) throws SQLException {
217+ throw new BigQueryJdbcSqlFeatureNotSupportedException ( "setAsciiStream is not supported." );
212218 }
213219
214220 @ Override
215221 @ Deprecated
216222 @ SuppressWarnings ("deprecation" )
217- public void setUnicodeStream (int parameterIndex , InputStream x , int length ) {
218- // TODO :NOT IMPLEMENTED
223+ public void setUnicodeStream (int parameterIndex , InputStream x , int length ) throws SQLException {
224+ throw new BigQueryJdbcSqlFeatureNotSupportedException ( "setUnicodeStream is not supported." );
219225 }
220226
221227 @ Override
222- public void setBinaryStream (int parameterIndex , InputStream x , int length ) {
223- // TODO :NOT IMPLEMENTED
228+ public void setBinaryStream (int parameterIndex , InputStream x , int length ) throws SQLException {
229+ throw new BigQueryJdbcSqlFeatureNotSupportedException ( "setBinaryStream is not supported." );
224230 }
225231
226232 @ Override
@@ -230,6 +236,9 @@ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQ
230236 setNull (parameterIndex , targetSqlType );
231237 return ;
232238 }
239+ if (setTemporalObject (parameterIndex , x )) {
240+ return ;
241+ }
233242 Class <?> javaType = BigQueryJdbcTypeMappings .getJavaType (targetSqlType );
234243 this .parameterHandler .setParameter (parameterIndex , x , javaType );
235244 }
@@ -241,9 +250,40 @@ public void setObject(int parameterIndex, Object x) throws SQLException {
241250 setNull (parameterIndex , Types .NULL );
242251 return ;
243252 }
253+ if (setTemporalObject (parameterIndex , x )) {
254+ return ;
255+ }
244256 this .parameterHandler .setParameter (parameterIndex , x , x .getClass ());
245257 }
246258
259+ private boolean setTemporalObject (int parameterIndex , Object x ) throws SQLException {
260+ if (x instanceof LocalDate ) {
261+ setDate (parameterIndex , Date .valueOf ((LocalDate ) x ));
262+ return true ;
263+ }
264+ if (x instanceof LocalTime ) {
265+ setTime (parameterIndex , Time .valueOf ((LocalTime ) x ));
266+ return true ;
267+ }
268+ if (x instanceof LocalDateTime ) {
269+ setTimestamp (parameterIndex , Timestamp .valueOf ((LocalDateTime ) x ));
270+ return true ;
271+ }
272+ if (x instanceof OffsetDateTime ) {
273+ setTimestamp (parameterIndex , Timestamp .from (((OffsetDateTime ) x ).toInstant ()));
274+ return true ;
275+ }
276+ if (x instanceof Instant ) {
277+ setTimestamp (parameterIndex , Timestamp .from ((Instant ) x ));
278+ return true ;
279+ }
280+ if (x instanceof ZonedDateTime ) {
281+ setTimestamp (parameterIndex , Timestamp .from (((ZonedDateTime ) x ).toInstant ()));
282+ return true ;
283+ }
284+ return false ;
285+ }
286+
247287 @ Override
248288 public void addBatch () {
249289 ArrayList <BigQueryJdbcParameter > currentParameterList =
@@ -470,24 +510,42 @@ public void setArray(int parameterIndex, Array x) throws SQLException {
470510 }
471511
472512 @ Override
473- public ResultSetMetaData getMetaData () {
474- // TODO(neenu) :IMPLEMENT metadata
513+ public ResultSetMetaData getMetaData () throws SQLException {
514+ checkClosed ();
515+ if (this .insertSchema != null ) {
516+ return BigQueryResultSetMetadata .of (this .insertSchema .getFields (), this );
517+ }
475518 return null ;
476519 }
477520
478521 @ Override
479- public void setDate (int parameterIndex , Date x , Calendar cal ) {
480- // TODO :NOT IMPLEMENTED
522+ public void setDate (int parameterIndex , Date x , Calendar cal ) throws SQLException {
523+ checkClosed ();
524+ if (x == null ) {
525+ setNull (parameterIndex , Types .DATE );
526+ return ;
527+ }
528+ setDate (parameterIndex , BigQueryTypeCoercionUtility .convertDateWithCalendar (x , cal ));
481529 }
482530
483531 @ Override
484- public void setTime (int parameterIndex , Time x , Calendar cal ) {
485- // TODO :NOT IMPLEMENTED
532+ public void setTime (int parameterIndex , Time x , Calendar cal ) throws SQLException {
533+ checkClosed ();
534+ if (x == null ) {
535+ setNull (parameterIndex , Types .TIME );
536+ return ;
537+ }
538+ setTime (parameterIndex , BigQueryTypeCoercionUtility .convertTimeWithCalendar (x , cal ));
486539 }
487540
488541 @ Override
489- public void setTimestamp (int parameterIndex , Timestamp x , Calendar cal ) {
490- // TODO :NOT IMPLEMENTED
542+ public void setTimestamp (int parameterIndex , Timestamp x , Calendar cal ) throws SQLException {
543+ checkClosed ();
544+ if (x == null ) {
545+ setNull (parameterIndex , Types .TIMESTAMP );
546+ return ;
547+ }
548+ setTimestamp (parameterIndex , BigQueryTypeCoercionUtility .convertTimestampWithCalendar (x , cal ));
491549 }
492550
493551 @ Override
@@ -501,9 +559,9 @@ public void setURL(int parameterIndex, URL x) throws SQLException {
501559 }
502560
503561 @ Override
504- public ParameterMetaData getParameterMetaData () {
505- // TODO(neenu) :IMPLEMENT
506- return null ;
562+ public ParameterMetaData getParameterMetaData () throws SQLException {
563+ checkClosed ();
564+ return new BigQueryParameterMetaData ( this . parameterCount , this . parameterHandler ) ;
507565 }
508566
509567 @ Override
0 commit comments