1 21 package oracle.toplink.essentials.queryframework; 23 24 import java.util.*; 25 import oracle.toplink.essentials.internal.helper.*; 26 import oracle.toplink.essentials.exceptions.*; 27 import oracle.toplink.essentials.internal.queryframework.*; 28 import oracle.toplink.essentials.internal.sessions.AbstractRecord; 29 30 41 public class DataReadQuery extends ReadQuery { 42 protected ContainerPolicy containerPolicy; 43 44 protected boolean useAbstractRecord = true; 46 47 51 public DataReadQuery() { 52 super(); 53 this.shouldMaintainCache = false; 54 useAbstractRecord = true; 55 setContainerPolicy(ContainerPolicy.buildPolicyFor(ClassConstants.Vector_class)); 56 } 57 58 62 public DataReadQuery(String sqlString) { 63 this(); 64 setSQLString(sqlString); 65 } 66 67 71 public DataReadQuery(Call call) { 72 this(); 73 setCall(call); 74 } 75 76 80 public Object clone() { 81 DataReadQuery cloneQuery = (DataReadQuery)super.clone(); 82 cloneQuery.setContainerPolicy(getContainerPolicy().clone(cloneQuery)); 83 return cloneQuery; 84 } 85 86 93 public Object executeDatabaseQuery() throws DatabaseException { 94 if (getContainerPolicy().overridesRead()) { 95 return getContainerPolicy().execute(); 96 } 97 return executeNonCursor(); 98 } 99 100 104 protected Object executeNonCursor() throws DatabaseException { 105 Vector rows = getQueryMechanism().executeSelect(); 106 if (useAbstractRecord ){ 107 Object results = getContainerPolicy().buildContainerFromVector(rows, getSession()); 108 return results; 109 } 110 ContainerPolicy containerPolicy = getContainerPolicy(); 111 Object reportResults = containerPolicy.containerInstance(rows.size()); 112 for (Iterator rowsEnum = rows.iterator(); rowsEnum.hasNext();) { 113 containerPolicy.addInto( ((AbstractRecord)rowsEnum.next()).getValues() , reportResults, getSession()); 114 } 115 return reportResults; 116 } 117 118 123 public ContainerPolicy getContainerPolicy() { 124 return containerPolicy; 125 } 126 127 131 public boolean isDataReadQuery() { 132 return true; 133 } 134 135 139 protected void prepare() { 140 super.prepare(); 141 getContainerPolicy().prepare(this, getSession()); 142 if (getContainerPolicy().overridesRead()) { 143 return; 144 } 145 getQueryMechanism().prepareExecuteSelect(); 146 } 147 148 152 public void prepareForExecution() throws QueryException { 153 super.prepareForExecution(); 154 getContainerPolicy().prepareForExecution(); 155 } 156 157 161 public void setContainerPolicy(ContainerPolicy containerPolicy) { 162 if (containerPolicy == null) { 165 return; 166 } 167 168 this.containerPolicy = containerPolicy; 169 } 170 171 177 public void useCollectionClass(Class concreteClass) { 178 setContainerPolicy(ContainerPolicy.buildPolicyFor(concreteClass)); 179 } 180 181 185 public void setUseAbstractRecord(boolean useAbstractRecord){ 186 this.useAbstractRecord = useAbstractRecord; 187 } 188 } 189 | Popular Tags |