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

java.lang.Object
  extended by net.vz.mongodb.jackson.WriteResult<T,K>

public class WriteResult<T,K>
extends Object

This class lets you access the results of the previous write. if you have STRICT mode on, this just stores the result of that getLastError call if you don't, then this will actually do the getlasterror call. if another operation has been done on this connection in the interim, calls will fail This class also gives you access to the saved objects, for the purposes of finding out the objects ids, if they were generated by MongoDB.

Since:
1.0
Author:
James Roper

Constructor Summary
protected WriteResult(JacksonDBCollection<T,K> jacksonDBCollection, com.mongodb.WriteResult writeResult, com.mongodb.DBObject... dbObjects)
           
 
Method Summary
 com.mongodb.CommandResult getCachedLastError()
          Gets the last result from getLastError()
 com.mongodb.DBObject getDbObject()
          Get the underlying DBObject that was serialised before it was saved.
 com.mongodb.DBObject[] getDbObjects()
          Get the underlying DBObjects that were serialised before they were saved.
 String getError()
          Gets the error String ("err" field)
 Object getField(String name)
          Gets a field
 com.mongodb.WriteConcern getLastConcern()
          Gets the last WriteConcern used when calling getLastError()
 com.mongodb.CommandResult getLastError()
          calls getLastError(com.mongodb.WriteConcern) with concern=null
 com.mongodb.CommandResult getLastError(com.mongodb.WriteConcern concern)
          This method does following: - returns the existing CommandResult if concern is null or less strict than the concern it was obtained with - otherwise attempts to obtain a CommandResult by calling getLastError with the concern
 int getN()
          Gets the "n" field, which contains the number of documents affected in the write operation.
 K getSavedId()
          Get the saved ID.
 K[] getSavedIds()
          Get the saved IDs.
 T getSavedObject()
          Get the object that was saved.
 T[] getSavedObjects()
          Get the objects that were saved.
 com.mongodb.WriteResult getWriteResult()
          The underlying write result
 boolean isLazy()
          Returns whether or not the result is lazy, meaning that getLastError was not called automatically
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WriteResult

protected WriteResult(JacksonDBCollection<T,K> jacksonDBCollection,
                      com.mongodb.WriteResult writeResult,
                      com.mongodb.DBObject... dbObjects)
Method Detail

getSavedObject

public T getSavedObject()
Get the object that was saved. This will contain the updated ID if the ID was generated.

Note, this operation is a little expensive because it has to deserialise the object. If you just want the ID, call getSavedId() instead.

Returns:
The saved object
Throws:
com.mongodb.MongoException - If no objects were saved

getSavedObjects

public T[] getSavedObjects()
Get the objects that were saved. These will contain the updated IDs if the IDs were generated.

This operation only works if object serialization is used. If stream serialization is used, the IDs are generated by the database, and cannot be known.

Note, this operation is a little expensive because it has to deserialise the objects. If you just want the IDs, call getSavedIds() instead.

Returns:
The saved objects

getSavedId

public K getSavedId()
Get the saved ID. This may be useful for finding out the ID that was generated by MongoDB if no ID was supplied.

Returns:
The saved ID
Throws:
com.mongodb.MongoException - If no objects were saved

getSavedIds

public K[] getSavedIds()
Get the saved IDs. This may be useful for finding out the IDs that were generated by MongoDB if no IDs were supplied.

Returns:
The saved IDs

getDbObject

public com.mongodb.DBObject getDbObject()
Get the underlying DBObject that was serialised before it was saved. This will contain the updated ID if an ID was generated.

Returns:
The underlying DBObject
Throws:
com.mongodb.MongoException - If no objects were saved

getDbObjects

public com.mongodb.DBObject[] getDbObjects()
Get the underlying DBObjects that were serialised before they were saved. These will contain the updated IDs if IDs were generated.

Returns:
The underlying DBObjects

getWriteResult

public com.mongodb.WriteResult getWriteResult()
The underlying write result

Returns:
Get the underlying MongoDB write result

getCachedLastError

public com.mongodb.CommandResult getCachedLastError()
Gets the last result from getLastError()

Returns:
The last error

getLastConcern

public com.mongodb.WriteConcern getLastConcern()
Gets the last WriteConcern used when calling getLastError()

Returns:
The last write concern.

getLastError

public com.mongodb.CommandResult getLastError()
calls getLastError(com.mongodb.WriteConcern) with concern=null

Returns:
The last error

getLastError

public com.mongodb.CommandResult getLastError(com.mongodb.WriteConcern concern)
This method does following: - returns the existing CommandResult if concern is null or less strict than the concern it was obtained with - otherwise attempts to obtain a CommandResult by calling getLastError with the concern

Parameters:
concern - the concern
Returns:
The last error for the concern

getError

public String getError()
Gets the error String ("err" field)

Returns:
The error string

getN

public int getN()
Gets the "n" field, which contains the number of documents affected in the write operation.

Returns:
The n field

getField

public Object getField(String name)
Gets a field

Parameters:
name - field name
Returns:
The value

isLazy

public boolean isLazy()
Returns whether or not the result is lazy, meaning that getLastError was not called automatically

Returns:
if it's lazy

toString

public String toString()
Overrides:
toString in class Object


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