Search in sources :

Example 1 with StdCouchDbConnector

use of org.ektorp.impl.StdCouchDbConnector in project sw360portal by sw360.

the class DatabaseConnectorTest method testSetUp.

@Test
public void testSetUp() throws Exception {
    // Default connector for testing
    HttpClient httpClient = new StdHttpClient.Builder().url(COUCH_DB_URL).build();
    CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
    CouchDbConnector db = new StdCouchDbConnector(COUCH_DB_DATABASE, dbInstance, factory);
    // Check that the document was inserted
    assertTrue(db.contains(id));
}
Also used : StdHttpClient(org.ektorp.http.StdHttpClient) HttpClient(org.ektorp.http.HttpClient) StdCouchDbInstance(org.ektorp.impl.StdCouchDbInstance) CouchDbInstance(org.ektorp.CouchDbInstance) StdCouchDbInstance(org.ektorp.impl.StdCouchDbInstance) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector) CouchDbConnector(org.ektorp.CouchDbConnector) Test(org.junit.Test)

Example 2 with StdCouchDbConnector

use of org.ektorp.impl.StdCouchDbConnector in project pac4j by pac4j.

the class CouchServer method start.

public CouchDbConnector start() {
    InMemoryCouchDb couchDbClient = new InMemoryCouchDb();
    couchDbClient.createDatabase("users");
    StdHttpClient stdHttpClient = new StdHttpClient(couchDbClient);
    StdCouchDbInstance stdCouchDbInstance = new StdCouchDbInstance(stdHttpClient);
    StdCouchDbConnector couchDbConnector = new StdCouchDbConnector("users", stdCouchDbInstance);
    couchDbConnector.createDatabaseIfNotExists();
    // uploading design doc:
    String designDocString = "{\"_id\":\"_design/pac4j\",\"language\":\"javascript\",\"views\":{\"by_username\":{\"map\":\"" + "function(doc){if (doc.username) emit(doc.username, doc);}\"},\"by_linkedid\":{\"map\":\"function(doc) {" + "if (doc.linkedid) emit(doc.linkedid, doc);}\"}}}";
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        couchDbConnector.create(objectMapper.readTree(designDocString));
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    return couchDbConnector;
}
Also used : InMemoryCouchDb(mcouch.core.InMemoryCouchDb) StdHttpClient(org.ektorp.http.StdHttpClient) StdCouchDbInstance(org.ektorp.impl.StdCouchDbInstance) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with StdCouchDbConnector

use of org.ektorp.impl.StdCouchDbConnector in project sw360portal by sw360.

the class DatabaseConnectorTest method setUp.

@Before
public void setUp() throws Exception {
    // Create the test object
    object = new TestObject();
    object.setName("Test");
    object.setText("This is some nice test text.");
    // Initialize the mapper factory
    factory = new MapperFactory(ImmutableList.<Class<?>>of(TestObject.class), Collections.<Class<?>>emptyList(), Maps.newHashMap());
    // Default connector for testing
    HttpClient httpClient = new StdHttpClient.Builder().url(COUCH_DB_URL).build();
    CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
    // Create database if it does not exists
    if (!dbInstance.checkIfDbExists(COUCH_DB_DATABASE)) {
        dbInstance.createDatabase(COUCH_DB_DATABASE);
    }
    CouchDbConnector db = new StdCouchDbConnector(COUCH_DB_DATABASE, dbInstance, factory);
    // Add the object
    db.create(object);
    // Save id and rev for teardown
    id = object.getId();
    rev = object.getRevision();
    // Now create the actual database connector
    connector = new DatabaseConnector(DatabaseTestProperties.getConfiguredHttpClient(), COUCH_DB_DATABASE, factory);
}
Also used : StdHttpClient(org.ektorp.http.StdHttpClient) HttpClient(org.ektorp.http.HttpClient) StdCouchDbInstance(org.ektorp.impl.StdCouchDbInstance) TestObject(org.eclipse.sw360.testthrift.TestObject) CouchDbInstance(org.ektorp.CouchDbInstance) StdCouchDbInstance(org.ektorp.impl.StdCouchDbInstance) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector) CouchDbConnector(org.ektorp.CouchDbConnector) Before(org.junit.Before)

Example 4 with StdCouchDbConnector

use of org.ektorp.impl.StdCouchDbConnector in project gora by apache.

the class CouchDBStore method initialize.

/**
 * Initialize the data store by reading the credentials, setting the client's properties up and
 * reading the mapping file. Initialize is called when then the call to
 * {@link org.apache.gora.store.DataStoreFactory#createDataStore} is made.
 *
 * @param keyClass
 * @param persistentClass
 * @param properties
 * @throws GoraException
 */
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws GoraException {
    LOG.debug("Initializing CouchDB store");
    super.initialize(keyClass, persistentClass, properties);
    final CouchDBParameters params = CouchDBParameters.load(properties);
    try {
        final String mappingFile = DataStoreFactory.getMappingFile(properties, this, DEFAULT_MAPPING_FILE);
        final HttpClient httpClient = new StdHttpClient.Builder().url("http://" + params.getServer() + ":" + params.getPort()).build();
        dbInstance = new StdCouchDbInstance(httpClient);
        final CouchDBMappingBuilder<K, T> builder = new CouchDBMappingBuilder<>(this);
        LOG.debug("Initializing CouchDB store with mapping {}.", new Object[] { mappingFile });
        builder.readMapping(mappingFile);
        mapping = builder.build();
        final ObjectMapperFactory myObjectMapperFactory = new CouchDBObjectMapperFactory();
        myObjectMapperFactory.createObjectMapper().addMixIn(persistentClass, CouchDbDocument.class);
        db = new StdCouchDbConnector(mapping.getDatabaseName(), dbInstance, myObjectMapperFactory);
        db.createDatabaseIfNotExists();
    } catch (Exception e) {
        throw new GoraException("Error while initializing CouchDB store", e);
    }
}
Also used : CouchDBObjectMapperFactory(org.apache.gora.couchdb.util.CouchDBObjectMapperFactory) StdCouchDbInstance(org.ektorp.impl.StdCouchDbInstance) DocumentNotFoundException(org.ektorp.DocumentNotFoundException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException) ObjectMapperFactory(org.ektorp.impl.ObjectMapperFactory) CouchDBObjectMapperFactory(org.apache.gora.couchdb.util.CouchDBObjectMapperFactory) GoraException(org.apache.gora.util.GoraException) HttpClient(org.ektorp.http.HttpClient) StdHttpClient(org.ektorp.http.StdHttpClient) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector)

Example 5 with StdCouchDbConnector

use of org.ektorp.impl.StdCouchDbConnector in project cas by apereo.

the class DefaultCouchDbConnectorFactory method createConnector.

/**
 * Create {@link CouchDbConnector} instance.
 *
 * @return CouchDbConnector instance from db properties.
 */
@Override
public CouchDbConnector createConnector() {
    val connector = new StdCouchDbConnector(couchDbProperties.getDbName(), getCouchDbInstance(), objectMapperFactory);
    LOGGER.debug("Connector created: [{}]", connector);
    return connector;
}
Also used : lombok.val(lombok.val) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector)

Aggregations

StdCouchDbConnector (org.ektorp.impl.StdCouchDbConnector)5 StdHttpClient (org.ektorp.http.StdHttpClient)4 StdCouchDbInstance (org.ektorp.impl.StdCouchDbInstance)4 HttpClient (org.ektorp.http.HttpClient)3 IOException (java.io.IOException)2 CouchDbConnector (org.ektorp.CouchDbConnector)2 CouchDbInstance (org.ektorp.CouchDbInstance)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 lombok.val (lombok.val)1 InMemoryCouchDb (mcouch.core.InMemoryCouchDb)1 CouchDBObjectMapperFactory (org.apache.gora.couchdb.util.CouchDBObjectMapperFactory)1 GoraException (org.apache.gora.util.GoraException)1 TestObject (org.eclipse.sw360.testthrift.TestObject)1 DocumentNotFoundException (org.ektorp.DocumentNotFoundException)1 ObjectMapperFactory (org.ektorp.impl.ObjectMapperFactory)1 Before (org.junit.Before)1 Test (org.junit.Test)1