This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
forked from hector-client/hector
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
core/src/main/java/me/prettyprint/cassandra/model/thrift/ThriftSuperSliceCounterQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package me.prettyprint.cassandra.model.thrift; | ||
|
||
import me.prettyprint.cassandra.model.*; | ||
import me.prettyprint.cassandra.serializers.LongSerializer; | ||
import me.prettyprint.cassandra.service.KeyspaceService; | ||
import me.prettyprint.cassandra.utils.Assert; | ||
import me.prettyprint.hector.api.Keyspace; | ||
import me.prettyprint.hector.api.Serializer; | ||
import me.prettyprint.hector.api.beans.CounterSuperSlice; | ||
import me.prettyprint.hector.api.beans.SuperSlice; | ||
import me.prettyprint.hector.api.exceptions.HectorException; | ||
import me.prettyprint.hector.api.query.QueryResult; | ||
import me.prettyprint.hector.api.query.SuperSliceCounterQuery; | ||
import me.prettyprint.hector.api.query.SuperSliceQuery; | ||
import org.apache.cassandra.thrift.ColumnParent; | ||
import org.apache.cassandra.thrift.CounterSuperColumn; | ||
import org.apache.cassandra.thrift.SuperColumn; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* A query for the thrift call get_slice. | ||
* <p> | ||
* Get a slice of super columns from a super column family. | ||
* | ||
* @author Ran Tavory | ||
* | ||
* @param <N> | ||
*/ | ||
public final class ThriftSuperSliceCounterQuery<K, SN, N> extends | ||
AbstractSliceQuery<K, SN, Long, CounterSuperSlice<SN, N>> implements SuperSliceCounterQuery<K, SN, N> { | ||
|
||
private K key; | ||
private final Serializer<N> nameSerializer; | ||
|
||
public ThriftSuperSliceCounterQuery(Keyspace keyspace, | ||
Serializer<K> keySerializer, | ||
Serializer<SN> sNameSerializer, | ||
Serializer<N> nameSerializer) { | ||
super(keyspace, keySerializer, sNameSerializer, LongSerializer.get()); | ||
Assert.notNull(sNameSerializer, "sNameSerializer cannot be null"); | ||
this.nameSerializer = nameSerializer; | ||
} | ||
|
||
@Override | ||
public SuperSliceCounterQuery<K, SN, N> setKey(K key) { | ||
this.key = key; | ||
return this; | ||
} | ||
|
||
@Override | ||
public QueryResult<CounterSuperSlice<SN, N>> execute() { | ||
return new QueryResultImpl<CounterSuperSlice<SN,N>>(keyspace.doExecute( | ||
new KeyspaceOperationCallback<CounterSuperSlice<SN,N>>() { | ||
@Override | ||
public CounterSuperSlice<SN, N> doInKeyspace(KeyspaceService ks) throws HectorException { | ||
ColumnParent columnParent = new ColumnParent(columnFamilyName); | ||
List<CounterSuperColumn> thriftRet = ks.getCounterSuperSlice(keySerializer.toByteBuffer(key), | ||
columnParent, getPredicate()); | ||
return new CounterSuperSliceImpl<SN, N>(thriftRet, columnNameSerializer, nameSerializer); | ||
} | ||
}), this); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SuperSliceQuery(" + key + "," + toStringInternal() + ")"; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public SuperSliceCounterQuery<K, SN, N> setColumnNames(SN... columnNames) { | ||
return (SuperSliceCounterQuery<K, SN, N>) super.setColumnNames(columnNames); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public SuperSliceCounterQuery<K, SN, N> setRange(SN start, SN finish, boolean reversed, int count) { | ||
return (SuperSliceCounterQuery<K, SN, N>) super.setRange(start, finish, reversed, count); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public SuperSliceCounterQuery<K, SN, N> setColumnFamily(String cf) { | ||
return (SuperSliceCounterQuery<K, SN, N>) super.setColumnFamily(cf); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/src/main/java/me/prettyprint/hector/api/query/SuperSliceCounterQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package me.prettyprint.hector.api.query; | ||
|
||
import me.prettyprint.hector.api.beans.CounterSuperSlice; | ||
import me.prettyprint.hector.api.beans.SuperSlice; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* A query for the call get_slice. | ||
* <p> | ||
* Get a slice of super columns from a super column family. | ||
* | ||
* @author Ran Tavory | ||
* | ||
* @param <SN> type of the super column name | ||
* @param <N> type of the column name | ||
*/ | ||
public interface SuperSliceCounterQuery<K, SN, N> extends Query<CounterSuperSlice<SN, N>> { | ||
|
||
SuperSliceCounterQuery<K, SN, N> setKey(K key); | ||
|
||
SuperSliceCounterQuery<K, SN, N> setColumnNames(SN... columnNames); | ||
|
||
SuperSliceCounterQuery<K, SN, N> setRange(SN start, SN finish, boolean reversed, int count); | ||
|
||
SuperSliceCounterQuery<K, SN, N> setColumnFamily(String cf); | ||
|
||
Collection<SN> getColumnNames(); | ||
|
||
} |