Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Page Tree
rootTUP:Bean Session

...

Quick summary of features

Bean Session has a variety of features. A short list is given here for reference.

...

Working with new beans

bean mapping is specified and added to the session for use. A bean is then registered if new, meaning it is associated with a subject and the session will track changes to it, or if it has already been serialized, it is fetched.

Code Block
Context context = ... // get the context
BeanSession beanSession = new BeanSession(context); // create a new bean session
Person person = ... // create a new bean. It is assumed a mapping already exists in the context.
Resource subject = Resource.uriRef("urn:my/bean/subject"); // get or create a subject
beanSession.register(subject, person); // tell the session to manage it.
// At this point the person bean is just like any other and you may change properties
// as needed.
// Once any and all changes have been made to the bean, save it to the backing context.
beanSession.save(subject);

Fetching beans

Alternately, if data already exists, i.e., there is existing RDF that an application needs represented in a bean, then the application would fetch the bean:

Code Block
Context context = ... // get the context
Resource subject = ... // set the correct subject
BeanSession beanSession = new BeanSession(context); // create a new bean session
Person person = (Person) beanSession.fetchBean(subject); // Now the bean is ready for use.

Refetching

Other capabilities include refetching beans. By refetching we mean that the values in the context are re-read and the state of the bean is updated. Since the bean session manages instances of beans, every effected bean would show changes seamlessly.

Code Block
//.. assuming that a bean session exists and you have the subject of the bean
Person person = (Person) beanSession.fetch(subject);
// if some other process updates the context and you need these changes
beanSession.refetch(subject);
// now the stated person as well as any other beans it references, reflects these changes.