Reputation: 47
I'm trying to switch a SQL-based application to use Couchdb for storing and retieving it's documents, which are based on a _design document (E.g. _design/VIEW_ALL_DOC).
The document structure is as below:
{
Map<String , String> properties = new HashMap<String,String>();
properties.put(PRICE_LIST_ID, "111000");
properties.put(FILE_NAME, "KOOO");
properties.put(VISIBILITY, "True");
properties.put(DELETION_FLAG, "0");
properties.put(FILE_CONTENT, "Pricelist");
properties.put(VERSION, "1.0");
properties.put(CREATION_DATE, "19-09-13");
properties.put(MODIFICATION_USER, "IKK");
properties.put(MODIFICATION_DATE, "20-09-13");
properties.put(CREATION_USER, "AOK");
properties.put(CUSTOMER_ID, "02227802");
properties.put(ORIGINAL_FILE_NAME, "Original");l
}
I have created the documents which is working fine but the problem lies on integrating and accessing the _design documents in the already existing Java application.
I used HttpClient lib to access the _design documents, like below:
HttpClient httpclient = new DefaultHttpClient();
HttpGet VIEW_ALL_DOCS = new HttpGet("http://localhost:5984/pricelistdocs/_design/VIEW_ALL_DOCS/_view/VIEW_ALL_DOCS");
The problem is that using the HttpClient structure would require alot of changes in the application when intergrating the Couchdb. Is there any other alternatives of access the _design/VIEW_ALL_DOC order than using the HttpClient lib?
Is there any concept of XML Blob for CouchDB document?
Even any soltion of using the HttpClient with java extractor or something like XML blob is also very good.
My goal, if possible, is to arrive at a solution that I'll use java Extrator to access and return extractor.getString(record, mapping.get(index));
the fields of the Couchdb documents like the old solution blow .
ResultSet rs = new ResultSet(response);
List<TransPriceListPdf> result = new ArrayList<TransPriceListPdf>();
while (rs.next()) {
TransPriceListPdf temp = new TransPriceListPdf();
temp.setPriceListId(rs.getString(1));
temp.setPdfFileVersion(rs.getInt(2));
temp.setPdfFileName(rs.getString(3));
temp.setOriginalFileName(rs.getString(4));
temp.setVisibility(VISIBILITY.valueof(rs.getString(5)));
temp.setDeletionFlag(rs.getInt(6) == 0 ? false : true);
temp.setPdfFileContents(rs.getBlob(7));
temp.setCreationDate(rs.getDate(8));
temp.setCreationUser(rs.getString(9));
temp.setModificationDate(rs.getDate(10));
temp.setModificationUser(rs.getString(11));
result.add(temp);
}
Although I'm still getting acquitance to Java and CouchDB. Please any Couchdb, Java or both help, tips, hints or assistance in fixing this issue will be much appreciated, no amount is little. Thank you for reading
Upvotes: 0
Views: 194
Reputation: 1760
I'm not sure what you really want to achieve here, but I guess you want get all documents you have saved in the database with the design document you have created. Provided that you have created documents correctly, you can use a Java Couch Db client (OR Mapper) such as lightCouch to convert your result set to a Java object through which you can iterate over the result set. It has fairly simple API to work with Couch DB that completely abstracts away the HTTP API exposed by Couch DB.
In order to minimize the changes required for the existing Java application you can use Adapter pattern, something that you might already know.
Upvotes: 1