1 29 30 package com.caucho.ejb.gen; 31 32 import com.caucho.bytecode.JClass; 33 import com.caucho.bytecode.JMethod; 34 import com.caucho.config.ConfigException; 35 import com.caucho.ejb.cfg.EjbEntityBean; 36 import com.caucho.ejb.ql.EjbSelectQuery; 37 import com.caucho.java.JavaWriter; 38 import com.caucho.util.L10N; 39 40 import java.io.IOException ; 41 42 45 public class AmberSelectCollectionMethod extends AbstractQueryMethod { 46 private static final L10N L = new L10N(AmberSelectCollectionMethod.class); 47 48 private EjbEntityBean _returnType; 49 private JMethod _method; 50 private String _contextClassName; 51 52 public AmberSelectCollectionMethod(EjbEntityBean type, 53 JMethod method, 54 String contextClassName, 55 EjbSelectQuery query) 56 throws ConfigException 57 { 58 super(type, method, query); 59 60 _returnType = type; 61 _method = method; 62 _contextClassName = contextClassName; 63 } 64 65 68 public JClass []getParameterTypes() 69 { 70 return _method.getParameterTypes(); 71 } 72 73 76 public JClass getReturnType() 77 { 78 return _method.getReturnType(); 79 } 80 81 86 public void generateCall(JavaWriter out, String []args) 87 throws IOException 88 { 89 out.print("com.caucho.ejb.xa.TransactionContext trans"); 90 out.println(" = _ejb_context.getTransactionManager().beginSupports();"); 91 92 out.println("try {"); 93 out.pushDepth(); 94 95 generatePrepareQuery(out, args); 96 97 out.println("com.caucho.amber.query.ResultSetImpl rs = (com.caucho.amber.query.ResultSetImpl) query.executeQuery();"); 98 out.println("java.util.ArrayList list = new java.util.ArrayList();"); 99 100 out.println("while (rs.next()) {"); 101 out.pushDepth(); 102 103 String beanClass = _returnType.getEJBClass().getName(); 104 105 out.println("list.add(rs.getObject(1));"); 110 111 out.popDepth(); 112 out.println("}"); 113 out.println(); 114 115 JClass retType = _method.getReturnType(); 117 if (retType.isAssignableTo(java.util.Collection .class)) 118 out.println("return list;"); 119 else 120 out.println("return null;"); 121 122 123 134 135 out.popDepth(); 136 out.println("} catch (java.sql.SQLException e) {"); 137 out.println(" throw new com.caucho.ejb.FinderExceptionWrapper(e);"); 138 out.println("} finally {"); 139 out.println(" trans.commit();"); 140 out.println("}"); 141 } 142 } 143 | Popular Tags |