
net.oneandone.troilus.WriteQueryDataImpl 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.addAll;
import static com.datastax.driver.core.querybuilder.QueryBuilder.appendAll;
import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker;
import static com.datastax.driver.core.querybuilder.QueryBuilder.discardAll;
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto;
import static com.datastax.driver.core.querybuilder.QueryBuilder.prependAll;
import static com.datastax.driver.core.querybuilder.QueryBuilder.putAll;
import static com.datastax.driver.core.querybuilder.QueryBuilder.removeAll;
import static com.datastax.driver.core.querybuilder.QueryBuilder.set;
import static com.datastax.driver.core.querybuilder.QueryBuilder.ttl;
import static com.datastax.driver.core.querybuilder.QueryBuilder.update;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import net.oneandone.troilus.java7.interceptor.WriteQueryData;
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.Insert;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
/**
* write query data implementation
*
*/
class WriteQueryDataImpl implements WriteQueryData {
private final ImmutableMap keys;
private final ImmutableList whereConditions;
private final ImmutableMap> valuesToMutate;
private final ImmutableMap> setValuesToAdd;
private final ImmutableMap> setValuesToRemove;
private final ImmutableMap> listValuesToAppend;
private final ImmutableMap> listValuesToPrepend;
private final ImmutableMap> listValuesToRemove;
private final ImmutableMap>> mapValuesToMutate;
private final ImmutableList onlyIfConditions;
private final Boolean ifNotExists;
/**
* constructor
*/
WriteQueryDataImpl() {
this(ImmutableMap.of(),
ImmutableList.of(),
ImmutableMap.>of(),
ImmutableMap.>of(),
ImmutableMap.>of(),
ImmutableMap.>of(),
ImmutableMap.>of(),
ImmutableMap.>of(),
ImmutableMap.>>of(),
ImmutableList.of(),
null);
}
private WriteQueryDataImpl(ImmutableMap keys,
ImmutableList whereConditions,
ImmutableMap> valuesToMutate,
ImmutableMap> setValuesToAdd,
ImmutableMap> setValuesToRemove,
ImmutableMap> listValuesToAppend,
ImmutableMap> listValuesToPrepend,
ImmutableMap> listValuesToRemove,
ImmutableMap>> mapValuesToMutate,
ImmutableList onlyIfConditions,
Boolean ifNotExists) {
this.keys = keys;
this.whereConditions = whereConditions;
this.valuesToMutate = valuesToMutate;
this.setValuesToAdd = setValuesToAdd;
this.setValuesToRemove = setValuesToRemove;
this.listValuesToAppend = listValuesToAppend;
this.listValuesToPrepend = listValuesToPrepend;
this.listValuesToRemove = listValuesToRemove;
this.mapValuesToMutate = mapValuesToMutate;
this.onlyIfConditions = onlyIfConditions;
this.ifNotExists = ifNotExists;
}
@Override
public WriteQueryDataImpl keys(ImmutableMap keys) {
return new WriteQueryDataImpl(keys,
this.whereConditions,
this.valuesToMutate,
this.setValuesToAdd,
this.setValuesToRemove,
this.listValuesToAppend,
this.listValuesToPrepend,
this.listValuesToRemove,
this.mapValuesToMutate,
this.onlyIfConditions,
this.ifNotExists);
}
@Override
public WriteQueryDataImpl whereConditions(ImmutableList whereConditions) {
return new WriteQueryDataImpl(this.keys,
whereConditions,
this.valuesToMutate,
this.setValuesToAdd,
this.setValuesToRemove,
this.listValuesToAppend,
this.listValuesToPrepend,
this.listValuesToRemove,
this.mapValuesToMutate,
this.onlyIfConditions,
this.ifNotExists);
}
@Override
public WriteQueryDataImpl valuesToMutate(ImmutableMap> valuesToMutate) {
return new WriteQueryDataImpl(this.keys,
this.whereConditions,
valuesToMutate,
this.setValuesToAdd,
this.setValuesToRemove,
this.listValuesToAppend,
this.listValuesToPrepend,
this.listValuesToRemove,
this.mapValuesToMutate,
this.onlyIfConditions,
this.ifNotExists);
}
@Override
public WriteQueryDataImpl setValuesToAdd(ImmutableMap> setValuesToAdd) {
return new WriteQueryDataImpl(this.keys,
this.whereConditions,
this.valuesToMutate,
setValuesToAdd,
this.setValuesToRemove,
this.listValuesToAppend,
this.listValuesToPrepend,
this.listValuesToRemove,
this.mapValuesToMutate,
this.onlyIfConditions,
this.ifNotExists);
}
@Override
public WriteQueryDataImpl setValuesToRemove(ImmutableMap> setValuesToRemove) {
return new WriteQueryDataImpl(this.keys,
this.whereConditions,
this.valuesToMutate,
this.setValuesToAdd,
setValuesToRemove,
this.listValuesToAppend,
this.listValuesToPrepend,
this.listValuesToRemove,
this.mapValuesToMutate,
this.onlyIfConditions,
this.ifNotExists);
}
@Override
public WriteQueryDataImpl listValuesToAppend(ImmutableMap> listValuesToAppend) {
return new WriteQueryDataImpl(this.keys,
this.whereConditions,
this.valuesToMutate,
this.setValuesToAdd,
this.setValuesToRemove,
listValuesToAppend,
this.listValuesToPrepend,
this.listValuesToRemove,
this.mapValuesToMutate,
this.onlyIfConditions,
this.ifNotExists);
}
@Override
public WriteQueryDataImpl listValuesToPrepend(ImmutableMap> listValuesToPrepend) {
return new WriteQueryDataImpl(this.keys,
this.whereConditions,
this.valuesToMutate,
this.setValuesToAdd,
this.setValuesToRemove,
this.listValuesToAppend,
listValuesToPrepend,
this.listValuesToRemove,
this.mapValuesToMutate,
this.onlyIfConditions,
this.ifNotExists);
}
@Override
public WriteQueryDataImpl listValuesToRemove(ImmutableMap> listValuesToRemove) {
return new WriteQueryDataImpl(this.keys,
this.whereConditions,
this.valuesToMutate,
this.setValuesToAdd,
this.setValuesToRemove,
this.listValuesToAppend,
this.listValuesToPrepend,
listValuesToRemove,
this.mapValuesToMutate,
this.onlyIfConditions,
this.ifNotExists);
}
@Override
public WriteQueryDataImpl mapValuesToMutate(ImmutableMap>> mapValuesToMutate) {
return new WriteQueryDataImpl(this.keys,
this.whereConditions,
this.valuesToMutate,
this.setValuesToAdd,
this.setValuesToRemove,
this.listValuesToAppend,
this.listValuesToPrepend,
this.listValuesToRemove,
mapValuesToMutate,
this.onlyIfConditions,
this.ifNotExists);
}
@Override
public WriteQueryDataImpl onlyIfConditions(ImmutableList onlyIfConditions) {
return new WriteQueryDataImpl(this.keys,
this.whereConditions,
this.valuesToMutate,
this.setValuesToAdd,
this.setValuesToRemove,
this.listValuesToAppend,
this.listValuesToPrepend,
this.listValuesToRemove,
this.mapValuesToMutate,
onlyIfConditions,
this.ifNotExists);
}
@Override
public WriteQueryDataImpl ifNotExists(Boolean ifNotExists) {
return new WriteQueryDataImpl(this.keys,
this.whereConditions,
this.valuesToMutate,
this.setValuesToAdd,
this.setValuesToRemove,
this.listValuesToAppend,
this.listValuesToPrepend,
this.listValuesToRemove,
this.mapValuesToMutate,
this.onlyIfConditions,
ifNotExists);
}
@Override
public ImmutableMap getKeys() {
return keys;
}
@Override
public boolean hasKey(ColumnName name) {
return hasKey(name.getName());
}
@Override
public boolean hasKey(String name) {
return getKeys().containsKey(name);
}
@SuppressWarnings("unchecked")
@Override
public T getKey(ColumnName name) {
return (T) getKey(name.getName());
}
@Override
public Object getKey(String name) {
return getKeys().get(name);
}
@Override
public ImmutableList getWhereConditions() {
return whereConditions;
}
@Override
public ImmutableMap> getValuesToMutate() {
return valuesToMutate;
}
@Override
public boolean hasValueToMutate(ColumnName name) {
return hasValueToMutate(name.getName());
}
@Override
public boolean hasValueToMutate(String name) {
return getValuesToMutate().containsKey(name);
}
@SuppressWarnings("unchecked")
@Override
public T getValueToMutate(ColumnName name) {
return (T) getValueToMutate(name.getName());
}
@Override
public Object getValueToMutate(String name) {
Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy