1 package org.apache.ojb.ejb.odmg; 2 3 17 18 import javax.ejb.CreateException ; 19 import javax.ejb.EJBException ; 20 import javax.ejb.SessionBean ; 21 import javax.naming.Context ; 22 import javax.naming.InitialContext ; 23 import javax.naming.NamingException ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.apache.ojb.broker.util.logging.Logger; 28 import org.apache.ojb.broker.util.logging.LoggerFactory; 29 import org.apache.ojb.ejb.SessionBeanImpl; 30 31 72 public class PersonArticleManagerODMGBean extends SessionBeanImpl implements SessionBean 73 { 74 private static final String PERSON_MANAGER_EJB_REF_NAME = "java:comp/env/ejb/ojb/odmg/PersonManager"; 75 private static final String ARTICLE_MANAGER_EJB_REF_NAME = "java:comp/env/ejb/ojb/odmg/ArticleManager"; 76 77 private Logger log = LoggerFactory.getLogger(PersonArticleManagerODMGBean.class); 78 79 private ArticleManagerODMGLocal am; 80 private PersonManagerODMGLocal pm; 81 82 public PersonArticleManagerODMGBean() 83 { 84 } 85 86 public void ejbCreate() 87 { 88 89 } 90 91 94 public List storeArticles(List articles) 95 { 96 return new ArrayList (getArticleManager().storeArticles(articles)); 97 } 98 99 102 public void deleteArticles(List articles) 103 { 104 getArticleManager().deleteArticles(articles); 105 } 106 107 110 public List storePersons(List persons) 111 { 112 return new ArrayList (getPersonManager().storePersons(persons)); 113 } 114 115 118 public void deletePersons(List persons) 119 { 120 getPersonManager().deletePersons(persons); 121 } 122 123 126 public int articleCount() 127 { 128 return getArticleManager().countArticles(); 129 } 130 131 134 public int personCount() 135 { 136 return getPersonManager().countPersons(); 137 } 138 139 private ArticleManagerODMGLocal getArticleManager() 140 { 141 if (am == null) 142 { 143 Context context = null; 144 try 145 { 146 context = new InitialContext (); 147 am = ((ArticleManagerODMGLocalHome) context.lookup(ARTICLE_MANAGER_EJB_REF_NAME)).create(); 148 log.info("** Found bean: " + am); 149 return am; 150 } 151 catch (NamingException e) 152 { 153 log.error("Lookup using ejb-ref " + ARTICLE_MANAGER_EJB_REF_NAME + " failed", e); 154 throw new EJBException (e); 155 } 156 catch (CreateException e) 157 { 158 log.error("Creation of ArticleManager failed", e); 159 throw new EJBException (e); 160 } 161 } 162 return am; 163 } 164 165 private PersonManagerODMGLocal getPersonManager() 166 { 167 if (pm == null) 168 { 169 Context context = null; 170 try 171 { 172 context = new InitialContext (); 173 pm = ((PersonManagerODMGLocalHome) context.lookup(PERSON_MANAGER_EJB_REF_NAME)).create(); 174 log.info("** Found bean: " + pm); 175 return pm; 176 } 177 catch (NamingException e) 178 { 179 log.error("Lookup using ejb-ref " + PERSON_MANAGER_EJB_REF_NAME + " failed", e); 180 throw new EJBException (e); 181 } 182 catch (CreateException e) 183 { 184 log.error("Creation of PersonManager failed", e); 185 throw new EJBException (e); 186 } 187 } 188 return pm; 189 } 190 } 191 | Popular Tags |