
net.oneandone.troilus.UpdateQuery 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 java.util.List;
import java.util.Map;
import java.util.Set;
import net.oneandone.troilus.java7.Batchable;
import net.oneandone.troilus.java7.UpdateWithUnitAndCounter;
import net.oneandone.troilus.java7.interceptor.WriteQueryData;
import com.datastax.driver.core.querybuilder.Clause;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* update query implementation
*/
class UpdateQuery extends WriteQuery implements UpdateWithUnitAndCounter {
/**
* @param ctx the context
* @param data the query data
*/
UpdateQuery(Context ctx, WriteQueryData data) {
super(ctx, data);
}
////////////////////
// factory methods
@Override
protected UpdateQuery newQuery(Context newContext) {
return new UpdateQuery(newContext, getData());
}
private UpdateQuery newQuery(WriteQueryData data) {
return new UpdateQuery(getContext(), data);
}
//
////////////////////
@Override
public BatchMutationQuery combinedWith(Batchable> other) {
return new BatchMutationQuery(getContext(), this, other);
}
/**
* @param entity the entity to insert
* @return the new insert query
*/@Override
public UpdateQuery entity(Object entity) {
ImmutableMap> values = getContext().getBeanMapper().toValues(entity, getContext().getDbSession().getColumnNames());
return newQuery(getData().valuesToMutate(Immutables.join(getData().getValuesToMutate(), values)));
}
@Override
public UpdateQuery withTtl(int ttlSec) {
return newQuery(getContext().withTtl(ttlSec));
}
@Override
public UpdateQuery value(String name, Object value) {
return newQuery(getData().valuesToMutate(Immutables.join(getData().getValuesToMutate(), name, Optionals.toGuavaOptional(value))));
}
@Override
public UpdateQuery value(ColumnName name, T value) {
return value(name.getName(), value);
}
@Override
public UpdateQuery values(ImmutableMap nameValuePairsToAdd) {
return newQuery(getData().valuesToMutate(Immutables.join(getData().getValuesToMutate(), Optionals.toGuavaOptional(nameValuePairsToAdd))));
}
@Override
public UpdateQuery removeSetValue(String name, Object value) {
ImmutableSet
© 2015 - 2025 Weber Informatics LLC | Privacy Policy