Origin
Origin

Reputation: 47

CouchDB: What is an alternatives to accessing a _design view or extracting the document Fields?

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");

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

Answers (1)

Bunti
Bunti

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

Related Questions