public class Insert extends AbstractMessage
struct {
MsgHeader header; // standard message header
int32 flags; // bit vector - see below
cstring fullCollectionName; // "dbname.collectionname"
document* documents; // one or more documents to insert into the collection
}
Modifier and Type | Field and Description |
---|---|
static int |
CONTINUE_ON_ERROR_BIT
The flag bit to keep inserting documents on an error.
|
HEADER_SIZE, myCollectionName, myDatabaseName
Constructor and Description |
---|
Insert(Header header,
BsonInputStream in)
Creates a new Insert.
|
Insert(String databaseName,
String collectionName,
List<Document> documents,
boolean continueOnError)
Creates a new Insert.
|
Insert(String databaseName,
String collectionName,
List<Document> documents,
boolean continueOnError,
VersionRange requiredServerVersion)
Creates a new Insert.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object object)
Determines if the passed object is of this same type as this object and
if so that its fields are equal.
|
List<Document> |
getDocuments()
Returns the documents to insert.
|
String |
getOperationName()
Returns a short name for the operation.
|
int |
hashCode()
Computes a reasonable hash code.
|
boolean |
isContinueOnError()
Returns true if the insert should continue with other documents if one of
the document inserts encounters an error.
|
int |
size()
Returns the total size of the message on the wire.
|
String |
toString() |
void |
validateSize(int maxDocumentSize)
Validates that the documents with the message do not exceed the maximum
document size specified.
|
void |
write(int messageId,
BsonOutputStream out)
Writes the message from the stream.
|
void |
write(int messageId,
BufferingBsonOutputStream out)
Writes the message from the stream.
|
finishHeader, getCollectionName, getDatabaseName, getReadPreference, getRequiredVersionRange, init, writeHeader, writeHeader
public static final int CONTINUE_ON_ERROR_BIT
public Insert(Header header, BsonInputStream in) throws IOException
header
- The header proceeding the insert message. This is used to
locate the end of the insert.in
- The stream to read the insert message from.IOException
- On a failure reading the insert message.public Insert(String databaseName, String collectionName, List<Document> documents, boolean continueOnError)
databaseName
- The name of the database.collectionName
- The name of the collection.documents
- The documents to be inserted.continueOnError
- If the insert should continue if one of the documents causes
an error.public Insert(String databaseName, String collectionName, List<Document> documents, boolean continueOnError, VersionRange requiredServerVersion)
databaseName
- The name of the database.collectionName
- The name of the collection.documents
- The documents to be inserted.continueOnError
- If the insert should continue if one of the documents causes
an error.requiredServerVersion
- The required version of the server to support processing the
message.public boolean equals(Object object)
equals
in class AbstractMessage
object
- The object to compare to.Object.equals(java.lang.Object)
public List<Document> getDocuments()
public String getOperationName()
Overridden to return the name of the operation: "INSERT".
public int hashCode()
hashCode
in class AbstractMessage
public boolean isContinueOnError()
public int size()
Overridden to return the size of the Insert
.
public String toString()
Overridden to output the documents and insert flags.
public void validateSize(int maxDocumentSize) throws DocumentToLargeException
Overridden to ensure the inserted documents are not too large in aggregate.
maxDocumentSize
- The maximum document size to validate against.DocumentToLargeException
- If one of the documents in the message is too large or the
documents in aggregate are too large.public void write(int messageId, BsonOutputStream out) throws IOException
Overridden to write the insert message.
messageId
- The id to be assigned to the message.out
- The sink for data written.IOException
- On an error writing to the stream.Message.write(int, BsonOutputStream)
public void write(int messageId, BufferingBsonOutputStream out) throws IOException
Overridden to write the insert message.
messageId
- The id to be assigned to the message.out
- The sink for data written.IOException
- On an error writing to the stream.Message.write(int, BsonOutputStream)
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.