OTM (Object/Triple Mapping)
Place holder for OTM documentation. Currently used for tracking development activities.
To do list
- Support for java.util.Map
- Cursors for query results
Otm Annotations
@Entity at Class level
'' ==> rdf:type
name ==> defaults to class name
model ==> the storage model; defaults to super-class
@Predicate at Field level
'' ==> predicate-uri; defaults to uriPrefix + field-name
inverse ==> defaults to false
model ==> the storage model; defaults to class
dataType ==> defaults based on field type
colType ==> defaults to direct predicate with no min cardinality restriction ;
options are predicate, rdfList, rdfBag, rdfSeq, rdfAlt
notOwned ==> defaults to false
type ==> property type; defaults based on rest of the definition
options are data-property or object-property
fetch ==> for associations; defaults to lazy
options are lazy or eager
cascade ==> for associations; defaults to 'all'
'all' implies saveOrUpdate, delete, flush, evict, refresh;
deleteOrphan - is for orphan association delete not implied by 'all'
@Id at Field level
@GeneratedValue at Field level
generator ==> IF id-generation is desired, name of generator (e.g. "GUID")
baseUri ==> for unique-id generation, uri prefix to use when creating ids
@UriPrefix at Class level
'' ==> base-uri; no defaults
alias ==> no defaults
@Alias at Global/Class level
'' ==> uri
alias ==> no defaults
@View at Class level
'' ==> OQL query string for the view
@SubView at Class level
@Embeddable at Class level
@Embedded at Field level
@PredicateMap at Field level
@ValueMap at Field level (todo)
key ==> key field from association
@Blob at Field level
@Projection at Field level for Views
var ==> OQL projection var name
To sum-up, class-level annotations are:
1. One of (@Entity or @Embeddable or @View or @SubView)
2. @UriPrefix
3. @Alias
and the field-level annotations are:
1. One of (@Predicate or @Embedded or @Id or @PredicateMap, @Blob, @Projection)
2. @GeneratedValue
Domain models and metadata
Implementing the domain model
- Transparent automated persistence
- no special class or interface needed for persistence
- persistent classes can be re-used outside the context of persistence
- persistent classes are not aware of the underlying persistence store or aware that they are being persisted
- Writing POJOs and persistent entity classes
- POJO best practices
- No argument constructor
- get/set property accessor methods
- any additional business methods
- Implementing POJO associations
- Same way as other properties
- Adding logic to accessor methods
- validation etc. can be defined on set methods by the app
- direct field access can be configured to by-pass during load from store (todo)
Object/Triple mapping metadata
- xml config (todo?)
- annotations
- global config (todo - specify default model/graph etc.)
- global annotation metadata (todo - package-info.java or after imports in a class)
- Manipulating metadata at runtime
- make metadata mutable (why? todo?)
- generic/meta apps can access object values directly from Mapper
Alternative entity representations
3 modes of operation:
- POJO - domain model implementation based on POJOs
- MAP - no java classes; entities represented with HashMaps?; allows quick prototyping (todo)
- DOM4J - no java classes; entities as XML elements; useful for import/export and xslt (todo)
- Creating dynamic applications (todo)
- configure an entity (xml etc.) and set props in a Map and access via Session with entity name
- mixing static and dynamic modes
- mapping a class several times - with different entity names
- Representing data in XML (todo)
- dom4j session returs dom Element for get/load etc.; tree configurable
Mapping persistent classes
Understanding entities and value types
1. Fine-grained domain models
- crude definition : more classes than rdf:type
- properties can be grouped and added to an embedded class (eg. DC for dc properties)
2. Defining the concept
- an object of entity type has its own id/subject-uri
- an object of value type has no id/subject-uri of its own (eg. DC or Address or java.util.Date)
3. Identifying entities and value types
- avoid shared references to value types
- life-cycle of a value type is bound to its owning entity instance
- entity classes must have an id/subject-uri property
Mapping entities with identity
1. Understanding identity and equality
- the == operator for instance equality
- equals() method for app level equality
- id/subject-uri identifies resources in triple-store
2. Handling triple-store identity
- exposed via the identifier property of entities
- should not change the value of identifier property (set once at load/create)
Class mapping options
1. Dynamic ITQL/SPARQL generation
- static/pre-cached/non-dynamic CRUD statements (todo)
- dirty check and skipping unmodified properties for updates (todo)
2. Making an entity immutable (todo)
- POJO is immutable if no setter method - all values set in constructor
- load from store needs to do direct field access
3. Naming entities for querying
- by default class name without the package prefix is imported into namespace
- for conflict resolution add an override (todo define @Entity())
4. Fine-grained models and mapping
- all properties are persisted by default except the ones with 'transient' keyword
- customize access-type : field|property|noop|custom.Class (todo)
- Using derived properties
- eg. @Formula("TOTAL + TAX_RATE * TOTAL) - ITQL/SPARQL support??? (todo)
- generated properties (eg. lastModified) - ITQL resolver??? (todo)
- mapping @Embedded/@Embeddable components
- use @AttributeOverrides? in entity class to change/define @Predicate (todo)
- back pointer from embedded component to parent via @Parent (todo)
Inheritence and custom types
Mapping class inheritence
- rdf:type identifies the class. Most specific rdf:type mapping defines the sub-class
- you can define an entity without an rdf:type but there is no sub-classing support
Data type and Serializers
- Defaults for basic java types corresponds to equivalent xsd types
- Untyped literals can be defined or an override can be specified
- Users can define new data types and register Serializers
- Supporting blobs
Mapping collections and associations
- collections must be initialized at declaration time; not in a constructor.
- use generics for the element type.
- all collections are stored as sets in the store
- support for rdf:list, rdf:bag etc.
- sorting of collections (todo)
- collections of componet/embedded classes
- no special syntax for associations; non embedded classes with no serializers are considered an assoication
- @Inverse to represent an inverse association (ie. the associated class references this)
- cascading of updates/deletes/merges
Advanced entity association mapping
- transparent indirect associations via a blank node (rdf:List, rdf:bag etc.)
- Mapping maps (todo @MapKey? - key defaults to @Id)
- polymorphic associations and collections - lazy loads creats only the super-class
Store level options
- provide options to specify custom CUD (todo)
- constraints. @unique @check @notnull (todo)
