1 19 20 package org.netbeans.modules.j2ee.sun.share.configbean; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.List ; 25 26 import javax.enterprise.deploy.model.DDBean ; 27 28 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 29 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Ejb; 30 import org.netbeans.modules.j2ee.sun.dd.api.ejb.FlushAtEndOfMethod; 31 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Cmp; 32 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Finder; 33 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Method; 34 import org.netbeans.modules.j2ee.sun.dd.api.ejb.OneOneFinders; 35 import org.netbeans.modules.j2ee.sun.dd.api.ejb.PrefetchDisabled; 36 import org.netbeans.modules.j2ee.sun.dd.api.ejb.QueryMethod; 37 38 import org.netbeans.modules.j2ee.sun.share.configbean.ConfigQuery; 39 40 41 45 public class CmpEntityEjb extends EntityEjb { 46 47 48 private Cmp cmp; 49 50 51 private FlushAtEndOfMethod flushAtEndOfMethod; 52 53 54 private String schema; 55 56 57 private String tableName; 58 59 60 private String consistency; 61 62 63 64 65 67 68 public CmpEntityEjb() { 69 } 70 71 75 public String getSchema() { 76 return this.schema; 77 } 78 79 85 public void setSchema(String schema) throws java.beans.PropertyVetoException { 86 String oldSchema = this.schema; 87 getVCS().fireVetoableChange("schema", oldSchema, schema); 88 this.schema = schema; 89 getPCS().firePropertyChange("schema", oldSchema, schema); 90 } 91 92 96 public String getTableName() { 97 return this.tableName; 98 } 99 100 106 public void setTableName(String tableName) throws java.beans.PropertyVetoException { 107 String oldTableName = this.tableName; 108 getVCS().fireVetoableChange("tableName", oldTableName, tableName); 109 this.tableName = tableName; 110 getPCS().firePropertyChange("tableName", oldTableName, tableName); 111 } 112 113 117 public String getConsistency() { 118 return this.consistency; 119 } 120 121 127 public void setConsistency(String consistency) throws java.beans.PropertyVetoException { 128 String oldConsistency = this.consistency; 129 getVCS().fireVetoableChange("consistency", oldConsistency, consistency); 130 this.consistency = consistency; 131 getPCS().firePropertyChange("consistency", oldConsistency, consistency); 132 } 133 134 138 public String getBeanName() { 139 return cleanDDBeanText(getDDBean()); 140 } 141 142 146 protected class CmpEntityEjbSnippet extends EntityEjb.EntityEjbSnippet { 147 public CommonDDBean getDDSnippet() { 148 Ejb ejb = (Ejb) super.getDDSnippet(); 149 String version = getAppServerVersion().getEjbJarVersionAsString(); 150 151 if(null != cmp){ 152 ejb.setCmp((Cmp) cmp.cloneVersion(version)); 153 } 154 155 if(null != flushAtEndOfMethod){ 156 try{ 157 ejb.setFlushAtEndOfMethod((FlushAtEndOfMethod)flushAtEndOfMethod.cloneVersion(version)); 158 }catch(org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException e){ 159 } 161 } 162 163 return ejb; 164 } 165 166 public boolean hasDDSnippet() { 167 if(super.hasDDSnippet()){ 168 return true; 169 } 170 171 if(null != cmp){ 172 return true; 173 } 174 175 if(null != flushAtEndOfMethod){ 176 return true; 177 } 178 return false; 179 } 180 } 181 182 java.util.Collection getSnippets() { 183 Collection snippets = new ArrayList (); 184 snippets.add(new CmpEntityEjbSnippet()); 185 186 188 return snippets; 189 } 190 191 192 protected void loadEjbProperties(Ejb savedEjb) { 193 super.loadEjbProperties(savedEjb); 194 Cmp cmp = savedEjb.getCmp(); 195 if(null != cmp){ 196 this.cmp = cmp; 197 } 198 199 FlushAtEndOfMethod flushAtEndOfMethod = null; 200 try{ 201 flushAtEndOfMethod = savedEjb.getFlushAtEndOfMethod(); 202 }catch(org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException e){ 203 } 205 206 if(null != flushAtEndOfMethod){ 207 this.flushAtEndOfMethod = flushAtEndOfMethod; 208 } 209 } 210 211 protected void clearProperties() { 212 super.clearProperties(); 213 214 cmp = null; 215 flushAtEndOfMethod = null; 216 schema = null; 217 tableName = null; 218 consistency = null; 219 } 220 221 222 226 public Cmp getCmp() { 227 return this.cmp; 228 } 229 230 231 234 public FlushAtEndOfMethod getFlushAtEndOfMethod() { 235 return this.flushAtEndOfMethod; 236 } 237 238 239 245 public void setCmp(Cmp cmp) throws java.beans.PropertyVetoException { 246 Cmp oldCmp = this.cmp; 247 getVCS().fireVetoableChange("cmp", oldCmp, cmp); 248 this.cmp = cmp; 249 getPCS().firePropertyChange("cmp", oldCmp, cmp); 250 } 251 252 253 258 public void setFlushAtEndOfMethod(FlushAtEndOfMethod flushAtEndOfMethod) throws java.beans.PropertyVetoException { 259 FlushAtEndOfMethod oldFlushAtEndOfMethod = this.flushAtEndOfMethod; 260 getVCS().fireVetoableChange("flushAtEndOfMethod", oldFlushAtEndOfMethod, flushAtEndOfMethod); this.flushAtEndOfMethod = flushAtEndOfMethod; 262 getPCS().firePropertyChange("flush at end of method", oldFlushAtEndOfMethod, flushAtEndOfMethod); } 264 265 266 public void addFinder(Finder finder){ 268 if(null == cmp){ 269 cmp = getConfig().getStorageFactory().createCmp(); 270 } 271 OneOneFinders oneOneFinders = cmp.getOneOneFinders(); 272 if(null == oneOneFinders){ 273 oneOneFinders = cmp.newOneOneFinders(); 274 cmp.setOneOneFinders(oneOneFinders); 275 } 276 oneOneFinders.addFinder(finder); 277 } 278 279 280 public void addMethod(Method method){ 281 288 if(null == flushAtEndOfMethod){ 289 flushAtEndOfMethod = getConfig().getStorageFactory().createFlushAtEndOfMethod(); 290 } 291 flushAtEndOfMethod.addMethod(method); 292 } 293 294 295 public void addQueryMethod(QueryMethod queryMethod){ 296 try{ 297 if(null == cmp){ 298 cmp = getConfig().getStorageFactory().createCmp(); 299 } 300 301 PrefetchDisabled prefetchDisabled = cmp.getPrefetchDisabled(); 302 if(null == prefetchDisabled){ 303 prefetchDisabled = cmp.newPrefetchDisabled(); 304 cmp.setPrefetchDisabled(prefetchDisabled); 305 } 306 prefetchDisabled.addQueryMethod(queryMethod); 307 }catch(org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException ex){ 308 } 310 } 311 312 313 public void removeFinder(Finder finder){ 314 if(null != cmp){ 315 OneOneFinders oneOneFinders = cmp.getOneOneFinders(); 316 if(null != oneOneFinders){ 317 oneOneFinders.removeFinder(finder); 318 } 319 try{ 320 if(oneOneFinders.sizeFinder() < 1){ 321 setCmp(null); 322 } 323 }catch(java.beans.PropertyVetoException ex){ 324 } 325 } 326 } 327 328 329 public void removeMethod(Method method){ 330 if(null != flushAtEndOfMethod){ 331 flushAtEndOfMethod.removeMethod(method); 332 } 333 } 334 335 336 public void removeQueryMethod(QueryMethod queryMethod){ 337 try{ 338 if(null != cmp){ 339 PrefetchDisabled prefetchDisabled = cmp.getPrefetchDisabled(); 340 if(null != prefetchDisabled){ 341 prefetchDisabled.removeQueryMethod(queryMethod); 342 } 343 } 344 }catch(org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException ex){ 345 } 347 } 348 349 350 public List getFinderMethods(){ 352 ArrayList methods = new ArrayList (); 353 DDBean ddBean = getDDBean(); 354 355 DDBean [] childBeans = ddBean.getChildBean("./query"); ConfigQuery.MethodData methodData = null; 358 DDBean queryMethods[]; 359 DDBean queryMethod; 360 DDBean methodNameBean; 361 String methodName; 362 DDBean methodParams; 363 DDBean methodParam[]; 364 for(int i=0; i<childBeans.length; i++){ 365 queryMethods = childBeans[i].getChildBean("./query-method"); if(queryMethods.length > 0){ 367 queryMethod = queryMethods[0]; 368 methodNameBean = queryMethod.getChildBean("./method-name")[0]; methodName = methodNameBean.getText(); 370 if((methodName != null) && (methodName.length() > 0)){ 371 methodParams = queryMethod.getChildBean("./method-params")[0]; methodParam = methodParams.getChildBean("./method-param"); ArrayList params = new ArrayList (); 374 if(methodParam != null){ 375 for(int j=0; j<methodParam.length; j++){ 376 params.add(methodParam[j].getText()); 377 } 378 } 379 methodData = new ConfigQuery.MethodData(methodName, params); 380 } 381 } 382 methods.add((Object )methodData); 383 } 384 return methods; 385 } 386 387 388 public List getPrefetchedMethods(){ 390 List prefetchedMethodList = new ArrayList (); 391 392 try{ 393 if(cmp != null){ 394 PrefetchDisabled prefetchDisabled = cmp.getPrefetchDisabled(); 395 if(prefetchDisabled != null){ 396 QueryMethod[] queryMethods = prefetchDisabled.getQueryMethod(); 397 if(queryMethods != null){ 398 for(int i=0; i<queryMethods.length; i++){ 399 prefetchedMethodList.add(queryMethods[i]); 400 } 401 } 402 } 403 } 404 }catch(org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException ex){ 405 } 407 return prefetchedMethodList; 408 } 409 410 411 public String getHelpId() { 412 return "AS_CFG_CmpEntityEjb"; } 414 } 415 416 | Popular Tags |