@@ -96,7 +96,11 @@ func jdbcSet(t ktType, idx int, name string) string {
9696if t .IsUUID () {
9797return fmt .Sprintf ("stmt.setObject(%d, %s)" , idx , name )
9898}
99- return fmt .Sprintf ("stmt.set%s(%d, %s)" , t .Name , idx , name )
99+ if t .IsNull && t .PrimitiveType != "" {
100+ return fmt .Sprintf ("if (%[3]s != null) stmt.set%[1]s(%[2]d, %[3]s) else stmt.setNull(%[2]d, Types.%[4]s)" , t .Name , idx , name , t .PrimitiveType )
101+ } else {
102+ return fmt .Sprintf ("stmt.set%s(%d, %s)" , t .Name , idx , name )
103+ }
100104}
101105
102106type Params struct {
@@ -320,12 +324,13 @@ func BuildDataClasses(conf Config, req *plugin.GenerateRequest) []Struct {
320324}
321325
322326type ktType struct {
323- Name string
324- IsEnum bool
325- IsArray bool
326- IsNull bool
327- DataType string
328- Engine string
327+ Name string
328+ IsEnum bool
329+ IsArray bool
330+ IsNull bool
331+ PrimitiveType string
332+ DataType string
333+ Engine string
329334}
330335
331336func (t ktType ) String () string {
@@ -374,12 +379,13 @@ func (t ktType) IsBigDecimal() bool {
374379func makeType (req * plugin.GenerateRequest , col * plugin.Column ) ktType {
375380typ , isEnum := ktInnerType (req , col )
376381return ktType {
377- Name : typ ,
378- IsEnum : isEnum ,
379- IsArray : col .IsArray ,
380- IsNull : ! col .NotNull ,
381- DataType : sdk .DataType (col .Type ),
382- Engine : req .Settings .Engine ,
382+ Name : typ ,
383+ IsEnum : isEnum ,
384+ IsArray : col .IsArray ,
385+ IsNull : ! col .NotNull ,
386+ PrimitiveType : ktPrimitiveType (typ ),
387+ DataType : sdk .DataType (col .Type ),
388+ Engine : req .Settings .Engine ,
383389}
384390}
385391
@@ -395,6 +401,25 @@ func ktInnerType(req *plugin.GenerateRequest, col *plugin.Column) (string, bool)
395401}
396402}
397403
404+ func ktPrimitiveType (t string ) string {
405+ switch t {
406+ case "Int" :
407+ return "INTEGER"
408+ case "Double" :
409+ return "DOUBLE"
410+ case "Long" :
411+ return "BIGINT"
412+ case "Short" :
413+ return "SMALLINT"
414+ case "Float" :
415+ return "REAL"
416+ case "Boolean" :
417+ return "BOOLEAN"
418+ default :
419+ return ""
420+ }
421+ }
422+
398423type goColumn struct {
399424id int
400425* plugin.Column
0 commit comments