|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.fourspaces.couchdb.Document
public class Document
Everything in CouchDB is a Document. In this case, the document is an object backed by a JSONObject. The Document is also aware of the database that it is connected to. This allows the Document to reload it's properties when needed. The only special fields are "_id", "_rev", "_revisions", and "_view_*".
All document have an _id and a _rev. If this is a new document those fields are populated when they are saved to the CouchDB server.
_revisions is only populated if the document has been retrieved via database.getDocumentWithRevisions(); So, if this document wasn't, then when you call document.getRevisions(), it will go back to the server to reload itself via database.getDocumentWithRevisions().
The Document can be treated like a JSONObject, eventhough it doesn't extend JSONObject (it's final).
You can also get/set values by calling document.get(key), document.put(key,value), just like a Map.
You can get a handle on the backing JSONObject by calling document.getJSONObject(); If this hasn't been loaded yet, it will load the data itself using the given database connection.
If you got this Document from a view, you are likely missing elements. To load them you can call document.load().
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Field Summary | |
---|---|
protected Database |
database
|
protected net.sf.json.JSONObject |
object
|
Constructor Summary | |
---|---|
Document()
Create a new Document |
|
Document(net.sf.json.JSONObject obj)
Create a new Document from a JSONObject |
Method Summary | |
---|---|
net.sf.json.JSONObject |
accumulate(String arg0,
boolean arg1)
|
net.sf.json.JSONObject |
accumulate(String arg0,
double arg1)
|
net.sf.json.JSONObject |
accumulate(String arg0,
int arg1)
|
net.sf.json.JSONObject |
accumulate(String arg0,
long arg1)
|
net.sf.json.JSONObject |
accumulate(String arg0,
Object arg1)
|
void |
accumulateAll(Map arg0)
|
View |
addView(String designDoc,
String viewName,
String function)
Add a view to this document. |
void |
clear()
|
boolean |
containsKey(Object arg0)
|
boolean |
containsValue(Object arg0)
|
void |
deleteView(String viewName)
Removes a view from this document. |
net.sf.json.JSONObject |
element(String arg0,
boolean arg1)
|
net.sf.json.JSONObject |
element(String arg0,
Collection arg1)
|
net.sf.json.JSONObject |
element(String arg0,
double arg1)
|
net.sf.json.JSONObject |
element(String arg0,
int arg1)
|
net.sf.json.JSONObject |
element(String arg0,
long arg1)
|
net.sf.json.JSONObject |
element(String arg0,
Map arg1)
|
net.sf.json.JSONObject |
element(String arg0,
Object arg1)
|
net.sf.json.JSONObject |
elementOpt(String arg0,
Object arg1)
|
Set |
entrySet()
|
Object |
get(Object arg0)
|
Object |
get(String arg0)
|
boolean |
getBoolean(String arg0)
|
double |
getDouble(String arg0)
|
String |
getId()
This document's id (if saved) |
int |
getInt(String arg0)
|
net.sf.json.JSONArray |
getJSONArray(String arg0)
|
net.sf.json.JSONObject |
getJSONObject()
Retrieves the backing JSONObject |
net.sf.json.JSONObject |
getJSONObject(String arg0)
|
long |
getLong(String arg0)
|
String |
getRev()
This document's Revision (if saved) |
String[] |
getRevisions()
A list of the revision numbers that this document has. |
String |
getString(String arg0)
|
View |
getView(String name)
Get a named view that is stored in the document. |
String |
getViewDocumentId()
This strips _design from the document id |
boolean |
has(String arg0)
|
boolean |
isEmpty()
|
Iterator |
keys()
|
Set |
keySet()
|
protected void |
load(net.sf.json.JSONObject object2)
Load data into this document from a differing JSONObject |
net.sf.json.JSONArray |
names()
|
Object |
opt(String arg0)
|
boolean |
optBoolean(String arg0)
|
boolean |
optBoolean(String arg0,
boolean arg1)
|
double |
optDouble(String arg0)
|
double |
optDouble(String arg0,
double arg1)
|
int |
optInt(String arg0)
|
int |
optInt(String arg0,
int arg1)
|
net.sf.json.JSONArray |
optJSONArray(String arg0)
|
net.sf.json.JSONObject |
optJSONObject(String arg0)
|
long |
optLong(String arg0)
|
long |
optLong(String arg0,
long arg1)
|
String |
optString(String arg0)
|
String |
optString(String arg0,
String arg1)
|
protected void |
populateRevisions()
|
Object |
put(Object arg0,
Object arg1)
|
void |
putAll(Map arg0)
|
void |
refresh()
Loads data from the server for this document. |
Object |
remove(Object arg0)
|
Object |
remove(String arg0)
|
void |
setId(String id)
|
void |
setRev(String rev)
|
int |
size()
|
String |
toString()
|
Collection |
values()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Field Detail |
---|
protected Database database
protected net.sf.json.JSONObject object
Constructor Detail |
---|
public Document()
public Document(net.sf.json.JSONObject obj)
obj
- Method Detail |
---|
protected void load(net.sf.json.JSONObject object2)
This is mainly for reloading data for an object that was retrieved from a view. This version doesn't overwrite any unsaved data that is currently present in this object.
object2
- public String getId()
public void setId(String id)
public String getViewDocumentId()
public String getRev()
public void setRev(String rev)
public String[] getRevisions() throws IOException
IOException
public View getView(String name)
name
-
public View addView(String designDoc, String viewName, String function)
This isn't persisted until the document is saved.
design
- document nameviewName
- function
-
public void deleteView(String viewName)
This isn't persisted until the document is saved.
viewName
- public void refresh() throws IOException
IOException
protected void populateRevisions() throws IOException
IOException
public net.sf.json.JSONObject getJSONObject()
public String toString()
toString
in class Object
public net.sf.json.JSONObject accumulate(String arg0, boolean arg1)
public net.sf.json.JSONObject accumulate(String arg0, double arg1)
public net.sf.json.JSONObject accumulate(String arg0, int arg1)
public net.sf.json.JSONObject accumulate(String arg0, long arg1)
public net.sf.json.JSONObject accumulate(String arg0, Object arg1)
public void accumulateAll(Map arg0)
public void clear()
clear
in interface Map
public boolean containsKey(Object arg0)
containsKey
in interface Map
public boolean containsValue(Object arg0)
containsValue
in interface Map
public net.sf.json.JSONObject element(String arg0, boolean arg1)
public net.sf.json.JSONObject element(String arg0, Collection arg1)
public net.sf.json.JSONObject element(String arg0, double arg1)
public net.sf.json.JSONObject element(String arg0, int arg1)
public net.sf.json.JSONObject element(String arg0, long arg1)
public net.sf.json.JSONObject element(String arg0, Map arg1)
public net.sf.json.JSONObject element(String arg0, Object arg1)
public net.sf.json.JSONObject elementOpt(String arg0, Object arg1)
public Set entrySet()
entrySet
in interface Map
public Object get(Object arg0)
get
in interface Map
public Object get(String arg0)
public boolean getBoolean(String arg0)
public double getDouble(String arg0)
public int getInt(String arg0)
public net.sf.json.JSONArray getJSONArray(String arg0)
public net.sf.json.JSONObject getJSONObject(String arg0)
public long getLong(String arg0)
public String getString(String arg0)
public boolean has(String arg0)
public Iterator keys()
public Set keySet()
keySet
in interface Map
public net.sf.json.JSONArray names()
public Object opt(String arg0)
public boolean optBoolean(String arg0, boolean arg1)
public boolean optBoolean(String arg0)
public double optDouble(String arg0, double arg1)
public double optDouble(String arg0)
public int optInt(String arg0, int arg1)
public int optInt(String arg0)
public net.sf.json.JSONArray optJSONArray(String arg0)
public net.sf.json.JSONObject optJSONObject(String arg0)
public long optLong(String arg0, long arg1)
public long optLong(String arg0)
public String optString(String arg0, String arg1)
public String optString(String arg0)
public Object put(Object arg0, Object arg1)
put
in interface Map
public void putAll(Map arg0)
putAll
in interface Map
public Object remove(Object arg0)
remove
in interface Map
public Object remove(String arg0)
public int size()
size
in interface Map
public Collection values()
values
in interface Map
public boolean isEmpty()
isEmpty
in interface Map
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |