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

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

/*
 * 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.List;

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;
import static info.archinnov.achilles.query.slice.SliceQueryProperties.SliceType;

public abstract class AsyncSelectPartitionRoot> extends SliceQueryRootExtended {

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

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

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forSelect()
     *      .withPartitionComponents(articleId)
     *      .get();
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... ORDER BY rating ASC LIMIT 100 * * @return AchillesFuture<List<TYPE>> */ public AchillesFuture> get() { return super.asyncGetInternal(); } /** * * Get selected entities asynchronously without filtering clustering keys using provided limit * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forSelect()
     *      .withPartitionComponents(articleId)
     *      .get(23);
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... ORDER BY rating ASC LIMIT 23 * * @return AchillesFuture<List<TYPE>> */ public AchillesFuture> get(int limit) { super.properties.limit(limit); return super.asyncGetInternal(); } /** * * Get first entity asynchronously without filtering clustering keys * To get the last entity, just use getOne() with orderByDescending() * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forSelect()
     *      .withPartitionComponents(articleId)
     *      .getOne();
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... ORDER BY rating ASC LIMIT 1 * * @return AchillesFuture<TYPE> */ public AchillesFuture getOne() { super.properties.limit(1); return super.asyncGetOneInternal(); } /** * * Get entities asynchronously with matching clustering keys * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forSelect()
     *      .withPartitionComponents(articleId)
     *      .getMatching(2);
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating=2 ORDER BY rating ASC LIMIT 100 * * @return AchillesFuture<List<TYPE>> */ public AchillesFuture> getMatching(Object... matchedClusteringKeys) { super.withClusteringsInternal(matchedClusteringKeys); return super.asyncGetInternal(); } /** * * Get first entity asynchronously with matching clustering keys * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forSelect()
     *      .withPartitionComponents(articleId)
     *      .getOneMatching(2);
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating=2 ORDER BY rating ASC LIMIT 1 * * @return AchillesFuture<TYPE> */ public AchillesFuture getOneMatching(Object... matchedClusteringKeys) { super.withClusteringsInternal(matchedClusteringKeys); return super.asyncGetOneInternal(); } /** * * Get first entities asynchronously with matching clustering keys * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forSelect()
     *      .withPartitionComponents(articleId)
     *      .getFirstMatching(10,2);
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating=2 ORDER BY rating ASC LIMIT 10 * * @return AchillesFuture<List<TYPE>> */ public AchillesFuture> getFirstMatching(int limit, Object... matchingClusteringKeys) { super.properties.ordering(ASCENDING); super.properties.limit(limit); super.withClusteringsInternal(matchingClusteringKeys); return super.asyncGetInternal(); } /** * * Get last entities asynchronously with matching clustering keys. It is similar to calling * getFirstMatching(...) combined with orderByDescending() * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forSelect()
     *      .withPartitionComponents(articleId)
     *      .getLastMatching(10,2);
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating=2 ORDER BY rating DESC LIMIT 10 * * @return AchillesFuture<List<TYPE>> */ public AchillesFuture> getLastMatching(int limit, Object... matchingClusteringKeys) { super.properties.ordering(DESCENDING); super.withClusteringsInternal(matchingClusteringKeys); super.properties.limit(limit); return super.asyncGetInternal(); } /** * * Filter with lower bound clustering key(s) * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forSelect()
     *      .withPartitionComponents(articleId)
     *      .fromClusterings(2,now)
     *      .get();
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND (rating,date)>=(2,now) ORDER BY rating ASC LIMIT 100 *
*
* Remark: the generated CQL query will take into account the defined clustering order of the table. For example if the clustering order is descending, *

     *     fromClustering("col1","col2)
     * 
* will generate *

     *     WHERE (col1,col2)<=(:col1,:col2)
     * 
* * @return slice DSL */ public SelectFromClusteringsAsync fromClusterings(Object... fromClusteringKeys) { super.fromClusteringsInternal(fromClusteringKeys); return new SelectFromClusteringsAsync<>(); } /** * * Filter with upper bound clustering key(s) * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forSelect()
     *      .withPartitionComponents(articleId)
     *      .toClusterings(3)
     *      .get();
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating<=3 ORDER BY rating ASC LIMIT 100 *
*
* Remark: the generated CQL query will take into account the defined clustering order of the table. For example if the clustering order is descending, *

     *     toClustering("col1","col2)
     * 
* will generate *

     *     WHERE (col1,col2)>=(:col1,:col2)
     * 
* * @return slice DSL */ public SelectEndAsync toClusterings(Object... toClusteringKeys) { super.toClusteringsInternal(toClusteringKeys); return new SelectEndAsync<>(); } /** * * Filter with matching clustering key(s) * *

     *
     *  asyncManager.sliceQuery(ArticleRating.class)
     *      .forSelect()
     *      .withPartitionComponents(articleId)
     *      .withClusterings(3)
     *      .get();
     *
     * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating=3 ORDER BY rating ASC LIMIT 100 * * @return slice DSL */ public SelectWithClusteringsAsync withClusterings(Object... clusteringKeys) { super.withClusteringsInternal(clusteringKeys); return new SelectWithClusteringsAsync<>(); } public abstract class SelectClusteringsRootWithLimitationAsync> { /** * * 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() { AsyncSelectPartitionRoot.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() { AsyncSelectPartitionRoot.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) { AsyncSelectPartitionRoot.super.properties.limit(limit); return getThis(); } /** * * Provide a consistency level for SELECT statement * * @param consistencyLevel * @return Slice DSL */ public T withConsistency(ConsistencyLevel consistencyLevel) { AsyncSelectPartitionRoot.super.properties.readConsistency(consistencyLevel); return getThis(); } public T withAsyncListeners(FutureCallback...asyncListeners) { AsyncSelectPartitionRoot.this.properties.asyncListeners(asyncListeners); return getThis(); } protected abstract T getThis(); /** * * Get first entity asynchronously with filtering clustering keys * To get the last entity, just use getOne() with orderByDescending() * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2)
         *      .getOne();
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating>=2 ORDER BY rating ASC LIMIT 1 * * @return AchillesFuture<TYPE> */ public AchillesFuture getOne() { AsyncSelectPartitionRoot.super.properties.limit(1); return AsyncSelectPartitionRoot.super.asyncGetOneInternal(); } /** * * Get first entity asynchronously with filtering clustering keys * To get the last entity, just use getOne() with orderByDescending() * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2)
         *      .get();
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating>=2 ORDER BY rating ASC LIMIT 100 * * @return AchillesFuture<List<TYPE>> */ public AchillesFuture> get() { return AsyncSelectPartitionRoot.super.asyncGetInternal(); } /** * * Get first entity asynchronously by filtering clustering keys with provided limit * To get the last entity, just use getOne() with orderByDescending() * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .fromClusterings(2)
         *      .get(23);
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating>=2 ORDER BY rating ASC LIMIT 23 * * @return AchillesFuture<List<TYPE>> */ public AchillesFuture> get(int limit) { AsyncSelectPartitionRoot.super.properties.limit(limit); return AsyncSelectPartitionRoot.super.asyncGetInternal(); } } public abstract class SelectClusteringsRootAsync> extends SelectClusteringsRootWithLimitationAsync { /** * * 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() { AsyncSelectPartitionRoot.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() { AsyncSelectPartitionRoot.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() { AsyncSelectPartitionRoot.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() { AsyncSelectPartitionRoot.super.properties.bounding(INCLUSIVE_END_BOUND_ONLY); return getThis(); } } public class SelectFromClusteringsAsync extends SelectClusteringsRootAsync> { /** * * Filter with upper bound clustering key(s) * *

         *
         *  asyncManager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .toClusterings(3)
         *      .get();
         *
         * 
* * Generated CQL query: * *
* SELECT * FROM article_rating WHERE article_id=... AND rating<=3 ORDER BY rating ASC LIMIT 100 *
*
* Remark: the generated CQL query will take into account the defined clustering order of the table. For example if the clustering order is descending, *

         *     toClustering("col1","col2)
         * 
* will generate *

         *     WHERE (col1,col2)>=(:col1,:col2)
         * 
* * @return slice DSL */ public SelectEndAsync toClusterings(Object... clusteringKeys) { AsyncSelectPartitionRoot.super.toClusteringsInternal(clusteringKeys); return new SelectEndAsync<>(); } @Override protected SelectFromClusteringsAsync getThis() { return SelectFromClusteringsAsync.this; } } public class SelectWithClusteringsAsync extends SelectClusteringsRootWithLimitationAsync> { /** * * Filter with clustering key(s) IN a list of provided values * *

         *
         *  manager.sliceQuery(ArticleRating.class)
         *      .forSelect()
         *      .withPartitionComponents(articleId)
         *      .withClusterings(3)
         *      .andClusteringsIN(now,tomorrow,yesterday)
         *      .get();
         *
         * 
* * 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 SelectEndWithLimitationAsync andClusteringsIN(Object... clusteringKeys) { AsyncSelectPartitionRoot.super.andClusteringsInInternal(clusteringKeys); return new SelectEndWithLimitationAsync<>(); } @Override protected SelectWithClusteringsAsync getThis() { return SelectWithClusteringsAsync.this; } } public class SelectEndAsync extends SelectClusteringsRootAsync> { @Override protected SelectEndAsync getThis() { return SelectEndAsync.this; } } public class SelectEndWithLimitationAsync extends SelectClusteringsRootWithLimitationAsync> { @Override protected SelectEndWithLimitationAsync getThis() { return SelectEndWithLimitationAsync.this; } } // public class SelectPartitionAsyncRoot { // // public AchillesFuture> get() { // return AsyncSelectPartitionRoot.super.asyncGetInternal(); // } // // public AchillesFuture> get(int limit) { // AsyncSelectPartitionRoot.super.properties.limit(limit); // return AsyncSelectPartitionRoot.super.asyncGetInternal(); // } // // public AchillesFuture getOne() { // AsyncSelectPartitionRoot.super.properties.limit(1); // return AsyncSelectPartitionRoot.super.asyncGetOneInternal(); // } // // public AchillesFuture> getMatching(Object... matchedClusteringKeys) { // AsyncSelectPartitionRoot.super.withClusteringsInternal(matchedClusteringKeys); // return AsyncSelectPartitionRoot.super.asyncGetInternal(); // } // // public AchillesFuture getOneMatching(Object... matchedClusteringKeys) { // AsyncSelectPartitionRoot.super.withClusteringsInternal(matchedClusteringKeys); // return AsyncSelectPartitionRoot.super.asyncGetOneInternal(); // } // // public AchillesFuture> getFirstMatching(int limit, Object... matchingClusteringKeys) { // AsyncSelectPartitionRoot.super.properties.ordering(ASCENDING); // AsyncSelectPartitionRoot.super.properties.limit(limit); // AsyncSelectPartitionRoot.super.withClusteringsInternal(matchingClusteringKeys); // return AsyncSelectPartitionRoot.super.asyncGetInternal(); // } // // public AchillesFuture> getLastMatching(int limit, Object... matchingClusteringKeys) { // AsyncSelectPartitionRoot.super.properties.ordering(DESCENDING); // AsyncSelectPartitionRoot.super.withClusteringsInternal(matchingClusteringKeys); // AsyncSelectPartitionRoot.super.properties.limit(limit); // return AsyncSelectPartitionRoot.super.asyncGetInternal(); // } // } // // public class SelectClusteringRootAsync { // // public AchillesFuture getOne() { // AsyncSelectPartitionRoot.super.properties.limit(1); // return AsyncSelectPartitionRoot.super.asyncGetOneInternal(); // } // // public AchillesFuture> get() { // return AsyncSelectPartitionRoot.super.asyncGetInternal(); // } // // public AchillesFuture> get(int limit) { // AsyncSelectPartitionRoot.super.properties.limit(limit); // return AsyncSelectPartitionRoot.super.asyncGetInternal(); // } // } }