Title: Separating Adaptable Persistence Attributes through Computational Reflection
1Separating Adaptable Persistence Attributes
through Computational Reflection
- Authors Francisco Ortin, Benjamin Lopez, J.
Baltazar Garcia Perez-Schofield. - IEEE Software, Nov Dec 2004
2Dominant Persistent-Application Development
- Directly Interface with SQL
- Example
- List coffees new Vector()
- String query "SELECT COF_NAME, PRICE FROM
COFFEES" - ResultSet rs stmt.executeQuery(query)
- while (rs.next())
- Coffee coffee new Coffee()
- coffee.setName(rs.getString("COF_NAME"))
- coffee.setPrice(rs.getFloat("PRICE"))
- coffees.add(coffee)
3Dominant Persistent-Application Development (2)
- Use Object-Relational Mapping Software
(Hibernate, OJB, etc) - Example
- ltclass-descriptor class"jdbctutorial.Coffee"
table"Coffee"gt - ltfield-descriptor name"name" column"Name"
jdbc-type"VARCHAR" length"100" /gt - ltfield-descriptor name"price" column"Price"
jdbc-type"FLOAT" length"100" /gt - lt/class-descriptorgt
4Dominant Persistent-Application Development (3)
- Object Serialization
- Example
- ltcoffeegt
- ltnamegt Colombian lt/namegt
- ltpricegt 11.22 lt/pricegt
- lt/coffeegt
5Dominant Persistent-Application Development (4)
Problems
- Runtime overhead
- Impedance mismatch
- http//www.agiledata.org/essays/impedanceMismatch.
html - Explicitly write code to make objects persist
6Orthogonal Persistence
- Purpose to provide a single uniform
computational model for all aspects of an
application handling long lived data - Principles
- Type Orthogonality all data objects should have
a full range of persistence - Persistence Independence A program's form
should be independent of the longevity of the
data it manipulates - Persistence By Reachability reachability from a
set of root objects should determine each
object's lifetime.
7Orthogonal Persistence (2)
- Examples Orthogonal Persistence for Java (OPJ),
Persistent Java (Pjama), PEVM - Drawbacks
- don't treat persistence as a completely separate
concern programmers have to follow certain steps
in the application to retrieve existing or create
new persistent objects. - no adaptation of existing features such as
security and concurrency)
8Persistence in Aspect-Oriented Programming
- AOP Approach Identify a set of cross-cutting
concerns and allow to program them separately
(outside of the application main logic) - AOP Persistence Goals
- Modularize Persistence as an effective aspect,
employing AOP techniques - Reuse persistence aspects regardless of the
application - Develop programs that are unaware of their data's
persistence nature.
9 Persistence in Aspect-Oriented Programming (2)
- Examples Shortcomings
- AspectJ example persistence and application
logic could be separate retrieval and deletion
have to be explicit, storing and updating don't. - PersAJ provides a model for persistence,
doesn't separate application data and persistence
code - Jorg Kienzle Rachid Guerraoui case study on
separating concurrency control and failure
handling code in a distributed system only
reviewed translations one facet of persistence
10Reflective Systems
- Definition a computational system's capability
to reason about and act upon itself. - Levels of Reflection
- Introspection access to system structure but not
modification (Java, C, C) - Structural Reflection dynamic altering of a
system's structure (Python, Smalltalk) - Computational Reflection dynamic customization
of system structure and semantics
11The nitr0 reflective system
- Nonrestrictive computationally reflective system
- Language Neutral currently Python, ECMAScript,
Java (subset) - Developed in Python 2.2
- Generic Interpreter capable of interpreting any
language based on a specification - Language Specification Files express lexical
and syntactic features using context free
grammar.
12Nitr0 Sample Application
13Nitr0 Sample Application (2)
- Things to note
- Java app statements to identify the application
name and language - The reflective app can access the author
program's internal structure, and language
semantics, dynamically adapting the application
through computational reflection. - Python app modifies 'firstName' and 'surname'
attributes, adds a 'middleName' attribute. - Could also modify the show method to display
middle name
14The Nitr0 Persistence System
- Subsystems
- Interpreter contextual analysis and application
execution. A subset of Java, eliminating
primitives. - Application offers representation of every
running program (classes, methods, objects, etc).
Independent of language (must be OO). - Persistence allows dynamic and transparent
customization of the app's reflective features
(e.g. storage, indexing, and update policy)
15The Nitr0 Persistence System Interpreter
- Generates the program's Abstract Syntax Tree
(AST) based on Java specification - Interprets AST
- Performs decoration of AST, following the Visitor
design pattern http//exciton.cs.oberlin.edu/javar
esources/DesignPatterns/VisitorPattern.htm - The programmer can obtain computational
reflection my modifying the execution visitor's
visit methods.
16The Nitr0 Persistence System Application
- Java runtime classes Classes (JClass), Fields
(JField), constructors (JConstructor), methods
constructors (JMethodGroup), references (JRef) - Instance interface (methods to make an element
persistent) makePersistent, makeTransient,
store, restore, getID - Unique ID Considerations JInstance returns IP
address, process ID, user ID, active thread ID,
millis since 01/01/1970
17The Nitr0 Persistence System Persistence
18The Nitr0 Persistence System Persistence (2)
- Notes
- Manager the module's Facade, implemented as a
Singleton - Storage and StoragePolicy abstract classes,
partial implementation.
19The Nitr0 Persistence System Persistence -
Storage
- Storages a way of keeping persistent
information - 3 Types of storage
- SimpleStorage dictionary
- BSDStorage linear hash, B tree, variable
length record storage - DBMStorage a unix based DBMS library.
20The Nitr0 Persistence System Persistence -
Policies
- Policies how to update the objects into the
selected storage - 2 policies
- SimplePolicy whenever a persistence object is
modified. - TimedPolicy whenever a timer reaches a
configurable number of seconds
21The Nitr0 Persistence System Persistence
Serialization
- Object serialization Python pickle module
(Object -gtbyte array and vice versa) - Swizzling Unswizzling converting persistence
object Ids (PIDs) to references. - Manager translates all persistent objects that
the current one has references to. - InstanceTable weak dictionary mapping PIDs to
memory references, also a cache. - InstanceTable uses weak references, garbage
collected.
22Sample Bibliography application
23Conclusion
- Runtime Performance
- To be addressed in the future using JIT
(Just-In-Time) compilation or adaptable native
code generation for the generic interpreter - Can be improved via a Python JIT compiler as all
objects are converted to Python. - Available at http//www.di.uniovi.es/reflection/la
b