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 CouchDbClientBase
host, httpClient, log -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance of this class, expects a configuration file namedcouchdb.propertiesto 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 TypeMethodDescriptionvoidclose()private org.apache.http.impl.conn.PoolingHttpClientConnectionManagercreateConnectionManager(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.HttpClientprivate org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> createRegistry(CouchDbProperties props) private voidregisterInterceptors(org.apache.http.impl.client.HttpClientBuilder clientBuilder) Adds request/response interceptors for logging and validation.voidshutdown()Shuts down the connection manager used by this client instance.Methods inherited from class 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.propertiesto 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:
createHttpClientin classCouchDbClientBase- Returns:
CloseableHttpClientinstance.
-
createContext
org.apache.http.protocol.HttpContext createContext()- Specified by:
createContextin classCouchDbClientBase- Returns:
HttpContextinstance 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:CouchDbClientBaseShuts down the connection manager used by this client instance.- Specified by:
shutdownin classCouchDbClientBase
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-