Package org.lightcouch
Class CouchDbClient
java.lang.Object
org.lightcouch.CouchDbClientBase
org.lightcouch.CouchDbClient
- All Implemented Interfaces:
Closeable
,AutoCloseable
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()
and dbClient.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:
-
Field Summary
Fields inherited from class org.lightcouch.CouchDbClientBase
host, httpClient, log
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance of this class, expects a configuration file namedcouchdb.properties
to be available in your application default classpath.CouchDbClient
(String configFileName) Constructs a new instance of this class.CouchDbClient
(String dbName, boolean createDbIfNotExist, String protocol, String host, int port, String username, String password) Constructs a new instance of this class.CouchDbClient
(CouchDbProperties properties) Constructs a new instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
(package private) org.apache.http.client.HttpClient
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 Details
-
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
Constructs a new instance of this class.- Parameters:
configFileName
- The configuration file name.
-
CouchDbClient
public CouchDbClient(String dbName, boolean createDbIfNotExist, String protocol, String host, int port, String username, 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
Constructs a new instance of this class.- Parameters:
properties
- An object containing configuration properties.- See Also:
-
-
Method Details
-
createHttpClient
- 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 KeyManagementException, NoSuchAlgorithmException, 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
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-