1 23 24 25 26 31 32 package com.sun.jdo.spi.persistence.support.ejb.cmp; 33 34 import java.util.Collection ; 35 import java.util.Set ; 36 37 import javax.ejb.EJBLocalObject ; 38 import javax.ejb.EJBException ; 39 import javax.ejb.EJBContext ; 40 41 import com.sun.jdo.api.persistence.support.PersistenceManager; 42 import com.sun.jdo.api.persistence.support.JDOHelper; 43 import com.sun.jdo.spi.persistence.support.sqlstore.ejb.CMPHelper; 44 import com.sun.jdo.spi.persistence.support.sqlstore.ejb.JDOEJB20Helper; 45 import com.sun.jdo.spi.persistence.utility.logging.Logger; 46 import com.sun.jdo.spi.persistence.utility.I18NHelper; 47 48 49 57 abstract public class JDOEJB20HelperImpl extends JDOEJB11HelperImpl 58 implements JDOEJB20Helper { 59 60 66 public EJBLocalObject convertPCToEJBLocalObject (Object pc, PersistenceManager pm) { 67 if (pc == null) return null; 68 Object jdoObjectId = pm.getObjectId(pc); 69 Object key = convertObjectIdToPrimaryKey(jdoObjectId); 70 try { 71 return CMPHelper.getEJBLocalObject(key, getContainer()); 72 } catch (Exception ex) { 73 EJBException e = new EJBException (I18NHelper.getMessage(messages, 74 "EXC_ConvertPCToEJBLocalObject", key.toString()), ex); logger.throwing("JDOEJB20HelperImpl", "convertPCToEJBLocalObject", e); throw e; 77 } 78 } 79 80 88 public EJBLocalObject convertPCToEJBLocalObject (Object pc, PersistenceManager pm, 89 EJBContext context) { 90 if (pc == null) return null; 91 Object jdoObjectId = pm.getObjectId(pc); 92 Object key = convertObjectIdToPrimaryKey(jdoObjectId); 93 try { 94 return CMPHelper.getEJBLocalObject(key, getContainer(), context); 95 } catch (Exception ex) { 96 EJBException e = new EJBException (I18NHelper.getMessage(messages, 97 "EXC_ConvertPCToEJBLocalObjectCtx", key.toString()), ex); logger.throwing("JDOEJB20HelperImpl", "convertPCToEJBLocalObjectCtx", e); throw e; 100 } 101 } 102 103 112 public Object convertEJBLocalObjectToPC(EJBLocalObject o, PersistenceManager pm, boolean validate) { 113 Object key = null; 114 try { 115 key = o.getPrimaryKey(); 116 } catch (Exception ex) { 117 EJBException e = new EJBException (I18NHelper.getMessage(messages, 118 "EXC_ConvertEJBObjectToPC", o.getClass().getName()), ex); logger.throwing("JDOEJB20HelperImpl", "convertEJBLocalObjectToPC", e); throw e; 121 } 122 return convertPrimaryKeyToPC(key, pm, validate); 123 } 124 125 132 public Collection convertCollectionPCToEJBLocalObject (Collection pcs, PersistenceManager pm){ 133 Collection rc = new java.util.ArrayList (); 134 Object o = null; 135 boolean debug = false; 136 137 for (java.util.Iterator it = pcs.iterator(); it.hasNext();) { 138 o = convertPCToEJBLocalObject((Object )it.next(), pm); 139 if(logger.isLoggable(Logger.FINEST) ) { 140 logger.finest( 141 "\n---JDOEJB20HelperImpl.convertCollectionPCToEJBLocalObject() adding: " + o); } 143 rc.add(o); 144 } 145 return rc; 146 } 147 148 155 public Set convertCollectionPCToEJBLocalObjectSet (Collection pcs, PersistenceManager pm) { 156 java.util.Set rc = new java.util.HashSet (); 157 Object o = null; 158 159 boolean debug = false; 160 161 for (java.util.Iterator it = pcs.iterator(); it.hasNext();) { 162 o = convertPCToEJBLocalObject((Object )it.next(), pm); 163 if(logger.isLoggable(Logger.FINEST) ) { 164 logger.finest( 165 "\n---JDOEJB20HelperImpl.convertCollectionPCToEJBLocalObjectSet() adding: " + o); } 167 rc.add(o); 168 } 169 return rc; 170 } 171 172 182 public Collection convertCollectionEJBLocalObjectToPC (Collection coll, PersistenceManager pm, 183 boolean validate) { 184 Collection rc = new java.util.ArrayList (); 185 Object o = null; 186 187 boolean debug = false; 188 189 for (java.util.Iterator it = coll.iterator(); it.hasNext();) { 190 o = convertEJBLocalObjectToPC((EJBLocalObject )it.next(), pm, validate); 191 if(logger.isLoggable(Logger.FINEST) ) { 192 logger.finest( 193 "\n---JDOEJB20HelperImpl.convertCollectionEJBLocalObjectToPC() adding: " + o); } 195 rc.add(o); 196 } 197 return rc; 198 } 199 200 208 abstract public void assertInstanceOfLocalInterfaceImpl(Object o); 209 210 220 protected void assertInstanceOfLocalInterfaceImpl(Object o, 221 String beanName) { 222 223 if (o == null) 226 return; 227 228 try { 229 CMPHelper.assertValidLocalObject(o, getContainer()); 230 231 } catch (EJBException ex) { 232 String msg = I18NHelper.getMessage(messages, "EXC_WrongLocalInstance", new Object [] {o.getClass().getName(), beanName, 234 ex.getMessage()}); 235 logger.log(Logger.WARNING, msg); 236 throw new IllegalArgumentException (msg); 237 } 238 } 239 240 } 241 | Popular Tags |