Databases Reference
In-Depth Information
def run_query(name, month):
MyModel.objects.filter(lowercase_name=name.lower(),
month_last_modified=month)
models.py
gets replaced by more elegant, clean, and reusable code like this:
# models.py:
Available for
download on
Wrox.com
class MyModel(models.Model):
name = models.CharField(max_length=64)
last_modified = models.DateTimeField(auto_now=True)
def run_query(name, month):
MyModel.objects.filter(name__iexact=name, last_modified__month=month)
# dbindexes.py:
from models import MyModel
from dbindexer.api import register_index
register_index(MyModel, {'name': 'iexact', 'last_modified': 'month'})
models_with_dbindexer.py
You can read more about django-nonrel by accessing the documentation, available online at
www.allbuttonspressed.com/projects/django-nonrel .
Using Spring Data
Though Rails and Django are popular web frameworks for agile development, a lot of enterprise
developers still use Java to build their new-generation applications. Spring is a popular Java
dependency injection framework that has been widely adopted around the world. Spring has included
NoSQL support via its Spring Data project. You can access information on the Spring Data project at
www.springsource.org/spring-data . Spring Data not only provides an abstraction layer for many
NoSQL products but also facilitates MapReduce-based processing and access to cloud platforms.
In the following section, I put together a small example using Spring Data to access and interact with
Redis. Spring Data supports Redis via a sub-project. It supports other NoSQL products using a similar
mechanism. Java client libraries to interface and interact with Redis exist today. One such library is
JRedis, http://code.google.com/p/jredis/ . Another is jedis, https://github.com/xetorthio/
jedis . Spring Data abstracts out these Java client libraries under RedisTemplate much the same way
as Spring abstracts out JDBC access via JdbcTemplate or Hibernate access via HibernateTemplate. The
objective of the template is to shield the user from the low-level details of the API.
To get started, download and build the Spring Data Redis sub-project from https://github
.com/SpringSource/spring-data-keyvalue . For simplicity and faster development, you can
use the SpringSource Tool Suite (STS), www.springsource.com/developer/sts , and create a new
Spring project using a project template. STS uses Maven to confi gure and build a project so the
defi nitions are specifi ed in a project's project object model (POM). You can read more about Maven
Search WWH ::




Custom Search