• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB 2.1 question

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to write code for following:

* There are 2 databases DB1 and DB2, they have same schema
* DB1 has some CAR objects, data of which needs to be transferred to DB2 via code
* CAR objects have 2 types of information - METADATA (common for a group of cars - like attribute list (color, weight, price etc.) ) and DATA (different for each car - like attribute values (red, 600kg, $10000 etc.)). There are 6 tables in total - 2 for MetaData, 4 for Data. Transfer of all CAR objects must happen in a single transaction including MetaData and Data

I am thinking of following:



Also I am thinking of using CMT to put transferCARs() in a transaction, with Required attribute for transferMetaData() and transferData() to continue the same transaction.

My questions are:

1. Should I put transferCARs() in a stateless session bean and transferMetaData() & transferData() in a BMP? Or should I put all methods in statless session bean?

2. Do you see any flaw in above thoughts and is there a better alternative?

In future I may have to add more tables to transferData() especially when we would like to transfer photo information for each CAR as well.


regards
Varun
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The business operation of moving data can be coded in a stateless Session EJB. A method signature for this operation might be:

Container Managed Transaction attributes can then be applied to the method above.

The private methods that help implement the business operation are not exposed to client objects. Hence, there is no need to apply CMT attributes to these methods.



The code in the Session EJB should use a Data Access Object for database operations (if not using Entity EJB). Raw JDBC code or Hibernate code goes in the DAO implmentation class, not the Session EJB method.
[ October 14, 2008: Message edited by: James Clark ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic