How to handle Keys (Sequences) generated in Database

Need some pointers about how to achieve following:
I am building a cache for TRADES and have a CacheStore supporting LOAD/STORE/REMOVE methods.
The TRADES cache is associated with TRADE table on the database. I have most of my business logic related to adding a trade in a Database Package.
If a new trade is being added to the table, Stored Procedure in my package will use a sequence number to assign it a UNIQUE KEY and will return the key with the call
Now, my cache is using TRADE KEY as a key for the trade objects. If my application is putting a new trade to the cache, then how should this be designed?
I do not really want to have sequences put in the cache as my stored procedure does it for me and there are few other applications which are using same SP.
Has anyone implemented something like this where the key is now known until the object is entered in the database?
I can have a TEMPORARY KEY assigned to the object and can replace the record once the trade has been successfully added to the table. As I can not do replace/update cache records in CacheStore, is there any way to achieve this?
Following is my cache-config:
<distributed-scheme>
     <scheme-name>PartitionedTradePOFScheme</scheme-name>
     <service-name>SweetTradeSvc</service-name>
     <serializer>
          <class-name>com.tangosol.io.pof.ConfigurablePofContext</class-name>
          <init-params>
               <init-param>
                    <param-type>String</param-type>
                    <param-value>position-pof-config.xml</param-value>
               </init-param>
          </init-params>
     </serializer>
     <backing-map-scheme>
          <read-write-backing-map-scheme>
               <internal-cache-scheme>
                    <local-scheme></local-scheme>
               </internal-cache-scheme>
                    <cachestore-scheme>
                    <class-scheme>
                         <class-name>com.db.spg.sweet.coherenceutil.DBCacheStoreTrade</class-name>
                         <init-params>
                              <init-param>
                                   <param-type>java.lang.String</param-type>
                                   <param-value>{cache-name}</param-value>
                              </init-param>
                         </init-params>
                    </class-scheme>
               </cachestore-scheme>
          </read-write-backing-map-scheme>
     </backing-map-scheme>
     <autostart>true</autostart>
</distributed-scheme>I am trying to be as clear as possible. If anything here is confusing, let me know.
Thanks

Jonathan.Knight wrote:
<li>The AQ messaging is asynchronous so there will be a time-lag between the original put of the trade and it being updated with the version from the DB.
<li>How does the AQ listener know what the key is of the temporary trade is that it needs to remove, presumably you write this to the DB then send it back in the AQ message?Agreed. From my CacheStore, I call Stored Procedure inside Database Package. I can pass this TEMP key to this SP as 1 extra parameter. So, I do not necessarily need to store it in the database, but just use merely as an extra parameter to be sent back to AQ. Also, when the client puts a new trade, the business logic for most of the trade processing is in our stored procedures. There, it will enrich that trade with additional information from other tables, it will also adjust the trader position and then will return with the new trade key to the client. GUI/Client Applications will provide the data required to create a trade. But SP will use this data and using other local stored procedures, it will obtain extra information for the trade, enrich all the information in a single trade record and then will create that new record.
<li>If the code the listens to the AQ messages removes the original version of the trade from the cache before putting the new version into the cache you will have a short period of time where there is that trade does not exist in the cache
<li>Alternatively if your AQ listener works the other way round and puts the new version into the cache before removing the original version you will have a short period where there are two copies of the same trade in the cache.
<li>Depending on what you use-cases for reading these trades back out of the cache you could have issues with the above times when there may be one, zero or two copies of the trade.Yes. I have been thinking about that as well. But I think, as the trade entered from GUI is merely an indicator for the background/database processing. If and only if the database processing is successful, that is considered a valid trade. So as far as I know, the duplicate/old copy of the trade would still be considered as in "waiting database update" state. I am designing my GUI accordingly. I will probably check with the users about this requirement once again though. You have a valid point.
<li>I assume your use-cases for accessing trades from the cache are not using the keys as they could not rely on having obtained the correct key for a trade as it might change. At this point, I am using these TRADE keys as my cache keys. Because, it is really easier for us to manage TRADES in the cache, especially when there are lot of lookups involved from our users
One more thing someone I had worked with long time back suggested that, having a staging/metadata cache for all these trades to be processed from the client. Add these trades in the database and then in QueueListener, add a new trade in Trade-Cache and remove the corresponding old trade from staging/metadata cache. This also seems good, though I need to see if that is going to complicate matters in terms of processing.
Thanks a lot JK for your suggestions. Let me know if the logic I explained makes sence.

