Skip to content

Commit 8a783bc

Browse files
committed
Address review feedback for CallableStatement
- Add explicit Java 8+ SQLType overrides for registerOutParameter (6) and setObject(String, Object, SQLType) (2) to ensure consistent Databricks-specific error messages - Split throw helpers into void/generic variants to avoid autoboxing fragility - Add exhaustive test coverage: all getXXX(int), getXXX(String), setXXX(String) methods, SQLType overloads, Calendar variants, deprecated getBigDecimal(int,int), null SQL, closed connection, executeQuery behavior, batch operations, getParameterMetaData - Test count: 18 → 26 Signed-off-by: Gopal Lal <gopal.lal@databricks.com> Co-authored-by: Isaac Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
1 parent d2e601f commit 8a783bc

2 files changed

Lines changed: 459 additions & 118 deletions

File tree

src/main/java/com/databricks/jdbc/api/impl/DatabricksCallableStatement.java

Lines changed: 111 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,20 @@ private void validateNoReturnValueSyntax(String sql) throws SQLException {
6060
}
6161
}
6262

63+
/**
64+
* Throws for methods with non-void return types. Always throws, never returns. The generic return
65+
* type avoids separate helpers for each return type.
66+
*/
6367
private <T> T throwOutParamNotSupported() throws SQLException {
6468
throw new DatabricksSQLFeatureNotSupportedException(OUT_PARAM_NOT_SUPPORTED);
6569
}
6670

67-
private <T> T throwNamedParamNotSupported() throws SQLException {
71+
/** Throws for void methods (registerOutParameter, named setXXX). */
72+
private void throwOutParamNotSupportedVoid() throws SQLException {
73+
throw new DatabricksSQLFeatureNotSupportedException(OUT_PARAM_NOT_SUPPORTED);
74+
}
75+
76+
private void throwNamedParamNotSupportedVoid() throws SQLException {
6877
throw new DatabricksSQLFeatureNotSupportedException(NAMED_PARAM_NOT_SUPPORTED);
6978
}
7079

@@ -74,35 +83,72 @@ private <T> T throwNamedParamNotSupported() throws SQLException {
7483

7584
@Override
7685
public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
77-
throwOutParamNotSupported();
86+
throwOutParamNotSupportedVoid();
7887
}
7988

8089
@Override
8190
public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
82-
throwOutParamNotSupported();
91+
throwOutParamNotSupportedVoid();
8392
}
8493

8594
@Override
8695
public void registerOutParameter(int parameterIndex, int sqlType, String typeName)
8796
throws SQLException {
88-
throwOutParamNotSupported();
97+
throwOutParamNotSupportedVoid();
8998
}
9099

91100
@Override
92101
public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
93-
throwOutParamNotSupported();
102+
throwOutParamNotSupportedVoid();
94103
}
95104

96105
@Override
97106
public void registerOutParameter(String parameterName, int sqlType, int scale)
98107
throws SQLException {
99-
throwOutParamNotSupported();
108+
throwOutParamNotSupportedVoid();
100109
}
101110

102111
@Override
103112
public void registerOutParameter(String parameterName, int sqlType, String typeName)
104113
throws SQLException {
105-
throwOutParamNotSupported();
114+
throwOutParamNotSupportedVoid();
115+
}
116+
117+
// Java 8+ SQLType-based overrides — explicit overrides to ensure consistent
118+
// Databricks-specific error messages rather than relying on default method delegation.
119+
120+
@Override
121+
public void registerOutParameter(int parameterIndex, SQLType sqlType) throws SQLException {
122+
throwOutParamNotSupportedVoid();
123+
}
124+
125+
@Override
126+
public void registerOutParameter(int parameterIndex, SQLType sqlType, int scale)
127+
throws SQLException {
128+
throwOutParamNotSupportedVoid();
129+
}
130+
131+
@Override
132+
public void registerOutParameter(int parameterIndex, SQLType sqlType, String typeName)
133+
throws SQLException {
134+
throwOutParamNotSupportedVoid();
135+
}
136+
137+
@Override
138+
public void registerOutParameter(String parameterName, SQLType sqlType) throws SQLException {
139+
throwOutParamNotSupportedVoid();
140+
}
141+
142+
@Override
143+
public void registerOutParameter(String parameterName, SQLType sqlType, int scale)
144+
throws SQLException {
145+
throwOutParamNotSupportedVoid();
146+
}
147+
148+
@Override
149+
public void registerOutParameter(String parameterName, SQLType sqlType, String typeName)
150+
throws SQLException {
151+
throwOutParamNotSupportedVoid();
106152
}
107153

