package javaxt.sql; import javaxt.json.JSONObject; import java.util.HashMap; import java.util.ArrayList; import javaxt.json.JSONArray; //****************************************************************************** //** Record Class //****************************************************************************** /** * Used to represent a record returned from a SQL query * ******************************************************************************/ public class Record { //extends javaxt.utils.Record protected Field[] fields; //************************************************************************** //** Constructor //************************************************************************** protected Record(Field[] fields){ if (fields==null) fields = new Field[0]; this.fields = fields; } //************************************************************************** //** update //************************************************************************** /** Called by the move() and addNew() methods in Recordset */ protected void update(java.sql.ResultSet rs){ try{ for (int i=1; i<=fields.length; i++) { Field Field = fields[i-1]; Field.setValue(rs==null ? null : new Value(rs.getObject(i))); Field.requiresUpdate(false); } } catch(Exception e){} } //************************************************************************** //** getFields //************************************************************************** /** Used to retrieve the an array of fields in the current record. */ public Field[] getFields(){ Field[] arr = new Field[fields.length]; for (int i=0; i-1 && i if (record.isDirty()){ for (javaxt.sql.Field field : record.getFields()){ if (field.isDirty()){ String val = field.getValue().toString(); System.out.println(field.getName() + ": " + val); } } } */ public boolean isDirty(){ for (Field field : fields){ if (field.isDirty()) return true; } return false; } // //************************************************************************** // //** clear // //************************************************************************** // protected void clear(){ // if (fields==null) return; // for (Field f : fields){ // f.clear(); // f = null; // } // fields = null; // } //************************************************************************** //** toJson //************************************************************************** /** Returns a JSON representation of this record */ public JSONObject toJson(){ JSONObject json = new JSONObject(); for (Field field : fields){ JSONObject f = field.toJson(); json.set(field.getName(), f.get("value")); } return json; } }