|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.schemarepo.Subject
public abstract class Subject
A Subject is a collection of mutually compatible Schemas.
Validation of schemas is pluggable and each subject may have its own
validation rules defined with its own Validator when registered with
a Repository. To create a Subject that validates its schemas,
use validatingSubject(Subject, ValidatorFactory).
Caching of schemas is pluggable via
cacheWith(Subject, SchemaEntryCache). A Subject can only
cache the schema to id mappings, as other properties of a Subject are not
safe to cache.
A Subject has a few basic methods for interacting with Schemas:
register(String) attempts to register a schema with the Subject,
according to the validation rules of the Subject. The operation is idempotent
-- the return value is the SchemaEntry corresponding to the schema
String whether the schema existed before the operation or not.registerIfLatest(String, SchemaEntry) attempts to register a schema
with the Subject, according to the validation rules of the Subject. The
operation succeeds only if the provided latest value is the current
latest schema in the system, and returns null otherwise.lookupById(String) looks up a schema by its id, and returns null if
such a schema does not exist. Since the mapping from id to schema is
immutable, this result is cacheable.lookupBySchema(String) looks up an id for a schema, and returns null
if no such schema exists. Since the mapping from id to schema is immutable,
this result is cacheable.allEntries() returns all the schema entries for the subject, ordered
from most recent to oldest. The result is not cacheable, since additional
entries may be added.
| Constructor Summary | |
|---|---|
protected |
Subject(String name)
A Subject has a name. |
| Method Summary | |
|---|---|
abstract Iterable<SchemaEntry> |
allEntries()
List the ids of schemas registered with the given subject, ordered from most recent to oldest. |
static Subject |
cacheWith(Subject subject,
SchemaEntryCache cache)
Create a Subject that caches id to schema mappings using the
SchemaEntryCache provided. |
abstract SubjectConfig |
getConfig()
|
String |
getName()
Return the Name of the Subject. |
abstract boolean |
integralKeys()
Indicates whether the keys generated by this subject can be expected to parse as an integer. |
abstract SchemaEntry |
latest()
Lookup the most recently registered schema for the given subject. |
abstract SchemaEntry |
lookupById(String id)
Lookup the SchemaEntry for the given subject by id. |
abstract SchemaEntry |
lookupBySchema(String schema)
Lookup the SchemaEntry for the given schema. |
static Subject |
readOnly(Subject subject)
Create a Subject that rejects modifications, throwing
IllegalStateException if a modification is attempted |
abstract SchemaEntry |
register(String schema)
If the provided schema has already been registered in this subject, return the id. |
abstract SchemaEntry |
registerIfLatest(String schema,
SchemaEntry latest)
Register the provided schema only if the current latest schema matches the provided latest entry. |
String |
toString()
|
static Subject |
validatingSubject(Subject subject,
ValidatorFactory factory)
Create a Subject that validates schemas as configured. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected Subject(String name)
Subject has a name. The name must not be null or empty, and
cannot contain whitespace. If the name contains whitespace an
IllegalArgumentException is thrown.
| Method Detail |
|---|
public String getName()
public abstract SubjectConfig getConfig()
SubjectConfig for this Subjectpublic abstract boolean integralKeys()
public abstract SchemaEntry register(String schema)
throws SchemaValidationException
SchemaEntry result and succeed.
schema - The schema to register
SchemaValidationException - If the schema change is not valid according the validation rules
of the subject
public abstract SchemaEntry registerIfLatest(String schema,
SchemaEntry latest)
throws SchemaValidationException
schema - The schema to registerlatest - the entry that must match the current actual latest value in order
to register this schema.
SchemaValidationException - If the schema change is not valid according the validation rules
of the subjectpublic abstract SchemaEntry lookupBySchema(String schema)
SchemaEntry for the given schema. Since the mapping of
schema to id is immutable, this result can be cached.
schema - The schema to look up
public abstract SchemaEntry lookupById(String id)
SchemaEntry for the given subject by id. Since the
mapping of schema to id is immutable the result can be cached.
id - the id of the schema to look up
public abstract SchemaEntry latest()
SchemaEntry or null if no schema is registered with
this subjectpublic abstract Iterable<SchemaEntry> allEntries()
SchemaEntry in the subject may grow over time.
SchemaEntry objects in this subject, ordered from most
recent to oldest.public String toString()
toString in class ObjectSubjectpublic static final Subject readOnly(Subject subject)
Subject that rejects modifications, throwing
IllegalStateException if a modification is attempted
public static Subject validatingSubject(Subject subject,
ValidatorFactory factory)
Subject that validates schemas as configured.
public static Subject cacheWith(Subject subject,
SchemaEntryCache cache)
Subject that caches id to schema mappings using the
SchemaEntryCache provided.
subject - The Subject to wrapcache - The SchemaEntryCache to cache with
Subject instance that caches SchemaEntry
values with the cache provided, if and only if both parameters are
not null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||