Business logic locks and CMP.

I’m trying to implement the following:
If a raw in the database (a CMP bean instance) was changed by a user then this
raw is “locked” for all other users (write lock) until the user decides to release
the lock.
The database raw has three fields: ID, UserLockID, and Data
The code in my stateless session bean façade that wraps the CMP will be:
ResourceHome home = (ResourceHome)EJBHomeFactory.getInstance().lookUpLocalHome(
“Resource” , ResourceHome.class );
Resource rsc = home.findByPrimaryKey(id);
If (rsc.getUserLockId() == null || rsc.getUserLockId() == user ){
rsc.setUserLockId(user);
rsc.setData(data);     
} else{
throw new LockException(“This raw is locked by another user”);
My questions are:
1) Do I need to worry about race conditions, for example two user accessing the
same raw at the same time and then overwriting each other changes (where the
last one wins)?
2) If the answer for 1. is Yes, should I use TransactionReadCommittedForUpdate
3) If the answer for 2 is Yes, on which methods should I define this isolation
level? The session bean method? The CMP method, which once ejbLoad? Getters and
setters?.
4) Last Question: Can I use TransactionReadCommittedForUpdate and an optimistic
concurrency strategy for the same bean?
Thanks in advance.

Why would not you just use database concurrency strategy and use dummy
update (or select for update) right before you are going to change the data?
If no one else have changed it, then the update will be successful and you
can continue with changing and committing. If someone else changed the data
(and committed it to database), you will get an exception. Looks pretty
simple and easy.
Or you can use exclusive concurrency strategy, but in this case you will not
be able to read field values from another transaction. I am not sure will
you be able even to find the bean or not. If I recall correctly, you will.
Michael Jouravlev.
"M.A." <[email protected]> wrote in message
news:3e95ca33$[email protected]..
>
I’m trying to implement the following:
If a raw in the database (a CMP bean instance) was changed by a user thenthis
raw is “locked” for all other users (write lock) until the user decides
to release
the lock.
The database raw has three fields: ID, UserLockID, and Data
The code in my stateless session bean façade that wraps the CMP will be:
ResourceHome home =(ResourceHome)EJBHomeFactory.getInstance().lookUpLocalHome(
“Resource” , ResourceHome.class );
Resource rsc = home.findByPrimaryKey(id);
If (rsc.getUserLockId() == null || rsc.getUserLockId() == user ){
rsc.setUserLockId(user);
rsc.setData(data);
} else{
throw new LockException(“This raw is locked by another user”);
My questions are:
1) Do I need to worry about race conditions, for example two useraccessing the
same raw at the same time and then overwriting each other changes (wherethe
last one wins)?
2) If the answer for 1. is Yes, should I useTransactionReadCommittedForUpdate
3) If the answer for 2 is Yes, on which methods should I define thisisolation
level? The session bean method? The CMP method, which once ejbLoad?Getters and
setters?.
4) Last Question: Can I use TransactionReadCommittedForUpdate and anoptimistic
concurrency strategy for the same bean?
Thanks in advance.

