@@ -176,21 +176,15 @@ protected final void init(long id) throws SQLException {
176176
177177 //Execute prepared statement
178178 stmt .setLong (1 , id );
179- java .sql .ResultSet rs = stmt .executeQuery ();
180- if (!rs .next ()){
181- rs .close ();
182- throw new IllegalArgumentException ();
179+ try (java .sql .ResultSet rs = stmt .executeQuery ()){
180+ if (rs .next ()){
181+ update (rs );
182+ this .id = id ;
183+ }
184+ else {
185+ throw new IllegalArgumentException ();
186+ }
183187 }
184-
185-
186- //Update model attributes
187- update (rs );
188- this .id = id ;
189-
190-
191- //Close recordset
192- rs .close ();
193-
194188 }
195189 }
196190 catch (IllegalArgumentException e ){
@@ -449,7 +443,7 @@ else if (packageName.startsWith("javaxt.geospatial.geometry") ||
449443
450444
451445
452- stmt = conn .getConnection ().prepareStatement (sql .toString (), java . sql . Statement . RETURN_GENERATED_KEYS );
446+ stmt = conn .getConnection ().prepareStatement (sql .toString (), new String []{ "id" } );
453447 insertStatements .put (className , stmt );
454448 insertStatements .notify ();
455449 }
@@ -491,35 +485,35 @@ else if (packageName.startsWith("javaxt.geospatial.geometry") ||
491485 javaxt .sql .Driver driver = conn .getDatabase ().getDriver ();
492486 if (driver ==null ) driver = new Driver ("" ,"" ,"" );
493487
494- Recordset rs = conn .getRecordset (
495- "select * from " + tableName + " where id=" + id , false );
496- if (rs .EOF ){
497- rs .addNew ();
498- rs .setValue ("id" , id );
499- }
500- it = fields .keySet ().iterator ();
501- while (it .hasNext ()){
502- java .lang .reflect .Field f = it .next ();
503- String columnName = fieldMap .get (f .getName ());
504- Object val = fields .get (f );
505- if (val instanceof JSONObject || val instanceof JSONArray ){
506- if (driver .equals ("PostgreSQL" )){
507- rs .setValue (columnName , new javaxt .sql .Function (
508- "?::jsonb" , new Object []{
509- val .toString ()
510- }
511- ));
488+ try (Recordset rs = conn .getRecordset (
489+ "select * from " + tableName + " where id=" + id , false )){
490+ if (rs .EOF ){
491+ rs .addNew ();
492+ rs .setValue ("id" , id );
493+ }
494+ it = fields .keySet ().iterator ();
495+ while (it .hasNext ()){
496+ java .lang .reflect .Field f = it .next ();
497+ String columnName = fieldMap .get (f .getName ());
498+ Object val = fields .get (f );
499+ if (val instanceof JSONObject || val instanceof JSONArray ){
500+ if (driver .equals ("PostgreSQL" )){
501+ rs .setValue (columnName , new javaxt .sql .Function (
502+ "?::jsonb" , new Object []{
503+ val .toString ()
504+ }
505+ ));
506+ }
507+ else {
508+ rs .setValue (columnName , val .toString ());
509+ }
512510 }
513511 else {
514- rs .setValue (columnName , val . toString () );
512+ rs .setValue (columnName , val );
515513 }
516514 }
517- else {
518- rs .setValue (columnName , val );
519- }
515+ rs .update ();
520516 }
521- rs .update ();
522- rs .close ();
523517
524518 }
525519 catch (SQLException e ){
0 commit comments