Avon Implementation
Overview
Avon Interfaces
Avon Model
Avon Storage
Avon Query Processor
DemoAvon Interfaces
Programmatic Interface: OMSjp 1.2
OML (last week)
Graphical Interfaces Eclipse Plugin
OMSjp Browser (DEMO)
Programmatic Interface
Programmatic Interface: OMSjp
Java interface to OM model
Support for multiple inheritance, classification, role modeling, query, data definition andmanipulation
Architecture
Client-Server
Multiple clients
Java Virtual Machine
Database Application
OMSjp
OMS Platform OMSjp Interface
Driver(s) Cache Java Virtual Machine
Database Application
OMSjp
OMS Platform OMSjp Interface
Driver(s) Cache
Inprocess
Personal mobile information systems
OMS Driver
Abstraction from underlying OM Implementation One per platform
DriverManager
Driver configuration via URL
Similar to JDBC<omsjp:platform:user/password@host:port/database>
<omsjp:avon:stefania/***@localhost/test.oms>
Mapping OM to Java
A person can be both, student and employee
Multiple Instantiation
Impedance mismatch with Java
person
student phd student employee
Mapping OM to Java…
Metamodel of OM Object
Most Important Classes
OMSObject
OMSObjectType
OMSInstance
OMSCollection
OMSAssociationExample: Type Schema
create type contact (…);
create type person subtype of contact ();
create type location (…);
create type organisation subtype of contact (…);
…
contact
person organisation
location
Example: Classification Schema
contact
Contacts
person
Persons
organisation
Organisations
cover
location
Locations located_at
(0:*) (0:*)
lives_at (1:*)
(0:*)
// Collections
create collection Contacts : set of contact;
create collection Persons : set of person;
create collection Organisations : set of organisation;
…
OMSObject
dress(ObjectType type), strip(ObjectType type)
setAttributeValue(…), getAttributeValue(…)
//create john object and set attribute values
final OMSObjectType contactType = database.getObjectType(“contact");
final OMSObject john = database.createObject(contactType);
john.setAttributeValue(contactType, “name", "John");
…
//dress john as person john.dress(personType);
john.setAttributeValue(personType, “birthDate", "20.12.1978");
OMSObject…
getMembershipCollections(), getMembershipCollections(Type type)
getLink(OMSAssociation assoc) and inverse
//get johns locations
final List<OMSObject> locations = john.getLinks(locatedAtAssoc) //get johns homeplaces
final List<OMSObject> homeplaces = john.getLinks(livesAtAssoc) //get membership collections
final List<OMSCollection> colls = john.getMembershipCollections()
homeplaces locations
OMSObject and OMSInstance
final Person johnPerson = (Person)john.browse(personType);
String birthDate = johnPerson.getBirthDate();
final Contact johnContact = (Contact)john.browse(contactType) johnContact.setName(“Johnny”);
getInstances(), getDressTypes()
browse(ObjectType type)
OMSInstance: Contact Class
public class Contact extends AbstractInstance {
public void setName(final String name) throws OMSException { this.setAttributeValue(“name", name);
}
public String getName() throws OMSException {
OMSString s = (OMSString) this.getAttributeValue(“name");
return s.getString();
} ...
}
Instance registration: Mapping of Java classes to database types contact=ch.ethz.globis.test.Contact
How to implement the OMSjp classes?
Create dataobjects, types, collections, hierarchies, constraints
Access datagetAttributeValue(…): …
Manipulate datasetAttributeValue(…)
ProcessingexecuteMethod(…): …
Collectionsadd, retrieve, remove members, hierarchies, constraints
…
… and PersistentModel and Metamodel
OMSjp interfaces represent metamodel concepts
Interface implementation implements a metamodelobject Objects
type Types
collection Collections
association Associations disjoint
Example: A Simple Metamodel
We need to store and retrieve data
attributes declared by types
attribute values of objects
collection membership
…
Example: A Simple Metamodel …
Where is it stored that personType has a name and attributes?
personType is an instance of type with name = “personType” and declaring the attributes “name” of type string and “birthdate” of type date
Where is it stored that type has a name and attributes?
type is an instance of type with name = “type” and declaring the
attributes “name” of type string and “attributes” of type list<attribute>
Example: A Simple Metamodel …
What is an attribute?
attribute is an instance of type with name = “attribute” and declaring the attributes “name” of type string and “type” of type type
(OMSjp Metamodel: What is a collection?
collection is an instance of type with name = “collection” and declaring the attributes “name” of type string and “extent” of type bulktype
… method, association, hierarchy, constraint?)
Example: A Simple Metamodel …
What Java classes can we use to representperson objects, person types, types, attributes?
What is common to all these objects?They are all objects which store values for the attributes declared by their types
final Object personType = new Object();
personType.dress(TYPE);
personType.setAttributeValue(TYPE, nameAttribute, “person");
personType.setAttributeValue(TYPE, attributesAttribute, …);
final Object person = new Object();
person.dress(personType);
person.setAttributeValue(personType, nameAttribute, “daniel");
…
A Vicious Circle
final Object type = new Object();
type.dress(type);
type.setAttributeValue(type, nameAttribute, “type");
final Object nameAttribute = new Object();
nameAttribute.dress(attribute);
final Object attribute = new Object();
attribute.dress(type);
• Type has not declared its attributes
• Name attribute does not exist
• Attribute type does not exist
• Type has not declared its attributes
• Name attribute has not been initialised
When creating the type type we want to set its attributes “name” and
“attributes”.
We need the objects representing the “name” and “attributes” attributes
When creating the “name” attribute we must have the object representing the attribute type
When creating the attribute type we must have the object representing the type type (… but this is the one we were about to create)
// create types
final Object object = new Object();
final Object type = new Object();
…
// create attributes
final Object typeName = new Object();
final Object typeAttributes = new Object();
…
// dress
object.dress(object);
object.dress(type);
type.dress(object);
…
// create attribute values
…
// set type attributes values
object.setAttributeValue(type, typeName, objectNameValue);
object.setAttributeValue(type, typeAttributes, objectAttributesValue);
type.setAttributeValue(type, typeName, typeNameValue);
…
// set attributes attribute values
typeName.setAttributeValue(attribute, attributeName, typeNameName);
typeName.setAttributeValue(attribute, attributeType, typeNameType);
typeAttributes.setAttributeValue(attribute, attributeName, typeAttributesName);
…
Bootstrap
Kind of pipelining to break out of vicious circle
Objects created during bootstrap must be available to userAvon Metamodel: Object Types
Avon Metamodel: Object Types …
name: String Collection
extent: Ranking<? ext Value>
RankingCollection
extent: Set<? ext Value>
SetCollection
extent: Bag<? ext Value>
BagCollection
extent: Sequence<? ext Value>
SequenceCollection
Avon Metamodel: Collections
Avon Metamodel: Types and Collections
(0:1)
(0:*)
type
Types
collection
Collections
method
Methods
objectType
ObjectTypes
type
BaseTypes
bulkType
BulkTypes
structuredType
StructuredTypes
partition
ObjectTypeISAs (0:*) (0:*)
BaseTypeISAs (0:*) (0:*) CollectionISAs
(0:*) (0:*)
HasMethods (1:1)
Extent (0:*)
Java Classes of Avon
initialise() Database CoreBootstrap BaseTypesBootstrap CollectionsBootstrap BootstrapManager
Java Classes of Avon …
Simplification the creation, retrieval and deletion of OMObject objects that represent the various
metamodel concepts
e.g. CollectionGateway.create(): OMObject
returns OMObject with types object and collection
Java Classes of Avon …
Simplification of setting and retrieving attribute values of OMObject objects
e.g. AttributeUtils.getName(OMObject): String
if argument is of type attribute, return its name AttributeUtils AssociationUtils
CollectionUtils
TypeUtils
ValueUtils Database
Utils
isAttribute(OMStructuredValue): boolean getName(OMObject): String
setName(OMObject, String) getType(OMObject): OMObject
AttributeUtils
isAssociation(OMObject): boolean getName(OMObject): String setName(OMObject, String)
getDomainCardinality(OMObject): OMStructuredValue getRangeCardinality(OMObject): OMStructuredValue getDomainCollection(OMObject): OMObject getRangeCollection(OMObject): OMObject getRelationCollection(OMObject): OMObject
AssociationUtils
Java Classes of Avon: Layering
Persistency Object Model
OMSjp
OMObject Database
Utils
Gateway
DBObject InformationUnit AttributeValue StorageBase
Utils
AvonObject AvonInstance AvonValue
AvonAssociation AvonCollection
AvonType
AvonSchema AvonDatabase
OML
Query
db4o
Storage Layer
Uses db4o
A new impedance mismatch between OM and java
Object activationStorage Layer
Storage Layer - DBObject
Corresponds to OMObject from the OM layer
Contains references to information units (an information unit for each type)
Dress adds information units
Strip removes information unitsStorage Layer - DBObject
Type : Object
Object
Type : Object
Object
Type : Student Type : Person
Type : Object
Object
Type : Student Type : Person Type : Object
Object
Type : PhDStudent Type : Person
dress (Object, Student)
createObject
strip (Object, Student)
dress (Object, PhDStudent)
Storage Layer - CompositeValue
Base class for StructuredValue and InformationUnit
Type (object type or structured type)
Values – associated with attributes of the typeStorage Layer - Activation
Db4o activation - process of populating theattributes of an object with previously stored data
container.activate (obj, 1)
Transparent activationQuery Engine
Language process with in a three level architecture.
ExtensionsQuery Engine
Parser process
JavaCC package used to generate parser and lexer.
Returns an AST (abstract syntax tree)QueryTree converter
Transforms the AST into a QT (query tree)
Uses the Visitor design pattern
Postorder AST processingQuery Tree
QT nodes are atomic construct that are used to build different database operations (Selection, Domain, Iterator, Object)
A Visitor interface is associated with the tree structureQuery Tree
SituatedAt rr (all $l in Locations having
($l.city = "Zurich"))
Query Tree Evaluator
Uses the Visitor interface of the QT
Postorder traversal
Returns only the last result from the OML script
Memorizes the result in the node structureSymbol Table
Stores temporary object references
Organized as a stack.
Duplicate names in different scopes are allowedQueries - storage layer
OM queries are transform into SODA queries sel (Locations, city, “Zurich”)
query.constrain (StringValue.class)
query. descend(“value”).constrain (“Zurich”) resStrVal = query.execute();
Temporary query results are stored in db4oExtensions
Allow OML to grow
Syntax expanders nodes (AST) set[ `obj1.version(1.2)`, `obj2.version(1.0)`];
`grant R to UserName`;
Extensions
An Extension Node is currently generated in the core AST.
A separate module processes extensionstrings ( `obj1.version(1.2)`, `obj2.version(1.0)`, ...)