Similar Messages

  • Knowing the Primary Key Sequence Generator of a table

    Hello All,
    I'm working on an application that uses Oracle toplinks/JPA for persistence. The entity classes in the application have primary key fields with annotations @Id and @GeneratedValue(strategy = GenerationType.AUTO). Per our understanding, this means the primary key generation is done by JPA/Top-links. When we see our database, we notice only one SEQUENCE table available and that table has only one row, while in the application, we are getting different sequence numbers for the primary key of each entity. So, not clear on how this sequence number is generated. Could anybody share information on where the sequence number is stored for each entity/table? Really appreciate your help here. Our database is MSSQL.
    Thank you,
    Venkatesh

    EclipseLink/TopLink uses Table sequencing for GenerationType.AUTO because it is more portable between databases. My understanding of your issue is from
    http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Table_sequencing
    Each row in the table represents one sequence generator, and your entities are all using the same default sequence generator and so all use the same row.
    To use multiple rows I believe you need to define multiple TableGenerators.
    Best Regards,
    Chris

  • How to handle key events in iphone

    I want to be able to detect physical keyboard (e.g. bluetooth) events in an iOS app.
    In Mac, there is a class NSEvent which handles both keyboard and mouse events, and in ios (iphone/ipad) the counterpart of NSEvent is UIEvent which handles only touch events. I know ios API does not provide this functionality, but how can i handle key events in iphone???

    in my application header part of the page is common of all page. header.jsff contains comandmenuItem named "proceduralhelp". if I click proceduralhelp a pop up opens .
    in my login page when first time I open popup and press escape popup is not closing.
    rest of the cases after login escpe will cose the popup.
    only on the loginpage that to for the first time it is not closing when pressing up on escape key. (then we click on close button. and once again open the popup in loginpage now if we press escape it works).
    Thanks,
    Raghavendra.

  • How to set key fields in a Database view

    Hi guru's
    iam balaji,plz guide me with how to set key fields in a view.......that field is a non key field in the base table....
    thanks in advance,
    Balaji.S

    take a look at this:
    Diagnosis
        In the view, not all of the mandatory fields were included as key
        fields. The key of the view therefore is not unique.
    System Response
        All the fields are regarded as key fields in order to guarantee that th
        key lengths are unique.
    Procedure
        For views with a large number of fields, this could have a negative
        effect on the performance for the language construction described below
        In this case, all the mandatory key fields should be included in the
        view.
    regards

  • How to set a sequence generator as a value

    When i am creating a new object in a table there is a unique id i want to keep to identify this object and I use sequence generator. I believe the command is DB_SEQ_PK.NEXTVAL, do i put this statement as a "SQL EXP" in the Source value for the specific variable i want to set it to? Please give me the right expression if i am wrong thank you.

    Raj,
    i tested it with the emp table the following way:
    Extend This Application
    A page or application component
    Component > Form > Table
    [selected EMP table, page 40, the rest default]
    Edit Page 40
    Edit Page Item P40_EMPNO
    Alternate source used: Only when current value is session state is null
    Source Type: SQL Query
    Source value or expression: SELECT CT_ID_SEQ.NEXTVAL FROM DUAL;
    Apply Changes
    Run Page
    [The empno field shows a value of 50]
    [I enter 'test' into the ename field and click 'Create']
    [I receive the error: ORA-01400: cannot insert NULL into ("EAS"."EMP"."EMPNO")]
    I'm not sure what i am doing wrong here.
    Thanks

  • How to handle key events in popup component

    Is there any possibility to handle keyboard events after a popup is opened
    requirement : I want to close popup when I press escape key (by default this functionality is present but in some scenarios this is not working ) so explicitly i want to handle key events for popup.
    Thanks,
    Raghavendra.

    in my application header part of the page is common of all page. header.jsff contains comandmenuItem named "proceduralhelp". if I click proceduralhelp a pop up opens .
    in my login page when first time I open popup and press escape popup is not closing.
    rest of the cases after login escpe will cose the popup.
    only on the loginpage that to for the first time it is not closing when pressing up on escape key. (then we click on close button. and once again open the popup in loginpage now if we press escape it works).
    Thanks,
    Raghavendra.

  • How to handle transactions when two different databases are involved.

    consider two tables namely Table-A and Table-B part of two different databases namely ORACLE and MYSQL.
    Now the project requirement is updating the Table-A(ORACLE) and Table-B (MYSQL) as one transaction. i.e. either update both the tables or rollback both the tables.
    Now my question is how could i handle this situation using JDBC(Type-4) driver.Because i think at a time only one JDBC driver can be loaded into the JVM.

    NareshAnkuskani wrote:
    Now my question is how could i handle this situation using JDBC(Type-4) driver.Because i think at a time only one JDBC driver can be loaded into the JVM.No, that is not true.
    But anyway, you need to use distributed (XA) transactions. i believe that the latest version (5.0) of mysql actually has support for XA transactions. you need to use a to setup a distributed transaction and attach the connections for the two databases to that transaction. then it should function as you desire.

  • How to handle and manage a multi Database access in runtime with LCDS?

    Hello there
    I got several customer working with the same application and I wonder how,  with LCDS,  to manage  in a runtime a multi dataBase access; without creating a configuration "mxl" file in
    the folder catalina for each database.
    Indeed, each customer have their own dataBase, and so far, I did not find out how to avoid creating a config xml file in catalina for every single database; which force me to create as well for each customer a  folder application, since the name of the config file in catalina require a folder application to be ran under tomcat....
    Thus, my question is :
    Is there anyway to create only one configuration mxl file in catalina (in the server side) and then from the client side (application) let the user select its environment (meaning its database) to run the application.... this technic can be also used for multi database environment such as : Dev / Test / Prod   environment (or database) where the same application can access to.
    Please if any one have an idea or already delt with; just let me know, because I'm entering in a bootle neck and the situation is getting serioulsy critical....
    Regards

    Hello Ulrich,
    with compact and repair I mean the MSAccess function "Compact and Repair".
    Please follow the link below for more details:
    http://office.microsoft.com/en-us/access-help/compact-and-repair-an-access-file-HP005187449.aspx
    Normally you can execute this function directly in Access or with the Windows ODBC Data Sources Administrator  => "Control Panel" => "Administrative Tools" => "Data Sources (ODBC)"...
     I want to execute this function via cvi code and not by hand ;-).
    Thank you for your support.
    Frank

  • How to vew the sequences from the database

    Hi
    I am using oracle 9i and i want to view the sequences that are existing in the database.Any anyone help me
    Thanking you in advance
    Dinny

    Use DBA_SEQUENCES, ALL_SEQUENCES, USER_SEQUENCES

  • Sequence generator

    Hi All,
    I am populating a dimension table with a primary key field populated from a sequence generator. The target table is on a SQL Server database and from the literature online, it appears a sequence generator object does not exist in S Server. How do I work around this ? I have tried to create a sequence object through ODI but Im not clear on how to call this sequence generator from the interface. Is this the right approach to populating this sequence fiels ? Any ideas ?
    Thanks
    MN

    Hi MN,
    Look into this link http://odiexperts.com/?p=450
    the other way is to using an variable and row number .
    In variable call like this ' SELECT NVL(MAX(<SEQUENCE_COLULMN_ID>,0)) FROM TARGET_TABLE
    In the interface call like this #VARIABLE+ROWNUM and call the variable in refresh mode and then the Interface.
    This way once the variable fetches the max value, using rownum for the number of insert we can increment the number .
    This method is for Oracle now dealing with SQL Server , i think you can make use of ROW_NUMBER() OVER (ORDER by COLUMN ) for rownum. You can google and learn more about it .
    I have personally not tried it sql server so i am not sure how much help row_number will be.
    Hope this helps.

  • Handling Key Event

    How to handle key events in the Console?
    Plz give sample code for it.
    Thanks in advance.

    Don't have any experience with it personally, but I think curses does this type of thing http://sourceforge.net/projects/javacurses/

  • Sequence generated keys in Apex

    In APEX, what is the best way to handle INSERTs when the primary key is generated from a SEQUENCE (triggers not allowed).
    Thanks,
    Mike

    Hi,
    How trigger will harm that ?????
    You trigger could be like
    create or replace
    TRIGGER MY_TBL_TRG_TRG
      BEFORE INSERT ON MY_TBL
      FOR EACH row
    BEGIN
      IF inserting THEN
        IF :NEW.PK_ID IS NULL THEN
          SELECT MY_TBL_PK__SEQ.nextval
          INTO :NEW.PK_ID
          FROM dual;
        END IF;
      END IF;
    END;If you insert table and supply PK value, it would not generate it from sequence.
    You should check shop rules.
    Regards,
    Jari

  • Help required to generate primary key sequence

    Hello All,
    I need your help in generating a sequence for primary key in my db table created using java dictionary project in my NWDS 7.3.
    The table column EMPL_ID is a primary and needs to be a sequence. The code in the JPA entity is as below. The underlying database is DB2 on Linux. Kindly help me resolve this issue.
    * The persistent class for the TMP_EMPL_DATA database table.
    @Entity
    @Table(name="TMP_EMPL_DATA")
    public class TmpEmplData implements Serializable {
         private static final long serialVersionUID = 1L;
         @Id
         @SequenceGenerator(name="EMPLID_GENERATOR", sequenceName="EMPID_SEQ", initialValue = 10000, allocationSize = 1)
         @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="EMPLID_GENERATOR")
         @Column(name="EMPL_ID")
         private String _emplId_;
    My bean class contains a public method as follows.
    public TmpEmplData createEmployee(String employeeName, int age, String location)
             TmpEmplData emplData = new TmpEmplData();
             emplData.set_emplName_(employeeName);
             emplData.setAge(age);
             emplData.setLocation(location);
             entityManager.persist(emplData);
             entityManager.find(TmpEmplData.class, emplData.get_emplId_());
             return emplData;
    During execution, i am getting an error as below.
    Caused by: javax.persistence.PersistenceException: The generated SQL statement is not valid for the underlying database platform (platform no. 99). For more details see attached exception. SQL statement is SELECT NEXT VALUE FOR "EMPID_SEQ" FROM ( VALUES (1) )
    at com.sap.engine.services.orpersistence.sqlmapper.mapping.JPASQLMapperImpl.createSequenceIDGeneratorSelectText(JPASQLMapperImpl.java:1239)
    at com.sap.engine.services.orpersistence.entitymanager.CachedJPASQLMapper.createSequenceIDGeneratorSelectText(CachedJPASQLMapper.java:259)
    at com.sap.engine.services.orpersistence.generator.GeneratorFactory.<init>(GeneratorFactory.java:156)
    at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl$MetaDataImpl.<init>(EntityManagerFactoryImpl.java:323)
    at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:137)
    at com.sap.engine.services.orpersistence.entitymanager.JtaEntityManagerFactoryImpl.<init>(JtaEntityManagerFactoryImpl.java:39)
    at com.sap.engine.services.orpersistence.provider.PersistenceProviderImpl.createJtaEntityManagerFactory(PersistenceProviderImpl.java:251)
    at com.sap.engine.services.orpersistence.provider.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:236)
    at com.sap.engine.services.orpersistence.container.EMFInstanceCreator.getEntityManagerFactory(EMFInstanceCreator.java:134)
    at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getEMF(ORPersistenceObjectFactory.java:300)
    at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getObjectInstance(ORPersistenceObjectFactory.java:73)
    at com.sap.engine.lib.injection.ReferenceObjectFactory.getObject(ReferenceObjectFactory.java:96)
    at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:113)
    ... 122 more
    Caused by: com.sap.engine.services.orpersistence.sqlmapper.generate.SQLMappingException: SQL statement is not valid for underlying database platform.
    at com.sap.engine.services.orpersistence.sqlmapper.common.CommonSQLMappingResult.getStatementString(CommonSQLMappingResult.java:237)
    at com.sap.engine.services.orpersistence.sqlmapper.mapping.JPASQLMapperImpl.createSequenceIDGeneratorSelectText(JPASQLMapperImpl.java:1237)
    ... 134 more
    Caused by: com.sap.sql.tree.StringRepresentationFailureException: Cannot represent next value expression as string.
    at com.sap.sql.tree.impl.OpenSqlTextExpert.nextValueExpressionToText(OpenSqlTextExpert.java:185)
    at com.sap.sql.tree.impl.NextValueExpressionBuilderImpl$NextValueExpressionImpl.toSqlTxt(NextValueExpressionBuilderImpl.java:140)
    at com.sap.sql.tree.impl.AbstractSqlTextExpert.selectSublistToText(AbstractSqlTextExpert.java:130)
    at com.sap.sql.tree.impl.SelectSublistImpl.toSqlTxt(SelectSublistImpl.java:150)
    at com.sap.sql.tree.impl.QuerySpecificationImpl.toSqlTxt(QuerySpecificationImpl.java:361)
    at com.sap.sql.tree.impl.SelectStatementImpl.toSqlTxt(SelectStatementImpl.java:139)
    at com.sap.sql.tree.impl.SQLStatementImpl.toSqlString(SQLStatementImpl.java:75)
    at com.sap.engine.services.orpersistence.sqlmapper.common.CommonSQLMappingResult.getStatementString(CommonSQLMappingResult.java:233)
    ... 135 more

    Hi,
    does the sequence exist? SAP JPA does not support creation of sequences, you have to create it manually.
    Maybe SAP JPA also does not support DB2 sequences with "Open SQL" correctly.
    - Tryp to set your data source to "native" or "vendor".
    - Try to turn on oracle compatibility:
    db2set DB2_COMPATIBILITY_VECTOR=ORA
    Regards
    Rolf

  • How to handle user exit sequence

    how do handle the userexit sequence i,e in which order the user exits are stored?

    one  and state solution
    go to debugger mode make  breakponint on statement call fm.
    and press f8 continiously and check exit fm one by one.

  • How to get the sequence value from the database

    Hi
    I created one sequence in the database.
    Then I want to take the current value or nextvalue of the sequence in a java program.
    How can i do this?
    can anybody please explain me?
    Thank you so much.

    Here you go ...
    Connection conn = null;
    PreparedStatement prepStmt = null;
    ResultSet rs  = null;
    int seqNo = 0;
    try {
         conn = dbConn.getConnection(); //manage your connection here
         String strSQL = "SELECT SEQ_NAME.NEXTVAL FROM DUAL";
         prepStmt = conn.prepareStatement(strSQL);
         rs = prepStmt.executeQuery();
         if(rs.next())
              seqNo = rs.getInt(1);
    catch (SQLException e)
    ...-Rohit

Maybe you are looking for