Skip to content

Instantly share code, notes, and snippets.

@arnaudbos
Created June 17, 2011 09:38
Show Gist options
  • Save arnaudbos/1031129 to your computer and use it in GitHub Desktop.
Save arnaudbos/1031129 to your computer and use it in GitHub Desktop.
Testing CouchDB doc create/get with Ektorp.
HttpClient authenticatedHttpClient = new StdHttpClient.Builder().host("host").port(5984).username("user").password("pass").build();
CouchDbInstance dbInstance = new StdCouchDbInstance(authenticatedHttpClient);
CouchDbConnector db = dbInstance.createConnector("luscinia", true);
List<String> countries = new ArrayList<String>();
countries.add("Paris");countries.add("Marseille");countries.add("Bordeaux");countries.add("Toulouse");
Map<String, List<String>> majorCitiesByCountry = new HashMap<String, List<String>>();
majorCitiesByCountry.put("France", countries);
Map<String, Object> referenceData = new HashMap<String, Object>();
referenceData.put("_id", "referenceData");
referenceData.put("countries", countries);
referenceData.put("majorCitiesByCountry", majorCitiesByCountry);
db.create(referenceData);
Map<String, Object> referenceData_2 = db.get(Map.class, "referenceData");
Log.i("referenceData = "+referenceData_2);
for (Map.Entry<String, Object> entry : referenceData_2.entrySet()) {
String k = entry.getKey();
Object v = entry.getValue();
Log.i(String.format("%s %s\n", k, v));
Log.i(v.getClass().toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment