Core Lookup Session Pattern

Map-backed lookup sessions — When you needa lookup OsidSession fast.

Overview

The core package provides concrete, in-memory lookup sessions built on top of the abstract Lookup Session Pattern. Instead of resolving each request against a live backend, these sessions hold a fixed collection of already-constructed OsidObjects in a synchronized HashMap and answer lookups directly from it. Populate the collection with the protected put[OsidObject] and remove[OsidObject] mutators; the map is synchronized so the collection may be modified by the OSID Provider while an OSID Consumer is reading.

The pattern comes in two layers. The Map session keys the collection by Id — it serves get[OsidObject](Id) and get[OsidObject]s() from that single map, and answers every other query by scanning the collection through a Filter. This is fine for small fixed sets. The Indexed Map OsidSession extends it and adds secondary indices so the common typed and related-object queries are answered by a hash lookup rather than a linear scan.

Indexed Dimensions

An AbstractIndexedMap[OsidObject]LookupSession maintains a secondary map for each indexed dimension, kept in step with the primary collection by the same put/remove mutators. Each index is built from the object's own accessor at insertion time:

IndexBuilt fromServes
genus type getGenusType() get[OsidObject]sByGenusType(Type)
record types getRecordTypes() get[OsidObject]sByRecordType(Type)
provider getProviderId() get[OsidObject]sByProvider(Id)
related object get[Related]Id() / get[Related]Ids() get[OsidObject]sBy[Related](Id)

In other words, there is an index for every dimension called out in alookup OsidSession.

Javadoc Reference

net.okapia.osid.jamocha.core.resource.spi — representative; every OSID domain has a parallel core.[domain].spi package.

Class Declaration Pattern

public abstract class AbstractMapOsidObjectLookupSession
extends AbstractOsidObjectLookupSession
implements OsidObjectLookupSession
public abstract class AbstractIndexedMapOsidObjectLookupSession
extends AbstractMapOsidObjectLookupSession
implements OsidObjectLookupSession

Constructor Pattern

AbstractIndexedMapOsidObjectLookupSession()
ParameterTypeDescription
no parameters — the collection is populated through the protected mutators

Key Population Pattern

protected void putOsidObject(OsidObject osidObject)
protected void removeOsidObject(Id osidObjectId)

Each mutator updates the primary Id map and every secondary index together, keeping the indices consistent with the collection.