org.usergrid.persistence.cassandra.IndexBucketScanner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of usergrid-core Show documentation
Show all versions of usergrid-core Show documentation
Core services for Usergrid system.
/*******************************************************************************
* Copyright 2012 Apigee Corporation
*
* 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 org.usergrid.persistence.cassandra;
import static org.usergrid.persistence.cassandra.CassandraPersistenceUtils.key;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.UUID;
import com.yammer.metrics.annotation.Metered;
import me.prettyprint.hector.api.beans.HColumn;
import org.apache.cassandra.config.ConfigurationException;
import org.apache.cassandra.db.marshal.AbstractType;
import org.apache.cassandra.db.marshal.TypeParser;
import org.usergrid.persistence.IndexBucketLocator;
import org.usergrid.persistence.IndexBucketLocator.IndexType;
/**
* A simple class to make working with index buckets easier. Scans all buckets
* and merges the results into a single column list to allow easy backwards
* compatibility with existing code
*
* @author tnine
*
*/
public class IndexBucketScanner {
private final CassandraService cass;
private final IndexBucketLocator indexBucketLocator;
private final UUID applicationId;
private final Object keyPrefix;
private final ApplicationCF columnFamily;
private final Object start;
private final Object finish;
private final boolean reversed;
private final int count;
private final String[] indexPath;
private final IndexType indexType;
public IndexBucketScanner(CassandraService cass, IndexBucketLocator locator, ApplicationCF columnFamily, UUID applicationId, IndexType indexType, Object keyPrefix, Object start, Object finish, boolean reversed, int count, String... indexPath){
this.cass = cass;
this.indexBucketLocator = locator;
this.applicationId = applicationId;
this.keyPrefix = keyPrefix;
this.columnFamily = columnFamily;
this.start = start;
this.finish = finish;
this.reversed = reversed;
this.count = count;
this.indexPath = indexPath;
this.indexType = indexType;
}
/**
* Search the collection index using all the buckets for the given
* collection
*
* @param indexKey
* @param slice
* @param count
* @param collectionName
* @return
* @throws Exception
*/
@Metered(group="core",name="IndexBucketScanner_load")
public List> load()
throws Exception {
List keys = indexBucketLocator.getBuckets(applicationId, indexType,
indexPath);
List