diff --git a/internal/core/gen.go b/internal/core/gen.go index 5a7ac0a..b754b26 100644 --- a/internal/core/gen.go +++ b/internal/core/gen.go @@ -166,17 +166,13 @@ func jdbcGet(t ktType, idx int) string { if t.IsInstant() { return fmt.Sprintf(`results.getTimestamp(%d).toInstant()`, idx) } - if t.IsUUID() { - var nullCast string - if t.IsNull { - nullCast = "?" - } - return fmt.Sprintf(`results.getObject(%d) as%s %s`, idx, nullCast, t.Name) - } - if t.IsBigDecimal() { - return fmt.Sprintf(`results.getBigDecimal(%d)`, idx) + + var nullCast string + if t.IsNull { + nullCast = "?" } - return fmt.Sprintf(`results.get%s(%d)`, t.Name, idx) + + return fmt.Sprintf(`results.getObject(%d) as %s%s`, idx, t.Name, nullCast) } func (v QueryValue) ResultSet() string { @@ -367,10 +363,6 @@ func (t ktType) IsUUID() bool { return t.Name == "UUID" } -func (t ktType) IsBigDecimal() bool { - return t.Name == "java.math.BigDecimal" -} - func makeType(req *plugin.GenerateRequest, col *plugin.Column) ktType { typ, isEnum := ktInnerType(req, col) return ktType{ diff --git a/internal/core/imports.go b/internal/core/imports.go index 7fdcb88..79fa99e 100644 --- a/internal/core/imports.go +++ b/internal/core/imports.go @@ -86,6 +86,9 @@ func (i *Importer) modelImports() [][]string { if i.usesType("UUID") { std["java.util.UUID"] = struct{}{} } + if i.usesType("BigDecimal") { + std["java.math.BigDecimal"] = struct{}{} + } stds := make([]string, 0, len(std)) for s := range std { @@ -120,6 +123,9 @@ func stdImports(uses func(name string) bool) map[string]struct{} { if uses("UUID") { std["java.util.UUID"] = struct{}{} } + if uses("BigDecimal") { + std["java.math.BigDecimal"] = struct{}{} + } return std } diff --git a/internal/core/postgresql_type.go b/internal/core/postgresql_type.go index ce53e19..a033890 100644 --- a/internal/core/postgresql_type.go +++ b/internal/core/postgresql_type.go @@ -36,7 +36,7 @@ func postgresType(req *plugin.GenerateRequest, col *plugin.Column) (string, bool return "Float", false case "pg_catalog.numeric": - return "java.math.BigDecimal", false + return "BigDecimal", false case "bool", "pg_catalog.bool": return "Boolean", false