
net.oneandone.troilus.CounterMutationQueryData Maven / Gradle / Ivy
/*
* Copyright 1&1 Internet AG, https://github.com/1and1/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.oneandone.troilus;
import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker;
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
import static com.datastax.driver.core.querybuilder.QueryBuilder.update;
import java.util.List;
import java.util.Map.Entry;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.Statement;
import com.datastax.driver.core.querybuilder.Clause;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
class CounterMutationQueryData {
private final ImmutableMap keys;
private final ImmutableList whereConditions;
private final String name;
private final long diff;
public CounterMutationQueryData() {
this(ImmutableMap.of(),
ImmutableList.of(),
null,
0);
}
private CounterMutationQueryData(ImmutableMap keys,
ImmutableList whereConditions,
String name,
long diff) {
this.keys = keys;
this.whereConditions = whereConditions;
this.name = name;
this.diff = diff;
}
public CounterMutationQueryData keys(ImmutableMap keys) {
return new CounterMutationQueryData(keys,
this.whereConditions,
this.name,
this.diff);
}
public CounterMutationQueryData whereConditions(ImmutableList whereConditions) {
return new CounterMutationQueryData(this.keys,
whereConditions,
this.name,
this.diff);
}
public CounterMutationQueryData name(String name) {
return new CounterMutationQueryData(this.keys,
this.whereConditions,
name,
this.diff);
}
public CounterMutationQueryData diff(long diff) {
return new CounterMutationQueryData(this.keys,
this.whereConditions,
this.name,
diff);
}
public ImmutableMap getKeys() {
return keys;
}
public ImmutableList getWhereConditions() {
return whereConditions;
}
public String getName() {
return name;
}
public long getDiff() {
return diff;
}
ListenableFuture toStatementAsync(Context ctx) {
com.datastax.driver.core.querybuilder.Update update = update(ctx.getDbSession().getTablename());
// key-based update
if (getWhereConditions().isEmpty()) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy