info.archinnov.achilles.internal.async.AsyncUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of achilles-core Show documentation
Show all versions of achilles-core Show documentation
CQL implementation for Achilles using Datastax Java driver
/*
* 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.internal.async;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import com.datastax.driver.core.ExecutionInfo;
import com.google.common.util.concurrent.MoreExecutors;
import info.archinnov.achilles.query.cql.TypedMapsWithPagingState;
import info.archinnov.achilles.type.Empty;
import info.archinnov.achilles.type.TypedMap;
import org.apache.commons.lang3.ArrayUtils;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.ResultSetFuture;
import com.datastax.driver.core.Row;
import com.google.common.base.Function;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import info.archinnov.achilles.async.AchillesFuture;
import info.archinnov.achilles.internal.statement.wrapper.AbstractStatementWrapper;
import info.archinnov.achilles.options.Options;
import javax.annotation.Nullable;
public class AsyncUtils {
public static final Function> RESULTSET_TO_ROWS = new Function>() {
@Override
public List apply(ResultSet resultSet) {
List rows = new ArrayList<>();
if (resultSet != null) {
final int availableWithoutFetching = resultSet.getAvailableWithoutFetching();
for (int i = 0; i < availableWithoutFetching; i++) {
rows.add(resultSet.one());
}
}
return rows;
}
};
public static final Function RESULTSET_TO_ROWS_WITH_EXECUTION_INFO = new Function() {
@Override
public RowsWithExecutionInfo apply(ResultSet resultSet) {
List rows = new ArrayList<>();
ExecutionInfo info = null;
if (resultSet != null) {
final int availableWithoutFetching = resultSet.getAvailableWithoutFetching();
for (int i = 0; i < availableWithoutFetching; i++) {
rows.add(resultSet.one());
}
info = resultSet.getExecutionInfo();
}
return new RowsWithExecutionInfo(rows, info);
}
};
public static final Function RESULTSET_TO_ROW = new Function() {
@Override
public Row apply(ResultSet resultSet) {
Row row = null;
if (resultSet != null) {
row = resultSet.one();
}
return row;
}
};
public static final Function> RESULTSET_TO_ITERATOR = new Function>() {
@Override
public Iterator apply(ResultSet resultSet) {
Iterator iterator = new ArrayList().iterator();
if (resultSet != null) {
iterator = resultSet.iterator();
}
return iterator;
}
};
public void maybeAddAsyncListeners(ListenableFuture> listenableFuture, Options options, ExecutorService executorService) {
if (options.hasAsyncListeners()) {
for (FutureCallback
© 2015 - 2025 Weber Informatics LLC | Privacy Policy