Package org.lightcouch
Class CouchDbClient
- java.lang.Object
-
- org.lightcouch.CouchDbClientBase
-
- org.lightcouch.CouchDbClient
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class CouchDbClient extends CouchDbClientBase implements java.io.Closeable
Presents a client to CouchDB database server.This class is the main object to use to gain access to the APIs.
Usage Example:
Create a new client instance:
CouchDbClient dbClient = new CouchDbClient();
Start using the API by the client:
Documents
CRUD
APIs is accessed by the client directly, eg.:dbClient.find(Foo.class, "doc-id")
View APIs
dbClient.view()
Change Notifications
dbClient.changes()
Replication
dbClient.replication()
anddbClient.replicator()
DB server
dbClient.context()
Design documents
dbClient.design()
At the end of a client usage; it's useful to call:
shutdown()
to ensure proper release of resources.- Since:
- 0.0.2
- See Also:
CouchDbClientAndroid
-
-
Field Summary
-
Fields inherited from class org.lightcouch.CouchDbClientBase
host, httpClient, log
-
-
Constructor Summary
Constructors Constructor Description CouchDbClient()
Constructs a new instance of this class, expects a configuration file namedcouchdb.properties
to be available in your application default classpath.CouchDbClient(java.lang.String configFileName)
Constructs a new instance of this class.CouchDbClient(java.lang.String dbName, boolean createDbIfNotExist, java.lang.String protocol, java.lang.String host, int port, java.lang.String username, java.lang.String password)
Constructs a new instance of this class.CouchDbClient(CouchDbProperties properties)
Constructs a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
private org.apache.http.impl.conn.PoolingHttpClientConnectionManager
createConnectionManager(CouchDbProperties props, org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> registry)
(package private) org.apache.http.protocol.HttpContext
createContext()
(package private) org.apache.http.client.HttpClient
createHttpClient(CouchDbProperties props)
private org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory>
createRegistry(CouchDbProperties props)
private void
registerInterceptors(org.apache.http.impl.client.HttpClientBuilder clientBuilder)
Adds request/response interceptors for logging and validation.void
shutdown()
Shuts down the connection manager used by this client instance.-
Methods inherited from class org.lightcouch.CouchDbClientBase
batch, bulk, changes, contains, context, delete, design, executeRequest, find, find, find, find, find, findAny, findDocs, get, get, get, getBaseUri, getDBUri, getGson, head, invokeUpdateHandler, post, post, put, put, remove, remove, replication, replicator, save, saveAttachment, saveAttachment, setGsonBuilder, syncDesignDocsWithDb, update, validate, view
-
-
-
-
Constructor Detail
-
CouchDbClient
public CouchDbClient()
Constructs a new instance of this class, expects a configuration file namedcouchdb.properties
to be available in your application default classpath.
-
CouchDbClient
public CouchDbClient(java.lang.String configFileName)
Constructs a new instance of this class.- Parameters:
configFileName
- The configuration file name.
-
CouchDbClient
public CouchDbClient(java.lang.String dbName, boolean createDbIfNotExist, java.lang.String protocol, java.lang.String host, int port, java.lang.String username, java.lang.String password)
Constructs a new instance of this class.- Parameters:
dbName
- The database name.createDbIfNotExist
- To create a new database if it does not already exist.protocol
- The protocol to use (i.e http or https)host
- The database host addressport
- The database listening portusername
- The Username credentialpassword
- The Password credential
-
CouchDbClient
public CouchDbClient(CouchDbProperties properties)
Constructs a new instance of this class.- Parameters:
properties
- An object containing configuration properties.- See Also:
CouchDbProperties
-
-
Method Detail
-
createHttpClient
org.apache.http.client.HttpClient createHttpClient(CouchDbProperties props)
- Specified by:
createHttpClient
in classCouchDbClientBase
- Returns:
CloseableHttpClient
instance.
-
createContext
org.apache.http.protocol.HttpContext createContext()
- Specified by:
createContext
in classCouchDbClientBase
- Returns:
HttpContext
instance for HTTP request execution.
-
createConnectionManager
private org.apache.http.impl.conn.PoolingHttpClientConnectionManager createConnectionManager(CouchDbProperties props, org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> registry)
-
createRegistry
private org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> createRegistry(CouchDbProperties props) throws java.security.KeyManagementException, java.security.NoSuchAlgorithmException, java.security.KeyStoreException
- Throws:
java.security.KeyManagementException
java.security.NoSuchAlgorithmException
java.security.KeyStoreException
-
registerInterceptors
private void registerInterceptors(org.apache.http.impl.client.HttpClientBuilder clientBuilder)
Adds request/response interceptors for logging and validation.- Parameters:
clientBuilder
-
-
shutdown
public void shutdown()
Description copied from class:CouchDbClientBase
Shuts down the connection manager used by this client instance.- Specified by:
shutdown
in classCouchDbClientBase
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-