Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tracking Events Using a Semi-Structured Repository : Page 4

Tracking the activities of a system and its users is too often not considered until the application is already deployed. Learn how to demonstrate an (almost) no hassle persistent bean pool that you can use to track the activities of an already developed system for later review.


advertisement
Tracking Events
Multi-user applications often do not properly track system events. This is sometimes caused by the complexity involved in persisting them. In any system there are many types of events (sometimes hundreds of types). When using a database to persist events, the overhead for maintaining a database schema with so many event types, and new event types being created with every new feature, is high. However, by using a semi-structured repository, the overhead for persisting events is greatly reduced.

To persist events in OpenRDF Elmo you need to create an interface for the event objects. You can use the same technique for persisting events as used previously for persisting exceptions. Create an event type interface as shown in Listing 4.

You can also create an event implementation class for this interface and merge it into the manager as shown previously, or use the delegate manager's designate method, shown here:



private static EntityManagerFactory factory = createEntityManagerFactory("rdf"); // singleton EntityManager entityManager = factory.createEntityManager(); ElmoManager manager = (ElmoManager) entityManager.getDelegate(); ModifiedEvent event = manager.designate(ModifiedEvent.class); event.setUser(user); event.getModified().add(target); event.setDate(new Date()); manager.close(); // event can no longer be used

The user and modified targets will also need to have interfaces, with annotations, listed in the elmo.roles file for them to be persisted. Objects that are referenced by multiple objects or events, such as user and modified targets, should have a getQName method. This method must return a qualified name that will be used to uniquely identify it in the repository.

With events now stored in the repository, you can use the repository to provide a history of the system. For example, to find out how an object was modified, you can query the repository.

js> sparql = "PREFIX evt: SELECT ?event WHERE { ?event evt:modified ?target }" js> query = manager.createQuery(sparql) js> query.setQName("target", new QName("http://example.org/rdf/orders/", "209")); js> event = query.singleResult js> println("order 209 was modified by" + event.user); js> println("order 209 was modified on" + event.date); js> println("order 209 was modified along with" + event.modified);

Tracking creation events is a similar by creating an interface and persisting it like in Listing 5. This event has an extra property reason that stores the user's inputted goal at the time of creation. This gives the user a chance to provide the reason why they are making a chance. This information can then be later retrieved using a query and provides necessary information to assess the correctness of the operation.

js> sparql = "PREFIX evt: SELECT ?event WHERE { ?event evt:created ?target }" js> query = manager.createQuery(sparql) js> query.setQName("target", new QName("http://example.org/rdf/orders/", "209")); js> event = query.singleResult js> println("Order 209 was created by" + event.user + "on" + event.date + "for" + event.reason );

Conclusion
Semi-structured repositories can provide more flexibility and less maintenance than traditional persistence layers. This type of repository is ideal for structures that are continually changing, have diverse properties, or are managed by independent teams. You can use the OpenRDF Elmo library to persist a wide variety of objects without necessarily modifying the original source. Without a lot of setup, you have seen how to create a repository, use it in your own software, and access it through a convenient search and browser interface.



James Leigh is an independent software consultant based in Toronto, has experience modeling business problems and concepts in software, and specializes in performance and technology integration. James has a background in semantic web technologies and decentralized networks. He is an active member in the OpenRDF community, and he's a developer of Sesame and Elmo.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap