Search in sources :

Example 1 with CouchDBObjectMapperFactory

use of org.apache.gora.couchdb.util.CouchDBObjectMapperFactory 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
   */
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) {
    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().addMixInAnnotations(persistentClass, CouchDbDocument.class);
        db = new StdCouchDbConnector(mapping.getDatabaseName(), dbInstance, myObjectMapperFactory);
        db.createDatabaseIfNotExists();
    } catch (IOException e) {
        LOG.error("Error while initializing CouchDB store: {}", new Object[] { e.getMessage() });
        throw new RuntimeException(e);
    }
}
Also used : CouchDBObjectMapperFactory(org.apache.gora.couchdb.util.CouchDBObjectMapperFactory) StdCouchDbInstance(org.ektorp.impl.StdCouchDbInstance) IOException(java.io.IOException) ObjectMapperFactory(org.ektorp.impl.ObjectMapperFactory) CouchDBObjectMapperFactory(org.apache.gora.couchdb.util.CouchDBObjectMapperFactory) HttpClient(org.ektorp.http.HttpClient) StdHttpClient(org.ektorp.http.StdHttpClient) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector)

Aggregations

IOException (java.io.IOException)1 CouchDBObjectMapperFactory (org.apache.gora.couchdb.util.CouchDBObjectMapperFactory)1 HttpClient (org.ektorp.http.HttpClient)1 StdHttpClient (org.ektorp.http.StdHttpClient)1 ObjectMapperFactory (org.ektorp.impl.ObjectMapperFactory)1 StdCouchDbConnector (org.ektorp.impl.StdCouchDbConnector)1 StdCouchDbInstance (org.ektorp.impl.StdCouchDbInstance)1