All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.archinnov.achilles.query.slice.AsyncIteratePartitionRoot Maven / Gradle / Ivy

There is a newer version: 6.1.0
Show newest version
/*
 * 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.query.slice;

import com.google.common.util.concurrent.FutureCallback;
import info.archinnov.achilles.async.AchillesFuture;
import info.archinnov.achilles.internal.metadata.holder.EntityMeta;
import info.archinnov.achilles.internal.persistence.operations.SliceQueryExecutor;
import info.archinnov.achilles.type.ConsistencyLevel;

import java.util.Iterator;

import static info.archinnov.achilles.query.slice.BoundingMode.*;
import static info.archinnov.achilles.query.slice.OrderingMode.ASCENDING;
import static info.archinnov.achilles.query.slice.OrderingMode.DESCENDING;

public abstract class AsyncIteratePartitionRoot> extends SliceQueryRootExtended {

    protected AsyncIteratePartitionRoot(SliceQueryExecutor sliceQueryExecutor, Class entityClass, EntityMeta meta, SliceQueryProperties.SliceType sliceType) {
        super(sliceQueryExecutor, entityClass, meta, sliceType);
    }

    /**
     *
     * Iterate over selected entities asynchronously without filtering clustering keys. If no limit has been set, the default LIMIT 100 applies
     *
     * 

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forIterate()
     *      .withPartitionComponents(articleId)
     *      .iterator();
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... ORDER BY rating ASC LIMIT 100 * * @return AchillesFuture<Iterator<TYPE>> */ public AchillesFuture> iterator() { return super.asyncIteratorInternal(); } /** * * Iterate over selected entities asynchronously without filtering clustering keys using provided fetch size * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forIterate()
     *      .withPartitionComponents(articleId)
     *      .iterator(23);
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... ORDER BY rating ASC ASC LIMIT 100 * *
* * Note: if the fetch size is set, then you won't be able to use IN clause for partition components together ORDER BY. * In this case, Achilles will remove automatically the ORDER BY clause * * * @return AchillesFuture<Iterator<TYPE>> */ public AchillesFuture> iterator(int batchSize) { super.properties.fetchSize(batchSize); return super.asyncIteratorInternal(); } /** * * Iterate over entities asynchronously with matching clustering keys * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forIterate()
     *      .withPartitionComponents(articleId)
     *      .iteratorWithMatching(2);
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating=2 ORDER BY rating ASC LIMIT 100 * * @return AchillesFuture<Iterator<TYPE>> */ public AchillesFuture> iteratorWithMatching(Object... clusterings) { super.withClusteringsInternal(clusterings); return super.asyncIteratorInternal(); } /** * * Iterate over entities asynchronously with matching clustering keys and fetch size * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forIterate()
     *      .withPartitionComponents(articleId)
     *      .iteratorWithMatchingAndBatchSize(10,2);
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating=2 ORDER BY rating ASC LIMIT 100 * * * Note: if the fetch size is set, then you won't be able to use IN clause for partition components together ORDER BY. * In this case, Achilles will remove automatically the ORDER BY clause * * * @return AchillesFuture<Iterator<TYPE>> */ public AchillesFuture> iteratorWithMatchingAndBatchSize(int batchSize, Object... clusterings) { super.properties.fetchSize(batchSize); super.withClusteringsInternal(clusterings); return super.asyncIteratorInternal(); } /** * * Filter with lower bound clustering key(s) * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forIterate()
     *      .withPartitionComponents(articleId)
     *      .fromClusterings(2,now)
     *      .iterator();
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND (rating,date)>=(2,now) ORDER BY rating ASC LIMIT 100 * * @return slice DSL */ public IterateFromClusteringsAsync fromClusterings(Object... clusteringKeys) { super.fromClusteringsInternal(clusteringKeys); return new IterateFromClusteringsAsync<>(); } /** * * Filter with upper bound clustering key(s) * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forIterate()
     *      .withPartitionComponents(articleId)
     *      .toClusterings(3)
     *      .iterator();
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating<=3 ORDER BY rating ASC LIMIT 100 * * @return slice DSL */ public IterateEndAsync toClusterings(Object... clusteringKeys) { super.toClusteringsInternal(clusteringKeys); return new IterateEndAsync<>(); } /** * * Filter with matching clustering key(s) * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forIterate()
     *      .withPartitionComponents(articleId)
     *      .withClusterings(3)
     *      .iterator();
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating=3 ORDER BY rating ASC LIMIT 100 * * @return slice DSL */ public IterateWithClusteringsAsync withClusterings(Object... clusteringKeys) { super.withClusteringsInternal(clusteringKeys); return new IterateWithClusteringsAsync<>(); } public abstract class IterateClusteringsRootWithLimitationAsync> { /** * * Use ascending order for the first clustering key. This is the default ordering * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2, now)
         *      .toClusterings(4)
         *      .orderByAscending()
         *      .get(20);
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND (rating,date)>=(2,now) AND (rating)<=4 ORDER BY rating ASC LIMIT 20 * @return Slice DSL */ public T orderByAscending() { AsyncIteratePartitionRoot.super.properties.ordering(ASCENDING); return getThis(); } /** * * Use descending order for the first clustering key * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2, now)
         *      .toClusterings(4)
         *      .orderByDescending()
         *      .get(20);
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND (rating,date)>=(2,now) AND (rating)<=4 ORDER BY rating DESC LIMIT 20 * @return Slice DSL */ public T orderByDescending() { AsyncIteratePartitionRoot.super.properties.ordering(DESCENDING); return getThis(); } /** * * Set a limit to the query. A default limit of 100 is always set to avoid OutOfMemoryException * You can remove it at your own risk using noLimit() * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2, now)
         *      .toClusterings(4)
         *      .limit(5)
         *      .get();
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND (rating,date)>=(2,now) AND (rating)<=4 ORDER BY rating ASC LIMIT 5 * @return Slice DSL */ public T limit(int limit) { AsyncIteratePartitionRoot.super.properties.limit(limit); return getThis(); } /** * * Provide a consistency level for SELECT statement * * @param consistencyLevel * @return Slice DSL */ public T withConsistency(ConsistencyLevel consistencyLevel) { AsyncIteratePartitionRoot.super.properties.readConsistency(consistencyLevel); return getThis(); } public T withAsyncListeners(FutureCallback...asyncListeners) { AsyncIteratePartitionRoot.this.properties.asyncListeners(asyncListeners); return getThis(); } protected abstract T getThis(); /** * * Iterate over entities asynchronously with filtering clustering keys * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forIterate()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2)
         *      .iterator();
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating>=2 ORDER BY rating ASC LIMIT 100 * * @return AchillesFuture<Iterator<TYPE>> */ public AchillesFuture> iterator() { return AsyncIteratePartitionRoot.super.asyncIteratorInternal(); } /** * * Iterate over entities asynchronously with filtering clustering keys and fetch zie * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forIterate()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2)
         *      .iterator(12);
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating>=2 ORDER BY rating ASC LIMIT 100 * * * Note: if the fetch size is set, then you won't be able to use IN clause for partition components together ORDER BY. * In this case, Achilles will remove automatically the ORDER BY clause * * * @return AchillesFuture<Iterator<TYPE>> */ public AchillesFuture> iterator(int batchSize) { AsyncIteratePartitionRoot.super.properties.fetchSize(batchSize); return AsyncIteratePartitionRoot.super.asyncIteratorInternal(); } } public abstract class IterateClusteringsRootAsync> extends IterateClusteringsRootWithLimitationAsync { /** * * Use inclusive upper & lower bounds * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2, now)
         *      .toClusterings(4)
         *      .withInclusiveBounds()
         *      .get(20);
         *
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND (rating,date)>=(2,now) AND (rating)<=4 ORDER BY rating ASC LIMIT 20 * @return Slice DSL */ public T withInclusiveBounds() { AsyncIteratePartitionRoot.super.properties.bounding(INCLUSIVE_BOUNDS); return getThis(); } /** * * Use exclusive upper & lower bounds * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2, now)
         *      .toClusterings(4)
         *      .withExclusiveBounds()
         *      .get(20);
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND (rating,date)>(2,now) AND (rating)<4 ORDER BY rating ASC LIMIT 20 * @return Slice DSL */ public T withExclusiveBounds() { AsyncIteratePartitionRoot.super.properties.bounding(EXCLUSIVE_BOUNDS); return getThis(); } /** * * Use inclusive lower bound and exclusive upper bounds * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2, now)
         *      .toClusterings(4)
         *      .withExclusiveBounds()
         *      .get(20);
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND (rating,date)>=(2,now) AND (rating)<4 ORDER BY rating ASC LIMIT 20 * @return Slice DSL */ public T fromInclusiveToExclusiveBounds() { AsyncIteratePartitionRoot.super.properties.bounding(INCLUSIVE_START_BOUND_ONLY); return getThis(); } /** * * Use exclusive lower bound and inclusive upper bounds * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2, now)
         *      .toClusterings(4)
         *      .withExclusiveBounds()
         *      .get(20);
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND (rating,date)>(2,now) AND (rating)<=4 ORDER BY rating ASC LIMIT 20 * @return Slice DSL */ public T fromExclusiveToInclusiveBounds() { AsyncIteratePartitionRoot.super.properties.bounding(INCLUSIVE_END_BOUND_ONLY); return getThis(); } } public class IterateFromClusteringsAsync extends IterateClusteringsRootAsync> { /** * * Filter with upper bound clustering key(s) * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forIterate()
         *      .withPartitionComponents(articleId)
         *      .toClusterings(3)
         *      .iterator();
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating<=3 ORDER BY rating ASC LIMIT 100 * * @return slice DSL */ public IterateEndAsync toClusterings(Object... clusteringKeys) { AsyncIteratePartitionRoot.super.toClusteringsInternal(clusteringKeys); return new IterateEndAsync<>(); } @Override protected IterateFromClusteringsAsync getThis() { return IterateFromClusteringsAsync.this; } } public class IterateWithClusteringsAsync extends IterateClusteringsRootWithLimitationAsync> { /** * * Filter with clustering key(s) IN a list of provided values * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forIterate()
         *      .withPartitionComponents(articleId)
         *      .withClusterings(3)
         *      .andClusteringsIN(now,tomorrow,yesterday)
         *      .iterator();
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating=3 AND date IN (now,tomorrow,yesterday) ORDER BY rating ASC LIMIT 100 * * @return slice DSL */ public IterateEndWithLimitationAsync andClusteringsIN(Object... clusteringKeys) { AsyncIteratePartitionRoot.super.andClusteringsInInternal(clusteringKeys); return new IterateEndWithLimitationAsync<>(); } @Override protected IterateWithClusteringsAsync getThis() { return IterateWithClusteringsAsync.this; } } public class IterateEndAsync extends IterateClusteringsRootAsync> { @Override protected IterateEndAsync getThis() { return IterateEndAsync.this; } } public class IterateEndWithLimitationAsync extends IterateClusteringsRootWithLimitationAsync> { @Override protected IterateEndWithLimitationAsync getThis() { return IterateEndWithLimitationAsync.this; } } }