Modeling Hierarchical Data in Postgres

Hierarchical data has historically been a challenge with relational databases. There are well-known solutions for implementing a hierarchy in a purely relational fashion, but their complexity and performance are not generally desirable. To overcome this, some modern RDBMSs have a special data type for hierarchical values. In the case of Postgres, this data type is the ltree.

The ltree data type allows for storing paths similar to filesystem paths or DNS records, and provides the ability to perform hierarchical queries which are much cleaner and more efficient than their purely relational counterparts. But often we want to have further constraints, such as requiring the existence of all ancestors in each path, and this requires additional work. Here we develop a complete implementation of the common use case of an entity hierarchy with the same properties as a filesystem directory tree.

ltree Basics

The ltree documentation refers to each ltree value as a path, and each component of the path as a label. A path is a series of labels separated by Continue reading

Blog List Example with Volley

In my previous iterations of the of the Blog List example, the BlogListService just returned a hardcoded list of BlogPost objects. In this post, we will actually retrieve the list of BlogPost objects from a restful JSON service.

Ideally, you can eliminate much of the HTTP traffic by using some sort of a client side caching layer. This is where Volley comes in.

So, in this post I’ll show two things:

  1. One of the many ways to consume JSON and convert it into java objects
  2. The use of Volley as an asynchronous network thread management and caching solution (replacing the AsyncTaskLoader in the prior examples).

Continue reading