This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Using AbstractMemStorage

Documents for the development of and with JVx.

--Using AbstractMemStorage

Postby Development@SIB » Sun Feb 03, 2013 2:54 am



This article is outdated - please use our new system at

https://doc.sibvisions.com




Sometimes you don't have a database accessible but you need a storage for temporary or session relevant data. In that case you could use an AbstractMemStorage. This storage stores data in an internal MemDataBook. It fully implements IStorage interface and allows clients to access data via databooks.

How to use an AbstractMemStorage?

The class is an abstract class and you should extend if if you need it. It alos is possible to create an anonymous class. The following example shows usage in the Session life-cycle object of an application:

Syntax: [ Download ] [ Hide ]
public IStorage getContacts() throws Exception
{
    AbstractMemStorage amsContacts = (AbstractMemStorage)get("contacts");
       
    if (amsContacts == null)
    {
        amsContacts = new AbstractMemStorage()
        {
            private int iId = 0;

            @Override
            public RowDefinition getRowDefinition() throws ModelException
            {
                RowDefinition rowdef = new RowDefinition();
                rowdef.addColumnDefinition(new ColumnDefinition("ID",
                                           new BigDecimalDataType()));
                rowdef.addColumnDefinition(new ColumnDefinition("FIRST_NAME"));
                rowdef.addColumnDefinition(new ColumnDefinition("LAST_NAME"));
                rowdef.addColumnDefinition(new ColumnDefinition("DOB",
                                           new TimestampDataType()));

                //important, otherwise our client does not receive "hidden"
                //columns like ID
                rowdef.setColumnView(null, new ColumnView("ID", "FIRST_NAME",
                                                          "LAST_NAME", "DOB"));
                               
                //important, otherwise our client does not write-back
                rowdef.setPrimaryKeyColumnNames(new String[] {"ID"});
                               
                return rowdef;
            }
                       
            @Override
            public void update(DataBookEvent pEvent) throws ModelException
            {
            }
                       
            @Override
            public void loadData(MemDataBook pBook, ICondition pFilter) throws
                                                                        ModelException
            {
            }
                       
            @Override
            public void insert(DataBookEvent pEvent) throws ModelException
            {
                pEvent.getChangedDataBook().setValue("ID", BigDecimal.valueOf(iId++));
            }
                       
            @Override
            public void delete(DataBookEvent pEvent) throws ModelException
            {
            }
        };

        amsContacts.open();

        put("contacts", amsContacts);
    }
       
    return amsContacts;
}
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation