Avg. Rating 3.8

Problem

I'm using the data management package from LiveCycle Data Services in order to have data synchronization between the clients. I have one case when I have to create some the items on the server, persist them in the database and push the new items to the clients. I use hibernate for persistence so I'm using HibernateAssembler and I'm not using JTA.

Solution

I'm using DataServiceTransaction api in order to do that.

Detailed explanation

There are several aproaches to do that:

If you did not extend HibernateAssembler and you are using the default behavior (so you do not have a DAO layer) the following code creates an InternalMessage and call the adapter invoke method (the operation code is CREATE_OPERATION- so the create method from the HibernateAssembler is called). At the end the createItem method from DataServiceTransaction is called and is propagating all the changes to the clients:

            DataDestination dt = DataDestination.getDataDestination("Test");          
            DataMessage fillMessage = InternalMessage.createMessage();
            fillMessage.setOperation(DataMessage.CREATE_OPERATION);              
            ASObject test = new ASObject();
            test.put("name", "Test created at:"+System.nanoTime());          
            test.setType("com.test.Item");                      
            BeanProxy proxy = new BeanProxy(test);
            fillMessage.setBody(proxy);
                          
            DataServiceTransaction tx = DataServiceTransaction.begin(false);
            Collection<Object> result = (Collection<Object>)dt.getAdapter().invoke(fillMessage);

            tx.refreshFill("Test", null);           
            tx.commit();



The second approach is much simpler and is assuming that you have a DAO layer.After the item is created and persisted in the database the same createItem is called

            DataServiceTransaction tx = DataServiceTransaction.begin(false);
            Item item = new Item();
            item.setName("Test created at:"+System.nanoTime());          
            new ItemDAO().create(item);
            tx.refreshFill("Test", null);
            tx.commit(); 

Report abuse

Related recipes