Similar Messages

  • Urgent: how to really seperate business logic class from data access class

    Hello,
    I've this problem here on my hand and i really need help urgently. so please allow me to thank anyone who replies to this thread =)
    Before i go any futhur, let me present a scenario. this will help make my question clearer.
    "A user choose to view his account information"
    here, i've attempted to do the following. i've tried to seperate my application into 3 layers, the GUI layer, the business logic layer, and the data access layer.
    classically, the GUI layer only knows which object it should invoke, for example in the case above, the GUI would instantiate an Account object and prob the displayAcctInfo method of the Account object.
    here is how my Account class looks like:
    public class Account
    private acctNo;
    private userid;
    private password;
    private Customer acctOwner;
    the way this class is being modelled is that there is a handle to a customer object.
    that being the case, when i want to retrieve back account information, how do i go about retrieveing the information on the customer? should my data access class have knowledge on how the customer is being programmed? ie setName, getName, setAge, getAge all these methods etc? if not, how do i restore the state of the Customer object nested inside?
    is there a better way to archieve the solution to my problem above? i would appriciate it for any help rendered =)
    Yours sincerely,
    Javier

    public class AccountThat looks like a business layer object to me.
    In a large application the GUI probably shouldn't ever touch business objects. It makes requests to the business layer for specific information. For example you might have a class called CustomerAccountSummary - the data for that might come entirely from the Account object or it might come from Account and Customer.
    When the GUI requests information it receives it as a 'primitive' - which is a class that has no behaviour (methods), just data. This keeps the interface between the GUI and business layer simple and makes it easier to maintain.
    When using a primitive there are four operations: query, create, update and delete.
    For a query the gui sets only the attributes in the primitive that will be specifically queried for (or a specialized primitive can be created for this.) The result of a query is either a single primitive or a collection of primitives. Each primitive will have all the attributes defined.
    For a create all of the attributes are set. The gui calls a method and passes the primtive.
    For an update, usually all fields are defined although this can vary. The gui calls a method and passes the primitive.
    For a delete, only the 'key' fields are set (more can be but they are not used.) The gui calls a method and passes the primitive.
    Also keep in mind that a clean seperation is always an idealization. For example verify that duplicate records are not created is a business logic requirement (the database doesn't care.) However, it is much easier and more efficient to handle that rule in the database rather than in the business layer.

  • Lock(Enque/Deque) is a logical lock & database lock

    Hi All,
    I have gone through various portals and SDN too, and found that locks are the logical locks and sometimes database locks too but still have some confusion.
    1) If these are the logical locks then why they are created by SE11 and once created then FM has been generated. All FM are stored somewhere right? So they would be in database.
    2) If these are the database locks then why they are at the application server level and few more things.
    Can anybody explain with the valid reasons? In which queue they fall and why?
    Thanks.
    An

    Hi Anurag,
    The SAP locks are created with naming standard EZ. They are not connected with the DB. It work like this
    You create Lock -> FM is automaically generated as follow EXample:   CALL FUNCTION 'DEQUEUE_EZARS_TRHDR_T'
        EXPORTING
    generated In your program you add CALL FUNCTION <name of your new lock enqueue FM>
    3. if object is not locked you can modify it.
    4. unlock it with second (dequeue) FM
    Information about these locks are stored in queue on specific application server (usually central instance) - in SM51 you can see it with description "Enqueue".
    So this is kind of mechanism that works if everybody goes according to rules. If someone will write it's own report were he access your objects, but he will ommitt this FM call (or ignore it's results), then he will be free to change it as he likes even if someone has already locked it.
    To use DB lockes other technices are used like SELECT SINGLE * FOR UPDATE

  • Where do I write business Logic?

    Hi,
    Where do I write bisiness Logic?
    Tutorial said "It is common practice to include the bean property and the Action
    implementation to which it refers within the same bean class".
    But I thought EventHander Impl is better to write business Logic
    like retrieving the data from database.
    Which is common use?
    Or I need to choose them depending on the situation?
    Thanks in advance for you help.
    tomo

    Thanks for the reply!!
    But I am still confused.
    I thought I can write business logic A and B.
    What is difference between A and B ??
    Hi tomo,
    In the two options you provide the difference is not that much. The ActionListener instance willhave to be registered in your JSP of course to listen to the button or hyperlink with the f:action_listner tag. But in both cases your biz logic is in your ui. I think that is the wrong direction for you to head.
    I think the real question should be (forgive me if I'm pulling the discussion away from your question, but I think this is relevant) where does the business logic go.
    As Kito said your biz logic belongs apart from your UI logic (classic MVC approach). So in the real world what does that mean? As you suggest in option B in your last post a bean provides an action so that it can be specified via the actionRef attribute. This action in turn invokes a method on the bean it comes from which then invokes the business logic on the 'real' business logic.
    The Action becomes simply a translator (or part of the Adaptor pattern from the GoF book).
    For example lets say you have a bean that does biz processing like this;
    public interface CatalogFacade {
      public Collection getProducts(ProductSearchCriteria criteria);
    }And you want to invoke that 'business logic' from your JSF UI. The button would be declared with this code
    <h:comman_button id="searchCommand" type="submit"
                        label="Search"
                        commandName="search"
                        actionRef="searchBean.searchAction"/>In your searchBean you have many options to return the searchAction but I prefer the following
    public class SearchBean {
       public SearchFacade searchFacade = null; // this could be a managed bean or an EJBSession or whatnot
       public ProductSearchCriteria productSearchCriteria = null; // this should be 'filled' in by the form the button is on
       private transient Action searchAction = new Action() {
        public String invoke() {
          return search();
      public Action getSearchAction() {
        return searchAction;
      public void search() {
        Collection products = searchFacade.search(productSearchCriteria);
        // place the products collection into the next page's bean so that is can be found via valueRef attributes
    }Notice that no database hits are happening in the UI code. Also there is no business logic here either.
    It is very important to keep these two concerns divided for ease of maintenance. The typical reasoning goes something like this, 'your ui is very likely to change so keep it separate from your business logic'. Other reasons to be careful about mixing UI and biz logic is the likely hood that you will get very different behavior (one probably wrong) if you have to and another client to your biz logic.
    For example in the earlier product search stuff. If we needed a web service front end to the 'searchProducts' functionality and we had the db hit happening in the action or page bean we would be stuck. With the above impl we get to just put a WS over the facade and we are done.
    Hope this helps.
    You can also look at some of the blueprint patterns for more info. They start here;
    http://java.sun.com/blueprints/patterns/index.html
    While some of the EJB specific patterns might be more involved than you need they provide excelent archtectural guidence for web only apps as well.
    Good luck,
    -bd-

  • Logical system and business system

    Hi experts, please help me with the below questions---
    1) What is the diff between logical system and business system?
    2)what is the difference between logical system(defined in R/3) and business system (defined in SLD) in idoc to file scenario.
    3) Is it require to give the logical system name of the xi server(Which we define in idx1 port) to the 3rd party system(Application system at the FTP side) to carry out file to idoc scerario?

    Hi,
    Business System :
    1. Business systems are logical systems, which function as senders or receivers within XI. Business systems can be SAP systems or third-party systems. Depending on the associated technical system.
    2. Business Systems should be mandatory used when dealing with Idoc's and Proxies .
    Business Service:
    1. Business Service requires manual adding on Inbound and Outbound Interfaces, Business Systems do not.
    2. Business Services are maintained across environments and so, their names cannot be changed. Business Systems names can be changed across environments by providing SLD level transport targets.
    3.In the Business Services we cannot maintain the Group and Targets in SLD. For Ease in transporting your ID/Configuration objects Groups and Targets are used in SLD for Business Systems.
    4.Business Service has no SLD Entries and No Assigned Products and SWCV's
    Regards
    Sangeetha

  • Bean containing both UI components and business logic

    Hello  ADF design experts,  please guide me.   I came across a critical design aspects.  I have main page having bunch of UI components,   Region 1,  Region 2. I will have to bind the UI components of the page to a managed bean having session scope and the reason is,  when control goes to region 1 or region 2, I will be doing lot of  processing of business logic  and then based on this,  I will have to update the UI components of the page.   Same thing with region 2 also.  And then,  I should be able to access the information    across regions and also across other UI components etc.
    I am seeing only  session scoped bean will be able to help me here to get my tasks done across regions and across all other UI components of the page because I am not in a position to pass too many parameters across regions.     Now the problem is,  I can not serialize this bean  because as I mentioned  lot of UI components are updated based on logic. 
    If I do not serialize the bean, I may have problem in future when application has to be deployed to cluster envt.
    I do not know how should I go with my design now.   Please provide me brilliant ideas and very thankful to your guidance.
    thanks

    Hi ADF,
    I dont want to disturb the discussion with you and Alej. I'm rising some question from your first post.
    I have main page having bunch of UI components, 
    ok fine.
    Region 1,  Region 2. I will have to bind the UI components of the page to a managed bean having session scope
    1.why need to do this binding for all ui components .?
    2.this question lead ask another question are you using ADFBc.? if so binding layer will take care why you bind all those things.
    3.why you need to put session scope.?
    if you are using region. the region can only be bounded TF right, then communicate with help of pageflow. inside the bounded you may have jsff/jspx,
    reason is,  when control goes to region 1 or region 2, I will be doing lot of  processing of business logic  and then based on this,  I will have to update the UI components of the page.   Same thing with region 2 also.
    from the reason i have question? why you need to communicate between two region instead of using Taskflow communication.
    And then,  I should be able to access the information  across regions and also across other UI components etc.
    ok fine.
    I am seeing only  session scoped bean will be able to help me here to get my tasks done across regions and across all other UI components of the page because I am not in a position to pass too many parameters across regions.     Now the problem is,  I can not serialize this bean  because as I mentioned  lot of UI components are updated based on logic. 
    from my point of view. your are using all powerful feature session bean, region communication to do your requirement.
    mixing all those things so only you can't able to get consistent results.
    I do not know how should I go with my design now.
    could you please explain your usecase.
    Please provide me brilliant ideas and very thankful to your guidance.
    yeah sure. people will do.
    thanks

  • How can I use JTA in my business logic and execute process with PAPI?

    HI All,
    How can I use JTA in my business logic and execute process with PAPI?
    When my business logic has exception, the process will rollback.
    or the process has some exceptions, my business logic also will rollback.
    I don't know how to do it.
    Does anyone know how to do it?

    Thank you for your reply, Daniel.
    But I think I did not express my mind clearly.
    There is a scene that I have 2 Application Server.
    My business code is deployed in one Server.
    The BPM is deployed in another Server.
    I want to execute Task use PAPI.(ProcessServiceSession.runActivity)
    In my business code, I will do something before execute Task.
    I need my business logic and Task in same transaction.
    To ensure them "all-or-nothing" .
    As you say, if The transactions are managed by Oracle BPM.
    then can I retrieve OBPM transcaction in my business code?

  • Business Logic and Business Rules

    Hi,
    I have a very basic question. If we develop a new screen on top of ECC using Webdynpro ABAP to replace a ECC default screen, say for an example, ME51n screen for purchase requisition to be replaced by a custom screen developed in ABAP Webdynpro, then how do we incorporate the inbuild business logic and the business rules of me51n in to this new screen developed in ABAP Webdynpro? In short, how do we incorporate business logic and rules in to ABAP Webdynpro application?
    do we have to code all the logic from scratch or we can use existing logic? If we can, how.
    Thank you for your help.
    Shai

    Duplicate thread
    Business Logic and Business Rules
    could you please close it.
    thanks
    sarbjeet singh

  • Entity Beans and Session beans to represet Business lOgic

    How cam we implement Entity Beans and Session beans to represent Business Logic.
    Can anyone explain how can we do this.
    Regards...

    I have session beans calling method in entity beans and any client
    doesn't have access to entity beans, only via session beans.
    If i define security policy and method permissions for session beans
    only, do entity beans use that permissions when calling their methods
    from sessions beans OR should i define the security policy for entity
    beans separately?If you want to set the permission on individual
    methods of entity bean ( with different roles)
    you have to do it separately.
    If you want to delegate the Authenticated user along with
    the method call to the Entity Bean you can use
    run-as-identity-principal.
    For more detail please check out the EJB2.0 Spec.
    -utpal

  • Business logic callable object and Dynamic User assignment

    hi all,
    I have to design scenario using VC and GP
    using VC i designed a form that consist of some input parameters value,product..
    i integrated the designs created in VC to CO's
    My workflow should be like this
    now if the value<500
    it should go for approval to user1->user3
    if 500<value<1000  means it should go for approval to user1->user2->user3
    i tried this by using a businesslogic callable object
    the input ot this businesslogic CO is "value" parameter
    reult state
    continue BOOL(@value<500)
    break  Bool(500<@value<1000)
    process
    sequential block1
    Altenateblock block
                  Action
                result state:
                 continue->target->seqblock2
                 break->target->seqblock3
                 business logic CO
    seqblock2
                            Action1
                            Action3
    seqblock3
                              Action1
                              Action2
                              Action3
    i designed the workflow like this
    but the problem is that during runtime its directly jumping to seqblock3 with out asking the input value for business callable object
    and its not exiting from that block3.its going like infinite  loop(action1->action2->action3->action1->action2->Action3)
    pls suggest me the way to achieve this task
    Thanks
    kiran
    Edited by: kiran_mareedu on Aug 26, 2009 3:48 AM

    Hi,
    I have the similar issue.
    In my case it is taking too much time for completion.
    It is a background step so it should execute automatically.
    I have also checked Queue's for this.
    But could not understand why it is taking soo much time?
    Regards,
    Pratik

  • How does the crop-lock and "Effect" settings logic work?

    The crop lock and Effect setting have in common the fact that they are unpredictable with a strange logic I have yet to figure out. Questions:
    What decision process causes the crop lock to remain locked, and then suddenly decide to stay open from one use to the next  (Or the reverse).?
    What makes the "Effects" decide to retain its last used settings, and sometimes not?  (Usually the last customized setting is NOT what I want for the next photo in line to be edited).
    Thanks!

    Thank you for the reply!
    richardplondon wrote:
    There is no distinction betwen edited and un-edited. And the tools and controls do not have any defaults of their own aside from what the images possess. You can't put the crop tool on 3:2 and then move from image to image clicking "apply"; this is simply not how the LR interface works.
    Understood, except that these settings are an exception.  The effects settings will be stuck in the last positions they where on before you created the edit button.  See attached photo for what I mean by edit buttons and associated settings.  This also applies to graduated filters.
    This is difficult to describe.   I think I've figured out the logic but cant understand why anyone would want it to work this way:   If I choose a setting *before* making the first mark (i.e. new button) with the tool, those settings will persist forever until I change them (even if I change catalogs).  If I change the settings AFTER applying the tool, they are forgotten even if I want to keep them.  I never want a custom setting to persist into the next photo because the last tool/setting I used will not likely be the first tool used in the next photo.
    And just to be clear, the effects I'm referring to are on the right. The timing of WHEN you adjust those settings determines whether or not they persist in what I consider an undesirable way.  In other words, in order to avoid messing up the presets, I must always start the tool before adjusting the effects. That is the only way to keep them from persisting into the next tool/button operation.

  • Business logic behind 2lis_12_vahdr ,itm and sch

    Hello friends,
    Could u help me in explaining the business logic behing the extractors 2lis_12_vahdr,VAitm,VASCH for deliveries?
    Also why we use process keys and where do we use process  key??
    Thanks in advance
    srini

    Hi Srinivas!!!
    The logic is like this.
    When an order is made, it will have order number, line item number and schedule line item number. The order number is the header data and all information related to the header data is stored in 2LIS_11_VAHDR. Each order may have different line item, (different material may be ordered) that is stored in 2LIS_11_VAITM. Each Line item may be need to be delivered at different time because the users requested or may be there was no enough material in the store, this is stored in 2LIS_11_VASCL.
    When delivery (2LIS_12_VDITM)gets created, it will abide by the schedule line agreement.
    that is the logic.
    thanks.
    Wond

  • Expert's advise: share EJB components and business logic

    Hi all,
    I've a J2EE applicacion and I want to know if is posible share my ejb business logic with other components in other enviroments and differents programming languages.
    for example, I show you my scenario...
    I've a J2EE application that will be run in a WebSphere server (running over windows) for my JSP cliente side(you know... the web browser), all is ok!!! but my application need also receive request from remote clients (components from other business applications) that may be compiled in .net (over windows) or c++ (over AS400 or linux) and send the response to the respective client.
    well...
    my question is if is posible, which can be the protocols or java technologies that i will need to use for implements some like this.
    thanks for your answer...

    Web services is one possibility.

  • Java for business logic and CFMX for GUI?

    For those familiar with ColdFusion MX, does it make since to use Java at the business logic and possibly data tier and have CF handle the GUI?
    What are the advantages/disadvantaes (methology, threading, memory use, performance, etc)?
    Thanks,
    Brett

    I can't think of any advantages to doing this except that you won't have to listen to people whine about learning something new. Go with Java Server Pages and Servlets to split this functionality. Once you get over the learning curve, you will be much happier.

  • Difference between data logic operation and business operation

    hiii, DI core, main component of DI API, performs all <b>data logic operaton</b> where as OBServer.dll perform <b>bussiness logic operation</b> at database level...
    what is the difference between these operations????

    Hi Nirdesh,
    The DI API offers a number of objects/methods that allow you to access the information stored in the database (tables) by using objects.
    The DI API is represented by the SboBobCOM.dll, in your code you only add a reference to this COM dll. This dll offerst the objects/methods you can access.
    The SbobobCOM.dll is using the OBServer.dll, this dll contains all the business logic rules (like for example: you cannot delete a BusinessPartern if it has already some documents created) that will control all actions you are trying to do with the DI API methods/objects.
    You have a schema representing both dlls in the DI API help file -> Introduction -> DI API components section.
    Regards
    Trinidad.

Maybe you are looking for

  • Itunes 9.0.3 not updating to 9.1

    I've downloaded and installed 9.1 three times now. It doesn't seem to be taking and my itunes is still saying its version 9.0.3. any help or tips?

  • Example CODE to show information on URLs

    import java.awt.Dimension; import javax.swing.JOptionPane; import javax.swing.JEditorPane; import javax.swing.JScrollPane; import java.net.URL; import java.net.URLConnection; import java.util.Date; import java.util.Iterator; /** Accepts an URL and du

  • 1080P mixed with 720P - how to make the workflow work best?

    Dear Forum I am starting a new documentary and before i start i want to clear something out.. I have shot most of the footage in 720P But maybe about 1/3 of the footage is in 1080P (I was requiered to do so because some of the footage was used for te

  • Why do I have a gray strip in the middle of my iPad?

    Why do I have a gray strip down the middle of my iPad?

  • To use SAP for one final

    Hello, We are replacing our current Lotus Notes based Approvals and Authorizations application for vendor invoices and are currently reviewing requirements and software options. One of the possibilities we are investigating is to combine Ariba (procu