Memory Module

Memory Module

The Memory Module creates 1-tier, in-memory implementations of the JBeans Session and Home interfaces. Each findBy method is implemented using Java conditional expressions. Beans are stored in a cache.

In-memory implementations are useful to create fast data access to data, such as static data. In-memory implementations are also a useful super-class layer for persistence media that has no finding functionality (e.g. properties files). In-memory implementations are also useful to provide a store for real-time data, which can be updated in-memory, for example a model of the markets for use in an arbitrage system.

The CJB, JDBC and in-memory implementations all use the com.javelin.beans.BeanCacheManager to cache Beans on the client side. This allows a JDBC implementation to populate the cache by calling the findByAll() method on the Bean's Session at initialization time. The Class Context bindings can then be swapped for In-Memory implementations once all the Beans are in Memory. This mechanism provides an alternative to Enumerated Types and trades a slight loss of performance for no database storage. For example if we wanted to read all the Currency Beans in from the database then subsequently from In-Memory implementations we would do the following: -

public void initialise()
{
    FXContext.getCurrencySession().findByAll();
    FXContext.bind( CurrencySession.class, MemoryCurrencySession.class, ClassContext.Session );
    FXContext.bind( CurrencySession.class, MemoryCurrencyHome.class, ClassContext.Home );
}

The Memory Module contains the following classes:-

  • com.javelin.generator.memory.MemorySessionClassWriter
  • com.javelin.generator.memory.MemoryHomeClassWriter
  • com.javelin.generator.memory.MemoryContextPropertiesWriter

In order to use the Memory module you need to include the following writer:-

$GENERATOR.AggregateWriter memory

Class Hierarchy

The top-level ServiceWriter class hierarchy is illustrated below: -

Memory Properties

 

Abstract Memory Writer (com.javelin.generator.memory.AbstractMemoryWriter)

The AbstractMemoryWriter is a super class that all Memory writers extend.

The AbstractMemoryWriter has the following methods: -

  • public String getMemoryHomeClassName()
  • public String getMemorySessionClassName()
  • public String getContextPropertiesClassName()

Memory Session Class Writer (com.javelin.generator.memory.MemorySessionClassWriter)

The Memory Session Class Writer creates in-memory BeanSessions.

The Sessions are created in the memory package, with the name pattern: -

Memory<ClassName>Session

MemorySessions are responsible for persisting dependent graphs of Beans. MemorySessions defer loading, finding and counting beans to the MemoryHome classes.

There is (currently) no transactional functionality in the MemorySessions.

By default the classes generated have the name and pattern: -

$MEMORYSESSION=public class $PACKAGE.memory.$THIS extends $BEANS.MemorySession implements $PACKAGE

Memory Home Class Writer (com.javelin.generator.memory.MemoryHomeClassWriter)

The Memory Home Class Writer creates in-memory BeanHomes.

The Homes are created in the memory package, with the name pattern: -

Memory<ClassName>Home

MemoryHomes are responsible for persisting, loading, finding and counting individual Beans.

By default the classes generated have the name and pattern: -

$MEMORYHOME=public class $PACKAGE.memory.$THIS extends $BEANS.memory.MemoryHome implements $PACKAGE

Memory Context Properties Writer (com.javelin.generator.memory.MemoryContextPropertiesWriter)

The Memory Context Properties Writer creates a Context Properties file in the memory package, with the name: -

MemoryContextProperties

The MemoryContextProperties class is responsible for binding the JBeans interface names to implementations. The binding patterns are as follows: -

<packageName>.<ClassName>=<packageName>.<ClassName>

<packageName>.<ClassName>=<packageName>.Lazy<ClassName>
<packageName>.<ClassName>Session=<packageName>.memory.Memory<ClassName>Session
<packageName>.<ClassName>Home=<packageName>.memory.Memory<ClassName>Home
<packageName>.<ClassName>Validator =<packageName>.<ClassName>Validator

To override the bindings in the memory properties class do the following: -

<ClassName>.memory.Object=<fully qualified class name>

<ClassName>.memory.Bean=<fully qualified class name>
<ClassName>.memory.Session=<fully qualified class name>
<ClassName>.memory.Home=<fully qualified class name>
<ClassName>.memory.Validator=<fully qualified class name>