Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save or update in Groovy

Usually in Java I execute a SELECT statement and check the size of ResultSet. If it is zero I issue a INSERT and otherwise an UPDATE.

Since Groovy provides syntactic sugar on top of JDBC, I'm wondering if it provides a way to ease this process? Is there an easier way to save or update a record?

Note: I know that Hibernate offers this, but I'd rather stick only with Groovy API.

like image 532
Kshitiz Sharma Avatar asked Aug 13 '13 09:08

Kshitiz Sharma


1 Answers

There's a lightweight ORM called GStorm here which I've had on my list of things to investigate which has basically no dependencies, but doesn't handle related domain objects

And a library to leverage Grails GORM here (which obviously pulls GORM out of Grails so has quite a few dependencies including Hibernate)

Other than that (and probably some other examples I've missed), there's nothing I know of to do what you're trying to do. I guess you'd have to write your own (you could switch between the INSERT or UPDATE depending on whether you pass a Primary Key -- assuming primary keys are auto-generated by the DB)

like image 122
tim_yates Avatar answered Oct 02 '22 12:10

tim_yates