Database Reference
In-Depth Information
protected Blog getInstance() {
return this;
}
@Override
protected Class<Blog> getType() {
return Blog.class;
}
// ----- ACCESS VIA QUERIES -----
public static Blog getBlogByName(String blogName,
SessionWrapper sessionWrapper)
throws BlogNotFoundException {
AllQueries queries = sessionWrapper.getAllQueries();
Result<Blog> rs = queries.getBlogByName(blogName);
if (rs.isExhausted()){
throw new BlogNotFoundException();
}
return rs.one();
}
}
For now, forget about the AbstractVO super class. That is just some abstraction, where
common things are thrown into AbstractVO . You can see the annotations that basically
show which keyspace and table this class is mapped to. Each instance variable is mapped
with a column in the table. For any column that has a different name than the attribute
name in the class, you will have to explicitly state that. Getters and setters do not have to
be dumb. You can get creative in there. For example, setPassword setter takes a plain
text password and hashes it before storing. Note that you must mention which field acts as
the partition key. You do not have to specify all the fields that consist of the primary key,
just the first component. Now you can use DataStax's mapper to create, retrieve, update,
and delete an object without having to marshal the results into the object. Here is an ex-
ample:
Blog blog =
new MappingManager(session)
Search WWH ::




Custom Search