1 21 package oracle.toplink.essentials.queryframework; 23 24 import java.util.*; 25 import oracle.toplink.essentials.mappings.converters.*; 26 import oracle.toplink.essentials.internal.helper.*; 27 import oracle.toplink.essentials.exceptions.*; 28 import oracle.toplink.essentials.internal.queryframework.*; 29 import oracle.toplink.essentials.internal.sessions.AbstractRecord; 30 31 43 public class DirectReadQuery extends DataReadQuery { 44 45 46 protected Converter valueConverter; 47 48 52 public DirectReadQuery() { 53 super(); 54 } 55 56 60 public DirectReadQuery(String sqlString) { 61 super(sqlString); 62 } 63 64 68 public DirectReadQuery(Call call) { 69 super(call); 70 } 71 72 77 public Converter getValueConverter() { 78 return valueConverter; 79 } 80 81 86 public void setValueConverter(Converter valueConverter) { 87 this.valueConverter = valueConverter; 88 } 89 90 95 public Object buildObject(AbstractRecord row) { 96 Object value = row.get(row.getFields().firstElement()); 97 if (getValueConverter() != null) { 98 value = getValueConverter().convertDataValueToObjectValue(value, session); 99 } 100 return value; 101 } 102 103 107 public Object executeNonCursor() throws DatabaseException, QueryException { 108 ContainerPolicy cp = getContainerPolicy(); 109 110 Vector rows = getQueryMechanism().executeSelect(); 111 Object result = cp.containerInstance(rows.size()); 112 DatabaseField resultDirectField = null; 113 114 for (Enumeration stream = rows.elements(); stream.hasMoreElements();) { 115 AbstractRecord row = (AbstractRecord)stream.nextElement(); 116 if (resultDirectField == null) { 117 resultDirectField = (DatabaseField)row.getFields().firstElement(); 118 } 119 Object value = row.get(resultDirectField); 120 if (getValueConverter() != null) { 121 value = getValueConverter().convertDataValueToObjectValue(value, session); 122 } 123 cp.addInto(value, result, getSession()); 124 } 125 return result; 126 } 127 } 128 | Popular Tags |