Class CollectionImpl

java.lang.Object
com.mysql.cj.xdevapi.CollectionImpl
All Implemented Interfaces:
Collection, DatabaseObject

public class CollectionImpl
extends java.lang.Object
implements Collection
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.mysql.cj.xdevapi.DatabaseObject

    DatabaseObject.DbObjectStatus, DatabaseObject.DbObjectType
  • Method Summary

    Modifier and Type Method Description
    AddStatement add​(DbDoc doc)
    Add a document in the form of a DbDoc.
    AddStatement add​(DbDoc... docs)
    Add a sequence of documents.
    AddStatement add​(java.lang.String... jsonString)
    Add one or more documents.
    AddStatement add​(java.util.Map<java.lang.String,​?> doc)
    Add a document in the form of a Map.
    Result addOrReplaceOne​(java.lang.String id, DbDoc doc)
    Adds the document to the collection.
    Result addOrReplaceOne​(java.lang.String id, java.lang.String jsonString)
    Adds the document to the collection.
    long count()
    Query the number of documents in this collection.
    Result createIndex​(java.lang.String indexName, DbDoc indexDefinition)
    Create a new statement defining the creation of an index on this collection.
    Result createIndex​(java.lang.String indexName, java.lang.String jsonIndexDefinition)
    Create a new statement defining the creation of an index on this collection.
    void dropIndex​(java.lang.String indexName)
    Create a new statement defining the removal of an index on this collection.
    boolean equals​(java.lang.Object other)  
    DatabaseObject.DbObjectStatus existsInDatabase()
    Query the existence of this database object.
    FindStatement find()
    Create a new find statement retrieving all documents in the collection.
    FindStatement find​(java.lang.String searchCondition)
    Create a new find statement retrieving documents matching the given search condition.
    java.lang.String getName()
    Retrieve the name of the database object represented by the Java object.
    DbDoc getOne​(java.lang.String id)
    Return the document with the given id.
    Schema getSchema()
    Retrieve the schema owning this database object.
    Session getSession()
    Retrieve the session owning the given schema object.
    int hashCode()  
    ModifyStatement modify​(java.lang.String searchCondition)
    Create a new modify statement affecting documents matching the given search condition.
    DbDoc newDoc()
    Create a new document.
    RemoveStatement remove​(java.lang.String searchCondition)
    Create a new removal statement affecting documents matching the given search condition.
    Result removeOne​(java.lang.String id)
    Removes the document with the given id.
    Result replaceOne​(java.lang.String id, DbDoc doc)
    Takes in a document object that will replace the matching document.
    Result replaceOne​(java.lang.String id, java.lang.String jsonString)
    Takes in a document object that will replace the matching document.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • getSession

      public Session getSession()
      Description copied from interface: DatabaseObject
      Retrieve the session owning the given schema object.
      Specified by:
      getSession in interface DatabaseObject
      Returns:
      Session
    • getSchema

      public Schema getSchema()
      Description copied from interface: DatabaseObject
      Retrieve the schema owning this database object.
      Specified by:
      getSchema in interface DatabaseObject
      Returns:
      Schema
    • getName

      public java.lang.String getName()
      Description copied from interface: DatabaseObject
      Retrieve the name of the database object represented by the Java object.
      Specified by:
      getName in interface DatabaseObject
      Returns:
      name
    • existsInDatabase

      public DatabaseObject.DbObjectStatus existsInDatabase()
      Description copied from interface: DatabaseObject
      Query the existence of this database object.
      Specified by:
      existsInDatabase in interface DatabaseObject
      Returns:
      DatabaseObject.DbObjectStatus
    • add

      public AddStatement add​(java.util.Map<java.lang.String,​?> doc)
      Description copied from interface: Collection
      Add a document in the form of a Map.
      Specified by:
      add in interface Collection
      Parameters:
      doc - map of key-value parameters representing the document fields
      Returns:
      AddStatement
    • add

      public AddStatement add​(java.lang.String... jsonString)
      Description copied from interface: Collection
      Add one or more documents.
      Specified by:
      add in interface Collection
      Parameters:
      jsonString - one or more documents given as JSON strings
      Returns:
      AddStatement
    • add

      public AddStatement add​(DbDoc doc)
      Description copied from interface: Collection
      Add a document in the form of a DbDoc.
      Specified by:
      add in interface Collection
      Parameters:
      doc - DbDoc
      Returns:
      AddStatement
    • add

      public AddStatement add​(DbDoc... docs)
      Description copied from interface: Collection
      Add a sequence of documents.
      Specified by:
      add in interface Collection
      Parameters:
      docs - one or more documents given as DbDoc
      Returns:
      AddStatement
    • find

      public FindStatement find()
      Description copied from interface: Collection
      Create a new find statement retrieving all documents in the collection.
      Specified by:
      find in interface Collection
      Returns:
      FindStatement
    • find

      public FindStatement find​(java.lang.String searchCondition)
      Description copied from interface: Collection
      Create a new find statement retrieving documents matching the given search condition.
      Specified by:
      find in interface Collection
      Parameters:
      searchCondition - condition expression
      Returns:
      FindStatement
    • modify

      public ModifyStatement modify​(java.lang.String searchCondition)
      Description copied from interface: Collection
      Create a new modify statement affecting documents matching the given search condition.
      Specified by:
      modify in interface Collection
      Parameters:
      searchCondition - condition expression
      Returns:
      ModifyStatement
    • remove

      public RemoveStatement remove​(java.lang.String searchCondition)
      Description copied from interface: Collection
      Create a new removal statement affecting documents matching the given search condition.
      Specified by:
      remove in interface Collection
      Parameters:
      searchCondition - condition expression
      Returns:
      RemoveStatement
    • createIndex

      public Result createIndex​(java.lang.String indexName, DbDoc indexDefinition)
      Description copied from interface: Collection
      Create a new statement defining the creation of an index on this collection.

      Example: collection.createIndex("myIndex", "{\"fields\": [{\"field\": \"$.myGeoJsonField\", \"type\": \"GEOJSON\", \"required\": true, \"options\": 2, \"srid\": 4326}], \"type\":\"SPATIAL\"}");

      Specified by:
      createIndex in interface Collection
      Parameters:
      indexName - index name
      indexDefinition - JSON document with the following fields:
      • fields: array of IndexField objects, each describing a single document member to be included in the index (see below)
      • type: string, (optional) the type of index. One of INDEX or SPATIAL (case insensitive). Default is INDEX and may be omitted.
      where single IndexField description consists of the following fields:
      • field: string, the full document path to the document member or field to be indexed
      • type: string, one of the supported SQL column types to map the field into (see below for a list). For numeric types, the optional UNSIGNED keyword may follow. For the TEXT type, the length to consider for indexing may be added. Type descriptions are case insensitive.
      • required: bool, (optional) true if the field is required to exist in the document. Defaults to false, except for GEOJSON where it defaults to true
      • options: int, (optional) special option flags for use when decoding GEOJSON data
      • srid: int, (optional) srid value for use when decoding GEOJSON data
      Returns:
      Result
    • createIndex

      public Result createIndex​(java.lang.String indexName, java.lang.String jsonIndexDefinition)
      Description copied from interface: Collection
      Create a new statement defining the creation of an index on this collection.

      Example: collection.createIndex("myIndex", "{\"fields\": [{\"field\": \"$.myGeoJsonField\", \"type\": \"GEOJSON\", \"required\": true, \"options\": 2, \"srid\": 4326}], \"type\":\"SPATIAL\"}");

      Specified by:
      createIndex in interface Collection
      Parameters:
      indexName - index name
      jsonIndexDefinition - JSON document with the following fields:
      • fields: array of IndexField objects, each describing a single document member to be included in the index (see below)
      • type: string, (optional) the type of index. One of INDEX or SPATIAL. Default is INDEX and may be omitted.
      where single IndexField description consists of the following fields:
      • field: string, the full document path to the document member or field to be indexed
      • type: string, one of the supported SQL column types to map the field into (see below for a list). For numeric types, the optional UNSIGNED keyword may follow. For the TEXT type, the length to consider for indexing may be added.
      • required: bool, (optional) true if the field is required to exist in the document. Defaults to false, except for GEOJSON where it defaults to true
      • options: int, (optional) special option flags for use when decoding GEOJSON data
      • srid: int, (optional) srid value for use when decoding GEOJSON data
      Returns:
      Result
    • dropIndex

      public void dropIndex​(java.lang.String indexName)
      Description copied from interface: Collection
      Create a new statement defining the removal of an index on this collection.
      Specified by:
      dropIndex in interface Collection
      Parameters:
      indexName - index name
    • count

      public long count()
      Description copied from interface: Collection
      Query the number of documents in this collection.
      Specified by:
      count in interface Collection
      Returns:
      The number of documents in this collection
    • newDoc

      public DbDoc newDoc()
      Description copied from interface: Collection
      Create a new document.
      Specified by:
      newDoc in interface Collection
      Returns:
      DbDoc
    • equals

      public boolean equals​(java.lang.Object other)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • replaceOne

      public Result replaceOne​(java.lang.String id, DbDoc doc)
      Description copied from interface: Collection
      Takes in a document object that will replace the matching document. If no matches are found, the function returns normally with no changes being made.
      Specified by:
      replaceOne in interface Collection
      Parameters:
      id - the document id of the document to be replaced
      doc - the new document, which may contain expressions. If document contains an _id value, it is ignored.
      Returns:
      Result object, which will indicate the number of affected documents (1 or 0, if none)
    • replaceOne

      public Result replaceOne​(java.lang.String id, java.lang.String jsonString)
      Description copied from interface: Collection
      Takes in a document object that will replace the matching document. If no matches are found, the function returns normally with no changes being made.
      Specified by:
      replaceOne in interface Collection
      Parameters:
      id - the document id of the document to be replaced
      jsonString - the new document, given as JSON string, which may contain expressions. If document contains an _id value, it is ignored.
      Returns:
      Result object, which will indicate the number of affected documents (1 or 0, if none)
    • addOrReplaceOne

      public Result addOrReplaceOne​(java.lang.String id, DbDoc doc)
      Description copied from interface: Collection
      Adds the document to the collection. The following algorithm applies:
      Specified by:
      addOrReplaceOne in interface Collection
      Parameters:
      id - the document id of the document to be replaced
      doc - the new document, which may contain expressions. If doc contains an _id value and it does not match the given id then the error will be thrown.
      Returns:
      Result object, which will indicate the number of affected documents (0 - if none, 1 - if added, 2 - if replaced)
    • addOrReplaceOne

      public Result addOrReplaceOne​(java.lang.String id, java.lang.String jsonString)
      Description copied from interface: Collection
      Adds the document to the collection. The following algorithm applies:
      Specified by:
      addOrReplaceOne in interface Collection
      Parameters:
      id - the document id of the document to be replaced
      jsonString - the new document, given as JSON string, which may contain expressions. If doc contains an _id value and it does not match the given id then the error will be thrown.
      Returns:
      Result object, which will indicate the number of affected documents (0 - if none, 1 - if added, 2 - if replaced)
    • getOne

      public DbDoc getOne​(java.lang.String id)
      Description copied from interface: Collection
      Return the document with the given id.
      Specified by:
      getOne in interface Collection
      Parameters:
      id - the document id of the document to be retrieved
      Returns:
      the document, or NULL if no match found
    • removeOne

      public Result removeOne​(java.lang.String id)
      Description copied from interface: Collection
      Removes the document with the given id.
      Specified by:
      removeOne in interface Collection
      Parameters:
      id - the document id of the document to be removed
      Returns:
      Returns a Result object, which will indicate the number of removed documents (1 or 0, if none)