Do I need to declare a transaction in this case?

I am struggling to understand when it is necessary to declare my own transaction to ensure the data is properly updated.
For example, in the following code, which is part of a java bean in the EJB project, KeyFacade is a stateless session bean tied to the entity "Key". it is a standard EJB created with the netBeans 5.5 wizard. I have changed no defaults.
Do I need to declare a transaction, commit the transaction and close it when I use the "KeyFacade.edit(key);" in order to ensure the database is updated? Or is it automatically done because the .edit() method uses the entityManager and the persistence is container managed?
Would it make a difference if this bean was part of a WAR project?
    public BigInteger getNextKey(String tableName){
        KeyFacadeLocal KeyFacade = this.lookupKeyFacade();
        Key key = KeyFacade.findByTablename(tableName);
        long nextKey = key.getKeyvalue();
        BigInteger BINextKey =BigInteger.valueOf((int)nextKey);
        //  now update the table by incrementing the key value by 1
        long incrementKey = nextKey + 1;
        key.setKeyvalue(incrementKey);
        KeyFacade.edit(key);
        return BINextKey;
    }

808239 wrote:
I have a Map<Integer, List<T>> data, and all the lists are initialized using Collections.synchronizedList().Seems like overkill to me. Your Map also looks like a Multimap, of which there are several existing implementations.
When I do the traversal, I want to traverse ALL lists in the map at the same timeI suspect not. What you want to do is to traverse each one in sequence.
so I have to sync all lists as shown in the API doc as follows: ...Seems like overkill to me, and will probably result in a very slow Map (not that there's any problem with that if it's the right thing to do; in this case, I suspect it isn't).
Is this approach ok?What are you trying to achieve? If you need full consistency for your iterators (ie, a snapshot of the entire Map at the time the iterator is created), you have a two choices (assuming you don't want to deal with update journals):
1. Lock the Map.
2. Clone the Map (and your clone() method should be synchronized).
Of the two, the second seems best to me, but neither is all that wonderful.
However, if all you need is weak consistency - that is to say, what you return reflects the state of the Map when Iterator.next() is called - all you really need to do is make sure that your Lists are synchronized when you do the read.
Since the List updates are the responsibility of your Map (I'm still presuming this is some sort of Multimap implementation), there's no real need to synchronize them; just synchronize the Map's own update methods.
I'd also suggest that you make sure your getValue() method hands back an [url http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#unmodifiableList%28java.util.List%29]unmodifiable List to clients; otherwise they could start adding or removing values themselves.
HIH
Winston

Similar Messages

  • When is it necessary to declare a transaction?

    I am struggling to understand when it is necessary to declare my own transaction to ensure the data is properly updated.
    For example, in the following code, which is part of a java bean in the EJB project, KeyFacade is a stateless session bean tied to the entity "Key". it is a standard EJB created with the netBeans 5.5 wizard. I have changed no defaults. Do I need to declare a transaction, commit the transaction and close it when I use the "KeyFacade.edit(key);" in order to ensure the database is updated? Or is it automatically done because the .edit() method uses the entityManager and the persistence is container managed? Would it make a difference if this bean was part of a WAR project?
        public BigInteger getNextKey(String tableName){
            KeyFacadeLocal KeyFacade = this.lookupKeyFacade();
            Key key = KeyFacade.findByTablename(tableName);
            long nextKey = key.getKeyvalue();
            BigInteger BINextKey =BigInteger.valueOf((int)nextKey);
            //  now update the table by incrementing the key value by 1
            long incrementKey = nextKey + 1;
            key.setKeyvalue(incrementKey);
            KeyFacade.edit(key);
            return BINextKey;
        }

    It depends where the method is defined. If it's defined as a business method of an EJB 3.0
    Session Bean, then the default is container-managed transactions with a transaction attribute
    of Required. That means if there is an existing transaction that is propagated into the business
    method invocation , the work performed within the method occurs within the incoming transaction.
    If there is no transaction propagated into the business method, the EJB container will automatically
    start a new one and commit it after the business method completes. This container-managed
    transaction demarcation behavior has nothing to do with what code is in the business method.
    You can change the transaction behavior of the EJB by using the @TransactionManagement
    and @TransactionAttribute annotations at either the class or bean level, as well as within ejb-jar.xml.
    The web tier doesn't have any notion of container-managed transactions. To start a global
    transaction from code running in the web tier, you would need to acquire the UserTransaction
    object and explicitly start and commit the transaction.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need Help for Non Transactional Data

    Hi,
    I need your help for getting the non-transactional data. I am looking for some solution where I can have employee list with both transaction and non transaction along with the measure in the report.
    Thanks in advance.
    Phani.

    Looks like you either want a procedure with OUT parameters, or to return a record (which you'd need to declare somewhere that your function and calling procedure can both see)

  • Need to declare GUID in Class to use in Workfloq

    Hi Guys!
    I created a new class (via SE24) with two attributes as its key - but its lenght exceeded 32 charaters. I went thru the blogs posted by Jocelyn where she mentions to use GUID to declare the key. Can someone please explain how do the go about this - using a GUID as the key for the class? I am unable to understand how will I establish the link between the GUID and two attributes.
    Any guidance would be appreciated.
    Regards,
    Anwar.

    hi saujanya!
    thanks a lot for looking into this.
    i have a few concerns here. first, let me paste the information that i read on one of the blogs on SDN on how to use GUID as Key field.
    What happens if the class represents something that has a unique key longer than 32 characters? In this case you would use a Globally Unique Id (GUID) to represent your unique key, and then relate the GUID back to the real key. A GUID is unique throughout your system - for this reason a lot of the latest SAP solutions use GUIDs rather than meaningful ids as technical ids. To create the GUID, you simply call function module GUID_CREATE. To relate the GUID back to the real key, you could either cross-reference the GUID in a separate custom table, or use an append structure to extend an existing table to also hold a GUID reference
    Here are my questions:
    1. The field INSTID that contains the Key can only be of lenght 32 characters. So if I declare the key to be longer than 32 characters, SAP gives me a warning - but is that ok?
    2. from the workflow side, i have only two values with me - objtype and objvalue - this is what i want to pass to my class. But i cannot use objtype and objvalue as my key because they are longer than 32 characters. therefore i need to use a guid. i have maintained a table, where i can find the guid using the objtype and objvalue. but my concern is what should i pass from the workflow and how do i get that in the class? this is were I am really confused.
    Appreciate your time for lookinginto this. any guidance would be greatly appreciated.
    regards,
    anwar.

  • I Need To Delete All Transactions and Balances From all Modules

    I Need To delete All Transactions From All Financial Modules (AP,Ar,Gl,Cm and FA)
    payables ( Delete All Invoices and Payment that validated and create accounting )
    Receivables ( Delete All Transactions and Receipts that completed and create accounting )
    Assets ( Delete All Asset Depreciation Amount )
    General Ledger ( Delete All Journals That Posted In General Ledger )
    I Need To Make This To Delete Any transaction Or Balances And Uploading Anew Balances and Journals
    Can I Make This By Purge and How Can I Do it ? Or any another Way ?
    Thanks,
    Mohamed Gamal
    Edited by: Mohamed Gamal on Sep 5, 2011 2:27 PM
    Edited by: Mohamed Gamal on Sep 5, 2011 2:28 PM

    Hello Mohamed.
    Each Application User's Guide (for AP, AR, GL, CM and FA) has a section dedicated to Archive and Purge process.
    Depending on the quantity of records you need to process perhaps you should consider other options like creating new organization(s), books, etc. and create only the desired open items in there.
    Octavio

  • Do I need to declare my custom setter accessor in my interface/header file

    Hi there:
    I'm working through a Objective C tutorial. I've got an instance var that is declared in the var section of my @interface (in the header file). It's also declared as a property...all the defaults apply (assign and whatever else).
    @property int foo
    I also have it synthesized in my @implementation code.
    @synthesize foo;
    I need a custom setter though that checks out the value being assigned. Do I need to declare this setter function in my @interface section in the header file?
    -(void)setFoo:(int)newValue {
    if (newValue < minAllowed) {
    NSLog(@"Invalid foo: %i is less than the minimum of %i allowed", newValue, minAllowed);
    return;
    if (newValue > maxAllowed) {
    NSLog(@"Invalid foo: %i is greater than the maximum of %i allowed", newValue, maxAllowed);
    return;
    foo = newValue;
    } // setFoo()

    The @property statement is the declaration of the accessor methods whether they are synthesized or custom coded.
    For a fairly clear, detailed explanation see Accessor Methods in the +Memory Management Programming Guide for Cocoa+.

  • Need to add Standard transaction code to User Menu.

    Hi All,
    I need to add Standard transaction code to User Menu. How this can be accomplished?
    Thanks

    Your Security and/or Basis team probably have control of the user menu settings.  On the other hand, if this is for YOUR user menu, you could choose to simply adjust your favorites.

  • Need to call sap transaction when the work item got rejected.

    Hi all,
    I need to call the ME22n transaction once i reject the Work item. Once i press the rejection button on the work item it should direct to the sap transaction. how can i make this functionality in the decision task. Do i need to implement an ext for this.
    Thanks.
    Neslin.

    You simply create a task for executing the SAP transaction (business object TSTC)
    you use this task as a dialog step at the rejected outcome of the user decision with the same agent as the user decision and in the details of the workflow step you tick the advance with dialog box.
    And... you're done.
    Kind regards, Rob Dielemans
    Edit: Instead of using BO TSTC it would be better to check the BO normally related to Me22n and see if a dialog maintain method exists
    Edited by: Rob Dielemans on Jul 16, 2009 9:55 AM

  • Need help with Monthly Transaction By Hour Report

    Post Author: cbcombs
    CA Forum: General
    Hello,Newbie needs to write a transaction report that is grouped by days of the week for a calendar month. It will have one column for each day of the week and each of those columns will contain a whole months of week day data. Then it will be grouped by each hour of the day. It will contain the number of transactions for each hour. And then a weekly average of the number of transactions for each hour of the day. The week starts on a Monday and goes through Sunday. They are probably going to want the dollar amount of the transactions too. Below is an example with the first two rows of data populated. Monthly Transaction Report For August 2007                   Mon            Tue             Wed             Thu            Fri             Sat             Sun            Average08:00                0                2               2                1                10                    5                    2                      3.1409:00                    25                    3                    5                    4                  5                    8                    6                      4.43  10:00                    5011:00                  10012:00                 15013:00                  15013:00                   12514:00                  10015:00                    5016:00                     1017:00                       2 Any help would be appreciated. 

    Post Author: kbrinton
    CA Forum: General
    You could use the cross tab expert and set the columns to the day and the row to hours with it summing your transactions. So for the rows choose your date field and then choose Group options and have it set to "for each hour". Then the column choose your date field and have it set to "for each day".  Then have it summarize your transactions.
    Hope this helps!!

  • When do we need to declare method as Synchronised

    Hi Everyone,
    I have a common class with number of methods which are used by some other servlet classes.It may possible that more than one class use same method at same time.
    All method are staic because I want to access method with class name instead of object.Do i need to declare all method as Synchroinised.There is no global varaible.
    reply as soon as possible.It is very urgent.
    Thanks

    If for example your class stores some values which can be updated by any1 then the methods should be syncronised to prevent them for entering a state where 2 events occur at the same time one reading and one writing.
    I use the syncronised method to ensure the my internal data class is not compromised. These methods are generally 4 times slower i think.
    Hope this helps

  • Need to add a Transaction in the SAP menu in the Given path

    Hi All,
    I need to add a transaction in the enhancement menu in the specified path.
    Kindly share the method.
    Thanks in Advance!
    Chirag Shah

    Hi ,
    Go to SE43 and give the AREA MENU , and press the create button and add the Tcode...
    Regards,
    Bharani

  • Why should I need to pay "overseas transaction fee" when I buy an iphone app in Hongkong dollar currency.

    why should I need to pay "overseas transaction fee" when I buy an iphone app in Hongkong dollar currency.

    I have bought some apps in apple store and pay it by Hongkong currency Credit Card. Afterwards I found there has some extra fees on statement and have been clarified as "overseas transaction fee"...

  • HT3702 How can I just prepay say 500 dollars on my itunes account, so that I dont need to have multiple transactions on my credit card...?

    Hello There! How can I just prepay say 500 dollars on my itunes account, so that I dont need to have multiple transactions on my credit card...? Cheers Dilip

    Hello DilipVenkat,
    Welcome to the Apple Support Communities. If you want to have a purchase iTunes Gift Cards to have credit on your account, just purchase an iTunes Gift Card at your local Apple Online Store or through iTunes. Store.
    iTunes: Sending iTunes Gifts
    http://support.apple.com/kb/ht2736
    iTunes Store: How to redeem a code
    http://support.apple.com/kb/HT1574
    Regards,
    -Norm G.

  • Im using iPhone5 and i register in apple store  for my apple ID for the apps, i use my visa then after it appear that i need contact iTunes support to complete this transaction. how many times Ive tried its still the same ....

    im using iPhone5 and i register in apple store  for my apple ID for the apps, i use my visa then after it appear that i need contact iTunes support to complete this transaction. how many times Ive tried its still the same ....

    To Contact iTunes Support...
    Click  >  Here

  • Do I need to declare parameters before using them?

    Hello,
    Say I have a piece of code like below:
    FORM UPLOAD_PC_FILE USING P_PATH
                               P_INTERNAL_TABLE.
       P_PCPATH_TOSTRING = P_PATH.
       CALL FUNCTION 'GUI_UPLOAD'
         EXPORTING
           FILENAME                      = P_PCPATH_TOSTRING
    *   FILETYPE                      = 'ASC'
    *   HAS_FIELD_SEPARATOR           = ' '
    *   HEADER_LENGTH                 = 0
    *   READ_BY_LINE                  = 'X'
    *   DAT_MODE                      = ' '
    *   CODEPAGE                      = ' '
    *   IGNORE_CERR                   = ABAP_TRUE
    *   REPLACEMENT                   = '#'
    *   CHECK_BOM                     = ' '
    *   VIRUS_SCAN_PROFILE            =
    *   NO_AUTH_CHECK                 = ' '
    IMPORTING
    *   FILELENGTH                    =
      HEADER                        =  WA_INBOUND
         TABLES
           DATA_TAB                      = P_INTERNAL_TABLE
    EXCEPTIONS
    FILE_OPEN_ERROR               = 1
    FILE_READ_ERROR               = 2
    NO_BATCH                      = 3
    GUI_REFUSE_FILETRANSFER       = 4
    INVALID_TYPE                  = 5
    NO_AUTHORITY                  = 6
    UNKNOWN_ERROR                 = 7
    BAD_DATA_FORMAT               = 8
    HEADER_NOT_ALLOWED            = 9
    SEPARATOR_NOT_ALLOWED         = 10
    HEADER_TOO_LONG               = 11
    UNKNOWN_DP_ERROR              = 12
    ACCESS_DENIED                 = 13
    DP_OUT_OF_MEMORY              = 14
    DISK_FULL                     = 15
    DP_TIMEOUT                    = 16
    OTHERS                        = 17
    Do I have to declare the P_INTERNAL_TABLE as an internal table or ABAP will automatically know that this is an internal table (I will always pass in internal tables when I call this form in the main program)?
    Thanks a lot!
    Regards,
    Anyi

    You must declare it before you use it.  In this case, you are declaring it in the signature of the FORM.  So here it is declared.  But when calling the form you must pass a valid internal table name  that has been declared before hand.
    For example.
    report zrich_0001.
    data: <b>itab</b> type table of string.
    perform upload tables <b>itab</b>.
    *       FORM upload                                                   *
    *  -->  L_ITAB                                                        *
    form upload tables <b>l_itab</b>.
      call function 'GUI_UPLOAD'
           exporting
                filename = 'C:test.txt'
           tables
                data_tab = <b>l_itab</b>.
    endform.
    Regards,
    Rich Heilman

Maybe you are looking for