net.vz.mongodb.jackson
Class DBRef<T,K>

java.lang.Object
  extended by net.vz.mongodb.jackson.DBRef<T,K>
Direct Known Subclasses:
FetchableDBRef

public class DBRef<T,K>
extends Object

A database reference object

Since:
1.2
Author:
James Roper

Constructor Summary
DBRef(K id, Class<T> type)
          Construct a new database reference with the given id and type.
DBRef(K id, String collectionName)
          Construct a new database reference with the given id and collection name
 
Method Summary
 T fetch()
          Fetch the object.
 T fetch(com.mongodb.DBObject fields)
          Fetch only the given fields of the object.
 String getCollectionName()
          Get the name of the collection this object lives in
 K getId()
          Get the ID of this object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBRef

public DBRef(K id,
             String collectionName)
Construct a new database reference with the given id and collection name

Parameters:
id - The id of the database reference to construct
collectionName - The name of the collection

DBRef

public DBRef(K id,
             Class<T> type)
      throws MongoJsonMappingException
Construct a new database reference with the given id and type. The type must be annotated with MongoCollection, so that the name can be worked out.

Parameters:
id - The id of the database reference to construct
type - The type of the object
Throws:
MongoJsonMappingException - If no MongoCollection annotation is found on the type
Method Detail

getId

public K getId()
Get the ID of this object

Returns:
The ID of this object

getCollectionName

public String getCollectionName()
Get the name of the collection this object lives in

Returns:
The name of the collection this object lives in

fetch

public T fetch()
Fetch the object. Should only be called for references that have been returned by the mapper, will return null otherwise.

Deserialisation is done by the ObjectMapper that fetched the object that this reference belongs to.

Returns:
If this DBRef was returned by the mapper, the referenced object, if it exists, or null

fetch

public T fetch(com.mongodb.DBObject fields)
Fetch only the given fields of the object. Should only be called for references that have been returned by the mapper, will return null otherwise.

Deserialisation is done by the ObjectMapper that fetched the object that this reference belongs to.

Unlike the fetch() method, calls to this are not cached.

Parameters:
fields - The fields to fetch
Returns:
If this DBRef was returned by the mapper, the referenced object, if it exists, or null


Copyright © 2011-2012 VZ Netzwerke. All Rights Reserved.