Skip to content

Commit

Permalink
Added Size method to batch type so when building a batch statement th…
Browse files Browse the repository at this point in the history
…e user can avoid the maximum limit. Also made the limit a exported constant.
  • Loading branch information
Phillip Couto committed Mar 20, 2014
1 parent f419ad3 commit 538e98d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -463,3 +468,5 @@ var (
ErrUnsupported = errors.New("feature not supported")
ErrTooManyStmts = errors.New("too many statements")
)

const BatchSizeMaximum = 65536

0 comments on commit 538e98d

Please sign in to comment.