Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2012-2014 DuyHai DOAN
*
* 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 info.archinnov.achilles.options;
import static info.archinnov.achilles.options.Options.LWTCondition;
import static info.archinnov.achilles.options.Options.LWTPredicate.LWTType.EQUAL_CONDITION;
import static info.archinnov.achilles.options.Options.LWTPredicate.LWTType.GTE_CONDITION;
import static info.archinnov.achilles.options.Options.LWTPredicate.LWTType.GT_CONDITION;
import static info.archinnov.achilles.options.Options.LWTPredicate.LWTType.LTE_CONDITION;
import static info.archinnov.achilles.options.Options.LWTPredicate.LWTType.LT_CONDITION;
import static info.archinnov.achilles.options.Options.LWTPredicate.LWTType.NOT_EQUAL_CONDITION;
import java.util.Arrays;
import java.util.List;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
import info.archinnov.achilles.internal.validation.Validator;
import info.archinnov.achilles.listener.LWTResultListener;
import info.archinnov.achilles.type.ConsistencyLevel;
/**
*
* @see OptionsBuilder
*/
public class OptionsBuilder {
private static final NoOptions NO_OPTIONS = new NoOptions();
private static final Options.LWTIfExists IF_EXISTS = Options.LWTIfExists.Singleton.INSTANCE.get();
private static final Options.LWTIfNotExists IF_NOT_EXISTS = Options.LWTIfNotExists.Singleton.INSTANCE.get();
/**
* Build an empty option
* @return NoOptions
*/
public static NoOptions noOptions() {
return NO_OPTIONS;
}
/**
* Use provided consistency level
* @param consistencyLevel
* @return BuiltOptions
*/
public static BuiltOptions withConsistency(ConsistencyLevel consistencyLevel) {
return new BuiltOptions(consistencyLevel);
}
static BuiltOptions withConsistencyO(Optional consistencyLevelO) {
return new BuiltOptions(consistencyLevelO, true);
}
/**
* Use provided time to live in seconds
* @param ttl
* @return BuiltOptions
*/
public static BuiltOptions withTtl(Integer ttl) {
return new BuiltOptions(ttl);
}
/**
* Use provided timestamp in micro seconds
* @param timestamp
* @return BuiltOptions
*/
public static BuiltOptions withTimestamp(Long timestamp) {
return new BuiltOptions(timestamp);
}
/**
* Use IF NOT EXISTS clause for INSERT operations. This has no effect on statements other than INSERT
* @return BuiltOptions
*/
public static BuiltOptions ifNotExists() {
return new BuiltOptions(IF_NOT_EXISTS);
}
/**
* Use IF EXISTS clause for DELETE operations. This has no effect on statements other than DELETE
* @return BuiltOptions
*/
public static BuiltOptions ifExists() {
return new BuiltOptions(IF_EXISTS);
}
/**
* Use ifEqualCondition(String columnName, Object value)
*/
@Deprecated
public static BuiltOptions ifConditions(LWTCondition... lwtConditions) {
return new BuiltOptions(lwtConditions);
}
/**
* Use LWT conditions for UPDATE operations. This has no effect on statements other than UPDATE
*
*
*
* @param columnName name of the column to be checked for LWT
* @param value expected value of the column to be checked for LWT
*
* @return BuiltOptions
*/
public static BuiltOptions ifEqualCondition(String columnName, Object value) {
return new BuiltOptions(new LWTCondition(EQUAL_CONDITION, columnName, value));
}
/**
* Use LWT conditions for UPDATE operations. This has no effect on statements other than UPDATE
*
*
*
* @param columnName name of the column to be checked for LWT
* @param value expected value of the column to be checked for LWT
*
* @return BuiltOptions
*/
public static BuiltOptions ifNotEqualCondition(String columnName, Object value) {
return new BuiltOptions(new LWTCondition(NOT_EQUAL_CONDITION, columnName, value));
}
/**
* Use LWT conditions for UPDATE operations. This has no effect on statements other than UPDATE
*
*
*
* @param columnName name of the column to be checked for LWT
* @param value expected value of the column to be checked for LWT
*
* @return BuiltOptions
*/
public static BuiltOptions ifGreaterCondition(String columnName, Object value) {
return new BuiltOptions(new LWTCondition(GT_CONDITION, columnName, value));
}
/**
* Use LWT conditions for UPDATE operations. This has no effect on statements other than UPDATE
*
*
*
* @param columnName name of the column to be checked for LWT
* @param value expected value of the column to be checked for LWT
*
* @return BuiltOptions
*/
public static BuiltOptions ifGreaterOrEqualCondition(String columnName, Object value) {
return new BuiltOptions(new LWTCondition(GTE_CONDITION, columnName, value));
}
/**
* Use LWT conditions for UPDATE operations. This has no effect on statements other than UPDATE
*
*
*
* @param columnName name of the column to be checked for LWT
* @param value expected value of the column to be checked for LWT
*
* @return BuiltOptions
*/
public static BuiltOptions ifLesserCondition(String columnName, Object value) {
return new BuiltOptions(new LWTCondition(LT_CONDITION, columnName, value));
}
/**
* Use LWT conditions for UPDATE operations. This has no effect on statements other than UPDATE
*
*
*
* @param columnName name of the column to be checked for LWT
* @param value expected value of the column to be checked for LWT
*
* @return BuiltOptions
*/
public static BuiltOptions ifLesserOrEqualCondition(String columnName, Object value) {
return new BuiltOptions(new LWTCondition(LTE_CONDITION, columnName, value));
}
/**
* Inject a LWT result listener for all LWT operations
*
*
*
* LWTResultListener LWTListener = new LWTResultListener() {
*
* public void onLWTSuccess() {
* // Do something on success
* }
*
* public void onLWTError(LWTResult LWTResult) {
*
* //Get type of LWT operation that fails
* LWTResult.Operation operation = LWTResult.operation();
*
* // Print out current values
* TypedMap currentValues = LWTResult.currentValues();
* for(Entry entry: currentValues.entrySet()) {
* System.out.println(String.format("%s = %s",entry.getKey(), entry.getValue()));
* }
* }
* };
*
* persistenceManager.update(user, OptionsBuilder.
* .ifEqualCondition("login","jdoe")
* .lwtResultListener(lwtListener));
*
*
* @param listener LWTResultListener
* @return BuiltOptions
*/
public static BuiltOptions lwtResultListener(LWTResultListener listener) {
return new BuiltOptions(listener);
}
public static BuiltOptions withAsyncListeners(FutureCallback