|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.fourspaces.couchdb.Session
public class Session
The Session is the main connection to the CouchDB instance. However, you'll only use the Session to obtain a reference to a CouchDB Database. All of the main work happens at the Database level.
It uses the Apache's HttpClient library for all communication with the server. This is a little more robust than the standard URLConnection.
Ex usage:
Session session = new Session(host,port);
Database db = session.getDatabase("dbname");
Field Summary | |
---|---|
protected String |
host
|
protected org.apache.http.client.HttpClient |
httpClient
|
protected CouchResponse |
lastResponse
|
protected org.apache.commons.logging.Log |
log
|
protected String |
pass
|
protected int |
port
|
protected boolean |
secure
|
protected String |
user
|
protected boolean |
usesAuth
|
Constructor Summary | |
---|---|
Session(String host,
int port)
Main constructor for obtaining a Session. |
|
Session(String host,
int port,
boolean secure)
Optional constructor that indicates an HTTPS connection should be used. |
|
Session(String host,
int port,
String user,
String pass)
Constructor for obtaining a Session with an HTTP-AUTH username/password This isn't supported by CouchDB - you need a proxy in front to use this |
|
Session(String host,
int port,
String user,
String pass,
boolean usesAuth,
boolean secure)
Constructor for obtaining a Session with an HTTP-AUTH username/password and (optionally) a secure connection This isn't supported by CouchDB - you need a proxy in front to use this |
Method Summary | |
---|---|
protected String |
buildUrl(String url)
For a given url (such as /_all_dbs/), build the database connection url |
protected String |
buildUrl(String url,
org.apache.http.NameValuePair[] params)
|
protected String |
buildUrl(String url,
String queryString)
|
Database |
createDatabase(String name)
Creates a new database (if the name doesn't already exist) |
boolean |
deleteDatabase(Database db)
Deletes a database from the CouchDB server |
boolean |
deleteDatabase(String name)
Deletes a database (by name) from the CouchDB server. |
protected String |
encodeParameter(String paramValue)
|
Database |
getDatabase(String name)
Loads a database instance from the server |
List<String> |
getDatabaseNames()
Retrieves a list of all database names from the server |
String |
getHost()
Read-only |
CouchResponse |
getLastResponse()
Returns the last response for this given session - useful for debugging purposes |
int |
getPort()
read-only |
protected CouchResponse |
http(org.apache.http.client.methods.HttpRequestBase req)
Method that actually performs the GET/PUT/POST/DELETE calls. |
boolean |
isSecure()
Is this a secured connection (set in constructor) |
void |
setConnectionTimeout(int milliseconds)
|
void |
setSocketTimeout(int milliseconds)
|
void |
setUserAgent(String ua)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected org.apache.commons.logging.Log log
protected final String host
protected final int port
protected final String user
protected final String pass
protected final boolean secure
protected final boolean usesAuth
protected CouchResponse lastResponse
protected org.apache.http.client.HttpClient httpClient
Constructor Detail |
---|
public Session(String host, int port, String user, String pass, boolean usesAuth, boolean secure)
host
- - hostnameport
- - port to useuser
- - usernamepass
- - passwordsecure
- - use an SSL connection?public Session(String host, int port, String user, String pass)
host
- port
- user
- - usernamepass
- - passwordpublic Session(String host, int port)
host
- port
- public Session(String host, int port, boolean secure)
host
- port
- secure
- Method Detail |
---|
public String getHost()
public int getPort()
public boolean isSecure()
public List<String> getDatabaseNames()
public Database getDatabase(String name)
name
-
public Database createDatabase(String name)
name
-
public boolean deleteDatabase(String name)
name
-
public boolean deleteDatabase(Database db)
db
-
protected String buildUrl(String url)
url
-
protected String buildUrl(String url, String queryString)
protected String buildUrl(String url, org.apache.http.NameValuePair[] params)
protected CouchResponse http(org.apache.http.client.methods.HttpRequestBase req)
This returns a CouchResponse, which can be used to get the status of the call (isOk), and any headers / body that was sent back.
method
-
public CouchResponse getLastResponse()
public void setUserAgent(String ua)
public void setConnectionTimeout(int milliseconds)
public void setSocketTimeout(int milliseconds)
protected String encodeParameter(String paramValue)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |