Package com.mysql.cj.xdevapi
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 AddStatementadd(DbDoc doc)Add a document in the form of a DbDoc.AddStatementadd(DbDoc... docs)Add a sequence of documents.AddStatementadd(java.lang.String... jsonString)Add one or more documents.AddStatementadd(java.util.Map<java.lang.String,?> doc)Add a document in the form of a Map.ResultaddOrReplaceOne(java.lang.String id, DbDoc doc)Adds the document to the collection.ResultaddOrReplaceOne(java.lang.String id, java.lang.String jsonString)Adds the document to the collection.longcount()Query the number of documents in this collection.ResultcreateIndex(java.lang.String indexName, DbDoc indexDefinition)Create a new statement defining the creation of an index on this collection.ResultcreateIndex(java.lang.String indexName, java.lang.String jsonIndexDefinition)Create a new statement defining the creation of an index on this collection.voiddropIndex(java.lang.String indexName)Create a new statement defining the removal of an index on this collection.booleanequals(java.lang.Object other)DatabaseObject.DbObjectStatusexistsInDatabase()Query the existence of this database object.FindStatementfind()Create a new find statement retrieving all documents in the collection.FindStatementfind(java.lang.String searchCondition)Create a new find statement retrieving documents matching the given search condition.java.lang.StringgetName()Retrieve the name of the database object represented by the Java object.DbDocgetOne(java.lang.String id)Return the document with the given id.SchemagetSchema()Retrieve the schema owning this database object.SessiongetSession()Retrieve the session owning the given schema object.inthashCode()ModifyStatementmodify(java.lang.String searchCondition)Create a new modify statement affecting documents matching the given search condition.DbDocnewDoc()Create a new document.RemoveStatementremove(java.lang.String searchCondition)Create a new removal statement affecting documents matching the given search condition.ResultremoveOne(java.lang.String id)Removes the document with the given id.ResultreplaceOne(java.lang.String id, DbDoc doc)Takes in a document object that will replace the matching document.ResultreplaceOne(java.lang.String id, java.lang.String jsonString)Takes in a document object that will replace the matching document.java.lang.StringtoString()
-
Method Details
-
getSession
Description copied from interface:DatabaseObjectRetrieve the session owning the given schema object.- Specified by:
getSessionin interfaceDatabaseObject- Returns:
Session
-
getSchema
Description copied from interface:DatabaseObjectRetrieve the schema owning this database object.- Specified by:
getSchemain interfaceDatabaseObject- Returns:
Schema
-
getName
public java.lang.String getName()Description copied from interface:DatabaseObjectRetrieve the name of the database object represented by the Java object.- Specified by:
getNamein interfaceDatabaseObject- Returns:
- name
-
existsInDatabase
Description copied from interface:DatabaseObjectQuery the existence of this database object.- Specified by:
existsInDatabasein interfaceDatabaseObject- Returns:
DatabaseObject.DbObjectStatus
-
add
Description copied from interface:CollectionAdd a document in the form of a Map.- Specified by:
addin interfaceCollection- Parameters:
doc- map of key-value parameters representing the document fields- Returns:
AddStatement
-
add
Description copied from interface:CollectionAdd one or more documents.- Specified by:
addin interfaceCollection- Parameters:
jsonString- one or more documents given as JSON strings- Returns:
AddStatement
-
add
Description copied from interface:CollectionAdd a document in the form of a DbDoc.- Specified by:
addin interfaceCollection- Parameters:
doc-DbDoc- Returns:
AddStatement
-
add
Description copied from interface:CollectionAdd a sequence of documents.- Specified by:
addin interfaceCollection- Parameters:
docs- one or more documents given asDbDoc- Returns:
AddStatement
-
find
Description copied from interface:CollectionCreate a new find statement retrieving all documents in the collection.- Specified by:
findin interfaceCollection- Returns:
FindStatement
-
find
Description copied from interface:CollectionCreate a new find statement retrieving documents matching the given search condition.- Specified by:
findin interfaceCollection- Parameters:
searchCondition- condition expression- Returns:
FindStatement
-
modify
Description copied from interface:CollectionCreate a new modify statement affecting documents matching the given search condition.- Specified by:
modifyin interfaceCollection- Parameters:
searchCondition- condition expression- Returns:
ModifyStatement
-
remove
Description copied from interface:CollectionCreate a new removal statement affecting documents matching the given search condition.- Specified by:
removein interfaceCollection- Parameters:
searchCondition- condition expression- Returns:
RemoveStatement
-
createIndex
Description copied from interface:CollectionCreate 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:
createIndexin interfaceCollection- Parameters:
indexName- index nameindexDefinition- 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.
- 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
Description copied from interface:CollectionCreate 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:
createIndexin interfaceCollection- Parameters:
indexName- index namejsonIndexDefinition- 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.
- 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:CollectionCreate a new statement defining the removal of an index on this collection.- Specified by:
dropIndexin interfaceCollection- Parameters:
indexName- index name
-
count
public long count()Description copied from interface:CollectionQuery the number of documents in this collection.- Specified by:
countin interfaceCollection- Returns:
- The number of documents in this collection
-
newDoc
Description copied from interface:CollectionCreate a new document.- Specified by:
newDocin interfaceCollection- Returns:
DbDoc
-
equals
public boolean equals(java.lang.Object other)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
replaceOne
Description copied from interface:CollectionTakes 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:
replaceOnein interfaceCollection- Parameters:
id- the document id of the document to be replaceddoc- 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
Description copied from interface:CollectionTakes 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:
replaceOnein interfaceCollection- Parameters:
id- the document id of the document to be replacedjsonString- 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
Description copied from interface:CollectionAdds the document to the collection. The following algorithm applies:- Specified by:
addOrReplaceOnein interfaceCollection- Parameters:
id- the document id of the document to be replaceddoc- 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
Description copied from interface:CollectionAdds the document to the collection. The following algorithm applies:- Specified by:
addOrReplaceOnein interfaceCollection- Parameters:
id- the document id of the document to be replacedjsonString- 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
Description copied from interface:CollectionReturn the document with the given id.- Specified by:
getOnein interfaceCollection- Parameters:
id- the document id of the document to be retrieved- Returns:
- the document, or NULL if no match found
-
removeOne
Description copied from interface:CollectionRemoves the document with the given id.- Specified by:
removeOnein interfaceCollection- 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)
-