1 21 package oracle.toplink.essentials.internal.ejb.cmp3; 23 24 import java.util.*; 25 import javax.persistence.Query; 26 import javax.persistence.TemporalType; 27 import javax.persistence.FlushModeType; 28 import javax.persistence.NoResultException; 29 import javax.persistence.NonUniqueResultException; 30 import oracle.toplink.essentials.queryframework.*; 31 import oracle.toplink.essentials.ejb.cmp3.*; 32 import oracle.toplink.essentials.internal.helper.*; 33 34 46 public class EJBQueryImpl extends oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl implements EJBQuery { 47 48 52 protected EJBQueryImpl(EntityManagerImpl entityManager) { 53 super(entityManager); 54 } 55 56 61 public EJBQueryImpl(DatabaseQuery query, EntityManagerImpl entityManager) { 62 super(query, entityManager); 63 } 64 65 70 public EJBQueryImpl(String ejbql, EntityManagerImpl entityManager) { 71 super(ejbql, entityManager); 72 } 73 74 80 public EJBQueryImpl(String queryDescription, EntityManagerImpl entityManager, boolean isNamedQuery) { 81 super(queryDescription, entityManager, isNamedQuery); 82 } 83 84 88 protected Object convertTemporalType(Object value, TemporalType type) { 89 ConversionManager conversionManager = ((oracle.toplink.essentials.internal.sessions.AbstractSession)getEntityManager().getActiveSession()).getDatasourcePlatform().getConversionManager(); 90 if (type == TemporalType.TIME) { 91 return conversionManager.convertObject(value, ClassConstants.TIME); 92 } else if (type == TemporalType.TIMESTAMP) { 93 return conversionManager.convertObject(value, ClassConstants.TIMESTAMP); 94 } else if (type == TemporalType.DATE) { 95 return conversionManager.convertObject(value, ClassConstants.SQLDATE); 96 } 97 return value; 98 } 99 100 103 public EntityManager getEntityManager() { 104 return (EntityManager)entityManager; 105 } 106 107 112 public Query setFirstResult(int startPosition) { 113 setFirstResultInternal(startPosition); 114 return this; 115 } 116 117 121 public Query setFlushMode(FlushModeType flushMode) { 122 if (flushMode == null) { 123 getDatabaseQuery().setFlushOnExecute(null); 124 } else { 125 getDatabaseQuery().setFlushOnExecute(flushMode == FlushModeType.AUTO); 126 } 127 return this; 128 } 129 130 139 public Query setHint(String hintName, Object value) { 140 setHintInternal(hintName, value); 141 return this; 142 } 143 144 149 public Query setMaxResults(int maxResult) { 150 setMaxResultsInternal(maxResult); 151 return this; 152 } 153 154 160 public Query setParameter(String name, Object value) { 161 setParameterInternal(name, value); 162 return this; 163 } 164 165 172 public Query setParameter(String name, Date value, TemporalType temporalType) { 173 return setParameter(name, convertTemporalType(value, temporalType)); 174 } 175 176 183 public Query setParameter(String name, Calendar value, TemporalType temporalType) { 184 return setParameter(name, convertTemporalType(value, temporalType)); 185 } 186 187 193 public Query setParameter(int position, Object value) { 194 setParameterInternal(position, value); 195 return this; 196 } 197 198 207 public Query setParameter(int position, Date value, TemporalType temporalType) { 208 return setParameter(position, convertTemporalType(value, temporalType)); 209 } 210 211 218 public Query setParameter(int position, Calendar value, TemporalType temporalType) { 219 return setParameter(position, convertTemporalType(value, temporalType)); 220 } 221 222 protected void throwNoResultException(String message) { 223 throw new NoResultException(message); 224 } 225 226 protected void throwNonUniqueResultException(String message) { 227 throw new NonUniqueResultException(message); 228 } 229 } 230 | Popular Tags |