1 28 package com.caucho.ejb.entity2; 29 30 import java.util.List; 31 import java.util.ArrayList; 32 import java.util.Date; 33 import java.util.Calendar; 34 35 import java.sql.Connection; 36 import java.sql.PreparedStatement; 37 import java.sql.ResultSet; 38 import java.sql.SQLException; 39 40 import javax.ejb.Query; 41 42 import com.caucho.amber.connection.AmberConnectionImpl; 43 44 import com.caucho.amber.query.AbstractQuery; 45 import com.caucho.amber.query.UserQuery; 46 47 import com.caucho.util.L10N; 48 49 import com.caucho.ejb.EJBExceptionWrapper; 50 51 54 public class EJBQueryImpl implements Query { 55 private static final L10N L = new L10N(EJBQueryImpl.class); 56 57 private AbstractQuery _query; 58 private UserQuery _userQuery; 59 60 private AmberConnectionImpl _aConn; 61 private int _firstResult; 62 private int _maxResults = Integer.MAX_VALUE / 2; 63 64 67 EJBQueryImpl(AbstractQuery query, AmberConnectionImpl aConn) 68 { 69 _query = query; 70 _aConn = aConn; 71 72 _userQuery = new UserQuery(query); 73 _userQuery.setSession(_aConn); 74 } 75 76 79 public List listResults() 80 { 81 try { 82 ArrayList results = new ArrayList(); 83 84 ResultSet rs = executeQuery(); 85 86 while (rs.next()) 87 results.add(rs.getObject(1)); 88 89 rs.close(); 90 91 return results; 92 } catch (Exception e) { 93 throw EJBExceptionWrapper.createRuntime(e); 94 } 95 } 96 97 100 public Object getSingleResult() 101 { 102 try { 103 ResultSet rs = executeQuery(); 104 105 Object value = null; 106 107 if (rs.next()) 108 value = rs.getObject(1); 109 110 rs.close(); 111 112 return value; 113 } catch (Exception e) { 114 throw EJBExceptionWrapper.createRuntime(e); 115 } 116 } 117 118 121 public int executeUpdate() 122 { 123 try { 124 return _userQuery.executeUpdate(); 125 } catch (Exception e) { 126 throw EJBExceptionWrapper.createRuntime(e); 127 } 128 } 129 130 133 protected ResultSet executeQuery() 134 throws SQLException 135 { 136 return _userQuery.executeQuery(); 137 } 138 139 142 public Query setMaxResults(int maxResult) 143 { 144 return this; 145 } 146 147 150 public Query setFirstResult(int startPosition) 151 { 152 return this; 153 } 154 155 158 public Query setHint(String hintName, Object value) 159 { 160 return this; 161 } 162 163 166 public Query setParameter(String name, Object value) 167 { 168 return this; 169 } 170 171 174 public Query setParameter(String name, Date value, TemporalType type) 175 { 176 return this; 177 } 178 179 182 public Query setParameter(String name, Calendar value, TemporalType type) 183 { 184 return this; 185 } 186 187 190 public Query setParameter(int index, Object value) 191 { 192 _userQuery.setObject(index, value); 193 194 return this; 195 } 196 197 200 public Query setParameter(int index, Date value, TemporalType type) 201 { 202 return this; 203 } 204 205 208 public Query setParameter(int index, Calendar value, TemporalType type) 209 { 210 return this; 211 } 212 } 213 | Popular Tags |