瀏覽代碼

Merge pull request #132 from phillipCouto/batch_size

Added code to make working with batches a tad easier
Ben Hood 11 年之前
父節點
當前提交
bbfb86162b
共有 1 個文件被更改,包括 10 次插入1 次删除
  1. 10 1
      session.go

+ 10 - 1
session.go

@@ -115,7 +115,7 @@ func (s *Session) ExecuteBatch(batch *Batch) error {
 	// Prevent the execution of the batch if greater than the limit
 	// Currently batches have a limit of 65536 queries.
 	// https://datastax-oss.atlassian.net/browse/JAVA-229
-	if len(batch.Entries) > 65536 {
+	if batch.Size() > BatchSizeMaximum {
 		return ErrTooManyStmts
 	}
 	var err error
@@ -340,6 +340,11 @@ func (b *Batch) RetryPolicy(r RetryPolicy) *Batch {
 	return b
 }
 
+// Size returns the number of batch statements to be executed by the batch operation.
+func (b *Batch) Size() int {
+	return len(b.Entries)
+}
+
 type BatchType int
 
 const (
@@ -463,3 +468,7 @@ var (
 	ErrUnsupported  = errors.New("feature not supported")
 	ErrTooManyStmts = errors.New("too many statements")
 )
+
+// BatchSizeMaximum is the maximum number of statements a batch operation can have.
+// This limit is set by cassandra and could change in the future.
+const BatchSizeMaximum = 65535