Topaz Overview

Contents

Motivations

What is Topaz?

Simple Example

Annotated java class (definition of Account not shown here):

@Entity(types = {"foaf:Person"}, model = "people")
public class Person {
  private URI id;
  private String name;
  private Account acc;
  private URI blog;

  @Id
  public void setId(URI id) { this.id = id; }
  public URI getId() { return id; }

Simple Example (Continued)

  @Predicate(uri = "foaf:name")
  public void setName(String name) { this.name = name; }
  public String getName() { return name; }

  @Predicate(uri = "foaf:holdsAccount")
  public void setAcc(Account acc) { this.acc = acc; }
  public Account getAcc() { return acc; }

  @Predicate(uri = "foaf:weblog")
  public void setBlog(URI blog) { this.blog = blog; }
  public URI getBlog() { return blog; }
}

Simple Example (Continued - usage)

Work with it:

Session sess = sessFactory.openSession();
Transaction txn = sess.beginTransaction();

Person p1 = new Person(...);
sess.saveOrUpdate(p1);

Person p2 = sess.get(Person.class,
                     "http://some.org/people/john");
Results r = sess.createQuery(
    "select p from Person p where p.name = 'John Bentley';")
    .execute();
while (r.next()) Person p = r.get("p")

txn.commit();

Simple Example Explained

@Entity(type = {"foaf:Person"}, model = "people")
public class Person {
  public URI id;
  private String name;
  private Account acc;
  private URI blog;

Simple Example Explained (Continued)

  @Id
  public void setId(URI id) { this.id = id; }
  public URI getId() { return id; }

Simple Example Explained (Continued)

  @Predicate(uri = "foaf:name")
  public void setName(String name) { this.name = name; }
  public String getName() { return name; }

  @Predicate(uri = "foaf:holdsAccount")
  public void setAcc(Account acc) { this.acc = acc; }
  public Account getAcc() { return acc; }

  @Predicate(uri = "foaf:weblog")
  public void setBlog(URI blog) { this.blog = blog; }
  public URI getBlog() { return blog; }

Mapping to RDF

Java (application) code:

Person p1 = new Person();
p1.id   = new URI("my:id1");
p1.name = "John Bentley";
p1.blog = new URI("http://cool.blogs.com/john");
p1.acc  = new Account(new URI("my:accnt1"), "jbentley");
sess.saveOrUpdate(p1);

continued...

Mapping to RDF (continued)

Resulting RDF (in N-Triples format):

<my:id1> <rdf:type> <foaf:Person> .
<my:id1> <foaf:name> "John Bentley" .
<my:id1> <foaf:weblog> <http://cool.blogs.com/john> .
<my:id1> <foaf:holdsAccount> <my:accnt1> .
<my:accnt1> <rdf:type> <foaf:OnlineAccount> .
<my:accnt1> <foaf:accountName> "jbentley" .

Handling Blobs

@Entity(type = "foaf:Person", model = "people")
public class Person {
  @Id
  public void setId(URI id) { this.id = id; }
  ...
  @Predicate(uri = "foaf:img")
  public Image pic;
}

@Entity(type = "foaf:Image", model = "people")
public class Image {
  private URI id;
  private byte[] data;
  @Id
  public void setId(URI id) { this.id = id; }
  public URI getId() { return id; }
  @Blob
  public void setData(byte[] data) { this.data = data; }
  public byte[] getData() { return data; }
}

Handling Blobs (Continued)

Work with it - just like other fields and classes:

Session sess = sf.openSession();
Transaction txn = sess.beginTransaction();

Person p1 = new Person(...);
p1.pic      = new Image();
p1.pic.id   = ...
p1.pic.data = ...
sess.saveOrUpdate(p1);

Person p2 = sess.get(Person.class,
                     "http://some.org/people/john");
display(p2.pic.data);

txn.commit();

Handling Blobs Explained

@Entity(type = "foaf:Image", model = "people")
public class Image {
  private URI id;
  private byte[] data;
  @Id
  public void setId(URI id) { this.id = id; }
  public URI getId() { return id; }
  @Blob
  public void setData(byte[] data) { this.data = data; }
  public byte[] getData() { return data; }
}

Handling Blobs Explained (continued)