org.schemarepo.api
Class TypedSchemaRepository<ID,SCHEMA,SUBJECT>

java.lang.Object
  extended by org.schemarepo.api.TypedSchemaRepository<ID,SCHEMA,SUBJECT>

public class TypedSchemaRepository<ID,SCHEMA,SUBJECT>
extends Object

This is a convenience class for interacting with a Schema Repository in an efficient manner. It is (lazily) cached whenever possible and strongly-typed. N.B.: Currently, there is no cache eviction mechanism, so this can potentially grow to unbounded sizes. N.B.2: registerIfLatest() is not supported in the TypedSchemaRepository, at least for now...


Constructor Summary
TypedSchemaRepository(Repository repo, Converter<ID> idConverter, Converter<SCHEMA> schemaConverter, Converter<SUBJECT> subjectConverter)
           
TypedSchemaRepository(Repository repo, Converter<ID> idConverter, Converter<SCHEMA> schemaConverter, Converter<SUBJECT> subjectConverter, SubjectConfig.Builder defaultSubjectConfigBuilder)
           
 
Method Summary
 SubjectConfig getConfig(SUBJECT subjectName)
          This retrieves mutable data, hence it is not cache-able and will always result in a call to the underlying schema repo implementation.
 SCHEMA getLatestSchema(SUBJECT subjectName)
          Gets the latest schema for a given subject.
 SCHEMA getSchema(SUBJECT subjectName, ID id)
          Gets a schema for a given subject and ID.
 ID getSchemaId(SUBJECT subjectName, SCHEMA schema)
          Gets a schema ID for a given subject and schema.
 List<SUBJECT> getSubjects()
          This retrieves mutable data, hence it is not cache-able and will always result in a call to the underlying schema repo implementation.
 ID registerSchema(SUBJECT subjectName, SCHEMA schema)
          Registers a new schema in the given subject and returns its ID.
 void setConfig(SUBJECT subjectName, SubjectConfig subjectConfig)
          This sets mutable data, hence it will always result in a call to the underlying schema repo implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypedSchemaRepository

public TypedSchemaRepository(Repository repo,
                             Converter<ID> idConverter,
                             Converter<SCHEMA> schemaConverter,
                             Converter<SUBJECT> subjectConverter,
                             SubjectConfig.Builder defaultSubjectConfigBuilder)

TypedSchemaRepository

public TypedSchemaRepository(Repository repo,
                             Converter<ID> idConverter,
                             Converter<SCHEMA> schemaConverter,
                             Converter<SUBJECT> subjectConverter)
Method Detail

getSchema

public SCHEMA getSchema(SUBJECT subjectName,
                        ID id)
Gets a schema for a given subject and ID. This retrieves immutable data, hence it is cache-able indefinitely.

Parameters:
subjectName - containing the sought schema
id - of the sought schema
Returns:
the sought schema, or null if the subject does not exist or if it does not have any registered schemas yet.

getLatestSchema

public SCHEMA getLatestSchema(SUBJECT subjectName)
Gets the latest schema for a given subject. This retrieves mutable data, hence it is not cache-able and will always result in a call to the underlying schema repo implementation.

Parameters:
subjectName - to get the latest schema for
Returns:
the latest schema for the requested subject, or null if the subject does not exist or if it contains no schemas yet.

getSchemaId

public ID getSchemaId(SUBJECT subjectName,
                      SCHEMA schema)
Gets a schema ID for a given subject and schema. This retrieves immutable data, hence it is cache-able indefinitely.

Parameters:
subjectName - containing the sought ID
schema - corresponding to the sought ID
Returns:
the sought ID, or null if the subject does not exist or if it does not have any registered schemas yet.

registerSchema

public ID registerSchema(SUBJECT subjectName,
                         SCHEMA schema)
                  throws SchemaValidationException
Registers a new schema in the given subject and returns its ID. If the schema already existed, its previous ID will be returned instead. This will only result in a call to the underlying schema repo implementation if the schema is not already known in the local cache. N.B.: If the subject does not exist yet, it will be initialized with a config built from the defaultSubjectConfigBuilder provided to the TypedSchemaRepository at construction time. If you wish to use a non-default configuration, you should first invoke setConfig(Object, org.schemarepo.SubjectConfig) before invoking this function.

Parameters:
subjectName - to register the schema into
schema - to register
Returns:
the ID of the registered schema
Throws:
SchemaValidationException

getConfig

public SubjectConfig getConfig(SUBJECT subjectName)
This retrieves mutable data, hence it is not cache-able and will always result in a call to the underlying schema repo implementation.

Parameters:
subjectName - to get the config for
Returns:
the requested subject's config, or null if the subject does not exist

setConfig

public void setConfig(SUBJECT subjectName,
                      SubjectConfig subjectConfig)
This sets mutable data, hence it will always result in a call to the underlying schema repo implementation. If the subject does not exist, it will be initialized with the given config, but will not contain any ID/schema pair.

Parameters:
subjectName - to change the config for
subjectConfig - to set for the given subject

getSubjects

public List<SUBJECT> getSubjects()
This retrieves mutable data, hence it is not cache-able and will always result in a call to the underlying schema repo implementation.

Returns:
the list of all Subjects currently registered


Copyright © 2015. All rights reserved.