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.ejb.cfg.EjbEntityBean; 35 import com.caucho.java.JavaWriter; 36 import com.caucho.java.gen.CallChain; 37 import com.caucho.java.gen.MethodCallChain; 38 import com.caucho.util.L10N; 39 40 import java.io.IOException ; 41 42 45 public class EntityCreateCall extends CallChain { 46 private static L10N L = new L10N(EntityCreateMethod.class); 47 48 private EjbEntityBean _bean; 49 50 private JMethod _createMethod; 51 private JMethod _postCreateMethod; 52 53 private CallChain _createCall; 54 private CallChain _postCreateCall; 55 56 private JClass _primKeyClass; 57 private String _contextClassName; 58 59 private boolean _isCMP; 60 61 public EntityCreateCall(EjbEntityBean bean, 62 JMethod createMethod, 63 JMethod postCreateMethod, 64 String contextClassName) 65 { 66 _bean = bean; 67 68 _createMethod = createMethod; 69 _postCreateMethod = postCreateMethod; 70 71 _createCall = new MethodCallChain(_createMethod); 72 73 if (_postCreateMethod != null) 74 _postCreateCall = new MethodCallChain(_postCreateMethod); 75 76 _contextClassName = contextClassName; 77 } 78 79 public void setCMP(boolean isCMP) 80 { 81 _isCMP = isCMP; 82 } 83 84 89 public void generateCall(JavaWriter out, String retVar, 90 String var, String []args) 91 throws IOException 92 { 93 if (_isCMP) { 94 out.println("try {"); 95 out.pushDepth(); 96 } 97 98 out.println(); 100 out.println("Bean bean = new Bean(cxt);"); 101 out.println("bean._ejb_trans = trans;"); 102 out.println("bean._ejb_flags = 1;"); 103 104 out.print(_createCall.getReturnType().getPrintName()); 105 out.println(" key;"); 106 107 _createCall.generateCall(out, "key", "bean", args); 108 109 if (_isCMP) { 110 String name = _bean.getEntityType().getName(); 111 out.println("trans.getAmberConnection().create(\"" + name + "\", bean);"); 112 out.println("cxt._amber = bean.__caucho_item;"); 113 out.println("Object okey = bean.__caucho_getPrimaryKey();"); 114 out.println("cxt.postCreate(okey);"); 115 } 116 117 out.println("trans.addObject(bean);"); 118 119 JClass retType = _createCall.getReturnType(); 120 if (_isCMP) { 121 } 122 else if (retType.isAssignableTo(Object .class)) 123 out.println("cxt.postCreate(key);"); 124 else { 125 out.print("Object okey = "); 126 out.printJavaTypeToObject("key", retType); 127 out.println(";"); 128 129 out.println("cxt.postCreate(okey);"); 130 } 131 132 out.println("if (__caucho_log.isLoggable(java.util.logging.Level.FINE))"); 134 out.println(" __caucho_log.fine(bean.__caucho_id + \":create(\" + key + \")\");"); 135 out.println(); 136 137 out.println("bean._ejb_state = QEntity._CAUCHO_IS_LOADED;"); 138 140 if (_postCreateCall != null) 141 _postCreateCall.generateCall(out, null, "bean", args); 142 143 if (_isCMP) { 144 out.popDepth(); 145 out.println("} catch (java.sql.SQLException e) {"); 146 out.println(" throw new com.caucho.ejb.CreateExceptionWrapper(e);"); 147 out.println("}"); 148 } 149 } 150 } 151 | Popular Tags |