1 package org.apache.ojb.broker.core; 2 3 17 18 import java.rmi.RemoteException ; 19 import java.util.Collection ; 20 import java.util.Enumeration ; 21 import java.util.Iterator ; 22 23 import javax.ejb.EJBException ; 24 import javax.ejb.SessionBean ; 25 import javax.ejb.SessionContext ; 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 30 import org.apache.ojb.broker.Identity; 31 import org.apache.ojb.broker.IdentityFactory; 32 import org.apache.ojb.broker.ManageableCollection; 33 import org.apache.ojb.broker.MtoNImplementor; 34 import org.apache.ojb.broker.PBKey; 35 import org.apache.ojb.broker.PBLifeCycleEvent; 36 import org.apache.ojb.broker.PBListener; 37 import org.apache.ojb.broker.PBStateEvent; 38 import org.apache.ojb.broker.PersistenceBroker; 39 import org.apache.ojb.broker.PersistenceBrokerEvent; 40 import org.apache.ojb.broker.PersistenceBrokerException; 41 import org.apache.ojb.broker.PersistenceBrokerInternal; 42 import org.apache.ojb.broker.TransactionAbortedException; 43 import org.apache.ojb.broker.TransactionInProgressException; 44 import org.apache.ojb.broker.TransactionNotInProgressException; 45 import org.apache.ojb.broker.accesslayer.ConnectionManagerIF; 46 import org.apache.ojb.broker.accesslayer.JdbcAccess; 47 import org.apache.ojb.broker.accesslayer.StatementManagerIF; 48 import org.apache.ojb.broker.accesslayer.sql.SqlGenerator; 49 import org.apache.ojb.broker.cache.ObjectCache; 50 import org.apache.ojb.broker.core.proxy.ProxyFactory; 51 import org.apache.ojb.broker.metadata.ClassDescriptor; 52 import org.apache.ojb.broker.metadata.DescriptorRepository; 53 import org.apache.ojb.broker.query.Query; 54 import org.apache.ojb.broker.util.BrokerHelper; 55 import org.apache.ojb.broker.util.ObjectModification; 56 import org.apache.ojb.broker.util.configuration.Configuration; 57 import org.apache.ojb.broker.util.configuration.ConfigurationException; 58 import org.apache.ojb.broker.util.logging.Logger; 59 import org.apache.ojb.broker.util.logging.LoggerFactory; 60 import org.apache.ojb.broker.util.sequence.SequenceManager; 61 62 105 106 public class PersistenceBrokerBean implements PersistenceBroker, SessionBean 107 { 108 private Logger m_log; 109 private SessionContext m_ctx; 110 private String m_ojbRepository; 111 private PBKey m_pbKey; 112 private PersistenceBrokerFactoryIF m_pbf; 113 114 118 public DescriptorRepository getDescriptorRepository() 119 { 120 return getBroker().getDescriptorRepository(); 121 } 122 123 127 public PBKey getPBKey() 128 { 129 return getBroker().getPBKey(); 130 } 131 132 136 public void delete(Object obj) throws PersistenceBrokerException 137 { 138 getBroker().delete(obj); 139 } 140 141 145 public void deleteByQuery(Query query) throws PersistenceBrokerException 146 { 147 getBroker().deleteByQuery(query); 148 } 149 150 154 public void removeFromCache(Object obj) throws PersistenceBrokerException 155 { 156 getBroker().removeFromCache(obj); 157 } 158 159 163 public void clearCache() throws PersistenceBrokerException 164 { 165 getBroker().clearCache(); 166 } 167 168 172 public void store(Object obj) throws PersistenceBrokerException 173 { 174 getBroker().store(obj); 175 } 176 177 181 public void abortTransaction() throws TransactionNotInProgressException 182 { 183 getBroker().abortTransaction(); 184 } 185 186 190 public void beginTransaction() 191 throws TransactionInProgressException, TransactionAbortedException 192 { 193 getBroker().beginTransaction(); 194 } 195 196 200 public void commitTransaction() 201 throws TransactionNotInProgressException, TransactionAbortedException 202 { 203 getBroker().commitTransaction(); 204 } 205 206 210 public boolean isInTransaction() throws PersistenceBrokerException 211 { 212 return getBroker().isInTransaction(); 213 } 214 215 219 public boolean close() 220 { 221 return getBroker().close(); 222 } 223 224 public boolean isClosed() 225 { 226 return getBroker().isClosed(); 227 } 228 229 233 public Collection getCollectionByQuery(Query query) 234 throws PersistenceBrokerException 235 { 236 return getBroker().getCollectionByQuery(query); 237 } 238 239 243 public int getCount(Query query) throws PersistenceBrokerException 244 { 245 return getBroker().getCount(query); 246 } 247 248 252 public ManageableCollection getCollectionByQuery( 253 Class collectionClass, 254 Query query) 255 throws PersistenceBrokerException 256 { 257 return getBroker().getCollectionByQuery(collectionClass, query); 258 } 259 260 264 public Iterator getIteratorByQuery(Query query) 265 throws PersistenceBrokerException 266 { 267 return getBroker().getIteratorByQuery(query); 268 } 269 270 274 public Iterator getReportQueryIteratorByQuery(Query query) 275 throws PersistenceBrokerException 276 { 277 return getBroker().getReportQueryIteratorByQuery(query); 278 } 279 280 284 public Object getObjectByIdentity(Identity id) 285 throws PersistenceBrokerException 286 { 287 return getBroker().getObjectByIdentity(id); 288 } 289 290 294 public Object getObjectByQuery(Query query) 295 throws PersistenceBrokerException 296 { 297 return getBroker().getObjectByQuery(query); 298 } 299 300 304 public Enumeration getPKEnumerationByQuery( 305 Class PrimaryKeyClass, 306 Query query) 307 throws PersistenceBrokerException 308 { 309 return getBroker().getPKEnumerationByQuery(PrimaryKeyClass, query); 310 } 311 312 316 public void store(Object obj, ObjectModification modification) 317 throws PersistenceBrokerException 318 { 319 getBroker().store(obj, modification); 320 } 321 322 323 327 public ClassDescriptor getClassDescriptor(Class clazz) 328 throws PersistenceBrokerException 329 { 330 return getBroker().getClassDescriptor(clazz); 331 } 332 333 337 public boolean hasClassDescriptor(Class clazz) 338 { 339 return getBroker().hasClassDescriptor(clazz); 340 } 341 342 343 347 public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException 348 { 349 return getBroker().getTopLevelClass(clazz); 350 } 351 352 356 public StatementManagerIF serviceStatementManager() 357 { 358 return getBroker().serviceStatementManager(); 359 } 360 361 365 public ConnectionManagerIF serviceConnectionManager() 366 { 367 return getBroker().serviceConnectionManager(); 368 } 369 370 public JdbcAccess serviceJdbcAccess() 371 { 372 return getBroker().serviceJdbcAccess(); 373 } 374 375 379 public SqlGenerator serviceSqlGenerator() 380 { 381 return getBroker().serviceSqlGenerator(); 382 } 383 384 public SequenceManager serviceSequenceManager() 385 { 386 return getBroker().serviceSequenceManager(); 387 } 388 389 public BrokerHelper serviceBrokerHelper() 390 { 391 return getBroker().serviceBrokerHelper(); 392 } 393 394 public ObjectCache serviceObjectCache() 395 { 396 return getBroker().serviceObjectCache(); 397 } 398 399 public IdentityFactory serviceIdentity() 400 { 401 return getBroker().serviceIdentity(); 402 } 403 404 public void fireBrokerEvent(PersistenceBrokerEvent event) 405 { 406 getBroker().fireBrokerEvent(event); 407 } 408 409 public void fireBrokerEvent(PBLifeCycleEvent event) 410 { 411 getBroker().fireBrokerEvent(event); 412 } 413 414 public void fireBrokerEvent(PBStateEvent event) 415 { 416 getBroker().fireBrokerEvent(event); 417 } 418 419 420 421 public ProxyFactory getProxyFactory() { 422 return getBroker().getProxyFactory(); 423 } 424 425 public Object createProxy(Class proxyClass, Identity realSubjectsIdentity) { 426 return getBroker().createProxy(proxyClass, realSubjectsIdentity); 427 } 428 429 433 public void addListener(PBListener listener) throws PersistenceBrokerException 434 { 435 getBroker().addListener(listener); 436 } 437 438 442 public void addListener(PBListener listener, boolean permanent) throws PersistenceBrokerException 443 { 444 getBroker().addListener(listener, permanent); 445 } 446 447 451 public void removeListener(PBListener listener) throws PersistenceBrokerException 452 { 453 getBroker().removeListener(listener); 454 } 455 456 460 public void retrieveAllReferences(Object pInstance) 461 throws PersistenceBrokerException 462 { 463 getBroker().retrieveAllReferences(pInstance); 464 } 465 466 470 public void retrieveReference(Object pInstance, String pAttributeName) 471 throws PersistenceBrokerException 472 { 473 getBroker().retrieveReference(pInstance, pAttributeName); 474 } 475 476 public void removeAllListeners(boolean permanent) throws PersistenceBrokerException 477 { 478 getBroker().removeAllListeners(permanent); 479 } 480 481 485 public void removeAllListeners() throws PersistenceBrokerException 486 { 487 getBroker().removeAllListeners(); 488 } 489 490 494 public void configure(Configuration pConfig) 495 throws ConfigurationException 496 { 497 getBroker().configure(pConfig); 498 } 499 500 504 public org.odbms.Query query() 505 { 506 return getBroker().query(); 507 } 508 509 private void ojbPrepare() 510 { 511 if (m_log.isDebugEnabled()) m_log.info("PersistenceBrokerBean: ejbActivate was called"); 512 Context context = null; 513 String ojbRepository = null; 515 try 516 { 517 context = new InitialContext (); 518 ojbRepository = (String ) context.lookup("java:comp/env/ojb.repository"); 519 } 520 catch (NamingException e) 521 { 522 m_log.error("Lookup for ojb repository failed", e); 523 } 524 if (ojbRepository == null || ojbRepository.equals("")) 526 { 527 m_log.info("No enviroment entry was found, use default repository"); 528 ojbRepository = "repository.xml"; 529 } 530 m_log.info("Use OJB repository file: " + ojbRepository); 531 m_pbKey = new PBKey(ojbRepository); 532 533 try 535 { 536 context = new InitialContext (); 537 m_pbf = ((PBFactoryIF) context.lookup(PBFactoryIF.PBFACTORY_JNDI_NAME)).getInstance(); 538 } 539 catch (NamingException e) 540 { 541 m_log.error("Lookup for PersistenceBrokerFactory failed", e); 542 throw new PersistenceBrokerException(e); 543 } 544 } 545 546 public void ejbActivate() throws EJBException , RemoteException 547 { 548 m_log = LoggerFactory.getLogger(PersistenceBrokerBean.class); 549 ojbPrepare(); 550 } 551 552 public void ejbPassivate() throws EJBException , RemoteException 553 { 554 m_log = null; 555 m_pbf = null; 556 } 557 558 public void ejbRemove() throws EJBException , RemoteException 559 { 560 m_ctx = null; 561 } 562 563 public void setSessionContext(SessionContext sessionContext) throws EJBException , RemoteException 564 { 565 m_ctx = sessionContext; 566 } 567 568 private PersistenceBrokerInternal getBroker() 569 { 570 return m_pbf.createPersistenceBroker(m_pbKey); 571 } 572 573 576 public void deleteMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException 577 { 578 throw new UnsupportedOperationException (); 579 } 580 581 584 public void addMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException 585 { 586 throw new UnsupportedOperationException (); 587 } 588 589 590 } 591 | Popular Tags |