1 29 package com.caucho.amber.ejb3; 30 31 import com.caucho.amber.manager.AmberConnection; 32 import com.caucho.amber.query.AbstractQuery; 33 import com.caucho.amber.query.UserQuery; 34 import com.caucho.ejb.EJBExceptionWrapper; 35 import com.caucho.util.L10N; 36 37 import javax.persistence.FlushModeType; 38 import javax.persistence.Query; 39 import javax.persistence.TemporalType; 40 import java.sql.ResultSet ; 41 import java.sql.SQLException ; 42 import java.util.ArrayList ; 43 import java.util.Calendar ; 44 import java.util.Date ; 45 import java.util.List ; 46 47 50 public class QueryImpl implements Query { 51 private static final L10N L = new L10N(QueryImpl.class); 52 53 private AbstractQuery _query; 54 private UserQuery _userQuery; 55 56 private AmberConnection _aConn; 57 private int _firstResult; 58 private int _maxResults = Integer.MAX_VALUE / 2; 59 60 63 QueryImpl(AbstractQuery query, AmberConnection aConn) 64 { 65 _query = query; 66 _aConn = aConn; 67 68 _userQuery = new UserQuery(query); 69 _userQuery.setSession(_aConn); 70 } 71 72 75 public List getResultList() 76 { 77 try { 78 ArrayList results = new ArrayList (); 79 80 ResultSet rs = executeQuery(); 81 82 while (rs.next()) 83 results.add(rs.getObject(1)); 84 85 rs.close(); 86 87 return results; 88 } catch (Exception e) { 89 throw EJBExceptionWrapper.createRuntime(e); 90 } 91 } 92 93 96 public Object getSingleResult() 97 { 98 try { 99 ResultSet rs = executeQuery(); 100 101 Object value = null; 102 103 if (rs.next()) 104 value = rs.getObject(1); 105 106 rs.close(); 107 108 return value; 109 } catch (Exception e) { 110 throw EJBExceptionWrapper.createRuntime(e); 111 } 112 } 113 114 117 public int executeUpdate() 118 { 119 try { 120 return _userQuery.executeUpdate(); 121 } catch (Exception e) { 122 throw EJBExceptionWrapper.createRuntime(e); 123 } 124 } 125 126 129 protected ResultSet executeQuery() 130 throws SQLException 131 { 132 return _userQuery.executeQuery(); 133 } 134 135 138 public Query setMaxResults(int maxResult) 139 { 140 return this; 141 } 142 143 146 public Query setFirstResult(int startPosition) 147 { 148 return this; 149 } 150 151 154 public Query setHint(String hintName, Object value) 155 { 156 return this; 157 } 158 159 162 public Query setParameter(String name, Object value) 163 { 164 return this; 165 } 166 167 170 public Query setParameter(String name, Date value, TemporalType type) 171 { 172 return this; 173 } 174 175 178 public Query setParameter(String name, Calendar value, TemporalType type) 179 { 180 return this; 181 } 182 183 186 public Query setParameter(int index, Object value) 187 { 188 _userQuery.setObject(index, value); 189 190 return this; 191 } 192 193 196 public Query setParameter(int index, Date value, TemporalType type) 197 { 198 return this; 199 } 200 201 204 public Query setParameter(int index, Calendar value, TemporalType type) 205 { 206 return this; 207 } 208 209 212 public Query setFlushMode(FlushModeType mode) 213 { 214 return this; 215 } 216 217 220 223 public Query setDouble(int index, double value) 224 { 225 _userQuery.setDouble(index, value); 226 227 return this; 228 } 229 } 230 | Popular Tags |