Class CouchDbDesign


  • public class CouchDbDesign
    extends java.lang.Object
    Provides API to work with design documents.

    Usage Example:

     // read from system files
     DesignDocument design1 = dbClient.design().getFromDesk("example");
     
     // sync with the database
     dbClient.design().synchronizeWithDb(design1);
     
     // sync all with the database
     dbClient.syncDesignDocsWithDb();
     
     // read from the database
     DesignDocument design2 = dbClient.design().getFromDb("_design/example");
     
    Since:
    0.0.2
    See Also:
    DesignDocument
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private CouchDbClientBase dbc  
      private static java.lang.String DESIGN_DOCS_DIR  
      private static java.lang.String DESIGN_PREFIX  
      private static java.lang.String FILTERS  
      private static java.lang.String FULLTEXT  
      private static java.lang.String INDEXES  
      private static java.lang.String JAVASCRIPT  
      private static java.lang.String LISTS  
      private static java.lang.String MAP_JS  
      private static java.lang.String REDUCE_JS  
      private static java.lang.String REWRITES  
      private static java.lang.String SHOWS  
      private static java.lang.String UPDATES  
      private static java.lang.String VALIDATE_DOC  
      private static java.lang.String VIEWS  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<DesignDocument> getAllFromDesk()
      Gets all design documents from desk.
      DesignDocument getFromDb​(java.lang.String id)
      Gets a design document from the database.
      DesignDocument getFromDb​(java.lang.String id, java.lang.String rev)
      Gets a design document from the database.
      DesignDocument getFromDesk​(java.lang.String id)
      Gets a design document from desk.
      private java.util.Map<java.lang.String,​java.lang.String> populateMap​(java.lang.String rootPath, java.util.List<java.lang.String> elements, java.lang.String element)  
      java.lang.String readContent​(java.util.List<java.lang.String> elements, java.lang.String rootPath, java.lang.String element)  
      void synchronizeAllWithDb()
      Synchronize all design documents on desk to the database.
      Response synchronizeWithDb​(DesignDocument document)
      Synchronizes a design document to the Database.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • synchronizeWithDb

        public Response synchronizeWithDb​(DesignDocument document)
        Synchronizes a design document to the Database.

        This method will first try to find a document in the database with the same id as the given document, if it is not found then the given document will be saved to the database.

        If the document was found in the database, it will be compared with the given document using equals(). If both documents are not equal, then the given document will be saved to the database and updates the existing document.

        Parameters:
        document - The design document to synchronize
        Returns:
        Response as a result of a document save or update, or returns null if no action was taken and the document in the database is up-to-date with the given document.
      • getFromDb

        public DesignDocument getFromDb​(java.lang.String id)
        Gets a design document from the database.
        Parameters:
        id - The document id
        Returns:
        DesignDocument
      • getFromDb

        public DesignDocument getFromDb​(java.lang.String id,
                                        java.lang.String rev)
        Gets a design document from the database.
        Parameters:
        id - The document id
        rev - The document revision
        Returns:
        DesignDocument
      • getAllFromDesk

        public java.util.List<DesignDocument> getAllFromDesk()
        Gets all design documents from desk.
        Returns:
        a list of all design documents
        See Also:
        getFromDesk(String)
      • getFromDesk

        public DesignDocument getFromDesk​(java.lang.String id)
        Gets a design document from desk.
        Parameters:
        id - The document id to get.
        Returns:
        DesignDocument
      • populateMap

        private java.util.Map<java.lang.String,​java.lang.String> populateMap​(java.lang.String rootPath,
                                                                                   java.util.List<java.lang.String> elements,
                                                                                   java.lang.String element)
      • readContent

        public java.lang.String readContent​(java.util.List<java.lang.String> elements,
                                            java.lang.String rootPath,
                                            java.lang.String element)