org.lightcouch.CouchDbClient Java Examples

The following examples show how to use org.lightcouch.CouchDbClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VersionedCouchDBProvider.java    From julongchain with Apache License 2.0 6 votes vote down vote up
public VersionedCouchDBProvider(){
       log.debug("Constructing CouchDB VersionedDBProvider");
	CouchDBDefinition couchDBDefinition = new CouchDBDefinition();
	CouchDbProperties properties = new CouchDbProperties(
			couchDBDefinition.getUserName(),
			true,
			"http",
			couchDBDefinition.getHost(),
			couchDBDefinition.getPort(),
			couchDBDefinition.getUserName(),
			couchDBDefinition.getPassword()

	)
			.setConnectionTimeout(couchDBDefinition.getRequestTimeOut())
			.setMaxConnections(couchDBDefinition.getMaxRetriesOnStartUp());
	this.databases = new HashMap<>();
	this.dbInstance = new CouchDbClient(properties);
}
 
Example #2
Source File: CouchDBBlockLogger.java    From exo-demo with MIT License 5 votes vote down vote up
/**
 * Constructor which allows the instantiating code to pass in CouchDBClient
 * configuration variables used to instantiate the logger's CouchDBClient..
 * 
 * @see org.lightcouch.CouchDbClient
 */
public CouchDBBlockLogger(
		String dbName, 
		boolean createDbIfNotExist, 
		String protocol, 
		String host, 
		int port, 
		String username, 
		String password) 
{
	this.client = new CouchDbClient(dbName, createDbIfNotExist, protocol, host, port, username, password);
	this.initialize();
}
 
Example #3
Source File: CouchDBUtil.java    From julongchain with Apache License 2.0 5 votes vote down vote up
public static void  CreateSystemDatabasesIfNotExist(CouchDbClient dbInstance){
    CouchDB couchDB = new CouchDB();
    String dbName1 = "_users";
    couchDB.createDatabaseIfNotExist(dbInstance, dbName1);
    String dbName2 = "_replicator";
    couchDB.createDatabaseIfNotExist(dbInstance, dbName2);
    String dbName3 = "_global_changes";
    couchDB.createDatabaseIfNotExist(dbInstance, dbName3);
}
 
Example #4
Source File: VersionedCouchDB.java    From julongchain with Apache License 2.0 5 votes vote down vote up
public VersionedCouchDB(CouchDbClient dbInstance, String dbName) throws LedgerException {
	this.couchDB = new CouchDB();
	this.groupName = dbName;
	dbName = constructMetadataName(dbName);
	couchDB.createDatabaseIfNotExist(dbInstance, dbName);
	this.metadataDB = dbInstance;
	this.dbInstance = dbInstance;
	this.namespaceDBs = new HashMap<>(32);
	this.committedDataCache = new CommittedVersions();
}
 
Example #5
Source File: VersionedCouchDB.java    From julongchain with Apache License 2.0 5 votes vote down vote up
private synchronized CouchDbClient getNamespaceDBHandle(String namespace) throws LedgerException {
	if (namespaceDBs.containsKey(namespace)) {
		return namespaceDBs.get(namespace);
	}
	namespace = constructNamespaceName(groupName, namespace);
	CouchDbClient db = namespaceDBs.get(namespace);
	if (db == null) {
		couchDB.createDatabaseIfNotExist(dbInstance, namespace);
	}
	namespaceDBs.put(namespace, db);
	return db;
}
 
Example #6
Source File: VersionedCouchDB.java    From julongchain with Apache License 2.0 5 votes vote down vote up
@Override
  public VersionedValue getState(String namespace, String key) throws LedgerException {
log.debug("GetState : ns = " + namespace + " key = " + key);
CouchDbClient db = getNamespaceDBHandle(namespace);
JSONObject doc = couchDB.readDoc(db, key);
if (doc == null) {
	return null;
}

return null;
  }
 
Example #7
Source File: CouchDBIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    cubeController.create(CONTAINER_NAME);
    cubeController.start(CONTAINER_NAME);
    client = new CouchDbClient(COUCHDB_NAME, true,
        "http", TestUtils.getDockerHost(), 5984, COUCHDB_USERNAME, COUCHDB_PASSWORD);
}
 
Example #8
Source File: CouchDBBlockLogger.java    From exo-demo with MIT License 4 votes vote down vote up
/**
 * Configures a CouchDBBlockLogger instance from a list of 
 * key-value parameters loaded from an exo-config file.
 * 
 * Expected parameters are:  
 * databaseName		The name of the CouchDB database to log to
 * useAsPrefix		When true, the logger will append the node's 
 * 					name to the "databaseName" value when determining 
 * 					the database name
 * host				Identifies the CouchDB instance hostname
 * port				Identifies the CouchDB listener port
 * prototcol			(optional) Should be "http" or "https" depending on your 
 * 					CouchDB configuration.  Defaults to "http"
 * username			(optional) Specifies the username to log into couchDB with
 * password			(optional) Specifies the password to log into couchDB with
 * blockSize			(optional) Determines the number of transactions in 
 * 					a block.  Defaults to 4.
 * createDb			(optional) Create the database if it doesn't already exist
 */
@Override
public void configure(DefaultKeyValue<String, String>[] parameters) {
	//Organize parameters into a map for easy access
	Map<String, String> parameterMap = new HashMap<String, String>();
	for (DefaultKeyValue<String, String> parameter : parameters) {
		parameterMap.put(parameter.getKey(), parameter.getValue());
	}
	
	//Determine database name
	String databaseName = parameterMap.get("databaseName");
	if (parameterMap.containsKey("useAsPrefix") && parameterMap.get("useAsPrefix").equals("true")) {
		databaseName = databaseName + ExoPlatformLocator.getPlatform().getAddress().getSelfName().toLowerCase();
	}
	
	//Determine protocol
	String protocol;
	if (parameterMap.containsKey("protocol")) {
		protocol = parameterMap.get("protocol");
	} else {
		protocol = "http";
	}
	
	//Determine if we should create the database, if it doesn't exist
	boolean createDB = parameterMap.containsKey("createDb") && parameterMap.get("createDb").equals("true");
	
	//See if a block size is defined in the config
	if (parameterMap.containsKey("blockSize")) {
		BLOCK_SIZE = Integer.parseInt(parameterMap.get("blockSize"));
	}
	
	this.client = new CouchDbClient(
		databaseName, 
		createDB, 
		protocol, 
		parameterMap.get("host"), 
		Integer.parseInt(parameterMap.get("port")),
		parameterMap.get("username"),
		parameterMap.get("password")
	);
	
	this.initialize();
	
}
 
Example #9
Source File: CouchDbConnection.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public CouchDbConnection(final CouchDbClient client) {
    this.client = client;
}
 
Example #10
Source File: CouchDbProvider.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
private CouchDbProvider(final CouchDbClient client, final String description) {
    this.client = client;
    this.description = "couchDb{ " + description + " }";
}
 
Example #11
Source File: CouchDBBlockLogger.java    From exo-demo with MIT License 2 votes vote down vote up
/**
 * Constructor which allows the instantiating code to pass 
 * in a subset of common CouchDBClient configuration variables 
 * used to instantiate the logger's CouchDBClient..
 * 
 * @see org.lightcouch.CouchDbClient
 */
public CouchDBBlockLogger(String dbName, String protocol, String host, int port) {
	this.client = new CouchDbClient(dbName, true, protocol, host, port, null, null);
	this.initialize();
}