1 21 package oracle.toplink.essentials.internal.indirection; 23 24 import oracle.toplink.essentials.queryframework.*; 25 import oracle.toplink.essentials.exceptions.*; 26 import oracle.toplink.essentials.internal.sessions.AbstractRecord; 27 import oracle.toplink.essentials.internal.sessions.AbstractSession; 28 29 37 public class QueryBasedValueHolder extends DatabaseValueHolder { 38 39 42 protected transient ReadQuery query; 43 44 47 50 public QueryBasedValueHolder(ReadQuery query, AbstractRecord row, AbstractSession session) { 51 this.row = row; 52 this.session = session; 53 54 if (!session.isUnitOfWork()) { 63 this.session = session.getRootSession(query); 64 } 65 this.query = query; 66 } 67 68 71 protected ReadQuery getQuery() { 72 return query; 73 } 74 75 protected Object instantiate() throws DatabaseException { 76 return instantiate(getSession()); 77 } 78 79 82 protected Object instantiate(AbstractSession session) throws DatabaseException { 83 if (session == null){ 84 throw ValidationException.instantiatingValueholderWithNullSession(); 85 } 86 return session.executeQuery(getQuery(), getRow()); 87 } 88 89 100 public Object instantiateForUnitOfWorkValueHolder(UnitOfWorkValueHolder unitOfWorkValueHolder) { 101 return instantiate(unitOfWorkValueHolder.getUnitOfWork()); 102 } 103 104 113 public void releaseWrappedValueHolder() { 114 AbstractSession session = getSession(); 115 if ((session != null) && session.isUnitOfWork()) { 116 setSession(session.getRootSession(query)); 117 } 118 } 119 120 123 protected void resetFields() { 124 super.resetFields(); 125 setQuery(null); 126 } 127 128 131 protected void setQuery(ReadQuery theQuery) { 132 query = theQuery; 133 } 134 135 149 public boolean isPessimisticLockingValueHolder() { 150 if ((getQuery() == null) || !getQuery().isObjectLevelReadQuery()) { 152 return false; 153 } 154 ObjectLevelReadQuery query = (ObjectLevelReadQuery)getQuery(); 155 156 return query.isLockQuery(getSession()); 162 } 163 } 164 | Popular Tags |