1 46 package groovy.sql; 47 48 import groovy.lang.GroovyObjectSupport; 49 import groovy.lang.MissingPropertyException; 50 51 import java.util.Iterator ; 52 import java.util.LinkedHashMap ; 53 54 62 public class GroovyRowResult extends GroovyObjectSupport { 63 64 private LinkedHashMap result; 65 66 public GroovyRowResult(LinkedHashMap result) { 67 this.result = result; 68 } 69 70 75 public Object getProperty(String property) { 76 try { 77 Object value = result.get(property); 78 if (value==null) { 79 value = result.get(property.toUpperCase()); 81 if (value==null) 82 throw new MissingPropertyException(property, GroovyRowResult.class); 83 } 84 return(value); 85 } 86 catch (Exception e) { 87 throw new MissingPropertyException(property, GroovyRowResult.class, e); 88 } 89 } 90 91 97 public Object getAt(int index) { 98 try { 99 if (index<0) 101 index += result.size(); 102 Iterator it = result.values().iterator(); 103 int i = 0; 104 Object obj = null; 105 while ( (obj==null) && (it.hasNext()) ) { 106 if (i==index) 107 obj = it.next(); 108 else 109 it.next(); 110 i++; 111 } 112 return(obj); 113 } 114 catch (Exception e) { 115 throw new MissingPropertyException(Integer.toString(index), GroovyRowResult.class, e); 116 } 117 } 118 119 public String toString() { 120 return(result.toString() ); 121 } 122 123 } 124 | Popular Tags |