@@ -96,7 +96,11 @@ func jdbcSet(t ktType, idx int, name string) string {
96
96
if t .IsUUID () {
97
97
return fmt .Sprintf ("stmt.setObject(%d, %s)" , idx , name )
98
98
}
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
+ }
100
104
}
101
105
102
106
type Params struct {
@@ -320,12 +324,13 @@ func BuildDataClasses(conf Config, req *plugin.GenerateRequest) []Struct {
320
324
}
321
325
322
326
type 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
329
334
}
330
335
331
336
func (t ktType ) String () string {
@@ -374,12 +379,13 @@ func (t ktType) IsBigDecimal() bool {
374
379
func makeType (req * plugin.GenerateRequest , col * plugin.Column ) ktType {
375
380
typ , isEnum := ktInnerType (req , col )
376
381
return 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 ,
383
389
}
384
390
}
385
391
@@ -395,6 +401,25 @@ func ktInnerType(req *plugin.GenerateRequest, col *plugin.Column) (string, bool)
395
401
}
396
402
}
397
403
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
+
398
423
type goColumn struct {
399
424
id int
400
425
* plugin.Column
0 commit comments