1 29 30 package com.caucho.ejb.cfg; 31 32 import com.caucho.bytecode.JMethod; 33 import com.caucho.config.ConfigException; 34 import com.caucho.ejb.gen.BeanAssembler; 35 import com.caucho.java.JavaWriter; 36 import com.caucho.java.gen.BaseMethod; 37 import com.caucho.util.L10N; 38 39 import java.io.IOException ; 40 41 44 public class EjbManyToOneSetMethod extends EjbMethod { 45 private static final L10N L = new L10N(EjbManyToOneSetMethod.class); 46 47 private CmrManyToOne _manyToOne; 48 49 56 public EjbManyToOneSetMethod(EjbView view, 57 JMethod apiMethod, JMethod implMethod, 58 CmrManyToOne manyToOne) 59 { 60 super(view, apiMethod, implMethod); 61 62 _manyToOne = manyToOne; 63 } 64 65 68 public void assembleBean(BeanAssembler beanAssembler, String fullClassName) 69 throws ConfigException 70 { 71 beanAssembler.addMethod(new BeanMethod(getImplMethod())); 72 } 73 74 class BeanMethod extends BaseMethod { 75 BeanMethod(JMethod method) 76 { 77 super(method); 78 } 79 80 86 protected void generateCall(JavaWriter out, String []args) 87 throws IOException 88 { 89 CmrRelation targetRelation = _manyToOne.getTargetRelation(); 90 91 String value = args[0]; 92 93 if (targetRelation instanceof CmrManyToOne) { 94 CmrManyToOne targetManyToOne = (CmrManyToOne) targetRelation; 95 96 JMethod srcGetter = _manyToOne.getGetter(); 97 JMethod dstSetter = targetManyToOne.getSetter(); 98 99 101 if (dstSetter != null) { 102 EjbEntityBean targetBean = _manyToOne.getTargetBean(); 103 String targetType = targetBean.getLocal().getName(); 104 105 String localType = _manyToOne.getBean().getLocal().getName(); 106 107 JMethod localDstSetter = targetBean.getMethod(targetBean.getLocal(), 108 dstSetter); 109 110 out.println(targetType + " oldBean = " + srcGetter.getName() + "();"); 111 112 out.println("if (" + value + " == oldBean || " + 113 value + " != null && " + value + ".equals(oldBean))"); 114 out.println(" return;"); 115 116 out.println("super." + getImplMethod().getName() + "(" + value + ");"); 117 118 out.println("if (oldBean != null) {"); 119 out.pushDepth(); 120 121 if (localDstSetter != null) { 122 out.print("oldBean"); 123 } 124 else { 125 out.print("((" + targetBean.getEJBClass().getName() + ") "); 126 out.print("((com.caucho.ejb.entity.EntityObject) oldBean)._caucho_getBean(_ejb_trans, false))"); 127 } 128 129 out.println("." + dstSetter.getName() + "((" + localType + ") null);"); 130 131 out.popDepth(); 132 out.println("}"); 133 134 out.println(); 135 out.println("if (" + value + " != null) {"); 136 out.pushDepth(); 137 138 if (localDstSetter != null) { 139 out.print(value); 140 } 141 else { 142 out.print("((" + targetBean.getEJBClass().getName() + ") "); 143 out.print("((com.caucho.ejb.entity.EntityObject) " + value + ")._caucho_getBean(_ejb_trans, false))"); 144 } 145 146 out.println("." + dstSetter.getName() + "((" + localType + ") _ejb_context.getEJBLocalObject());"); 147 148 out.popDepth(); 149 out.println("}"); 150 151 return; 152 } 153 } 154 155 out.println("super." + getImplMethod().getName() + "(" + value + ");"); 156 } 157 } 158 } 159 | Popular Tags |