Interface CrudRepository<T>

All Known Implementing Classes:
AbstractJongoRepository

public interface CrudRepository<T>
Author:
Carlos Ortiz.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the number of all documents in the collection.
    long
    count(String query)
    Returns the number of documents that match the query
    long
    count(String query, Object... queryParams)
    Returns the number of documents that match the query
    void
    deleteFile(String storeName)
    Deletes the File with the given name.
    void
    deleteFile(org.bson.types.ObjectId fileId)
    Deletes the File with the given Id.
    find(String query)
    Search all documents in the given collection that match the query.
    find(String query, Object... queryParams)
    Finds all documents of the given collection that match the template query
    §§
    Gets all documents of a the given collection.
    Finds by the Id.
    Finds by the Id.
    findOne(String query)
    Search for documents of the given collection that match the query.
    In only return the first Document
    findOne(String query, Object... queryParams)
    Search for documents of the given collection that match the query.
    In only return the first Document
    getFileInfo(String storeName)
    Gets the file information based on its name..
    getFileInfo(org.bson.types.ObjectId fileId)
    Gets the file information based on its id..
    void
    insert(T document)
    Inserts the document into the collection.
    void
    insert(T... documents)
    Inserts multiple documents into the collection.
     
    readFile(String storeName)
    Returns the InputStream of the file with the given name.
    readFile(org.bson.types.ObjectId fileId)
    Returns the InputStream of the file with the given id.
    void
    remove(String query)
    Removes all Documents that are found using the given query.
    void
    remove(String query, Object... queryParams)
    Removes all Documents that are found using the given query.
    void
    Removes a Document with the given id
    void
    Removes by the Id.
    void
    save(String query, Object... queryParams)
    Inserts in the given collection the json "As Is"
    Json String can contain placeholders this will allow the user to have predefine json strings
    that will be substitute with the given queryParams.Params are not Name therefor if the same value is needed multiple times for now it has to be send multiple times.Order of the queryParams should match the same in the json string.
    Example
    String Json ="{name:#,address: #,age:#}"
    save("testCollection",Json,"Dr.John Z.", new Address(), 125);
    void
    save(T document)
    Saves the document into the collection.
    saveFile(InputStream inputStream, String storeName, String contentType)
    Saves the given InputStream as with the given name.
    saveFile(InputStream inputStream, String storeName, String contentType, org.bson.types.ObjectId fileId)
    Saves the given InputStream as with the given name.
    void
    update(String id, Object updateObject)
    Updates the object with the given id with the given Object information.
    void
    update(String id, Object updateObject, boolean multi, boolean upsert)
    Updates the object with the given id with the given Object information.
    void
    update(String id, String modifier, boolean multi, boolean upsert)
    Updates the given
    void
    update(String id, String modifier, boolean multi, boolean upsert, Object... params)
    Updates the given
    updateFile(InputStream inputStream, String storeName, String contentType)
    "Updates" the file with the new information (A name change is NOT valid )
    updateFile(org.bson.types.ObjectId fileId, InputStream inputStream, String storeName, String contentType)
    "Updates" the file with the new information (A name change is valid as long a file with new name does not exists)
    updateFile(org.bson.types.ObjectId fileId, InputStream inputStream, String storeName, String contentType, boolean sameFileId)
    "Updates" the file with the new information (A name change is valid as long a file with new name does not exists)
  • Method Details

    • insert

      void insert(T document) throws MongoDataException
      Inserts the document into the collection.
      Parameters:
      document - document to be inserted (aka Pojo).
      Throws:
      MongoDataException - if the document can't be inserted.
    • insert

      void insert(T... documents) throws MongoDataException
      Inserts multiple documents into the collection.
      Parameters:
      documents - documents to be inserted (aka Pojo).
      Throws:
      MongoDataException - if the documents can't be inserted.
    • save

      void save(T document) throws MongoDataException
      Saves the document into the collection.
      Parameters:
      document - Document to be save (aka Pojo).
      Throws:
      MongoDataException - if Document can't be save.
    • save

      void save(String query, Object... queryParams) throws MongoDataException
      Inserts in the given collection the json "As Is"
      Json String can contain placeholders this will allow the user to have predefine json strings
      that will be substitute with the given queryParams.Params are not Name therefor if the same value is needed multiple times for now it has to be send multiple times.Order of the queryParams should match the same in the json string.
      Example
      String Json ="{name:#,address: #,age:#}"
      save("testCollection",Json,"Dr.John Z.", new Address(), 125);
      Parameters:
      query - Name of the Query to be look in default-queries.xml or custom-queries.properties
      queryParams - Params of the json.
      Throws:
      MongoDataException
    • update

      void update(String id, Object updateObject, boolean multi, boolean upsert) throws MongoDataException
      Updates the object with the given id with the given Object information.
      Parameters:
      id - Id of the object to be updated.
      multi - If set to true, updates multiple documents that meet the query criteria. If set to false, updates one document.
      upsert - If set to true, creates a new document when no document matches the query criteria.
      updateObject - Object to be use to updated.
      Throws:
      MongoDataException - if document can't be save.
    • update

      void update(String id, Object updateObject) throws MongoDataException

      Updates the object with the given id with the given Object information.

      Should be equals to update(String, Object, boolean, boolean) with String,Object,false,false

      Parameters:
      id - Id of the object to be updated.
      updateObject - Object to be use to updated.
      Throws:
      MongoDataException - if document can't be save.
    • update

      void update(String id, String modifier, boolean multi, boolean upsert) throws MongoDataException
      Updates the given
      Parameters:
      id - Id of the object to be updated.
      modifier - The modifications to apply.
      multi - If set to true, updates multiple documents that meet the query criteria. If set to false, updates one document.
      upsert - If set to true, creates a new document when no document matches the query criteria.
      Throws:
      MongoDataException - if document can't be save.
    • update

      void update(String id, String modifier, boolean multi, boolean upsert, Object... params) throws MongoDataException
      Updates the given
      Parameters:
      id - Id of the object to be updated.
      modifier - The modifications to apply.
      multi - If set to true, updates multiple documents that meet the query criteria. If set to false, updates one document.
      upsert - If set to true, creates a new document when no document matches the query criteria.
      params - Params of the modifier query.
      Throws:
      MongoDataException - if document can't be save.
    • count

      long count() throws MongoDataException
      Returns the number of all documents in the collection.
      Returns:
      the count of all documents
      Throws:
      MongoDataException - if an error occurs
    • count

      long count(String query) throws MongoDataException
      Returns the number of documents that match the query
      Parameters:
      query - the query the documents should match
      Returns:
      the count of documents that match the query
      Throws:
      MongoDataException - if an error occurs
    • count

      long count(String query, Object... queryParams) throws MongoDataException
      Returns the number of documents that match the query
      Parameters:
      query - the query the documents should match
      queryParams - the query parameters
      Returns:
      the count of documents that match the query
      Throws:
      MongoDataException - if an error occurs
    • findAll

      Iterable<T> findAll() throws MongoDataException
      Gets all documents of a the given collection. Tries to convert them in to Instances of the given class. Order of the params should match the same in the json string.
      Example
      String Json ="{name:#,address: #,age:#}"
      find("testCollection",Json,"Dr. John.Z", new Address(), 125);
      Returns:
      A Iterable Instance of all the documents.This is lazy loaded
      Throws:
      MongoDataException - If couldn't search for the documents. or a mapping exception happen.
    • find

      Iterable<T> find(String query) throws MongoDataException
      Search all documents in the given collection that match the query.
      Parameters:
      query - Name of the Query to be look in default-queries.xml or custom-queries.properties
      Returns:
      A Iterable Instance of all the documents that match the query.This is lazy loaded
      Throws:
      MongoDataException
    • find

      Iterable<T> find(String query, Object... queryParams) throws MongoDataException
      Finds all documents of the given collection that match the template query
      §§
      Parameters:
      query - Name of the Template Query to be look in default-queries.xml or custom-queries .properties
      queryParams - Params to be use in the template query. Must match the order of the templates .
      Template queryParams are not named, therefor they have to be send multiple times if needed
      Returns:
      A Iterable Instance of all the documents.This is lazy loaded
      Throws:
      MongoDataException - If couldn't search for the documents. or a mapping exception happen.
    • findOne

      T findOne(String query) throws MongoDataException
      Search for documents of the given collection that match the query.
      In only return the first Document
      Parameters:
      query - Name of the Template Query to be look in default-queries.xml or custom-queries .properties
      Returns:
      A instance of the given class. Null if nothing is found.
      Throws:
      MongoDataException - If couldn't search for the documents. or a mapping exception happen.
    • findOne

      T findOne(String query, Object... queryParams) throws MongoDataException
      Search for documents of the given collection that match the query.
      In only return the first Document
      Parameters:
      query - Name of the Template Query to be look in default-queries.xml or custom-queries .properties
      queryParams - Params to be use in the template query. Must match the order of the templates .
      Template queryParams are not named, therefor they have to be send multiple times if needed
      Returns:
      A instance of the given class. Null if nothing is found.
      Throws:
      MongoDataException - If couldn't search for the documents. or a mapping exception happen.
    • remove

      void remove(String query, Object... queryParams) throws MongoDataException
      Removes all Documents that are found using the given query.
      Parameters:
      query - Name of the Template Query to be look in default-queries.xml or custom-queries .properties
      queryParams - Params to be use in the template query. Must match the order of the templates
      Throws:
      MongoDataException
    • findById

      T findById(String id) throws MongoDataException

      Finds by the Id.

      Internal transforms the given String to and Object Id

      Parameters:
      id - String representation of the Id.
      Returns:
      A instance of the object with the given Id.
      Throws:
      IllegalArgumentException - If given id is not a Valid Object Id.
      MongoDataException
    • remove

      void remove(String query) throws MongoDataException
      Removes all Documents that are found using the given query.
      Parameters:
      query - Name of the Template Query to be look in default-queries.xml or custom-queries .properties
      Throws:
      MongoDataException
    • removeById

      void removeById(String id) throws MongoDataException
      Removes a Document with the given id
      Parameters:
      id - Id of the object to be remove
      Throws:
      MongoDataException
    • saveFile

      FileInfo saveFile(InputStream inputStream, String storeName, String contentType, org.bson.types.ObjectId fileId) throws MongoDataException, org.apache.commons.io.FileExistsException
      Saves the given InputStream as with the given name. Closes the Stream after its done.
      Parameters:
      inputStream - InputStream to be Save.
      storeName - File name for the inputStream.
      Returns:
      FileInfo with all the information of the file.
      Throws:
      MongoDataException - If Can't save the file.
      org.apache.commons.io.FileExistsException - If a file with the given file name already exists.
    • saveFile

      FileInfo saveFile(InputStream inputStream, String storeName, String contentType) throws MongoDataException, org.apache.commons.io.FileExistsException
      Saves the given InputStream as with the given name. Closes the Stream after its done.
      Parameters:
      inputStream - InputStream to be Save.
      storeName - File name for the inputStream.
      Returns:
      FileInfo with all the information of the file.
      Throws:
      MongoDataException - If Can't save the file.
      org.apache.commons.io.FileExistsException - If a file with the given file name already exists.
    • getFileInfo

      FileInfo getFileInfo(org.bson.types.ObjectId fileId) throws FileNotFoundException
      Gets the file information based on its id..
      Parameters:
      fileId - file Id to look up the information.
      Returns:
      File Information of the file.
      Throws:
      FileNotFoundException - If file with the given id does not exist.
    • getFileInfo

      FileInfo getFileInfo(String storeName) throws FileNotFoundException
      Gets the file information based on its name..
      Parameters:
      storeName - file name to look up the information.
      Returns:
      File Information of the file.
      Throws:
      FileNotFoundException - If file with the given id does not exist.
    • readFile

      FileInfo readFile(org.bson.types.ObjectId fileId) throws FileNotFoundException
      Returns the InputStream of the file with the given id.
      Parameters:
      fileId - File Id to read.
      Returns:
      A InputStream with that file Information.
      Throws:
      FileNotFoundException - If there is no file with that Id.
    • readFile

      FileInfo readFile(String storeName) throws FileNotFoundException
      Returns the InputStream of the file with the given name.
      Parameters:
      storeName - File Id to read.
      Returns:
      A InputStream with that file Information.
      Throws:
      FileNotFoundException - If there is no file with that name.
    • deleteFile

      void deleteFile(org.bson.types.ObjectId fileId) throws FileNotFoundException
      Deletes the File with the given Id.
      Parameters:
      fileId - Id of the file to delete.
      Throws:
      FileNotFoundException - If there is no file with that id.
    • deleteFile

      void deleteFile(String storeName) throws FileNotFoundException
      Deletes the File with the given name.
      Parameters:
      storeName - Name of the file to delete.
      Throws:
      FileNotFoundException - If there is no file with that name.
    • updateFile

      FileInfo updateFile(org.bson.types.ObjectId fileId, InputStream inputStream, String storeName, String contentType) throws FileNotFoundException, MongoDataException, org.apache.commons.io.FileExistsException

      "Updates" the file with the new information (A name change is valid as long a file with new name does not exists)

      Mongodb Does not actually support any update Operation in GridFs therefor Calling this method should be as calling deleteFile(org.bson.types.ObjectId) and then saveFile(java.io.InputStream, String,String) It will generate also new FileInfo Including It's Id

      Parameters:
      fileId - File id to be Updated
      inputStream - new InputStream of the file.
      storeName - File name of the inputStream (can differ from the original).
      Returns:
      The new FileInfo of the "Updated" file
      Throws:
      FileNotFoundException - If File with Given Id Does not exists.
      MongoDataException - If unable to save the File.
      org.apache.commons.io.FileExistsException - If a file name exists with the new storeName (this should Only happen if you change the file name)
    • updateFile

      FileInfo updateFile(org.bson.types.ObjectId fileId, InputStream inputStream, String storeName, String contentType, boolean sameFileId) throws FileNotFoundException, MongoDataException, org.apache.commons.io.FileExistsException

      "Updates" the file with the new information (A name change is valid as long a file with new name does not exists)

      Mongodb Does not actually support any update Operation in GridFs therefor Calling this method should be as calling deleteFile(org.bson.types.ObjectId) and then saveFile(java.io.InputStream, String,String) It will generate also new FileInfo Including It's Id

      Parameters:
      fileId - File id to be Updated
      inputStream - new InputStream of the file.
      storeName - File name of the inputStream (can differ from the original).
      Returns:
      The new FileInfo of the "Updated" file
      Throws:
      FileNotFoundException - If File with Given Id Does not exists.
      MongoDataException - If unable to save the File.
      org.apache.commons.io.FileExistsException - If a file name exists with the new storeName (this should Only happen if you change the file name)
    • updateFile

      FileInfo updateFile(InputStream inputStream, String storeName, String contentType) throws FileNotFoundException, MongoDataException, org.apache.commons.io.FileExistsException

      "Updates" the file with the new information (A name change is NOT valid )

      Mongodb Does not actually support any update Operation in GridFs therefor Calling this method should be as calling deleteFile(org.bson.types.ObjectId) and then saveFile(java.io.InputStream, String,String) It will generate also new FileInfo Including It's Id

      Parameters:
      storeName - File id to be Updated. (Have to the the same as the original of not it will throw a FileNotFoundException)
      inputStream - new InputStream of the file.
      Returns:
      The new FileInfo of the "Updated" file
      Throws:
      FileNotFoundException - If File with Given Id Does not exists.
      MongoDataException - If unable to save the File.
      org.apache.commons.io.FileExistsException - this exception is highly unlikely to happen but posible.
    • findByStringId

      T findByStringId(String id) throws MongoDataException

      Finds by the Id.

      No internal Modification is done, uses Mongodb default '_id' field name

      Parameters:
      id - String representation of the Id.
      Returns:
      A instance of the object with the given Id.
      Throws:
      MongoDataException
    • listFilesByName

      List<FileInfo> listFilesByName(String filename)
    • removeByStringId

      void removeByStringId(String id) throws MongoDataException

      Removes by the Id.

      No internal Modification is done, uses Mongodb default '_id' field name

      Parameters:
      id - String representation of the Id.
      Throws:
      MongoDataException