108154
// ---------------------------------------------------------------------------
@@ -434,232 +480,245 @@ public <T> T getObject(String parameterName, Class<T> type) throws SQLException
434480

435481
@Override
436482
public void setURL(String parameterName, URL val) throws SQLException {
437-
throwNamedParamNotSupported();
483+
throwNamedParamNotSupportedVoid();
438484
}
439485

440486
@Override
441487
public void setNull(String parameterName, int sqlType) throws SQLException {
442-
throwNamedParamNotSupported();
488+
throwNamedParamNotSupportedVoid();
443489
}
444490

445491
@Override
446492
public void setBoolean(String parameterName, boolean x) throws SQLException {
447-
throwNamedParamNotSupported();
493+
throwNamedParamNotSupportedVoid();
448494
}
449495

450496
@Override
451497
public void setByte(String parameterName, byte x) throws SQLException {
452-
throwNamedParamNotSupported();
498+
throwNamedParamNotSupportedVoid();
453499
}
454500

455501
@Override
456502
public void setShort(String parameterName, short x) throws SQLException {
457-
throwNamedParamNotSupported();
503+
throwNamedParamNotSupportedVoid();
458504
}
459505

460506
@Override
461507
public void setInt(String parameterName, int x) throws SQLException {
462-
throwNamedParamNotSupported();
508+
throwNamedParamNotSupportedVoid();
463509
}
464510

465511
@Override
466512
public void setLong(String parameterName, long x) throws SQLException {
467-
throwNamedParamNotSupported();
513+
throwNamedParamNotSupportedVoid();
468514
}
469515

470516
@Override
471517
public void setFloat(String parameterName, float x) throws SQLException {
472-
throwNamedParamNotSupported();
518+
throwNamedParamNotSupportedVoid();
473519
}
474520

475521
@Override
476522
public void setDouble(String parameterName, double x) throws SQLException {
477-
throwNamedParamNotSupported();
523+
throwNamedParamNotSupportedVoid();
478524
}
479525

480526
@Override
481527
public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
482-
throwNamedParamNotSupported();
528+
throwNamedParamNotSupportedVoid();
483529
}
484530

485531
@Override
486532
public void setString(String parameterName, String x) throws SQLException {
487-
throwNamedParamNotSupported();
533+
throwNamedParamNotSupportedVoid();
488534
}
489535

490536
@Override
491537
public void setBytes(String parameterName, byte[] x) throws SQLException {
492-
throwNamedParamNotSupported();
538+
throwNamedParamNotSupportedVoid();
493539
}
494540

495541
@Override
496542
public void setDate(String parameterName, Date x) throws SQLException {
497-
throwNamedParamNotSupported();
543+
throwNamedParamNotSupportedVoid();
498544
}
499545

500546
@Override
501547
public void setTime(String parameterName, Time x) throws SQLException {
502-
throwNamedParamNotSupported();
548+
throwNamedParamNotSupportedVoid();
503549
}
504550

505551
@Override
506552
public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
507-
throwNamedParamNotSupported();
553+
throwNamedParamNotSupportedVoid();
508554
}
509555

510556
@Override
511557
public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
512-
throwNamedParamNotSupported();
558+
throwNamedParamNotSupportedVoid();
513559
}
514560

515561
@Override
516562
public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
517-
throwNamedParamNotSupported();
563+
throwNamedParamNotSupportedVoid();
518564
}
519565

520566
@Override
521567
public void setObject(String parameterName, Object x, int targetSqlType, int scale)
522568
throws SQLException {
523-
throwNamedParamNotSupported();
569+
throwNamedParamNotSupportedVoid();
524570
}
525571

526572
@Override
527573
public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
528-
throwNamedParamNotSupported();
574+
throwNamedParamNotSupportedVoid();
529575
}
530576

531577
@Override
532578
public void setObject(String parameterName, Object x) throws SQLException {
533-
throwNamedParamNotSupported();
579+
throwNamedParamNotSupportedVoid();
534580
}
535581

536582
@Override
537583
public void setCharacterStream(String parameterName, Reader reader, int length)
538584
throws SQLException {
539-
throwNamedParamNotSupported();
585+
throwNamedParamNotSupportedVoid();
540586
}
541587

542588
@Override
543589
public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
544-
throwNamedParamNotSupported();
590+
throwNamedParamNotSupportedVoid();
545591
}
546592

547593
@Override
548594
public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
549-
throwNamedParamNotSupported();
595+
throwNamedParamNotSupportedVoid();
550596
}
551597

552598
@Override
553599
public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
554-
throwNamedParamNotSupported();
600+
throwNamedParamNotSupportedVoid();
555601
}
556602

