user2903819
user2903819

Reputation: 180

How to create deep copy of BoudStatement of datastax java driver?

Is there a way to bind only few named variables of prepared statement and create a partial bound statement and then later create multiple bound statements out of it with filling in remaining named variables (from a list for example)?

p = session.prepare("select a from b where c=? AND d=?")
bound = p.bind("c", 1)

l.map(v => bound.bind("d", l))

In last statement above, I would like to clone 'bound' every time so I can then use all bound statements in executeAsync.

Upvotes: 0

Views: 87

Answers (1)

Mikhail Baksheev
Mikhail Baksheev

Reputation: 1414

Just create prepared statement with predefined value:

p = session.prepare("select a from b where c=1 AND d=?")
l.map(v => bound.bind("d", l))

If you don't know value c at a compile time, create statement string dynamically:

c=1
p = session.prepare("select a from b where c=" + c + " AND d=?")
l.map(v => bound.bind("d", l))

And I don't see big problem with repeated binding of one value again and again. It's much more clear solution than clone bound statements.

Upvotes: 1

Related Questions