1 22 package org.jboss.ejb; 23 24 import java.lang.reflect.Method ; 25 import java.rmi.RemoteException ; 26 import java.util.Collection ; 27 import java.util.Enumeration ; 28 import java.util.HashMap ; 29 import java.util.Hashtable ; 30 import java.util.Iterator ; 31 import java.util.Map ; 32 33 import javax.ejb.EJBException ; 34 import javax.ejb.EJBHome ; 35 import javax.ejb.EJBLocalHome ; 36 import javax.ejb.EJBLocalObject ; 37 import javax.ejb.EJBMetaData ; 38 import javax.ejb.EJBObject ; 39 import javax.ejb.Handle ; 40 import javax.ejb.HomeHandle ; 41 import javax.ejb.RemoveException ; 42 import javax.ejb.TimedObject ; 43 import javax.ejb.Timer ; 44 import javax.management.ObjectName ; 45 import javax.transaction.Transaction ; 46 47 import org.jboss.invocation.Invocation; 48 import org.jboss.invocation.InvocationType; 49 import org.jboss.invocation.MarshalledInvocation; 50 import org.jboss.metadata.ConfigurationMetaData; 51 import org.jboss.metadata.EntityMetaData; 52 import org.jboss.monitor.StatisticsProvider; 53 import org.jboss.util.collection.SerializableEnumeration; 54 55 72 public class EntityContainer 73 extends Container 74 implements EJBProxyFactoryContainer, InstancePoolContainer, 75 EntityContainerMBean 76 { 77 81 protected Map homeMapping = new HashMap (); 82 83 87 protected Map beanMapping = new HashMap (); 88 89 90 protected EntityPersistenceManager persistenceManager; 91 92 93 protected InstanceCache instanceCache; 94 95 96 protected InstancePool instancePool; 97 98 102 protected Interceptor interceptor; 103 104 107 protected boolean readOnly = false; 108 109 114 protected static GlobalTxEntityMap globalTxEntityMap = new GlobalTxEntityMap(); 115 116 public static GlobalTxEntityMap getGlobalTxEntityMap() 117 { 118 return globalTxEntityMap; 119 } 120 121 130 public static void synchronizeEntitiesWithinTransaction(Transaction tx) 131 { 132 if(tx != null) 134 { 135 getGlobalTxEntityMap().synchronizeEntities(tx); 136 } 137 } 138 139 141 public boolean isReadOnly() 142 { 143 return readOnly; 144 } 145 146 public LocalProxyFactory getLocalProxyFactory() 147 { 148 return localProxyFactory; 149 } 150 151 public void setInstancePool(InstancePool ip) 152 { 153 if (ip == null) 154 throw new IllegalArgumentException ("Null pool"); 155 156 this.instancePool = ip; 157 ip.setContainer(this); 158 } 159 160 public InstancePool getInstancePool() 161 { 162 return instancePool; 163 } 164 165 public void setInstanceCache(InstanceCache ic) 166 { 167 if (ic == null) 168 throw new IllegalArgumentException ("Null cache"); 169 170 this.instanceCache = ic; 171 ic.setContainer(this); 172 } 173 174 public InstanceCache getInstanceCache() 175 { 176 return instanceCache; 177 } 178 179 public EntityPersistenceManager getPersistenceManager() 180 { 181 return persistenceManager; 182 } 183 184 public void setPersistenceManager(EntityPersistenceManager pm) 185 { 186 if (pm == null) 187 throw new IllegalArgumentException ("Null persistence manager"); 188 189 persistenceManager = pm; 190 pm.setContainer(this); 191 } 192 193 public void addInterceptor(Interceptor in) 194 { 195 if (interceptor == null) 196 { 197 interceptor = in; 198 } 199 else 200 { 201 Interceptor current = interceptor; 202 while (current.getNext() != null) 203 { 204 current = current.getNext(); 205 } 206 207 current.setNext(in); 208 } 209 } 210 211 public Interceptor getInterceptor() 212 { 213 return interceptor; 214 } 215 216 public Class getHomeClass() 217 { 218 return homeInterface; 219 } 220 221 public Class getRemoteClass() 222 { 223 return remoteInterface; 224 } 225 226 236 public Object createBeanClassInstance() throws Exception { 237 return persistenceManager.createBeanClassInstance(); 238 } 239 240 242 protected void createService() throws Exception 243 { 244 ClassLoader oldCl = SecurityActions.getContextClassLoader(); 246 SecurityActions.setContextClassLoader(getClassLoader()); 247 248 try 249 { 250 if (metaData.getHome() != null) 252 homeInterface = classLoader.loadClass(metaData.getHome()); 253 if (metaData.getRemote() != null) 254 remoteInterface = classLoader.loadClass(metaData.getRemote()); 255 256 super.createService(); 258 259 checkCoherency (); 261 262 setupBeanMapping(); 264 265 setupHomeMapping(); 267 268 setupMarshalledInvocationMapping(); 270 271 try 273 { 274 ObjectName containerName = super.getJmxName(); 275 Hashtable props = containerName.getKeyPropertyList(); 276 props.put("plugin", "pool"); 277 ObjectName poolName = new ObjectName (containerName.getDomain(), props); 278 server.registerMBean(instancePool, poolName); 279 } 280 catch(Throwable t) 281 { 282 log.debug("Failed to register cache as mbean", t); 283 } 284 instancePool.create(); 286 287 for (Iterator it = proxyFactories.keySet().iterator(); it.hasNext(); ) 288 { 289 String invokerBinding = (String )it.next(); 290 EJBProxyFactory ci = (EJBProxyFactory)proxyFactories.get(invokerBinding); 291 ci.create(); 292 } 293 294 try 296 { 297 ObjectName containerName = super.getJmxName(); 298 Hashtable props = containerName.getKeyPropertyList(); 299 props.put("plugin", "cache"); 300 ObjectName cacheName = new ObjectName (containerName.getDomain(), props); 301 server.registerMBean(instanceCache, cacheName); 302 } 303 catch(Throwable t) 304 { 305 log.debug("Failed to register cache as mbean", t); 306 } 307 instanceCache.create(); 309 310 persistenceManager.create(); 312 313 Interceptor in = interceptor; 315 while (in != null) 316 { 317 in.setContainer(this); 318 in.create(); 319 in = in.getNext(); 320 } 321 readOnly = ((EntityMetaData)metaData).isReadOnly(); 322 } 323 finally 324 { 325 SecurityActions.setContextClassLoader(oldCl); 327 } 328 } 329 330 protected void startService() throws Exception 331 { 332 ClassLoader oldCl = SecurityActions.getContextClassLoader(); 334 SecurityActions.setContextClassLoader(getClassLoader()); 335 336 try 337 { 338 super.startService(); 340 341 for (Iterator it = proxyFactories.keySet().iterator(); it.hasNext(); ) 343 { 344 String invokerBinding = (String )it.next(); 345 EJBProxyFactory ci = (EJBProxyFactory)proxyFactories.get(invokerBinding); 346 ci.start(); 347 } 348 349 instanceCache.start(); 351 352 instancePool.start(); 354 355 Interceptor i = interceptor; 356 while(i != null) 357 { 358 i.start(); 359 i = i.getNext(); 360 } 361 362 restoreTimers(); 364 } 365 finally 366 { 367 SecurityActions.setContextClassLoader(oldCl); 369 } 370 } 371 372 protected void stopService() throws Exception 373 { 374 ClassLoader oldCl = SecurityActions.getContextClassLoader(); 376 SecurityActions.setContextClassLoader(getClassLoader()); 377 378 try 379 { 380 Interceptor in = interceptor; 385 while (in != null) 386 { 387 in.stop(); 388 in = in.getNext(); 389 } 390 391 instancePool.stop(); 393 394 395 persistenceManager.stop(); 397 398 instanceCache.stop(); 400 401 for (Iterator it = proxyFactories.keySet().iterator(); it.hasNext(); ) 403 { 404 String invokerBinding = (String )it.next(); 405 EJBProxyFactory ci = (EJBProxyFactory)proxyFactories.get(invokerBinding); 406 ci.stop(); 407 } 408 409 super.stopService(); 411 } 412 finally 413 { 414 SecurityActions.setContextClassLoader(oldCl); 416 } 417 } 418 419 protected void destroyService() throws Exception 420 { 421 ClassLoader oldCl = SecurityActions.getContextClassLoader(); 423 SecurityActions.setContextClassLoader(getClassLoader()); 424 425 try 426 { 427 for (Iterator it = proxyFactories.keySet().iterator(); it.hasNext(); ) 429 { 430 String invokerBinding = (String )it.next(); 431 EJBProxyFactory ci = (EJBProxyFactory)proxyFactories.get(invokerBinding); 432 ci.destroy(); 433 } 434 435 instanceCache.destroy(); 437 instanceCache.setContainer(null); 438 try 439 { 440 ObjectName containerName = super.getJmxName(); 441 Hashtable props = containerName.getKeyPropertyList(); 442 props.put("plugin", "cache"); 443 ObjectName cacheName = new ObjectName (containerName.getDomain(), props); 444 server.unregisterMBean(cacheName); 445 } 446 catch(Throwable ignore) 447 { 448 } 449 450 persistenceManager.destroy(); 452 persistenceManager.setContainer(null); 453 454 instancePool.destroy(); 456 instancePool.setContainer(null); 457 try 458 { 459 ObjectName containerName = super.getJmxName(); 460 Hashtable props = containerName.getKeyPropertyList(); 461 props.put("plugin", "pool"); 462 ObjectName poolName = new ObjectName (containerName.getDomain(), props); 463 server.unregisterMBean(poolName); 464 } 465 catch(Throwable ignore) 466 { 467 } 468 469 Interceptor in = interceptor; 471 while (in != null) 472 { 473 in.destroy(); 474 in.setContainer(null); 475 in = in.getNext(); 476 } 477 478 MarshalledInvocation.removeHashes(homeInterface); 479 MarshalledInvocation.removeHashes(remoteInterface); 480 481 super.destroyService(); 483 } 484 finally 485 { 486 SecurityActions.setContextClassLoader(oldCl); 488 } 489 } 490 491 public Object internalInvokeHome(Invocation mi) throws Exception 492 { 493 Method method = mi.getMethod(); 494 if (method != null && method.getName().equals("remove")) 495 { 496 InvocationType type = mi.getType(); 498 if (type == InvocationType.HOME) 499 mi.setType(InvocationType.REMOTE); 500 else if (type == InvocationType.LOCALHOME) 501 mi.setType(InvocationType.LOCAL); 502 mi.setMethod(EJBOBJECT_REMOVE); 503 504 Object arg = mi.getArguments()[0]; 506 if (arg instanceof Handle ) 507 { 508 if (arg == null) 509 throw new RemoteException ("Null handle"); 510 Handle handle = (Handle ) arg; 511 EJBObject ejbObject = handle.getEJBObject(); 512 mi.setId(ejbObject.getPrimaryKey()); 513 } 514 else 515 mi.setId(arg); 516 517 mi.setArguments(new Object [0]); 518 return getInterceptor().invoke(mi); 519 } 520 return getInterceptor().invokeHome(mi); 521 } 522 523 public Object internalInvoke(Invocation mi) throws Exception 524 { 525 return getInterceptor().invoke(mi); 527 } 528 529 531 public void remove(Invocation mi) 532 throws RemoteException , RemoveException 533 { 534 Transaction tx = mi.getTransaction(); 537 if (!getBeanMetaData().getContainerConfiguration().getSyncOnCommitOnly()) 538 synchronizeEntitiesWithinTransaction(tx); 539 540 EntityEnterpriseContext ctx = (EntityEnterpriseContext)mi.getEnterpriseContext(); 542 getPersistenceManager().removeEntity(ctx); 543 544 Object pk = ctx.getId(); 545 removeTimerService(pk); 546 547 ctx.setId(null); 552 removeCount++; 553 } 554 555 558 public Handle getHandle(Invocation mi) 559 throws RemoteException 560 { 561 throw new Error ("Not yet implemented"); 563 } 564 565 public Object getPrimaryKey(Invocation mi) 566 throws RemoteException 567 { 568 return mi.getId(); 569 } 570 571 574 public EJBHome getEJBHome(Invocation mi) 575 throws RemoteException 576 { 577 EJBProxyFactory ci = getProxyFactory(); 578 if (ci == null) 579 { 580 String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor"; 581 throw new IllegalStateException (msg); 582 } 583 return (EJBHome ) ci.getEJBHome(); 584 } 585 586 public boolean isIdentical(Invocation mi) 587 throws RemoteException 588 { 589 EJBProxyFactory ci = getProxyFactory(); 590 if (ci == null) 591 { 592 String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor"; 593 throw new IllegalStateException (msg); 594 } 595 596 return ci.isIdentical(this, mi); 597 } 598 599 602 public EJBLocalHome getEJBLocalHome(Invocation mi) 603 { 604 return localProxyFactory.getEJBLocalHome(); 605 } 606 607 610 public void removeLocalHome(Invocation mi) 611 throws RemoteException , RemoveException 612 { 613 throw new Error ("Not Yet Implemented"); 614 } 615 616 619 public EJBLocalObject createLocalHome(Invocation mi) 620 throws Exception 621 { 622 final EntityEnterpriseContext ctx = (EntityEnterpriseContext)mi.getEnterpriseContext(); 624 getPersistenceManager().createEntity(mi.getMethod(), mi.getArguments(), ctx); 625 626 createCount++; 628 return localProxyFactory.getEntityEJBLocalObject(ctx.getId(), true); 629 } 630 631 634 public void postCreateLocalHome(Invocation mi) throws Exception 635 { 636 getPersistenceManager().postCreateEntity(mi.getMethod(),mi.getArguments(), 638 (EntityEnterpriseContext) mi.getEnterpriseContext()); 639 } 640 641 public Object findLocal(Invocation mi) 642 throws Exception 643 { 644 Method method = mi.getMethod(); 645 Object [] args = mi.getArguments(); 646 EntityEnterpriseContext instance = (EntityEnterpriseContext)mi.getEnterpriseContext(); 647 648 boolean syncOnCommitOnly = metaData.getContainerConfiguration().getSyncOnCommitOnly(); 649 Transaction tx = mi.getTransaction(); 650 651 Class returnType = method.getReturnType(); 652 if (Collection .class.isAssignableFrom(returnType) || returnType == Enumeration .class) 653 { 654 if (!syncOnCommitOnly) 656 { 657 synchronizeEntitiesWithinTransaction(tx); 658 } 659 660 Collection c = getPersistenceManager().findEntities(method, args, instance, localProxyFactory); 662 663 if (returnType == Enumeration .class) 665 { 666 return java.util.Collections.enumeration(c); 667 } 668 else 669 { 670 return c; 671 } 672 } 673 else 674 { 675 return findSingleObject(tx, method, args, instance, localProxyFactory); 676 } 677 } 678 679 681 686 public Object find(Invocation mi) throws Exception 687 { 688 EJBProxyFactory ci = getProxyFactory(); 689 if (ci == null) 690 { 691 String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor"; 692 throw new IllegalStateException (msg); 693 } 694 695 Method method = mi.getMethod(); 696 Object [] args = mi.getArguments(); 697 EntityEnterpriseContext instance = (EntityEnterpriseContext)mi.getEnterpriseContext(); 698 699 boolean syncOnCommitOnly = metaData.getContainerConfiguration().getSyncOnCommitOnly(); 700 Transaction tx = mi.getTransaction(); 701 702 Class returnType = method.getReturnType(); 703 if (Collection .class.isAssignableFrom(returnType) || returnType == Enumeration .class) 704 { 705 if (!syncOnCommitOnly) 707 { 708 synchronizeEntitiesWithinTransaction(tx); 709 } 710 711 Collection c = getPersistenceManager().findEntities(method, args, instance, ci); 713 714 if (returnType == Enumeration .class) 717 { 718 return new SerializableEnumeration(c); 719 } 720 else 721 { 722 return c; 723 } 724 } 725 else 726 { 727 return findSingleObject(tx, method, args, instance, ci); 728 } 729 } 730 731 736 public void invokeEjbStore(EntityEnterpriseContext ctx) throws Exception 737 { 738 if (ctx.getId() != null) 739 { 740 final EntityPersistenceManager pm = getPersistenceManager(); 741 pm.invokeEjbStore(ctx); 742 } 743 } 744 745 748 public void storeEntity(EntityEnterpriseContext ctx) throws Exception 749 { 750 if (ctx.getId() != null) 751 { 752 final EntityPersistenceManager pm = getPersistenceManager(); 753 if(pm.isStoreRequired(ctx)) 754 { 755 pm.storeEntity(ctx); 756 } 757 } 758 } 759 760 763 public void postCreateHome(Invocation mi) throws Exception 764 { 765 getPersistenceManager().postCreateEntity(mi.getMethod(),mi.getArguments(), 767 (EntityEnterpriseContext) mi.getEnterpriseContext()); 768 } 769 770 774 public EJBObject createHome(Invocation mi) 775 throws Exception 776 { 777 getPersistenceManager().createEntity(mi.getMethod(),mi.getArguments(), 779 (EntityEnterpriseContext) mi.getEnterpriseContext()); 780 781 createCount++; 783 return ((EntityEnterpriseContext)mi.getEnterpriseContext()).getEJBObject(); 784 } 785 786 789 public EJBObject getEJBObject(Invocation mi) 790 throws RemoteException 791 { 792 EJBProxyFactory ci = getProxyFactory(); 793 if (ci == null) 794 { 795 String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor"; 796 throw new IllegalStateException (msg); 797 } 798 return (EJBObject )ci.getEntityEJBObject(((EntityCache) instanceCache).createCacheKey(mi.getId())); 800 } 801 802 804 807 public void removeHome(Invocation mi) 808 throws RemoteException , RemoveException 809 { 810 throw new Error ("Not yet implemented"); 811 } 812 813 public EJBMetaData getEJBMetaDataHome(Invocation mi) 814 throws RemoteException 815 { 816 EJBProxyFactory ci = getProxyFactory(); 817 if (ci == null) 818 { 819 String msg = "No ProxyFactory, check for ProxyFactoryFinderInterceptor"; 820 throw new IllegalStateException (msg); 821 } 822 return ci.getEJBMetaData(); 823 } 824 825 828 public HomeHandle getHomeHandleHome(Invocation mi) 829 throws RemoteException 830 { 831 throw new Error ("Not yet implemented"); 833 } 834 835 839 public long getCacheSize() 840 { 841 return instanceCache.getCacheSize(); 842 } 843 844 847 public void flushCache() 848 { 849 instanceCache.flush(); 850 } 851 852 854 public Map retrieveStatistic() 855 { 856 Map lStatistics = new HashMap (); 858 StatisticsProvider lProvider = (StatisticsProvider) getPersistenceManager(); 859 lStatistics.putAll( lProvider.retrieveStatistic() ); 860 lProvider = (StatisticsProvider) getInstancePool(); 861 lStatistics.putAll( lProvider.retrieveStatistic() ); 862 return lStatistics; 863 } 864 865 public void resetStatistic() 866 { 867 } 868 869 871 private void setupHomeMappingImpl(Method [] m, 872 String finderName, 873 String append) 874 throws Exception 875 { 876 boolean isEJB1x = metaData.getApplicationMetaData().isEJB1x(); 878 879 for (int i = 0; i < m.length; i++) 880 { 881 String methodName = m[i].getName(); 882 try 883 { 884 try { 886 String ejbHomeMethodName = "ejbHome" + methodName.substring(0,1).toUpperCase() + methodName.substring(1); 887 homeMapping.put(m[i], beanClass.getMethod(ejbHomeMethodName, m[i].getParameterTypes())); 888 889 continue; 890 } 891 catch (NoSuchMethodException ignore) {} 893 894 if (methodName.startsWith("find")) 896 { 897 homeMapping.put(m[i], this.getClass().getMethod(finderName, new Class [] { Invocation.class })); 898 } 899 else if (methodName.equals("create") || 900 (isEJB1x == false && methodName.startsWith("create"))) 901 { 902 homeMapping.put(m[i], this.getClass().getMethod("create"+append, new Class [] { Invocation.class })); 903 beanMapping.put(m[i], this.getClass().getMethod("postCreate"+append, new Class [] { Invocation.class })); 904 } 905 else 906 { 907 homeMapping.put(m[i], this.getClass().getMethod(methodName+append, new Class [] { Invocation.class })); 908 } 909 } 910 catch (NoSuchMethodException e) 911 { 912 throw new NoSuchMethodException ("Could not find matching method for "+m[i]); 913 } 914 } 915 } 916 917 protected void setupHomeMapping() throws Exception 918 { 919 try { 920 if (homeInterface != null) 921 { 922 Method [] m = homeInterface.getMethods(); 923 setupHomeMappingImpl( m, "find", "Home" ); 924 } 925 if (localHomeInterface != null) 926 { 927 Method [] m = localHomeInterface.getMethods(); 928 setupHomeMappingImpl( m, "findLocal", "LocalHome" ); 929 } 930 931 933 Class handleClass = Class.forName("javax.ejb.Handle"); 935 936 Method [] handleMethods = handleClass.getMethods(); 938 939 for (int j=0; j<handleMethods.length ;j++) 941 { 942 if (handleMethods[j].getName().equals("getEJBObject")) 944 { 945 homeMapping.put(handleMethods[j], 947 this.getClass().getMethod("getEJBObject", 948 new Class [] {Invocation.class})); 949 } 950 } 951 } 952 catch (Exception e) 953 { 954 homeMapping.clear(); 956 beanMapping.clear(); 957 958 throw e; 959 } 960 } 961 962 private void setupBeanMappingImpl( Method [] m, String intfName ) 963 throws Exception 964 { 965 for (int i = 0; i < m.length; i++) 966 { 967 if (!m[i].getDeclaringClass().getName().equals(intfName)) 968 { 969 beanMapping.put(m[i], beanClass.getMethod(m[i].getName(), m[i].getParameterTypes())); 971 } 972 else 973 { 974 beanMapping.put(m[i], getClass().getMethod(m[i].getName(), 976 new Class [] { Invocation.class })); 977 } 978 } 979 } 980 981 protected void setupBeanMapping() throws Exception 982 { 983 try { 984 if (remoteInterface != null) 985 { 986 Method [] m = remoteInterface.getMethods(); 987 setupBeanMappingImpl( m, "javax.ejb.EJBObject" ); 988 } 989 if (localInterface != null) 990 { 991 Method [] m = localInterface.getMethods(); 992 setupBeanMappingImpl( m, "javax.ejb.EJBLocalObject" ); 993 } 994 if( TimedObject .class.isAssignableFrom( beanClass ) ) { 995 beanMapping.put( 997 TimedObject .class.getMethod( "ejbTimeout", new Class [] { Timer .class } ), 998 beanClass.getMethod( "ejbTimeout", new Class [] { Timer .class } ) 999 ); 1000 } 1001 } 1002 catch (Exception e) 1003 { 1004 homeMapping.clear(); 1006 beanMapping.clear(); 1007 1008 throw e; 1009 } 1010 } 1011 1012 protected void setupMarshalledInvocationMapping() throws Exception 1013 { 1014 if (homeInterface != null) 1016 { 1017 Method [] m = homeInterface.getMethods(); 1018 for (int i = 0 ; i<m.length ; i++) 1019 { 1020 marshalledInvocationMapping.put( new Long (MarshalledInvocation.calculateHash(m[i])), m[i]); 1021 } 1022 } 1023 1024 if (remoteInterface != null) 1025 { 1026 Method [] m = remoteInterface.getMethods(); 1027 for (int j = 0 ; j<m.length ; j++) 1028 { 1029 marshalledInvocationMapping.put( new Long (MarshalledInvocation.calculateHash(m[j])), m[j]); 1030 } 1031 } 1032 1033 Method getEJBObjectMethod = Class.forName("javax.ejb.Handle").getMethod("getEJBObject", new Class [0]); 1035 1036 marshalledInvocationMapping.put(new Long (MarshalledInvocation.calculateHash(getEJBObjectMethod)),getEJBObjectMethod); 1038 } 1039 1040 Interceptor createContainerInterceptor() 1041 { 1042 return new ContainerInterceptor(); 1043 } 1044 1045 protected void checkCoherency () throws Exception 1046 { 1047 if (metaData.isClustered()) 1050 { 1051 boolean clusteredProxyFactoryFound = false; 1052 for (Iterator it = proxyFactories.keySet().iterator(); it.hasNext(); ) 1053 { 1054 String invokerBinding = (String )it.next(); 1055 EJBProxyFactory ci = (EJBProxyFactory)proxyFactories.get(invokerBinding); 1056 if (ci instanceof org.jboss.proxy.ejb.ClusterProxyFactory) 1057 clusteredProxyFactoryFound = true; 1058 } 1059 1060 if (!clusteredProxyFactoryFound) 1061 { 1062 log.warn("*** EJB '" + this.metaData.getEjbName() + "' deployed as CLUSTERED but not a single clustered-invoker is bound to container ***"); 1063 } 1064 } 1065 } 1066 1067 private Object findSingleObject(Transaction tx, 1068 Method method, 1069 Object [] args, 1070 EntityEnterpriseContext instance, 1071 GenericEntityObjectFactory factory) 1072 throws Exception 1073 { 1074 if(method.getName().equals("findByPrimaryKey")) 1075 { 1076 if(args[0] == null) 1077 throw new IllegalArgumentException ("findByPrimaryKey called with null argument."); 1078 1079 if(metaData.getContainerConfiguration().getCommitOption() != ConfigurationMetaData.B_COMMIT_OPTION) 1080 { 1081 Object key = instance.getCacheKey(); 1082 if(key == null) 1083 { 1084 key = ((EntityCache)instanceCache).createCacheKey(args[0]); 1085 } 1086 1087 if(instanceCache.isActive(key)) 1088 { 1089 return factory.getEntityEJBObject(key); 1090 } 1091 } 1092 } 1093 else if(!metaData.getContainerConfiguration().getSyncOnCommitOnly()) 1094 { 1095 EntityContainer.synchronizeEntitiesWithinTransaction(tx); 1096 } 1097 1098 return getPersistenceManager().findEntity(method, args, instance, factory); 1099 } 1100 1101 1103 1106 class ContainerInterceptor 1107 extends AbstractContainerInterceptor 1108 { 1109 public Object invokeHome(Invocation mi) throws Exception 1110 { 1111 Method miMethod = mi.getMethod(); 1113 Method m = (Method ) homeMapping.get(miMethod); 1114 if( m == null ) 1115 { 1116 String msg = "Invalid invocation, check your deployment packaging" 1117 +", method="+miMethod; 1118 throw new EJBException (msg); 1119 } 1120 1121 if (m.getDeclaringClass().equals(EntityContainer.class)) 1122 { 1123 try 1124 { 1125 return mi.performCall(EntityContainer.this, m, new Object [] { mi }); 1126 } 1127 catch (Exception e) 1128 { 1129 rethrow(e); 1130 } 1131 } 1132 else { 1134 EnterpriseContext ctx = (EnterpriseContext) mi.getEnterpriseContext(); 1135 try 1136 { 1137 AllowedOperationsAssociation.pushInMethodFlag(AllowedOperationsAssociation.IN_EJB_HOME); 1138 return mi.performCall(ctx.getInstance(), m, mi.getArguments()); 1139 } 1140 catch (Exception e) 1141 { 1142 rethrow(e); 1143 } 1144 finally{ 1145 AllowedOperationsAssociation.popInMethodFlag(); 1146 } 1147 } 1148 1149 throw new org.jboss.util.UnreachableStatementException(); 1151 } 1152 1153 public Object invoke(Invocation mi) throws Exception 1154 { 1155 Method miMethod = mi.getMethod(); 1157 Method m = (Method ) beanMapping.get(miMethod); 1158 if( m == null ) 1159 { 1160 String msg = "Invalid invocation, check your deployment packaging" 1161 +", method="+miMethod; 1162 throw new EJBException (msg); 1163 } 1164 1165 if (m.getDeclaringClass().equals(EntityContainer.class)) 1167 { 1168 try 1170 { 1171 return mi.performCall(EntityContainer.this, m, new Object []{ mi }); 1172 } 1173 catch (Exception e) 1174 { 1175 rethrow(e); 1176 } 1177 } 1178 else 1179 { 1180 try 1182 { 1183 EnterpriseContext ctx = (EnterpriseContext) mi.getEnterpriseContext(); 1184 Object instance = ctx.getInstance(); 1185 1186 return mi.performCall(instance, m, mi.getArguments()); 1187 } 1188 catch (Exception e) 1189 { 1190 rethrow(e); 1191 } 1192 } 1193 1194 throw new org.jboss.util.UnreachableStatementException(); 1196 } 1197 } 1198} 1199 | Popular Tags |