Skip to content

Commit

Permalink
JCBC-155: Adding JavaDoc for *View.java files.
Browse files Browse the repository at this point in the history
This changeset adds JavaDoc for AbstractView, SpatialView and View.
It is intended to clarify their usage and what they can be used for.

Change-Id: I62b9bda1eb4b006fa012be909cec92a66e3fafdc
Reviewed-on: http://review.couchbase.org/22872
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information
daschl authored and Michael Nitschinger committed Nov 29, 2012
1 parent 21fe279 commit 328ea1e
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 15 deletions.
Expand Up @@ -23,34 +23,77 @@
package com.couchbase.client.protocol.views;

/**
* A base class for views and spatial views.
* The base class for Views and Spatial Views.
*
* This class acts as a base class for both map/reduce views and spatial
* views. Do not use this class directly, but instead create instances from
* either the View or the SpatialView classes.
*/
public abstract class AbstractView {
private final String viewName;
private final String designDocumentName;
private final String databaseName;

public AbstractView(String dn, String ddn, String vn) {
databaseName = dn;
designDocumentName = ddn;
viewName = vn;
/**
* Instantiate a AbstractView object.
*
* This should only be used by subclasses like View or SpatialView.
*
* @param database the name of the database.
* @param designDoc the name of the corresponding design document.
* @param view the name of the view itself.
*/
public AbstractView(String database, String designDoc, String view) {
databaseName = database;
designDocumentName = designDoc;
viewName = view;
}

/**
* Returns the database (bucket) name.
*
* @return the database (bucket) name.
*/
public String getDatabaseName() {
return databaseName;
}

/**
* Returns the design document name.
*
* @return the name of the design document.
*/
public String getDesignDocumentName() {
return designDocumentName;
}

/**
* Returns the view name.
*
* @return the name of the view.
*/
public String getViewName() {
return viewName;
}

/**
* Checks if the view has a "map" method defined.
*
* @return true if it has a "map" method defined, false otherwise.
*/
public abstract boolean hasMap();

/**
* Checks if the view has a "reduce" method defined.
*
* @return true if it has a "reduce" method defined, false otherwise.
*/
public abstract boolean hasReduce();

/**
* Returns the URI/String representation of the View.
*
* @return the URI path of the View to query against the cluster.
*/
public abstract String getURI();
}
30 changes: 27 additions & 3 deletions src/main/java/com/couchbase/client/protocol/views/SpatialView.java
Expand Up @@ -28,23 +28,47 @@
*/
public class SpatialView extends AbstractView {

public SpatialView(String dn, String ddn, String vn) {
super(dn, ddn, vn);
/**
* Create a new Spatial View object.
*
* @param database the name of the database.
* @param designDoc the name of the corresponding design document.
* @param viewName the name of the view itself.
*/
public SpatialView(String database, String designDoc, String viewName) {
super(database, designDoc, viewName);
}

/**
* Will always return true, because Spatial Views need to have a map
* function.
*
* @return true.
*/
@Override
public boolean hasMap() {
return true;
}

/**
* Will always return false, because Spatial Views can't have reduce
* functions.
*
* @return false.
*/
@Override
public boolean hasReduce() {
return false;
}

/**
* Returns the URI/String representation of the Spatial View.
*
* @return the URI path of the Spatial View to query against the cluster.
*/
@Override
public String getURI() {
return "/" + getDatabaseName() + "/_design/" + getDesignDocumentName()
+ "/_spatial/" + getViewName();
}
}
}
43 changes: 36 additions & 7 deletions src/main/java/com/couchbase/client/protocol/views/View.java
Expand Up @@ -23,33 +23,62 @@
package com.couchbase.client.protocol.views;

/**
* Holds information about a view that can be queried in
* Couchbase Server.
* Represents a View definition inside the Couchbase cluster.
*
* This class knows whether the view contains "map" and/or "reduce" functions.
* It also is able to generate the URI representation of itself to be used
* against the cluster. Also, instances of a View can be used in combination
* with DesignDocuments to actually create them.
*/
public class View extends AbstractView {

private final boolean map;
private final boolean reduce;

public View(String dn, String ddn, String vn, boolean m, boolean r) {
super(dn, ddn, vn);
map = m;
reduce = r;
/**
* Create a new View object.
*
* @param database the name of the database.
* @param designDoc the name of the corresponding design document.
* @param viewName the name of the view itself.
* @param map if the View contains a map function or not.
* @param reduce if the View contains a reduce function or not.
*/
public View(String database, String designDoc, String viewName,
boolean map, boolean reduce) {
super(database, designDoc, viewName);
this.map = map;
this.reduce = reduce;
}

/**
* Checks if the view has a "map" method defined.
*
* @return true if it has a "map" method defined, false otherwise.
*/
@Override
public boolean hasMap() {
return map;
}

/**
* Checks if the view has a "reduce" method defined.
*
* @return true if it has a "reduce" method defined, false otherwise.
*/
@Override
public boolean hasReduce() {
return reduce;
}

/**
* Returns the URI/String representation of the View.
*
* @return the URI path of the View to query against the cluster.
*/
@Override
public String getURI() {
return "/" + getDatabaseName() + "/_design/" + getDesignDocumentName()
+ "/_view/" + getViewName();
}
}
}

0 comments on commit 328ea1e

Please sign in to comment.