557603
@Override
558604
public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
559-
throwNamedParamNotSupported();
605+
throwNamedParamNotSupportedVoid();
560606
}
561607

562608
@Override
563609
public void setRowId(String parameterName, RowId x) throws SQLException {
564-
throwNamedParamNotSupported();
610+
throwNamedParamNotSupportedVoid();
565611
}
566612

567613
@Override
568614
public void setNString(String parameterName, String value) throws SQLException {
569-
throwNamedParamNotSupported();
615+
throwNamedParamNotSupportedVoid();
570616
}
571617

572618
@Override
573619
public void setNCharacterStream(String parameterName, Reader value, long length)
574620
throws SQLException {
575-
throwNamedParamNotSupported();
621+
throwNamedParamNotSupportedVoid();
576622
}
577623

578624
@Override
579625
public void setNClob(String parameterName, NClob value) throws SQLException {
580-
throwNamedParamNotSupported();
626+
throwNamedParamNotSupportedVoid();
581627
}
582628

583629
@Override
584630
public void setClob(String parameterName, Reader reader, long length) throws SQLException {
585-
throwNamedParamNotSupported();
631+
throwNamedParamNotSupportedVoid();
586632
}
587633

588634
@Override
589635
public void setBlob(String parameterName, InputStream inputStream, long length)
590636
throws SQLException {
591-
throwNamedParamNotSupported();
637+
throwNamedParamNotSupportedVoid();
592638
}
593639

594640
@Override
595641
public void setNClob(String parameterName, Reader reader, long length) throws SQLException {
596-
throwNamedParamNotSupported();
642+
throwNamedParamNotSupportedVoid();
597643
}
598644

599645
@Override
600646
public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
601-
throwNamedParamNotSupported();
647+
throwNamedParamNotSupportedVoid();
602648
}
603649

604650
@Override
605651
public void setBlob(String parameterName, Blob x) throws SQLException {
606-
throwNamedParamNotSupported();
652+
throwNamedParamNotSupportedVoid();
607653
}
608654

609655
@Override
610656
public void setClob(String parameterName, Clob x) throws SQLException {
611-
throwNamedParamNotSupported();
657+
throwNamedParamNotSupportedVoid();
612658
}
613659

614660
@Override
615661
public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
616-
throwNamedParamNotSupported();
662+
throwNamedParamNotSupportedVoid();
617663
}
618664

619665
@Override
620666
public void setBinaryStream(String parameterName, InputStream x, long length)
621667
throws SQLException {
622-
throwNamedParamNotSupported();
668+
throwNamedParamNotSupportedVoid();
623669
}
624670

625671
@Override
626672
public void setCharacterStream(String parameterName, Reader reader, long length)
627673
throws SQLException {
628-
throwNamedParamNotSupported();
674+
throwNamedParamNotSupportedVoid();
629675
}
630676

631677
@Override
632678
public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
633-
throwNamedParamNotSupported();
679+
throwNamedParamNotSupportedVoid();
634680
}
635681

636682
@Override
637683
public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
638-
throwNamedParamNotSupported();
684+
throwNamedParamNotSupportedVoid();
639685
}
640686

641687
@Override
642688
public void setCharacterStream(String parameterName, Reader reader) throws SQLException {
643-
throwNamedParamNotSupported();
689+
throwNamedParamNotSupportedVoid();
644690
}
645691

646692
@Override
647693
public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
648-
throwNamedParamNotSupported();
694+
throwNamedParamNotSupportedVoid();
649695
}
650696

651697
@Override
652698
public void setClob(String parameterName, Reader reader) throws SQLException {
653-
throwNamedParamNotSupported();
699+
throwNamedParamNotSupportedVoid();
654700
}
655701

656702
@Override
657703
public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
658-
throwNamedParamNotSupported();
704+
throwNamedParamNotSupportedVoid();
659705
}
660706

661707
@Override
662708
public void setNClob(String parameterName, Reader reader) throws SQLException {
663-
throwNamedParamNotSupported();
709+
throwNamedParamNotSupportedVoid();
710+
}
711+
712+
// Java 8+ SQLType-based named parameter overrides
713+
714+
@Override
715+
public void setObject(String parameterName, Object x, SQLType targetSqlType, int scaleOrLength)
716+
throws SQLException {
717+
throwNamedParamNotSupportedVoid();
718+
}
719+
720+
@Override
721+
public void setObject(String parameterName, Object x, SQLType targetSqlType) throws SQLException {
722+
throwNamedParamNotSupportedVoid();
664723
}
665724
}

0 commit comments

Comments
 (0)