index int64 0 0 | repo_id stringlengths 26 205 | file_path stringlengths 51 246 | content stringlengths 8 433k | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/util/RangeBuilder.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.util;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.UUID;
import com.google.common.base.Preconditions;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.model.ByteBufferRange;
import com.netflix.astyanax.serializers.BooleanSerializer;
import com.netflix.astyanax.serializers.ByteBufferSerializer;
import com.netflix.astyanax.serializers.BytesArraySerializer;
import com.netflix.astyanax.serializers.DateSerializer;
import com.netflix.astyanax.serializers.DoubleSerializer;
import com.netflix.astyanax.serializers.IntegerSerializer;
import com.netflix.astyanax.serializers.LongSerializer;
import com.netflix.astyanax.serializers.StringSerializer;
import com.netflix.astyanax.serializers.UUIDSerializer;
/**
* Utility builder to construct a ByteBufferRange to be used in a slice query.
*
* @author elandau
*
*/
public class RangeBuilder {
private static ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate(0);
private static final int DEFAULT_MAX_SIZE = Integer.MAX_VALUE;
private ByteBuffer start = EMPTY_BUFFER;
private ByteBuffer end = EMPTY_BUFFER;
private int limit = DEFAULT_MAX_SIZE;
private boolean reversed = false;
/**
* @deprecated use setLimit instead
*/
@Deprecated
public RangeBuilder setMaxSize(int count) {
return setLimit(count);
}
public RangeBuilder setLimit(int count) {
Preconditions.checkArgument(count >= 0, "Invalid count in RangeBuilder : " + count);
this.limit = count;
return this;
}
/**
* @deprecated Use setReversed(boolean reversed)
* @return
*/
@Deprecated
public RangeBuilder setReversed() {
reversed = true;
return this;
}
public RangeBuilder setReversed(boolean reversed) {
this.reversed = reversed;
return this;
}
public RangeBuilder setStart(String value) {
start = StringSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setStart(byte[] value) {
start = BytesArraySerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setStart(int value) {
start = IntegerSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setStart(long value) {
start = LongSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setStart(boolean value) {
start = BooleanSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setStart(ByteBuffer value) {
start = ByteBufferSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setStart(Date value) {
start = DateSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setStart(double value) {
start = DoubleSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setStart(UUID value) {
start = UUIDSerializer.get().toByteBuffer(value);
return this;
}
public <T> RangeBuilder setStart(T value, Serializer<T> serializer) {
start = serializer.toByteBuffer(value);
return this;
}
public RangeBuilder setEnd(String value) {
end = StringSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setEnd(byte[] value) {
end = BytesArraySerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setEnd(int value) {
end = IntegerSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setEnd(long value) {
end = LongSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setEnd(boolean value) {
end = BooleanSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setEnd(ByteBuffer value) {
end = ByteBufferSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setEnd(Date value) {
end = DateSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setEnd(double value) {
end = DoubleSerializer.get().toByteBuffer(value);
return this;
}
public RangeBuilder setEnd(UUID value) {
end = UUIDSerializer.get().toByteBuffer(value);
return this;
}
public <T> RangeBuilder setEnd(T value, Serializer<T> serializer) {
end = serializer.toByteBuffer(value);
return this;
}
public ByteBufferRange build() {
return new ByteBufferRangeImpl(clone(start), clone(end), limit, reversed);
}
public static ByteBuffer clone(ByteBuffer original) {
ByteBuffer clone = ByteBuffer.allocate(original.capacity());
original.rewind();// copy from the beginning
clone.put(original);
original.rewind();
clone.flip();
return clone;
}
}
| 7,800 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/util/WriteAheadMutationBatchExecutor.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.util;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.MutationBatch;
import com.netflix.astyanax.WriteAheadEntry;
import com.netflix.astyanax.WriteAheadLog;
import com.netflix.astyanax.connectionpool.OperationResult;
import com.netflix.astyanax.connectionpool.exceptions.NoAvailableHostsException;
import com.netflix.astyanax.connectionpool.exceptions.WalException;
import com.netflix.astyanax.impl.NoOpWriteAheadLog;
public class WriteAheadMutationBatchExecutor {
private ListeningExecutorService executor;
private WriteAheadLog wal = new NoOpWriteAheadLog();
private Predicate<Exception> retryablePredicate = Predicates.alwaysFalse();
private final Keyspace keyspace;
private long waitOnNoHosts = 1000;
public WriteAheadMutationBatchExecutor(Keyspace keyspace, int nThreads) {
this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(nThreads,
new ThreadFactoryBuilder().setDaemon(true).build()));
this.keyspace = keyspace;
}
public WriteAheadMutationBatchExecutor(Keyspace keyspace, ExecutorService executor) {
this.executor = MoreExecutors.listeningDecorator(executor);
this.keyspace = keyspace;
}
public WriteAheadMutationBatchExecutor usingWriteAheadLog(WriteAheadLog wal) {
this.wal = wal;
return this;
}
public WriteAheadMutationBatchExecutor usingRetryablePredicate(Predicate<Exception> predicate) {
this.retryablePredicate = predicate;
return this;
}
/**
* Replay records from the WAL
*/
public List<ListenableFuture<OperationResult<Void>>> replayWal(int count) {
List<ListenableFuture<OperationResult<Void>>> futures = Lists.newArrayList();
WriteAheadEntry walEntry;
while (null != (walEntry = wal.readNextEntry()) && count-- > 0) {
MutationBatch m = keyspace.prepareMutationBatch();
try {
walEntry.readMutation(m);
futures.add(executeWalEntry(walEntry, m));
}
catch (WalException e) {
wal.removeEntry(walEntry);
}
}
return futures;
}
/**
* Write a mutation to the wal and execute it
*/
public ListenableFuture<OperationResult<Void>> execute(final MutationBatch m) throws WalException {
final WriteAheadEntry walEntry = wal.createEntry();
walEntry.writeMutation(m);
return executeWalEntry(walEntry, m);
}
private ListenableFuture<OperationResult<Void>> executeWalEntry(final WriteAheadEntry walEntry,
final MutationBatch m) {
return executor.submit(new Callable<OperationResult<Void>>() {
public OperationResult<Void> call() throws Exception {
try {
OperationResult<Void> result = m.execute();
wal.removeEntry(walEntry);
return result;
}
catch (Exception e) {
if (e instanceof NoAvailableHostsException) {
Thread.sleep(waitOnNoHosts);
}
if (retryablePredicate.apply(e))
executor.submit(this);
else
wal.removeEntry(walEntry);
throw e;
}
}
});
}
public void shutdown() {
executor.shutdown();
}
}
| 7,801 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/util/CsvRowsWriter.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.util;
import com.netflix.astyanax.model.Rows;
public class CsvRowsWriter implements RowsWriter {
@Override
public void write(Rows<?, ?> rows) {
// TODO Auto-generated method stub
}
}
| 7,802 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/util/CsvColumnReader.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.util;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import com.netflix.astyanax.shaded.org.apache.cassandra.utils.Pair;
import org.apache.commons.csv.CSVParser;
/**
* Read a CSV where each row represents a single column
*
* rowkey, columname, columnvalue
*
* @author elandau
*
*/
public class CsvColumnReader implements RecordReader {
private CSVParser parser;
private boolean hasHeaderLine = true;
public CsvColumnReader(Reader reader) {
this.parser = new CSVParser(reader);
}
public CsvColumnReader setHasHeaderLine(boolean flag) {
this.hasHeaderLine = flag;
return this;
}
@Override
public void start() throws IOException {
// First line contains the column names. First column expected to be the
// row key
if (hasHeaderLine) {
parser.getLine();
}
}
@Override
public void shutdown() {
}
@Override
public List<Pair<String, String>> next() throws IOException {
// Iterate rows
String[] row = parser.getLine();
if (null == row)
return null;
List<Pair<String, String>> columns = new ArrayList<Pair<String, String>>();
// Build row mutation for all columns
columns.add(Pair.create("key", row[0]));
if (row.length == 3)
columns.add(Pair.create(row[1], row[2]));
return columns;
}
}
| 7,803 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/partitioner/BOP20Partitioner.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.partitioner;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.codec.binary.Hex;
import com.google.common.collect.Lists;
import com.netflix.astyanax.connectionpool.TokenRange;
import com.netflix.astyanax.connectionpool.impl.TokenRangeImpl;
public class BOP20Partitioner implements Partitioner {
public static final String MINIMUM = "0000000000000000000000000000000000000000";
public static final String MAXIMUM = "ffffffffffffffffffffffffffffffffffffffff";
public static final BigInteger ONE = new BigInteger("1", 16);
public static final int KEY_LENGTH = 20;
@Override
public String getMinToken() {
return MINIMUM;
}
@Override
public String getMaxToken() {
return MAXIMUM;
}
@Override
public List<TokenRange> splitTokenRange(String first, String last, int count) {
List<TokenRange> tokens = Lists.newArrayList();
for (int i = 0; i < count; i++) {
String startToken = getTokenMinusOne(getSegmentToken(count, i, new BigInteger(first, 16), new BigInteger(last, 16)));
String endToken;
if (i == count-1 && last.equals(getMaxToken()))
endToken = getMinToken();
else
endToken = getSegmentToken(count, i+1, new BigInteger(first, 16), new BigInteger(last, 16));
tokens.add(new TokenRangeImpl(startToken, endToken, new ArrayList<String>()));
}
return tokens;
}
@Override
public List<TokenRange> splitTokenRange(int count) {
return splitTokenRange(getMinToken(), getMaxToken(), count);
}
@Override
public String getTokenForKey(ByteBuffer key) {
if (key.remaining() != KEY_LENGTH) {
throw new IllegalArgumentException("Key must be a 20 byte array");
}
return new String(Hex.encodeHexString(key.duplicate().array()));
}
@Override
public String getTokenMinusOne(String token) {
if (token.equals("0") || token.equals(MINIMUM))
return MAXIMUM;
return new BigInteger(token, 16).subtract(ONE).toString(16);
}
public static String getSegmentToken(int size, int position, BigInteger minInitialToken, BigInteger maxInitialToken ) {
BigInteger decValue = minInitialToken;
if (position != 0)
decValue = maxInitialToken.multiply(new BigInteger("" + position)).divide(new BigInteger("" + size));
return decValue.toString(16);
}
}
| 7,804 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/partitioner/OrderedBigIntegerPartitioner.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.partitioner;
import java.nio.ByteBuffer;
import com.netflix.astyanax.serializers.BigIntegerSerializer;
public class OrderedBigIntegerPartitioner extends BigInteger127Partitioner {
private static final OrderedBigIntegerPartitioner instance = new OrderedBigIntegerPartitioner();
public static Partitioner get() {
return instance;
}
protected OrderedBigIntegerPartitioner() {
}
@Override
public String getTokenForKey(ByteBuffer key) {
return BigIntegerSerializer.get().fromByteBuffer(key).toString();
}
} | 7,805 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/partitioner/Murmur3Partitioner.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.partitioner;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.common.collect.Lists;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.connectionpool.TokenRange;
import com.netflix.astyanax.connectionpool.impl.TokenRangeImpl;
public class Murmur3Partitioner implements Partitioner {
public static final BigInteger MINIMUM = new BigInteger(Long.toString(Long.MIN_VALUE));
public static final BigInteger MAXIMUM = new BigInteger(Long.toString(Long.MAX_VALUE));
public static final BigInteger ONE = new BigInteger("1");
private static final com.netflix.astyanax.shaded.org.apache.cassandra.dht.Murmur3Partitioner partitioner =
new com.netflix.astyanax.shaded.org.apache.cassandra.dht.Murmur3Partitioner();
private static final Murmur3Partitioner instance = new Murmur3Partitioner();
public static Partitioner get() {
return instance;
}
private Murmur3Partitioner() {
}
@Override
public String getMinToken() {
return MINIMUM.toString();
}
@Override
public String getMaxToken() {
return MAXIMUM.toString();
}
@Override
public List<TokenRange> splitTokenRange(String first, String last, int count) {
if (first.equals(last)) {
last = getTokenMinusOne(last);
}
List<TokenRange> tokens = Lists.newArrayList();
List<String> splits = splitRange(new BigInteger(first), new BigInteger(last), count);
Iterator<String> iter = splits.iterator();
String current = iter.next();
while (iter.hasNext()) {
String next = iter.next();
tokens.add(new TokenRangeImpl(current, next, new ArrayList<String>()));
current = next;
}
return tokens;
}
@Override
public List<TokenRange> splitTokenRange(int count) {
return splitTokenRange(getMinToken(), getMaxToken(), count);
}
@Override
public String getTokenForKey(ByteBuffer key) {
return partitioner.getToken(key).toString();
}
public <T> String getTokenForKey(T key, Serializer<T> serializer) {
return partitioner.getToken(serializer.toByteBuffer(key)).toString();
}
@Override
public String getTokenMinusOne(String token) {
Long lToken = Long.parseLong(token);
// if zero rotate to the Maximum else minus one.
if (lToken.equals(MINIMUM))
return MAXIMUM.toString();
else
return Long.toString(lToken - 1);
}
public static List<String> splitRange(BigInteger first, BigInteger last, int count) {
List<String> tokens = Lists.newArrayList();
tokens.add(first.toString());
BigInteger delta = (last.subtract(first).divide(BigInteger.valueOf((long)count)));
BigInteger current = first;
for (int i = 0; i < count-1; i++) {
current = current.add(delta);
tokens.add(current.toString());
}
tokens.add(last.toString());
return tokens;
}
}
| 7,806 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/partitioner/LongBOPPartitioner.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.partitioner;
import java.nio.ByteBuffer;
/**
* This partitioner is used mostly for tests
* @author elandau
*
*/
public class LongBOPPartitioner extends BigInteger127Partitioner {
private static final LongBOPPartitioner instance = new LongBOPPartitioner();
public static Partitioner get() {
return instance;
}
protected LongBOPPartitioner() {
}
@Override
public String getTokenForKey(ByteBuffer key) {
return Long.toString(key.duplicate().asLongBuffer().get());
}
} | 7,807 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/partitioner/BigInteger127Partitioner.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.partitioner;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.netflix.astyanax.shaded.org.apache.cassandra.dht.RandomPartitioner;
import com.google.common.collect.Lists;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.connectionpool.TokenRange;
import com.netflix.astyanax.connectionpool.impl.TokenRangeImpl;
public class BigInteger127Partitioner implements Partitioner {
public static final BigInteger MINIMUM = new BigInteger("" + 0);
public static final BigInteger MAXIMUM = new BigInteger("" + 2).pow(127).subtract(new BigInteger("1"));
public static final BigInteger ONE = new BigInteger("1");
private static final RandomPartitioner partitioner = new RandomPartitioner();
private static final BigInteger127Partitioner instance = new BigInteger127Partitioner();
public static Partitioner get() {
return instance;
}
public BigInteger127Partitioner() {
}
@Override
public String getMinToken() {
return MINIMUM.toString();
}
@Override
public String getMaxToken() {
return MAXIMUM.toString();
}
@Override
public List<TokenRange> splitTokenRange(String first, String last, int count) {
if (first.equals(last)) {
first = getMinToken();
last = getMaxToken();
}
List<TokenRange> tokens = Lists.newArrayList();
List<String> splits = splitRange(new BigInteger(first), new BigInteger(last), count);
Iterator<String> iter = splits.iterator();
String current = iter.next();
while (iter.hasNext()) {
String next = iter.next();
tokens.add(new TokenRangeImpl(current, next, new ArrayList<String>()));
current = next;
}
return tokens;
}
@Override
public List<TokenRange> splitTokenRange(int count) {
return splitTokenRange(getMinToken(), getMaxToken(), count);
}
@Override
public String getTokenForKey(ByteBuffer key) {
return partitioner.getToken(key).toString();
}
public <T> String getTokenForKey(T key, Serializer<T> serializer) {
return partitioner.getToken(serializer.toByteBuffer(key)).toString();
}
@Override
public String getTokenMinusOne(String token) {
BigInteger bigInt = new BigInteger(token);
// if zero rotate to the Maximum else minus one.
if (bigInt.equals(MINIMUM))
return MAXIMUM.toString();
else
return bigInt.subtract(ONE).toString();
}
public static List<String> splitRange(BigInteger first, BigInteger last, int count) {
List<String> tokens = Lists.newArrayList();
tokens.add(first.toString());
BigInteger delta = (last.subtract(first).divide(BigInteger.valueOf((long)count)));
BigInteger current = first;
for (int i = 0; i < count-1; i++) {
current = current.add(delta);
tokens.add(current.toString());
}
tokens.add(last.toString());
return tokens;
}
}
| 7,808 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/shaded/org/apache/cassandra/db | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/shaded/org/apache/cassandra/db/marshal/ShadedTypeParser.java | /*******************************************************************************
* Copyright 2018 Netflix
*
* 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 com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal;
import com.netflix.astyanax.shaded.org.apache.cassandra.exceptions.ConfigurationException;
import com.netflix.astyanax.shaded.org.apache.cassandra.exceptions.SyntaxException;
import com.netflix.astyanax.shaded.org.apache.cassandra.utils.FBUtilities;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
/**
* Extend {@link TypeParser} to support shaded {@link AbstractType} from shaded package.
*
* This implementation uses some ugly reflection because {@link TypeParser#parse(String)} was apparently never meant
* to be overridden -- too many references to private fields (e.g. {@link TypeParser#idx}, etc.) and private methods
* ({@link TypeParser#getAbstractType}, etc.) which a derived method can't access. This ugliness could have been
* avoided if TypeParser hadn't tried to restrict extension by setting everything private instead of protected.
*/
public class ShadedTypeParser extends TypeParser {
private static final org.slf4j.Logger Logger = LoggerFactory.getLogger(ShadedTypeParser.class);
public static final String SHADED_PREFIX = "com.netflix.astyanax.shaded.";
protected static TypeParser EMPTY_PARSER;
static {
try {
EMPTY_PARSER = new ShadedTypeParser("");
} catch (ConfigurationException e) {
Logger.error("ShadedTypeParser failed to create EMPTY_PARSER; message=" + e.getMessage(), e);
}
}
/*******************************************************************************************************************
* Begin ugly reflection required to work around TypeParser's lack of design for extension:
******************************************************************************************************************/
protected static Field strField;
protected static Field idxField;
protected static Field cacheField;
protected static Map<String, AbstractType<?>> cache;
protected static Method skipBlankMethod;
protected static Method skipBlankMethod2;
protected static Method isEOSMethod;
protected static Method isEOSMethod2;
protected static Method isIdentifierCharMethod;
protected static void init() throws ConfigurationException {
try {
strField = ShadedTypeParser.class.getSuperclass().getDeclaredField("str");
strField.setAccessible(true);
idxField = ShadedTypeParser.class.getSuperclass().getDeclaredField("idx");
idxField.setAccessible(true);
cacheField = ShadedTypeParser.class.getSuperclass().getDeclaredField("cache");
cacheField.setAccessible(true);
cache = (Map<String, AbstractType<?>>)cacheField.get(null);
skipBlankMethod = ShadedTypeParser.class.getSuperclass().getDeclaredMethod("skipBlank");
skipBlankMethod.setAccessible(true);
skipBlankMethod2 = ShadedTypeParser.class.getSuperclass().getDeclaredMethod("skipBlank", String.class, int.class);
skipBlankMethod2.setAccessible(true);
isEOSMethod = ShadedTypeParser.class.getSuperclass().getDeclaredMethod("isEOS");
isEOSMethod.setAccessible(true);
isEOSMethod2 = ShadedTypeParser.class.getSuperclass().getDeclaredMethod("isEOS", String.class, int.class);
isEOSMethod2.setAccessible(true);
isIdentifierCharMethod = ShadedTypeParser.class.getSuperclass().getDeclaredMethod("isIdentifierChar", int.class);
isIdentifierCharMethod.setAccessible(true);
} catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException e) {
throw new ConfigurationException(
"ShadedTypeParser init() failed for reflection; message=" + e.getMessage(), e);
}
}
protected String getStr() throws IllegalAccessException {
return (String)strField.get(this);
}
protected int getIdx() throws IllegalAccessException {
return idxField.getInt(this);
}
protected void setIdx(int idx) throws IllegalAccessException {
idxField.setInt(this, idx);
}
protected void skipBlank() throws InvocationTargetException, IllegalAccessException {
skipBlankMethod.invoke(this);
}
protected static int skipBlank(String str, int i) throws InvocationTargetException, IllegalAccessException {
return (Integer)skipBlankMethod2.invoke(null, str, i);
}
protected boolean isEOS() throws InvocationTargetException, IllegalAccessException {
return (Boolean)isEOSMethod.invoke(this);
}
protected static boolean isEOS(String str, int i) throws InvocationTargetException, IllegalAccessException {
return (Boolean)isEOSMethod2.invoke(null, str, i);
}
private static boolean isIdentifierChar(int c) throws InvocationTargetException, IllegalAccessException {
return (Boolean)isIdentifierCharMethod.invoke(null, c);
}
protected static Method getRawAbstractTypeMethod(Class typeClass) throws NoSuchMethodException {
return ShadedTypeParser.class.getSuperclass().getDeclaredMethod("getRawAbstractType",
typeClass, EMPTY_PARSER.getClass());
}
/*******************************************************************************************************************
* End ugly reflection required to work around TypeParser's lack of design for extension
******************************************************************************************************************/
public static ShadedTypeParser buildTypeParser(String str, int idx) throws ConfigurationException {
return new ShadedTypeParser(str, idx);
}
public ShadedTypeParser(String str) throws ConfigurationException {
this(str, 0);
}
public ShadedTypeParser(String str, int idx) throws ConfigurationException {
super(str);
init();
try {
setIdx(idx);
} catch (IllegalAccessException e) {
throw new ConfigurationException(
"ShadedTypeParser constructor failed for reflection; message=" + e.getMessage(), e);
}
}
public static String getShadedClassName(String className){
if(className.startsWith(SHADED_PREFIX)){
return className;
} else if (className.contains(".")){
return SHADED_PREFIX + className;
} else {
return SHADED_PREFIX + "org.apache.cassandra.db.marshal." + className;
}
}
public static String getShadedTypeName(String typeName){
if ( typeName.startsWith( "org.apache.cassandra.db.marshal." ) ) {
return typeName.substring( "org.apache.cassandra.db.marshal.".length() );
} else if ( typeName.startsWith( SHADED_PREFIX + "org.apache.cassandra.db.marshal." ) ) {
return typeName.substring( (SHADED_PREFIX + "org.apache.cassandra.db.marshal.").length() );
}
return typeName;
}
/*******************************************************************************************************************
* Begin methods very slightly modified from {@link TypeParser} to support shaded classes
******************************************************************************************************************/
public static AbstractType<?> parse(String str) throws SyntaxException, ConfigurationException {
try{
if (str == null) {
return BytesType.instance;
} else {
str = getShadedClassName(str);
AbstractType<?> type = null;
type = (AbstractType) cache.get(str);
if (type != null) {
return type;
} else {
int i = 0;
i = skipBlank(str, i);
int j;
for (j = i; !isEOS(str, i) && isIdentifierChar(str.charAt(i)); ++i) {
;
}
if (i == j) {
return BytesType.instance;
} else {
String name = str.substring(j, i);
name = getShadedClassName(name);
i = skipBlank(str, i);
if (!isEOS(str, i) && str.charAt(i) == '(') {
ShadedTypeParser typeParser = buildTypeParser(str, i);
type = getAbstractType(name, typeParser);
} else {
type = getAbstractType(name);
}
cache.put(str, type);
return type;
}
}
}
} catch (IllegalAccessException | InvocationTargetException e) {
throw new ConfigurationException(
"ShadedTypeParser parse(String) failed for reflection; message=" + e.getMessage(), e);
}
}
public AbstractType<?> parse() throws SyntaxException, ConfigurationException {
try {
skipBlank();
String name = this.readNextIdentifier();
name = getShadedClassName(name);
skipBlank();
return !isEOS() && this.getStr().charAt(getIdx()) == '(' ? getAbstractType(name, this) : getAbstractType(name);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new ConfigurationException(
"ShadedTypeParser parse() failed for reflection; message=" + e.getMessage(), e);
}
}
protected static AbstractType<?> getAbstractType(String compareWith) throws ConfigurationException {
String className = getShadedClassName(compareWith);
Class typeClass = FBUtilities.classForName(className, "abstract-type");
try {
Field field = typeClass.getDeclaredField("instance");
return (AbstractType)field.get((Object)null);
} catch (NoSuchFieldException | IllegalAccessException var4) {
try {
Method getRawAbstractTypeMethod = getRawAbstractTypeMethod(typeClass);
return (AbstractType<?>) getRawAbstractTypeMethod.invoke(null, typeClass, EMPTY_PARSER);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new ConfigurationException(
"ShadedTypeParser getAbstractType failed for reflection; message=" + e.getMessage(), e);
}
}
}
protected static AbstractType<?> getAbstractType(String compareWith, TypeParser parser) throws SyntaxException, ConfigurationException {
String className = getShadedClassName(compareWith);
Class typeClass = FBUtilities.classForName(className, "abstract-type");
AbstractType type;
try {
Method method = typeClass.getDeclaredMethod("getInstance", TypeParser.class);
return (AbstractType)method.invoke((Object)null, parser);
} catch (NoSuchMethodException | IllegalAccessException var6) {
try {
Method getRawAbstractTypeMethod = getRawAbstractTypeMethod(typeClass);
type = (AbstractType<?>) getRawAbstractTypeMethod.invoke(null, typeClass);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new ConfigurationException(
"ShadedTypeParser getAbstractType() failed for reflection; message=" + e.getMessage(), e);
}
return AbstractType.parseDefaultParameters(type, parser);
} catch (InvocationTargetException var8) {
ConfigurationException ex = new ConfigurationException("Invalid definition for comparator " + typeClass.getName() + ".");
ex.initCause(var8.getTargetException());
throw ex;
}
}
/*******************************************************************************************************************
* End methods copy-pasted from {@link TypeParser} and modified slightly to to work with shaded classes
******************************************************************************************************************/
}
| 7,809 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/ddl/KeyspaceDefinition.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.ddl;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
public interface KeyspaceDefinition {
KeyspaceDefinition setName(String name);
String getName();
KeyspaceDefinition setStrategyClass(String strategyClass);
String getStrategyClass();
KeyspaceDefinition setStrategyOptions(Map<String, String> options);
KeyspaceDefinition addStrategyOption(String name, String value);
Map<String, String> getStrategyOptions();
KeyspaceDefinition addColumnFamily(ColumnFamilyDefinition cfDef);
List<ColumnFamilyDefinition> getColumnFamilyList();
ColumnFamilyDefinition getColumnFamily(String columnFamily);
Collection<String> getFieldNames();
Object getFieldValue(String name);
KeyspaceDefinition setFieldValue(String name, Object value);
/**
* Get metadata for all fields
* @return
*/
Collection<FieldMetadata> getFieldsMetadata();
void setFields(Map<String, Object> options);
/**
* Return the entire keyspace defintion as a set of flattened properties
* @return
* @throws Exception
*/
Properties getProperties() throws Exception;
/**
* Populate the definition from a set of properties
* @param data
* @throws Exception
*/
void setProperties(Properties props) throws Exception;
}
| 7,810 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/ddl/SchemaChangeResult.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.ddl;
public interface SchemaChangeResult {
String getSchemaId();
}
| 7,811 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/ddl/ColumnFamilyDefinition.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.ddl;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* Wrapper for a column family definition. This provides additional utility methods on
* top of the existing thrift structure.
*
* @author elandau
*
*/
public interface ColumnFamilyDefinition {
public ColumnFamilyDefinition setComment(String comment);
public String getComment();
public ColumnFamilyDefinition setKeyspace(String keyspace);
public String getKeyspace();
@Deprecated
public ColumnFamilyDefinition setMemtableFlushAfterMins(Integer value);
@Deprecated
public Integer getMemtableFlushAfterMins();
@Deprecated
public ColumnFamilyDefinition setMemtableOperationsInMillions(Double value);
@Deprecated
public Double getMemtableOperationsInMillions();
@Deprecated
public ColumnFamilyDefinition setMemtableThroughputInMb(Integer value);
@Deprecated
public Integer getMemtableThroughputInMb();
public ColumnFamilyDefinition setMergeShardsChance(Double value);
public Double getMergeShardsChance();
public ColumnFamilyDefinition setMinCompactionThreshold(Integer value);
public Integer getMinCompactionThreshold();
public ColumnFamilyDefinition setMaxCompactionThreshold(Integer value);
public Integer getMaxCompactionThreshold();
public ColumnFamilyDefinition setCompactionStrategy(String strategy);
public String getCompactionStrategy();
public ColumnFamilyDefinition setCompactionStrategyOptions(Map<String, String> options);
public Map<String, String> getCompactionStrategyOptions();
public ColumnFamilyDefinition setCompressionOptions(Map<String, String> options);
public Map<String, String> getCompressionOptions();
ColumnFamilyDefinition setBloomFilterFpChance(Double chance);
Double getBloomFilterFpChance();
ColumnFamilyDefinition setCaching(String caching);
String getCaching();
ColumnFamilyDefinition setName(String name);
String getName();
ColumnFamilyDefinition setReadRepairChance(Double value);
Double getReadRepairChance();
ColumnFamilyDefinition setLocalReadRepairChance(Double value);
Double getLocalReadRepairChance();
ColumnFamilyDefinition setReplicateOnWrite(Boolean value);
Boolean getReplicateOnWrite();
ColumnFamilyDefinition setRowCacheProvider(String value);
String getRowCacheProvider();
ColumnFamilyDefinition setRowCacheSavePeriodInSeconds(Integer value);
Integer getRowCacheSavePeriodInSeconds();
ColumnFamilyDefinition setRowCacheSize(Double size);
Double getRowCacheSize();
ColumnFamilyDefinition setComparatorType(String value);
String getComparatorType();
ColumnFamilyDefinition setDefaultValidationClass(String value);
String getDefaultValidationClass();
ColumnFamilyDefinition setId(Integer id);
Integer getId();
ColumnFamilyDefinition setKeyAlias(ByteBuffer alias);
ByteBuffer getKeyAlias();
ColumnFamilyDefinition setKeyCacheSavePeriodInSeconds(Integer value);
Integer getKeyCacheSavePeriodInSeconds();
ColumnFamilyDefinition setKeyCacheSize(Double keyCacheSize);
Double getKeyCacheSize();
ColumnFamilyDefinition setKeyValidationClass(String keyValidationClass);
String getKeyValidationClass();
List<ColumnDefinition> getColumnDefinitionList();
ColumnFamilyDefinition addColumnDefinition(ColumnDefinition def);
ColumnDefinition makeColumnDefinition();
void clearColumnDefinitionList();
Collection<String> getFieldNames();
Object getFieldValue(String name);
ColumnFamilyDefinition setFieldValue(String name, Object value);
ColumnFamilyDefinition setGcGraceSeconds(Integer seconds);
Integer getGcGraceSeconds();
/**
* Get metadata for all fields
* @return
*/
Collection<FieldMetadata> getFieldsMetadata();
public void setFields(Map<String, Object> options);
/**
* Get the entire column family definition as a Properties object
* with maps and lists flattened into '.' delimited properties
* @return
*/
Properties getProperties() throws Exception;
/**
* Set the column family definition from a properties file
* @param properties
* @throws Exception
*/
void setProperties(Properties properties) throws Exception;
}
| 7,812 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/ddl/FieldMetadata.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.ddl;
/**
* Encapsulates field metadata
* @author elandau
*
*/
public class FieldMetadata {
private final String name;
private final String type;
private final boolean isContainer;
public FieldMetadata(String name, String type, boolean isContainer) {
super();
this.name = name;
this.type = type;
this.isContainer = isContainer;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public boolean isContainer() {
return this.isContainer;
}
}
| 7,813 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/ddl/ColumnDefinition.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.ddl;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Map;
/**
* Interface to get/set a single column definition. The column definition is
* only valid within the context of a ColumnFamilyDefinition
*
* @author elandau
*
*/
public interface ColumnDefinition {
/**
* Sets the column string name
*
* @param name
*/
ColumnDefinition setName(String name);
/**
* Sets the column byte array name
*
* @param name
*/
ColumnDefinition setName(byte[] name);
/**
* Sets the column byte buffer name
*
* @param name
*/
ColumnDefinition setName(ByteBuffer name);
/**
* Sets the validation class for the column values. See ComparatorType for
* possible values. Setting the validation class here makes it possible to
* have different values types per column within the same column family.
*
* @param value
*/
ColumnDefinition setValidationClass(String value);
/**
* Sets an index on this column.
*
* @param name Name of index - This name must be globally unique
* @param type "KEYS"
*/
ColumnDefinition setIndex(String name, String type);
/**
* Sets a keys index on this column
*
* @param name
*/
ColumnDefinition setKeysIndex(String name);
/**
* Enable a secondary KEY index
* @return
*/
ColumnDefinition setKeysIndex();
/**
* Enable a secondary index of custom type
* @param type
* @return
*/
ColumnDefinition setIndexWithType(String type);
/**
* Get the column name
*/
String getName();
/**
* Get the raw column name. In most cases the column name is a string but
* the actual column name is stored as a byte array
*/
ByteBuffer getRawName();
/**
* Return the value validation type. See ComparatorType for possible values.
*/
String getValidationClass();
/**
* Return the index name
*/
String getIndexName();
/**
* Return the index type. At the time of this writing only KEYS index is
* supported
*/
String getIndexType();
/**
* Returns true if there is an index on this column
*/
boolean hasIndex();
/**
* Get a map of all options associated with this column
*/
Map<String, String> getOptions();
/**
* Get an option
* @param name Option name (TODO: Document these)
* 'class_name' - com.datastax.bdp.cassandra.index.solr.SolrSecondaryIndex
* @param defaultValue Default value to return if option not found
*/
String getOption(String name, String defaultValue);
/**
* Set all extra options for this column. Will override any previous values.
* @param index_options
*/
ColumnDefinition setOptions(Map<String, String> index_options);
/**
* Set an option
* @param name
* @param value
* @return Previous value or null if not previously set
*/
String setOption(String name, String value);
/**
* Return list of valid field names
*/
Collection<String> getFieldNames();
/**
* Get metadata for all fields
*/
Collection<FieldMetadata> getFieldsMetadata();
/**
* Return a field value by name
* @param name
*/
Object getFieldValue(String name);
/**
* Set a field value by name
*
* @param name
* @param value
*/
ColumnDefinition setFieldValue(String name, Object value);
ColumnDefinition setFields(Map<String, Object> fields);
}
| 7,814 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/ddl | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/ddl/impl/SchemaChangeResponseImpl.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.ddl.impl;
import com.netflix.astyanax.ddl.SchemaChangeResult;
public class SchemaChangeResponseImpl implements SchemaChangeResult {
private String schemaId;
@Override
public String getSchemaId() {
return schemaId;
}
public SchemaChangeResponseImpl setSchemaId(String id) {
this.schemaId = id;
return this;
}
}
| 7,815 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/cql/CqlStatement.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.cql;
import com.netflix.astyanax.Execution;
import com.netflix.astyanax.model.ConsistencyLevel;
public interface CqlStatement extends Execution<CqlStatementResult> {
public CqlStatement withConsistencyLevel(ConsistencyLevel cl);
public CqlStatement withCql(String cql);
public CqlPreparedStatement asPreparedStatement();
}
| 7,816 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/cql/CqlSchema.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.cql;
public interface CqlSchema {
}
| 7,817 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/cql/CqlStatementResult.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.cql;
import com.netflix.astyanax.model.ColumnFamily;
import com.netflix.astyanax.model.Rows;
public interface CqlStatementResult {
long asCount();
<K, C> Rows<K, C> getRows(ColumnFamily<K, C> columnFamily);
CqlSchema getSchema();
}
| 7,818 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/cql/CqlPreparedStatement.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.cql;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.UUID;
import com.netflix.astyanax.Execution;
import com.netflix.astyanax.Serializer;
public interface CqlPreparedStatement extends Execution<CqlStatementResult> {
/**
* Specify a value of custom type for which a convenience method does not exist
* @param value
* @param serializer
* @return
*/
<V> CqlPreparedStatement withByteBufferValue(V value, Serializer<V> serializer);
/**
* Set the next parameter value to this ByteBuffer
* @param value
* @return
*/
CqlPreparedStatement withValue(ByteBuffer value);
/**
* Add a list of ByteBuffer values
* @param value
* @return
*/
CqlPreparedStatement withValues(List<ByteBuffer> value);
/**
* Set the next parameter value to this String
* @param value
* @return
*/
CqlPreparedStatement withStringValue(String value);
/**
* Set the next parameter value to this Integer
* @param value
* @return
*/
CqlPreparedStatement withIntegerValue(Integer value);
/**
* Set the next parameter value to this Boolean
* @param value
* @return
*/
CqlPreparedStatement withBooleanValue(Boolean value);
/**
* Set the next parameter value to this Double
* @param value
* @return
*/
CqlPreparedStatement withDoubleValue(Double value);
/**
* Set the next parameter value to this Long
* @param value
* @return
*/
CqlPreparedStatement withLongValue(Long value);
/**
* Set the next parameter value to this Float
* @param value
* @return
*/
CqlPreparedStatement withFloatValue(Float value);
/**
* Set the next parameter value to this Short
* @param value
* @return
*/
CqlPreparedStatement withShortValue(Short value);
/**
* Set the next parameter value to this UUID
* @param value
* @return
*/
CqlPreparedStatement withUUIDValue(UUID value);
}
| 7,819 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/shallows/EmptyKeyspaceTracer.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.shallows;
import com.netflix.astyanax.CassandraOperationTracer;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
public class EmptyKeyspaceTracer implements CassandraOperationTracer {
private static EmptyKeyspaceTracer instance = new EmptyKeyspaceTracer();
public static EmptyKeyspaceTracer getInstance() {
return instance;
}
private EmptyKeyspaceTracer() {
}
@Override
public CassandraOperationTracer start() {
return this;
}
@Override
public void success() {
}
@Override
public void failure(ConnectionException e) {
}
}
| 7,820 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/shallows/EmptyColumnList.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.shallows;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.model.AbstractColumnList;
import com.netflix.astyanax.model.Column;
public class EmptyColumnList<C> extends AbstractColumnList<C> {
@SuppressWarnings("unchecked")
@Override
public Iterator<Column<C>> iterator() {
return new EmptyIterator();
}
@Override
public Column<C> getColumnByName(C columnName) {
return null;
}
@Override
public Column<C> getColumnByIndex(int idx) {
return null;
}
@Override
public <C2> Column<C2> getSuperColumn(C columnName, Serializer<C2> colSer) {
return null;
}
@Override
public <C2> Column<C2> getSuperColumn(int idx, Serializer<C2> colSer) {
return null;
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public int size() {
return 0;
}
@Override
public boolean isSuperColumn() {
return false;
}
@Override
public Collection<C> getColumnNames() {
return new HashSet<C>();
}
}
| 7,821 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/shallows/EmptyKeyspaceTracerFactory.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.shallows;
import com.netflix.astyanax.CassandraOperationTracer;
import com.netflix.astyanax.CassandraOperationType;
import com.netflix.astyanax.KeyspaceTracerFactory;
import com.netflix.astyanax.model.ColumnFamily;
public class EmptyKeyspaceTracerFactory implements KeyspaceTracerFactory {
public static final EmptyKeyspaceTracerFactory instance = new EmptyKeyspaceTracerFactory();
public static EmptyKeyspaceTracerFactory getInstance() {
return instance;
}
private EmptyKeyspaceTracerFactory() {
}
@Override
public CassandraOperationTracer newTracer(CassandraOperationType type) {
return EmptyKeyspaceTracer.getInstance();
}
@Override
public CassandraOperationTracer newTracer(CassandraOperationType type, ColumnFamily<?, ?> columnFamily) {
return EmptyKeyspaceTracer.getInstance();
}
public String toString() {
return "EmptyKeyspaceTracerFactory";
}
}
| 7,822 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/shallows/EmptyColumn.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.shallows;
import java.nio.ByteBuffer;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.model.AbstractColumnImpl;
import com.netflix.astyanax.model.ColumnList;
public class EmptyColumn<C> extends AbstractColumnImpl<C> {
public EmptyColumn() {
super(null);
}
@Override
public <V> V getValue(Serializer<V> valSer) {
throw new UnsupportedOperationException();
}
@Override
public <C2> ColumnList<C2> getSubColumns(Serializer<C2> ser) {
throw new UnsupportedOperationException();
}
@Override
public boolean isParentColumn() {
return false;
}
@Override
public long getTimestamp() {
throw new UnsupportedOperationException();
}
@Override
public ByteBuffer getRawName() {
throw new UnsupportedOperationException();
}
@Override
public int getTtl() {
throw new UnsupportedOperationException();
}
@Override
public boolean hasValue() {
return false;
}
}
| 7,823 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/shallows/EmptyCheckpointManager.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.shallows;
import java.util.SortedMap;
import java.util.concurrent.ConcurrentMap;
import com.google.common.collect.Maps;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.query.CheckpointManager;
public class EmptyCheckpointManager implements CheckpointManager {
private ConcurrentMap<String, String> tokenMap = Maps.newConcurrentMap();
/**
* Do nothing since checkpoints aren't being persisted.
*/
@Override
public void trackCheckpoint(String startToken, String checkpointToken) {
tokenMap.put(startToken, checkpointToken);
}
/**
* Since no checkpoint management is done here simply use the startToken as the
* start checkpoint for the range
*/
@Override
public String getCheckpoint(String startToken) {
return tokenMap.get(startToken);
}
@Override
public SortedMap<String, String> getCheckpoints() throws ConnectionException {
return Maps.newTreeMap();
}
}
| 7,824 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/shallows/EmptyRowsImpl.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.shallows;
import java.util.Collection;
import java.util.Iterator;
import com.netflix.astyanax.model.Row;
import com.netflix.astyanax.model.Rows;
public class EmptyRowsImpl<K, C> implements Rows<K, C> {
@SuppressWarnings("unchecked")
@Override
public Iterator<Row<K, C>> iterator() {
return new EmptyIterator();
}
@Override
public Row<K, C> getRow(K key) {
return null;
}
@Override
public int size() {
return 0;
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public Row<K, C> getRowByIndex(int i) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<K> getKeys() {
// TODO Auto-generated method stub
return null;
}
}
| 7,825 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/ListSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.List;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.AbstractType;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.ListType;
/**
* Serializer implementation for generic lists.
*
* @author vermes
*
* @param <T>
* element type
*/
public class ListSerializer<T> extends AbstractSerializer<List<T>> {
private final ListType<T> myList;
/**
* @param elements
*/
public ListSerializer(AbstractType<T> elements) {
myList = ListType.getInstance(elements);
}
@Override
public List<T> fromByteBuffer(ByteBuffer arg0) {
if (arg0 == null) return null;
ByteBuffer dup = arg0.duplicate();
return myList.compose(dup);
}
@Override
public ByteBuffer toByteBuffer(List<T> arg0) {
return arg0 == null ? null : myList.decompose(arg0);
}
} | 7,826 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/ByteBufferOutputStream.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.List;
/**
* Utility to collect data written to an {@link OutputStream} in
* {@link ByteBuffer}s.
*
* Originally from org.apache.avro.util.ByteBufferOutputStream, moved into
* Hector and added getByteBuffer to return single ByteBuffer from contents.
*/
public class ByteBufferOutputStream extends OutputStream {
public static final int INIT_BUFFER_SIZE = 64;
public static final int MAX_BUFFER_SIZE = 8192;
private List<ByteBuffer> buffers;
private int bufferSize = INIT_BUFFER_SIZE;
public ByteBufferOutputStream() {
reset();
}
/** Returns all data written and resets the stream to be empty. */
public List<ByteBuffer> getBufferList() {
List<ByteBuffer> result = buffers;
reset();
for (ByteBuffer buffer : result) {
buffer.flip();
}
return result;
}
public ByteBuffer getByteBuffer() {
List<ByteBuffer> list = getBufferList();
// if there's just one bytebuffer in list, return it
if (list.size() == 1) {
return list.get(0);
}
int size = 0;
for (ByteBuffer buffer : list) {
size += buffer.remaining();
}
ByteBuffer result = ByteBuffer.allocate(size);
for (ByteBuffer buffer : list) {
result.put(buffer);
}
return (ByteBuffer) result.rewind();
}
/** Prepend a list of ByteBuffers to this stream. */
public void prepend(List<ByteBuffer> lists) {
for (ByteBuffer buffer : lists) {
buffer.position(buffer.limit());
}
buffers.addAll(0, lists);
}
/** Append a list of ByteBuffers to this stream. */
public void append(List<ByteBuffer> lists) {
for (ByteBuffer buffer : lists) {
buffer.position(buffer.limit());
}
buffers.addAll(lists);
}
public void reset() {
buffers = new LinkedList<ByteBuffer>();
bufferSize = INIT_BUFFER_SIZE;
buffers.add(ByteBuffer.allocate(bufferSize));
}
private ByteBuffer getBufferWithCapacity(int capacity) {
ByteBuffer buffer = buffers.get(buffers.size() - 1);
if (buffer.remaining() < capacity) {
buffer = ByteBuffer.allocate(bufferSize);
buffers.add(buffer);
}
return buffer;
}
@Override
public void write(int b) {
ByteBuffer buffer = getBufferWithCapacity(1);
buffer.put((byte) b);
}
public void writeShort(short value) {
ByteBuffer buffer = getBufferWithCapacity(2);
buffer.putShort(value);
}
public void writeChar(char value) {
ByteBuffer buffer = getBufferWithCapacity(2);
buffer.putChar(value);
}
public void writeInt(int value) {
ByteBuffer buffer = getBufferWithCapacity(4);
buffer.putInt(value);
}
public void writeFloat(float value) {
ByteBuffer buffer = getBufferWithCapacity(4);
buffer.putFloat(value);
}
public void writeLong(long value) {
ByteBuffer buffer = getBufferWithCapacity(8);
buffer.putLong(value);
}
public void writeDouble(double value) {
ByteBuffer buffer = getBufferWithCapacity(8);
buffer.putDouble(value);
}
@Override
public void write(byte[] b, int off, int len) {
ByteBuffer buffer = buffers.get(buffers.size() - 1);
int remaining = buffer.remaining();
while (len > remaining) {
buffer.put(b, off, remaining);
len -= remaining;
off += remaining;
bufferSize *= 2;
if (bufferSize > MAX_BUFFER_SIZE)
bufferSize = MAX_BUFFER_SIZE;
buffer = ByteBuffer.allocate(bufferSize);
buffers.add(buffer);
remaining = buffer.remaining();
}
buffer.put(b, off, len);
}
/** Add a buffer to the output without copying, if possible. */
public void write(ByteBuffer buffer) {
if (buffer.remaining() < bufferSize) {
write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
}
else { // append w/o copying bytes
ByteBuffer dup = buffer.duplicate();
dup.position(buffer.limit()); // ready for flip
buffers.add(dup);
}
}
}
| 7,827 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/SpecificCompositeSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.AbstractType;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.CompositeType;
import com.google.common.base.Preconditions;
public class SpecificCompositeSerializer extends CompositeSerializer {
private final CompositeType type;
private List<String> comparators;
public SpecificCompositeSerializer(CompositeType type) {
Preconditions.checkNotNull(type);
this.type = type;
comparators = new ArrayList<String>( type.types.size() );
for ( AbstractType<?> compType : type.types ) {
String typeName = compType.toString();
comparators.add( ComparatorType.getShadedTypeName(typeName) );
}
}
@Override
public ByteBuffer fromString(String string) {
return type.fromString(string);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return type.getString(byteBuffer);
}
@Override
public List<String> getComparators() {
return comparators;
}
}
| 7,828 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/BooleanSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.BooleanType;
/**
* Converts bytes to Boolean and vice versa
*
* @author Bozhidar Bozhanov
*
*/
public final class BooleanSerializer extends AbstractSerializer<Boolean> {
private static final BooleanSerializer instance = new BooleanSerializer();
public static BooleanSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Boolean obj) {
if (obj == null) {
return null;
}
boolean bool = obj;
byte[] b = new byte[1];
b[0] = bool ? (byte) 1 : (byte) 0;
return ByteBuffer.wrap(b);
}
@Override
public Boolean fromByteBuffer(ByteBuffer bytes) {
if ((bytes == null) || (bytes.remaining() < 1)) {
return null;
}
ByteBuffer dup = bytes.duplicate();
byte b = dup.get();
return b == (byte) 1;
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
throw new IllegalStateException("Boolean columns can't be paginated");
}
@Override
public ByteBuffer fromString(String str) {
return BooleanType.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return fromByteBuffer(byteBuffer).toString();
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.BOOLEANTYPE;
}
}
| 7,829 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/BytesArraySerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.BytesType;
import com.netflix.astyanax.Serializer;
/**
* A BytesArraySerializer translates the byte[] to and from ByteBuffer.
*
* @author Patricio Echague
*
*/
public final class BytesArraySerializer extends AbstractSerializer<byte[]> implements Serializer<byte[]> {
private static final BytesArraySerializer instance = new BytesArraySerializer();
public static BytesArraySerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(byte[] obj) {
if (obj == null) {
return null;
}
return ByteBuffer.wrap(obj);
}
@Override
public byte[] fromByteBuffer(ByteBuffer byteBuffer) {
if (byteBuffer == null) {
return null;
}
ByteBuffer dup = byteBuffer.duplicate();
byte[] bytes = new byte[dup.remaining()];
byteBuffer.get(bytes, 0, bytes.length);
return bytes;
}
@Override
public ByteBuffer fromString(String str) {
return BytesType.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
if (byteBuffer == null) return null;
return BytesType.instance.getString(byteBuffer.duplicate());
}
}
| 7,830 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/SnappyStringSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.UTF8Type;
import org.apache.commons.codec.binary.StringUtils;
import org.xerial.snappy.SnappyInputStream;
import org.xerial.snappy.SnappyOutputStream;
public class SnappyStringSerializer extends AbstractSerializer<String> {
private static final SnappyStringSerializer instance = new SnappyStringSerializer();
public static SnappyStringSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(String obj) {
if (obj == null) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
SnappyOutputStream snappy;
try {
snappy = new SnappyOutputStream(out);
snappy.write(StringUtils.getBytesUtf8(obj));
snappy.close();
return ByteBuffer.wrap(out.toByteArray());
} catch (IOException e) {
throw new RuntimeException("Error compressing column data", e);
}
}
@Override
public String fromByteBuffer(ByteBuffer byteBuffer) {
if (byteBuffer == null) {
return null;
}
SnappyInputStream snappy = null;
ByteArrayOutputStream baos = null;
try {
ByteBuffer dup = byteBuffer.duplicate();
snappy = new SnappyInputStream(
new ByteArrayInputStream(dup.array(), 0,
dup.limit()));
baos = new ByteArrayOutputStream();
for (int value = 0; value != -1;) {
value = snappy.read();
if (value != -1) {
baos.write(value);
}
}
snappy.close();
baos.close();
return StringUtils.newStringUtf8(baos.toByteArray());
} catch (IOException e) {
throw new RuntimeException("Error decompressing column data", e);
} finally {
if (snappy != null) {
try {
snappy.close();
} catch (IOException e) {
}
}
if (baos != null) {
try {
baos.close();
} catch (IOException e) {
}
}
}
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.BYTESTYPE;
}
@Override
public ByteBuffer fromString(String str) {
return UTF8Type.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return UTF8Type.instance.getString(byteBuffer);
}
}
| 7,831 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/UUIDSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.UUID;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.UUIDType;
/**
* A UUIDSerializer translates the byte[] to and from UUID types.
*
* @author Ed Anuff
*
*/
public class UUIDSerializer extends AbstractSerializer<UUID> {
private static final UUIDSerializer instance = new UUIDSerializer();
public static UUIDSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(UUID uuid) {
if (uuid == null) {
return null;
}
long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();
byte[] buffer = new byte[16];
for (int i = 0; i < 8; i++) {
buffer[i] = (byte) (msb >>> 8 * (7 - i));
}
for (int i = 8; i < 16; i++) {
buffer[i] = (byte) (lsb >>> 8 * (7 - i));
}
return ByteBuffer.wrap(buffer);
}
@Override
public UUID fromByteBuffer(ByteBuffer bytes) {
if (bytes == null) {
return null;
}
ByteBuffer dup = bytes.duplicate();
return new UUID(dup.getLong(), dup.getLong());
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.UUIDTYPE;
}
@Override
public ByteBuffer fromString(String str) {
return UUIDType.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return UUIDType.instance.getString(byteBuffer);
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
throw new RuntimeException("UUIDSerializer.getNext() Not implemented.");
}
}
| 7,832 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/ByteSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.IntegerType;
public class ByteSerializer extends AbstractSerializer<Byte> {
private static final ByteSerializer instance = new ByteSerializer();
public static ByteSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Byte obj) {
if (obj == null) {
return null;
}
ByteBuffer b = ByteBuffer.allocate(1);
b.put(obj);
b.rewind();
return b;
}
@Override
public Byte fromByteBuffer(ByteBuffer byteBuffer) {
if (byteBuffer == null) {
return null;
}
ByteBuffer dup = byteBuffer.duplicate();
byte in = dup.get();
return in;
}
@Override
public ByteBuffer fromString(String str) {
// Verify value is a short
return toByteBuffer(Byte.parseByte(str));
}
@Override
public String getString(ByteBuffer byteBuffer) {
return IntegerType.instance.getString(byteBuffer);
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
Byte val = fromByteBuffer(byteBuffer.duplicate());
if (val == Byte.MAX_VALUE) {
throw new ArithmeticException("Can't paginate past max byte");
}
val++;
return toByteBuffer(val);
}
}
| 7,833 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/PrefixedSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.connectionpool.exceptions.SerializationException;
public class PrefixedSerializer<P, S> extends AbstractSerializer<S> {
private static Logger log = LoggerFactory.getLogger(PrefixedSerializer.class);
P prefix;
Serializer<P> prefixSerializer;
ByteBuffer prefixBytes;
Serializer<S> suffixSerializer;
public PrefixedSerializer(P prefix, Serializer<P> prefixSerializer, Serializer<S> suffixSerializer) {
this.prefix = prefix;
this.prefixSerializer = prefixSerializer;
this.suffixSerializer = suffixSerializer;
prefixBytes = prefixSerializer.toByteBuffer(prefix);
prefixBytes.rewind();
}
@Override
public ByteBuffer toByteBuffer(S s) {
if (s == null) {
return null;
}
ByteBuffer sb = suffixSerializer.toByteBuffer(s);
sb.rewind();
ByteBuffer bb = ByteBuffer.allocate(prefixBytes.remaining() + sb.remaining());
bb.put(prefixBytes.slice());
bb.put(sb);
bb.rewind();
return bb;
}
@Override
public S fromByteBuffer(ByteBuffer bytes) throws SerializationException {
if ((bytes == null) || !bytes.hasArray()) {
return null;
}
ByteBuffer dup = bytes.duplicate();
if (compareByteArrays(prefixBytes.array(),
prefixBytes.arrayOffset() + prefixBytes.position(),
prefixBytes.remaining(), dup.array(), dup.arrayOffset()
+ dup.position(), prefixBytes.remaining()) != 0) {
log.error("Unprefixed value received, throwing exception...");
throw new SerializationException("Unexpected prefix value");
}
dup.position(prefixBytes.remaining());
S s = suffixSerializer.fromByteBuffer(dup);
return s;
}
@Override
public List<S> fromBytesList(List<ByteBuffer> list) {
List<S> objList = new ArrayList<S>(list.size());
for (ByteBuffer s : list) {
try {
ByteBuffer bb = s.slice();
objList.add(fromByteBuffer(bb));
}
catch (SerializationException e) {
// not a prefixed key, discard
log.warn("Unprefixed value received, discarding...");
}
}
return objList;
}
@Override
public <V> Map<S, V> fromBytesMap(Map<ByteBuffer, V> map) {
Map<S, V> objMap = new LinkedHashMap<S, V>(computeInitialHashSize(map.size()));
for (Entry<ByteBuffer, V> entry : map.entrySet()) {
try {
ByteBuffer bb = entry.getKey().slice();
objMap.put(fromByteBuffer(bb), entry.getValue());
}
catch (SerializationException e) {
// not a prefixed key, discard
log.warn("Unprefixed value received, discarding...");
}
}
return objMap;
}
private static int compareByteArrays(byte[] bytes1, int offset1, int len1, byte[] bytes2, int offset2, int len2) {
if (null == bytes1) {
if (null == bytes2) {
return 0;
}
else {
return -1;
}
}
if (null == bytes2) {
return 1;
}
if (len1 < 0) {
len1 = bytes1.length - offset1;
}
if (len2 < 0) {
len2 = bytes2.length - offset2;
}
int minLength = Math.min(len1, len2);
for (int i = 0; i < minLength; i++) {
int i1 = offset1 + i;
int i2 = offset2 + i;
if (bytes1[i1] == bytes2[i2]) {
continue;
}
// compare non-equal bytes as unsigned
return (bytes1[i1] & 0xFF) < (bytes2[i2] & 0xFF) ? -1 : 1;
}
if (len1 == len2) {
return 0;
}
else {
return (len1 < len2) ? -1 : 1;
}
}
}
| 7,834 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/DynamicCompositeSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import com.netflix.astyanax.model.DynamicComposite;
/**
* @author Todd Nine
*
*/
public class DynamicCompositeSerializer extends
AbstractSerializer<DynamicComposite> {
private static final DynamicCompositeSerializer instance = new DynamicCompositeSerializer();
public static DynamicCompositeSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(DynamicComposite obj) {
return obj.serialize();
}
@Override
public DynamicComposite fromByteBuffer(ByteBuffer byteBuffer) {
if (byteBuffer == null)
return null;
ByteBuffer dup = byteBuffer.duplicate();
DynamicComposite composite = new DynamicComposite();
composite.deserialize(dup);
return composite;
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.DYNAMICCOMPOSITETYPE;
}
@Override
public ByteBuffer fromString(String string) {
throw new UnsupportedOperationException();
}
@Override
public String getString(ByteBuffer byteBuffer) {
throw new UnsupportedOperationException();
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
throw new IllegalStateException(
"DynamicComposite columns can't be paginated this way.");
}
}
| 7,835 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/CompositeRangeBuilder.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import com.netflix.astyanax.model.ByteBufferRange;
import com.netflix.astyanax.model.Equality;
public abstract class CompositeRangeBuilder implements ByteBufferRange {
private ByteBufferOutputStream start = new ByteBufferOutputStream();
private ByteBufferOutputStream end = new ByteBufferOutputStream();
private int limit = Integer.MAX_VALUE;
private boolean reversed = false;
private boolean lockComponent = false;
private List<RangeQueryRecord> records = new ArrayList<RangeQueryRecord>();
protected void nextComponent() {
getNextComponent();
// flip to a new record, which is for a new component
records.add(new RangeQueryRecord());
}
abstract protected void getNextComponent();
abstract protected void append(ByteBufferOutputStream out, Object value, Equality equality);
public CompositeRangeBuilder withPrefix(Object object) {
if (lockComponent) {
throw new IllegalStateException("Prefix cannot be added once equality has been specified");
}
append(start, object, Equality.EQUAL);
append(end, object, Equality.EQUAL);
getLastRecord().addQueryOp(object, Equality.EQUAL);
nextComponent();
return this;
}
public CompositeRangeBuilder limit(int count) {
this.limit = count;
return this;
}
public CompositeRangeBuilder reverse() {
reversed = true;
ByteBufferOutputStream temp = start;
start = end;
end = temp;
return this;
}
public CompositeRangeBuilder greaterThan(Object value) {
lockComponent = true;
append(start, value, Equality.GREATER_THAN);
getLastRecord().addQueryOp(value, Equality.GREATER_THAN);
return this;
}
public CompositeRangeBuilder greaterThanEquals(Object value) {
lockComponent = true;
append(start, value, Equality.GREATER_THAN_EQUALS);
getLastRecord().addQueryOp(value, Equality.GREATER_THAN_EQUALS);
return this;
}
public CompositeRangeBuilder lessThan(Object value) {
lockComponent = true;
append(end, value, Equality.LESS_THAN);
getLastRecord().addQueryOp(value, Equality.LESS_THAN);
return this;
}
public CompositeRangeBuilder lessThanEquals(Object value) {
lockComponent = true;
append(end, value, Equality.LESS_THAN_EQUALS);
getLastRecord().addQueryOp(value, Equality.LESS_THAN_EQUALS);
return this;
}
private RangeQueryRecord getLastRecord() {
if (records.size() == 0) {
RangeQueryRecord record = new RangeQueryRecord();
records.add(record);
}
return records.get(records.size()-1);
}
@Override
@Deprecated
public ByteBuffer getStart() {
return start.getByteBuffer();
}
@Override
@Deprecated
public ByteBuffer getEnd() {
return end.getByteBuffer();
}
@Override
@Deprecated
public boolean isReversed() {
return reversed;
}
@Override
@Deprecated
public int getLimit() {
return limit;
}
public CompositeByteBufferRange build() {
return new CompositeByteBufferRange(start, end, limit, reversed, records);
}
public static class RangeQueryRecord {
private List<RangeQueryOp> ops = new ArrayList<RangeQueryOp>();
public RangeQueryRecord() {
}
public void addQueryOp(Object value, Equality operator) {
add(new RangeQueryOp(value, operator));
}
public void add(RangeQueryOp rangeOp) {
ops.add(rangeOp);
}
public List<RangeQueryOp> getOps() {
return ops;
}
}
public static class RangeQueryOp {
private final Object value;
private final Equality operator;
public RangeQueryOp(Object value, Equality operator) {
this.value = value;
this.operator = operator;
}
public Object getValue() {
return value;
}
public Equality getOperator() {
return operator;
}
}
public static class CompositeByteBufferRange implements ByteBufferRange {
private final ByteBufferOutputStream start;
private final ByteBufferOutputStream end;
private int limit;
private boolean reversed;
private final List<RangeQueryRecord> records;
private CompositeByteBufferRange(ByteBufferOutputStream rangeStart, ByteBufferOutputStream rangeEnd,
int rangeLimit, boolean rangeReversed,
List<RangeQueryRecord> rangeRecords) {
this.start = rangeStart;
this.end = rangeEnd;
this.limit = rangeLimit;
this.reversed = rangeReversed;
this.records = rangeRecords;
}
public CompositeByteBufferRange(int rangeLimit, boolean rangeReversed, List<RangeQueryRecord> rangeRecords) {
// This is only meant to be called by internally
this.start = null;
this.end = null;
this.limit = rangeLimit;
this.reversed = rangeReversed;
this.records = rangeRecords;
}
@Override
public ByteBuffer getStart() {
return start.getByteBuffer();
}
@Override
public ByteBuffer getEnd() {
return end.getByteBuffer();
}
@Override
public boolean isReversed() {
return reversed;
}
@Override
public int getLimit() {
return limit;
}
public List<RangeQueryRecord> getRecords() {
return records;
}
}
}
| 7,836 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/ByteBufferSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.BytesType;
/**
* The BytesExtractor is a simple identity function. It supports the Extractor
* interface and implements the fromBytes and toBytes as simple identity
* functions. However, the from and to methods both return the results of
* {@link ByteBuffer#duplicate()}
*
*
* @author Ran Tavory
* @author zznate
*/
public final class ByteBufferSerializer extends AbstractSerializer<ByteBuffer> {
private static ByteBufferSerializer instance = new ByteBufferSerializer();
public static ByteBufferSerializer get() {
return instance;
}
@Override
public ByteBuffer fromByteBuffer(ByteBuffer bytes) {
if (bytes == null) {
return null;
}
return bytes.duplicate();
}
@Override
public ByteBuffer toByteBuffer(ByteBuffer obj) {
if (obj == null) {
return null;
}
return obj.duplicate();
}
@Override
public List<ByteBuffer> toBytesList(List<ByteBuffer> list) {
return list;
}
@Override
public List<ByteBuffer> fromBytesList(List<ByteBuffer> list) {
return list;
}
@Override
public <V> Map<ByteBuffer, V> toBytesMap(Map<ByteBuffer, V> map) {
return map;
}
@Override
public <V> Map<ByteBuffer, V> fromBytesMap(Map<ByteBuffer, V> map) {
return map;
}
@Override
public ByteBuffer fromString(String str) {
return BytesType.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return BytesType.instance.getString(byteBuffer);
}
}
| 7,837 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/FloatSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.FloatType;
/**
* Uses IntSerializer via translating Float objects to and from raw long bytes
* form.
*
* @author Todd Nine
*/
public class FloatSerializer extends AbstractSerializer<Float> {
private static final FloatSerializer instance = new FloatSerializer();
public static FloatSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Float obj) {
return IntegerSerializer.get().toByteBuffer(
Float.floatToRawIntBits(obj));
}
@Override
public Float fromByteBuffer(ByteBuffer bytes) {
if (bytes == null)
return null;
ByteBuffer dup = bytes.duplicate();
return Float
.intBitsToFloat(IntegerSerializer.get().fromByteBuffer(dup));
}
@Override
public ByteBuffer fromString(String str) {
return FloatType.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return FloatType.instance.getString(byteBuffer);
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
float val = fromByteBuffer(byteBuffer.duplicate());
if (val == Float.MAX_VALUE) {
throw new ArithmeticException("Can't paginate past max float");
}
return toByteBuffer(val + Float.MIN_VALUE);
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.FLOATTYPE;
}
}
| 7,838 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/AbstractSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.netflix.astyanax.Serializer;
/**
* A base class for serializer implementations. Takes care of the default
* implementations of to/fromBytesList and to/fromBytesMap. Extenders of this
* class only need to implement toByteBuffer and fromByteBuffer.
*
* @author Ed Anuff
*
* @param <T>
*/
public abstract class AbstractSerializer<T> implements Serializer<T> {
@Override
public abstract ByteBuffer toByteBuffer(T obj);
@Override
public byte[] toBytes(T obj) {
ByteBuffer bb = toByteBuffer(obj);
byte[] bytes = new byte[bb.remaining()];
bb.get(bytes, 0, bytes.length);
return bytes;
}
@Override
public T fromBytes(byte[] bytes) {
return fromByteBuffer(ByteBuffer.wrap(bytes));
}
/*
* public ByteBuffer toByteBuffer(T obj) { return
* ByteBuffer.wrap(toBytes(obj)); }
*
* public ByteBuffer toByteBuffer(T obj, ByteBuffer byteBuffer, int offset,
* int length) { byteBuffer.put(toBytes(obj), offset, length); return
* byteBuffer; }
*/
@Override
public abstract T fromByteBuffer(ByteBuffer byteBuffer);
/*
* public T fromByteBuffer(ByteBuffer byteBuffer) { return
* fromBytes(byteBuffer.array()); }
*
* public T fromByteBuffer(ByteBuffer byteBuffer, int offset, int length) {
* return fromBytes(Arrays.copyOfRange(byteBuffer.array(), offset, length));
* }
*/
public Set<ByteBuffer> toBytesSet(List<T> list) {
Set<ByteBuffer> bytesList = new HashSet<ByteBuffer>(computeInitialHashSize(list.size()));
for (T s : list) {
bytesList.add(toByteBuffer(s));
}
return bytesList;
}
public List<T> fromBytesSet(Set<ByteBuffer> set) {
List<T> objList = new ArrayList<T>(set.size());
for (ByteBuffer b : set) {
objList.add(fromByteBuffer(b));
}
return objList;
}
public List<ByteBuffer> toBytesList(List<T> list) {
return Lists.transform(list, new Function<T, ByteBuffer>() {
@Override
public ByteBuffer apply(T s) {
return toByteBuffer(s);
}
});
}
public List<ByteBuffer> toBytesList(Collection<T> list) {
List<ByteBuffer> bytesList = new ArrayList<ByteBuffer>(list.size());
for (T s : list) {
bytesList.add(toByteBuffer(s));
}
return bytesList;
}
public List<ByteBuffer> toBytesList(Iterable<T> list) {
return Lists.newArrayList(Iterables.transform(list, new Function<T, ByteBuffer>() {
@Override
public ByteBuffer apply(T s) {
return toByteBuffer(s);
}
}));
}
public List<T> fromBytesList(List<ByteBuffer> list) {
List<T> objList = new ArrayList<T>(list.size());
for (ByteBuffer s : list) {
objList.add(fromByteBuffer(s));
}
return objList;
}
public <V> Map<ByteBuffer, V> toBytesMap(Map<T, V> map) {
Map<ByteBuffer, V> bytesMap = new LinkedHashMap<ByteBuffer, V>(computeInitialHashSize(map.size()));
for (Entry<T, V> entry : map.entrySet()) {
bytesMap.put(toByteBuffer(entry.getKey()), entry.getValue());
}
return bytesMap;
}
public <V> Map<T, V> fromBytesMap(Map<ByteBuffer, V> map) {
Map<T, V> objMap = new LinkedHashMap<T, V>(computeInitialHashSize(map.size()));
for (Entry<ByteBuffer, V> entry : map.entrySet()) {
objMap.put(fromByteBuffer(entry.getKey()), entry.getValue());
}
return objMap;
}
public int computeInitialHashSize(int initialSize) {
return Double.valueOf(Math.floor(initialSize / 0.75)).intValue() + 1;
}
public ComparatorType getComparatorType() {
return ComparatorType.BYTESTYPE;
}
@Override
public ByteBuffer fromString(String string) {
throw new UnsupportedOperationException(this.getClass().getCanonicalName());
}
@Override
public String getString(ByteBuffer byteBuffer) {
throw new UnsupportedOperationException(this.getClass().getCanonicalName());
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
ByteBufferOutputStream next = new ByteBufferOutputStream();
try {
next.write(byteBuffer);
next.write((byte) 0);
return next.getByteBuffer();
}
finally {
try {
next.close();
}
catch (Throwable t) {
}
}
}
}
| 7,839 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/LongSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.LongType;
/**
* Converts bytes to Long and vise a versa
*
* @author Ran Tavory
*
*/
public final class LongSerializer extends AbstractSerializer<Long> {
private static final LongSerializer instance = new LongSerializer();
public static LongSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Long obj) {
if (obj == null) {
return null;
}
return ByteBuffer.allocate(8).putLong(0, obj);
}
@Override
public Long fromByteBuffer(ByteBuffer byteBuffer) {
if (byteBuffer == null)
return null;
ByteBuffer dup = byteBuffer.duplicate();
if (dup.remaining() == 8) {
long l = dup.getLong();
return l;
} else if (dup.remaining() == 4) {
return (long) dup.getInt();
}
return null;
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.LONGTYPE;
}
@Override
public ByteBuffer fromString(String str) {
return LongType.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return LongType.instance.getString(byteBuffer);
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
Long val = fromByteBuffer(byteBuffer.duplicate());
if (val == Long.MAX_VALUE) {
throw new ArithmeticException("Can't paginate past max long");
}
return toByteBuffer(val + 1);
}
}
| 7,840 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/TimeUUIDSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.TimeUUIDType;
import com.netflix.astyanax.util.TimeUUIDUtils;
public class TimeUUIDSerializer extends UUIDSerializer {
private static final TimeUUIDSerializer instance = new TimeUUIDSerializer();
public static TimeUUIDSerializer get() {
return instance;
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.TIMEUUIDTYPE;
}
@Override
public ByteBuffer fromString(String str) {
return TimeUUIDType.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
if (byteBuffer == null) return null;
ByteBuffer dup = byteBuffer.duplicate();
long micros = TimeUUIDUtils.getMicrosTimeFromUUID(this.fromByteBuffer(dup));
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date(micros / 1000));
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
UUID uuid = fromByteBuffer(byteBuffer.duplicate());
return toByteBuffer(new java.util.UUID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits() + 1));
}
}
| 7,841 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/MapSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.AbstractType;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.MapType;
import java.nio.ByteBuffer;
import java.util.Map;
/**
* Serializer implementation for generic maps.
*
* @author vermes
*
* @param <K>
* key type
* @param <V>
* value type
*/
public class MapSerializer<K, V> extends AbstractSerializer<Map<K, V>> {
private final MapType<K, V> myMap;
/**
* @param key
* @param value
*/
public MapSerializer(AbstractType<K> key, AbstractType<V> value) {
myMap = MapType.getInstance(key, value);
}
@Override
public Map<K, V> fromByteBuffer(ByteBuffer arg0) {
if (arg0 == null) return null;
ByteBuffer dup = arg0.duplicate();
return myMap.compose(dup);
}
@Override
public ByteBuffer toByteBuffer(Map<K, V> arg0) {
return arg0 == null ? null : myMap.decompose(arg0);
}
} | 7,842 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/AnnotatedCompositeSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.annotations.Component;
import com.netflix.astyanax.model.Equality;
import com.netflix.astyanax.model.RangeEndpoint;
/**
* Serializer for a Pojo annotated with Component field annotations
*
* Serialized data is formatted as a list of components with each component
* having the format: <2 byte length><data><0>
*
* @author elandau
*
* @param <T>
*/
public class AnnotatedCompositeSerializer<T> extends AbstractSerializer<T> {
private static final byte END_OF_COMPONENT = 0;
private static final ByteBuffer EMPTY_BYTE_BUFFER = ByteBuffer.allocate(0);
private static final int DEFAULT_BUFFER_SIZE = 128;
private static final int COMPONENT_OVERHEAD = 3;
/**
* Serializer for a single component within the Pojo
*
* @author elandau
*
* @param <P>
*/
public static class ComponentSerializer<P> implements Comparable<ComponentSerializer<?>> {
private Field field;
private Serializer<P> serializer;
private int ordinal;
public ComponentSerializer(Field field, Serializer<P> serializer, int ordinal) {
this.field = field;
this.field.setAccessible(true);
this.serializer = serializer;
this.ordinal = ordinal;
}
public Field getField() {
return this.field;
}
public ByteBuffer serialize(Object obj) throws IllegalArgumentException, IllegalAccessException {
Object value = field.get(obj);
ByteBuffer buf = serializer.toByteBuffer((P) value);
return buf;
}
public void deserialize(Object obj, ByteBuffer value) throws IllegalArgumentException, IllegalAccessException {
field.set(obj, serializer.fromByteBuffer(value));
}
public void setFieldValueDirectly(Object obj, Object value) {
try {
field.set(obj, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public Object getFieldValueDirectly(Object obj) {
try {
return field.get(obj);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public ByteBuffer serializeValue(Object value) {
ByteBuffer buf = serializer.toByteBuffer((P) value);
return buf;
}
@Override
public int compareTo(ComponentSerializer<?> other) {
return this.ordinal - other.ordinal;
}
public Serializer<P> getSerializer() {
return this.serializer;
}
}
private final List<ComponentSerializer<?>> components;
private final Class<T> clazz;
private final int bufferSize;
public AnnotatedCompositeSerializer<T> clone() {
AnnotatedCompositeSerializer<T> clone = new AnnotatedCompositeSerializer<T>(this.clazz, this.bufferSize, false);
return clone;
}
public AnnotatedCompositeSerializer(Class<T> clazz, boolean includeParentFields) {
this(clazz, DEFAULT_BUFFER_SIZE, includeParentFields);
}
public AnnotatedCompositeSerializer(Class<T> clazz) {
this(clazz, DEFAULT_BUFFER_SIZE, false);
}
public AnnotatedCompositeSerializer(Class<T> clazz, int bufferSize) {
this(clazz, bufferSize, false);
}
public AnnotatedCompositeSerializer(Class<T> clazz, int bufferSize, boolean includeParentFields) {
this.clazz = clazz;
this.components = new ArrayList<ComponentSerializer<?>>();
this.bufferSize = bufferSize;
for (Field field : getFields(clazz, includeParentFields)) {
Component annotation = field.getAnnotation(Component.class);
if (annotation != null) {
Serializer s = SerializerTypeInferer.getSerializer(field.getType());
components.add(makeComponent(field, s, annotation.ordinal()));
}
}
Collections.sort(this.components);
}
private List<Field> getFields(Class clazz, boolean recursively) {
List<Field> allFields = new ArrayList<Field>();
if (clazz.getDeclaredFields() != null && clazz.getDeclaredFields().length > 0) {
allFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
}
if (recursively && clazz.getSuperclass() != null && !clazz.getSuperclass().equals(Object.class)) {
allFields.addAll(getFields(clazz.getSuperclass(), true));
}
return allFields;
}
@Override
public ByteBuffer toByteBuffer(T obj) {
ByteBuffer bb = ByteBuffer.allocate(bufferSize);
for (ComponentSerializer<?> serializer : components) {
try {
// First, serialize the ByteBuffer for this component
ByteBuffer cb = serializer.serialize(obj);
if (cb == null) {
cb = ByteBuffer.allocate(0);
}
if (cb.limit() + COMPONENT_OVERHEAD > bb.remaining()) {
int exponent = (int) Math.ceil(Math.log((double) (cb.limit() + COMPONENT_OVERHEAD + bb.limit())) / Math.log(2));
int newBufferSize = (int) Math.pow(2, exponent);
ByteBuffer temp = ByteBuffer.allocate(newBufferSize);
bb.flip();
temp.put(bb);
bb = temp;
}
// Write the data: <length><data><0>
bb.putShort((short) cb.remaining());
bb.put(cb.slice());
bb.put(END_OF_COMPONENT);
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
bb.flip();
return bb;
}
@Override
public T fromByteBuffer(ByteBuffer byteBuffer) {
byteBuffer = byteBuffer.duplicate();
try {
T obj = createContents(clazz);
for (ComponentSerializer<?> serializer : components) {
ByteBuffer data = getWithShortLength(byteBuffer);
if (data != null) {
if (data.remaining() > 0) {
serializer.deserialize(obj, data);
}
byte end_of_component = byteBuffer.get();
if (end_of_component != END_OF_COMPONENT) {
throw new RuntimeException("Invalid composite column. Expected END_OF_COMPONENT.");
}
}
else {
throw new RuntimeException("Missing component data in composite type");
}
}
return obj;
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.COMPOSITETYPE;
}
private static int getShortLength(ByteBuffer bb) {
int length = (bb.get() & 0xFF) << 8;
return length | (bb.get() & 0xFF);
}
private static ByteBuffer getWithShortLength(ByteBuffer bb) {
int length = getShortLength(bb);
return getBytes(bb, length);
}
private static ByteBuffer getBytes(ByteBuffer bb, int length) {
ByteBuffer copy = bb.duplicate();
copy.limit(copy.position() + length);
bb.position(bb.position() + length);
return copy;
}
private static <P> ComponentSerializer<P> makeComponent(Field field, Serializer<P> serializer, int ordinal) {
return new ComponentSerializer<P>(field, serializer, ordinal);
}
private T createContents(Class<T> clazz) throws InstantiationException, IllegalAccessException {
return clazz.newInstance();
}
public CompositeRangeBuilder buildRange() {
return new CompositeRangeBuilder() {
private int position = 0;
public void getNextComponent() {
position++;
}
public void append(ByteBufferOutputStream out, Object value, Equality equality) {
ComponentSerializer<?> serializer = components.get(position);
// First, serialize the ByteBuffer for this component
ByteBuffer cb;
try {
cb = serializer.serializeValue(value);
}
catch (Exception e) {
throw new RuntimeException(e);
}
if (cb == null) {
cb = EMPTY_BYTE_BUFFER;
}
// Write the data: <length><data><0>
out.writeShort((short) cb.remaining());
out.write(cb.slice());
out.write(equality.toByte());
}
};
}
public <T1> RangeEndpoint makeEndpoint(T1 value, Equality equality) {
RangeEndpoint endpoint = new RangeEndpoint() {
private ByteBuffer out = ByteBuffer.allocate(bufferSize);
private int position = 0;
private boolean done = false;
@Override
public RangeEndpoint append(Object value, Equality equality) {
ComponentSerializer<?> serializer = components.get(position);
position++;
// First, serialize the ByteBuffer for this component
ByteBuffer cb;
try {
cb = serializer.serializeValue(value);
}
catch (Exception e) {
throw new RuntimeException(e);
}
if (cb == null) {
cb = EMPTY_BYTE_BUFFER;
}
if (cb.limit() + COMPONENT_OVERHEAD > out.remaining()) {
int exponent = (int) Math.ceil(Math.log((double) (cb.limit() + COMPONENT_OVERHEAD) / (double) out.limit()) / Math.log(2));
int newBufferSize = out.limit() * (int) Math.pow(2, exponent);
ByteBuffer temp = ByteBuffer.allocate(newBufferSize);
out.flip();
temp.put(out);
out = temp;
}
// Write the data: <length><data><0>
out.putShort((short) cb.remaining());
out.put(cb.slice());
out.put(equality.toByte());
return this;
}
@Override
public ByteBuffer toBytes() {
if (!done) {
out.flip();
done = true;
}
return out;
}
};
endpoint.append(value, equality);
return endpoint;
}
public List<ComponentSerializer<?>> getComponents() {
return components;
}
public Class<T> getClazz() {
return clazz;
}
}
| 7,843 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/JacksonSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.annotate.JsonSerialize;
public class JacksonSerializer<T> extends AbstractSerializer<T> {
private static final ObjectMapper mapper = new ObjectMapper();
static {
mapper.getSerializationConfig().withSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY);
mapper.enableDefaultTyping();
}
private final Class<T> clazz;
public JacksonSerializer(Class<T> clazz) {
this.clazz = clazz;
}
@Override
public ByteBuffer toByteBuffer(T entity) {
try {
byte[] bytes = mapper.writeValueAsBytes(entity);
return ByteBuffer.wrap(bytes);
} catch (Exception e) {
throw new RuntimeException("Error serializing entity ", e);
}
}
@Override
public T fromByteBuffer(ByteBuffer byteBuffer) {
try {
return mapper.readValue(new ByteArrayInputStream(byteBuffer.array()), clazz);
} catch (Exception e) {
throw new RuntimeException("Error serializing entity ", e);
}
}
}
| 7,844 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/TypeInferringSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import com.netflix.astyanax.Serializer;
/**
* A serializer that dynamically delegates to a proper serializer based on the
* value passed
*
* @author Bozhidar Bozhanov
*
* @param <T>
* type
*/
public class TypeInferringSerializer<T> extends AbstractSerializer<T> implements Serializer<T> {
@SuppressWarnings("rawtypes")
private static final TypeInferringSerializer instance = new TypeInferringSerializer();
@SuppressWarnings("unchecked")
public static <T> TypeInferringSerializer<T> get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(T obj) {
return SerializerTypeInferer.getSerializer(obj).toByteBuffer(obj);
}
@Override
public T fromByteBuffer(ByteBuffer byteBuffer) {
throw new IllegalStateException(
"The type inferring serializer can only be used for data going to the database, and not data coming from the database");
}
}
| 7,845 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/StringSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.UTF8Type;
/**
* A StringSerializer translates the byte[] to and from string using utf-8
* encoding.
*
* @author Ran Tavory
*
*/
public final class StringSerializer extends AbstractSerializer<String> {
private static final String UTF_8 = "UTF-8";
private static final StringSerializer instance = new StringSerializer();
private static final Charset charset = Charset.forName(UTF_8);
public static StringSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(String obj) {
if (obj == null) {
return null;
}
return ByteBuffer.wrap(obj.getBytes(charset));
}
@Override
public String fromByteBuffer(ByteBuffer byteBuffer) {
if (byteBuffer == null) {
return null;
}
final ByteBuffer dup = byteBuffer.duplicate();
return charset.decode(dup).toString();
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.UTF8TYPE;
}
@Override
public ByteBuffer fromString(String str) {
return UTF8Type.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return UTF8Type.instance.getString(byteBuffer);
}
}
| 7,846 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/ObjectSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.connectionpool.exceptions.SerializationException;
/**
* The ObjectSerializer is used to turn objects into their binary
* representations.
*
* @author Bozhidar Bozhanov
*
*/
public class ObjectSerializer extends AbstractSerializer<Object> implements
Serializer<Object> {
private static final ObjectSerializer INSTANCE = new ObjectSerializer();
@Override
public ByteBuffer toByteBuffer(Object obj) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
oos.close();
return ByteBuffer.wrap(baos.toByteArray());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
@Override
public Object fromByteBuffer(ByteBuffer bytes) {
if ((bytes == null) || !bytes.hasRemaining()) {
return null;
}
try {
ByteBuffer dup = bytes.duplicate();
int l = dup.remaining();
ByteArrayInputStream bais = new ByteArrayInputStream(dup.array(),
dup.arrayOffset() + dup.position(), l);
ObjectInputStream ois = new ObjectInputStream(bais);
Object obj = ois.readObject();
dup.position(dup.position() + (l - ois.available()));
ois.close();
return obj;
} catch (Exception ex) {
throw new SerializationException(ex);
}
}
public static ObjectSerializer get() {
return INSTANCE;
}
}
| 7,847 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/IntegerSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
/**
* Converts bytes to Integer (32 bit) and vice versa.
*
* It is important not to confuse IntegerSerializer with IntegerType in cassandra.
* IntegerSerializer serializes 32 bit integers while IntegerType comparator in cassandra
* is a BigInteger.
*
* @author Bozhidar Bozhanov
*
*/
public final class IntegerSerializer extends AbstractSerializer<Integer> {
private static final IntegerSerializer instance = new IntegerSerializer();
public static IntegerSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Integer obj) {
if (obj == null) {
return null;
}
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(obj);
b.rewind();
return b;
}
@Override
public Integer fromByteBuffer(ByteBuffer byteBuffer) {
if ((byteBuffer == null) || (byteBuffer.remaining() != 4)) {
return null;
}
ByteBuffer dup = byteBuffer.duplicate();
int in = dup.getInt();
return in;
}
@Override
public Integer fromBytes(byte[] bytes) {
if ((bytes == null) || (bytes.length != 4)) {
return null;
}
ByteBuffer bb = ByteBuffer.allocate(4).put(bytes, 0, 4);
bb.rewind();
return bb.getInt();
}
@Override
public ByteBuffer fromString(String str) {
return toByteBuffer(Integer.parseInt(str));
}
@Override
public String getString(ByteBuffer byteBuffer) {
return Integer.toString(fromByteBuffer(byteBuffer));
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
Integer val = fromByteBuffer(byteBuffer.duplicate());
if (val == Integer.MAX_VALUE) {
throw new ArithmeticException("Can't paginate past max int");
}
return toByteBuffer(val + 1);
}
public ComparatorType getComparatorType() {
return ComparatorType.INT32TYPE;
}
}
| 7,848 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/BigIntegerSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.IntegerType;
/**
* Serializer implementation for BigInteger
*
* @author zznate
*/
public final class BigIntegerSerializer extends AbstractSerializer<BigInteger> {
private static final BigIntegerSerializer INSTANCE = new BigIntegerSerializer();
public static BigIntegerSerializer get() {
return INSTANCE;
}
@Override
public BigInteger fromByteBuffer(final ByteBuffer byteBuffer) {
if (byteBuffer == null) {
return null;
}
ByteBuffer dup = byteBuffer.duplicate();
int length = dup.remaining();
byte[] bytes = new byte[length];
dup.get(bytes);
return new BigInteger(bytes);
}
@Override
public ByteBuffer toByteBuffer(BigInteger obj) {
if (obj == null) {
return null;
}
return ByteBuffer.wrap(obj.toByteArray());
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.INTEGERTYPE;
}
@Override
public ByteBuffer fromString(String str) {
return IntegerType.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return IntegerType.instance.getString(byteBuffer);
}
@Override
public ByteBuffer getNext(final ByteBuffer byteBuffer) {
if (byteBuffer == null)
return null;
BigInteger bigint = fromByteBuffer(byteBuffer.duplicate());
bigint = bigint.add(new BigInteger("1"));
return toByteBuffer(bigint);
}
}
| 7,849 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/DateSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.Date;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.DateType;
/**
* Converts bytes to Date and vice versa, by first converting the Date to or
* from a long which represents the specified number of milliseconds since the
* standard base time known as "the Unix epoch", that is January 1, 1970,
* 00:00:00 UTC.
*
* @author Jim Ancona
* @see java.util.Date
*/
public final class DateSerializer extends AbstractSerializer<Date> {
private static final LongSerializer LONG_SERIALIZER = LongSerializer.get();
private static final DateSerializer instance = new DateSerializer();
public static DateSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Date obj) {
if (obj == null) {
return null;
}
return LONG_SERIALIZER.toByteBuffer(obj.getTime());
}
@Override
public Date fromByteBuffer(ByteBuffer bytes) {
if (bytes == null) {
return null;
}
ByteBuffer dup = bytes.duplicate();
return new Date(LONG_SERIALIZER.fromByteBuffer(dup));
}
@Override
public ByteBuffer fromString(String str) {
return DateType.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return DateType.instance.getString(byteBuffer);
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
return toByteBuffer(new Date(fromByteBuffer(byteBuffer).getTime() + 1));
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.DATETYPE;
}
}
| 7,850 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/JaxbSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import com.netflix.astyanax.connectionpool.exceptions.SerializationException;
/**
* Serializes Objects using Jaxb. An instance of this class may only serialize
* JAXB compatible objects of classes known to its configured context.
*
* @author shuzhang0@gmail.com
*/
public class JaxbSerializer extends AbstractSerializer<Object> {
/** The cached per-thread marshaller. */
private ThreadLocal<Marshaller> marshaller;
/** The cached per-thread unmarshaller. */
private ThreadLocal<Unmarshaller> unmarshaller;
/**
* Lazily initialized singleton factory for producing default
* XMLStreamWriters.
*/
private static XMLOutputFactory outputFactory;
/**
* Lazily initialized singleton factory for producing default
* XMLStreamReaders.
*/
private static XMLInputFactory inputFactory;
/**
* Constructor.
*
* @param serializableClasses
* List of classes which can be serialized by this instance. Note
* that concrete classes directly referenced by any class in the
* list will also be serializable through this instance.
*/
public JaxbSerializer(final Class... serializableClasses) {
marshaller = new ThreadLocal<Marshaller>() {
@Override
protected Marshaller initialValue() {
try {
return JAXBContext.newInstance(serializableClasses).createMarshaller();
}
catch (JAXBException e) {
throw new IllegalArgumentException("Classes to serialize are not JAXB compatible.", e);
}
}
};
unmarshaller = new ThreadLocal<Unmarshaller>() {
@Override
protected Unmarshaller initialValue() {
try {
return JAXBContext.newInstance(serializableClasses).createUnmarshaller();
}
catch (JAXBException e) {
throw new IllegalArgumentException("Classes to serialize are not JAXB compatible.", e);
}
}
};
}
/** {@inheritDoc} */
@Override
public ByteBuffer toByteBuffer(Object obj) {
if (obj == null) {
return null;
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try {
XMLStreamWriter writer = createStreamWriter(buffer);
marshaller.get().marshal(obj, writer);
writer.flush();
writer.close();
}
catch (JAXBException e) {
throw new SerializationException("Object to serialize " + obj
+ " does not seem compatible with the configured JaxbContext;"
+ " note this Serializer works only with JAXBable objects.", e);
}
catch (XMLStreamException e) {
throw new SerializationException("Exception occurred writing XML stream.", e);
}
return ByteBuffer.wrap(buffer.toByteArray());
}
/** {@inheritDoc} */
@Override
public Object fromByteBuffer(ByteBuffer bytes) {
if (bytes == null || !bytes.hasRemaining()) {
return null;
}
ByteBuffer dup = bytes.duplicate();
ByteArrayInputStream bais = new ByteArrayInputStream(dup.array());
try {
XMLStreamReader reader = createStreamReader(bais);
Object ret = unmarshaller.get().unmarshal(reader);
reader.close();
return ret;
}
catch (JAXBException e) {
throw new SerializationException("Jaxb exception occurred during deserialization.", e);
}
catch (XMLStreamException e) {
throw new SerializationException("Exception reading XML stream.", e);
}
}
/**
* Get a new XML stream writer.
*
* @param output
* An underlying OutputStream to write to.
* @return a new {@link XMLStreamWriter} which writes to the specified
* OutputStream. The output written by this XMLStreamWriter is
* understandable by XMLStreamReaders produced by
* {@link #createStreamReader(InputStream)}.
* @throws XMLStreamException
*/
// Provides hook for subclasses to override how marshalling results are
// serialized (ex. encoding).
protected XMLStreamWriter createStreamWriter(OutputStream output) throws XMLStreamException {
if (outputFactory == null) {
outputFactory = XMLOutputFactory.newInstance();
}
return outputFactory.createXMLStreamWriter(output);
}
/**
* Get a new XML stream reader.
*
* @param input
* the underlying InputStream to read from.
* @return a new {@link XmlStreamReader} which reads from the specified
* InputStream. The reader can read anything written by
* {@link #createStreamWriter(OutputStream)}.
* @throws XMLStreamException
*/
protected XMLStreamReader createStreamReader(InputStream input) throws XMLStreamException {
if (inputFactory == null) {
inputFactory = XMLInputFactory.newInstance();
}
return inputFactory.createXMLStreamReader(input);
}
}
| 7,851 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/DoubleSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.DoubleType;
/**
* Uses LongSerializer via translating Doubles to and from raw long bytes form.
*
* @author Yuri Finkelstein
*/
public class DoubleSerializer extends AbstractSerializer<Double> {
private static final DoubleSerializer instance = new DoubleSerializer();
public static DoubleSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Double obj) {
return LongSerializer.get().toByteBuffer(
Double.doubleToRawLongBits(obj));
}
@Override
public Double fromByteBuffer(ByteBuffer bytes) {
if (bytes == null)
return null;
ByteBuffer dup = bytes.duplicate();
return Double
.longBitsToDouble(LongSerializer.get().fromByteBuffer(dup));
}
@Override
public ByteBuffer fromString(String str) {
return DoubleType.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return DoubleType.instance.getString(byteBuffer);
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
double val = fromByteBuffer(byteBuffer.duplicate());
if (val == Double.MAX_VALUE) {
throw new ArithmeticException("Can't paginate past max double");
}
return toByteBuffer(val + Double.MIN_VALUE);
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.DOUBLETYPE;
}
}
| 7,852 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/AsciiSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.AsciiType;
/**
* Almost identical to StringSerializer except we use the US-ASCII character set
* code
*
* @author zznate
*/
public final class AsciiSerializer extends AbstractSerializer<String> {
private static final String US_ASCII = "US-ASCII";
private static final AsciiSerializer instance = new AsciiSerializer();
private static final Charset charset = Charset.forName(US_ASCII);
public static AsciiSerializer get() {
return instance;
}
@Override
public String fromByteBuffer(final ByteBuffer byteBuffer) {
if (byteBuffer == null) {
return null;
}
ByteBuffer dup = byteBuffer.duplicate();
return charset.decode(dup).toString();
}
@Override
public ByteBuffer toByteBuffer(String obj) {
if (obj == null) {
return null;
}
return ByteBuffer.wrap(obj.getBytes(charset));
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.ASCIITYPE;
}
@Override
public ByteBuffer fromString(String str) {
return AsciiType.instance.fromString(str);
}
@Override
public String getString(final ByteBuffer byteBuffer) {
if (byteBuffer == null)
return null;
return AsciiType.instance.getString(byteBuffer.duplicate());
}
}
| 7,853 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/CharSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
/**
* Uses Char Serializer
*
* @author Todd Nine
*/
public class CharSerializer extends AbstractSerializer<Character> {
private static final CharSerializer instance = new CharSerializer();
public static CharSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Character obj) {
if (obj == null)
return null;
ByteBuffer buffer = ByteBuffer.allocate(Character.SIZE / Byte.SIZE);
buffer.putChar(obj);
buffer.rewind();
return buffer;
}
@Override
public Character fromByteBuffer(ByteBuffer bytes) {
if (bytes == null) {
return null;
}
ByteBuffer dup = bytes.duplicate();
return dup.getChar();
}
@Override
public ByteBuffer fromString(String str) {
if (str == null || str.length() == 0)
return null;
return toByteBuffer(str.charAt(0));
}
@Override
public String getString(ByteBuffer byteBuffer) {
return fromByteBuffer(byteBuffer).toString();
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
throw new IllegalStateException("Char columns can't be paginated");
}
} | 7,854 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/ComparatorType.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.ShadedTypeParser;
import static com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.ShadedTypeParser.SHADED_PREFIX;
/**
* @author: peter
*/
public enum ComparatorType {
ASCIITYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.AsciiType", AsciiSerializer.get()),
BYTESTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.BytesType", ByteBufferSerializer.get()),
INTEGERTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.IntegerType", BigIntegerSerializer.get()),
INT32TYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.Int32Type", Int32Serializer.get()),
DECIMALTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.DecimalType", BigDecimalSerializer.get()),
LEXICALUUIDTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.LexicalUUIDType", UUIDSerializer.get()),
LOCALBYPARTITIONERTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.LocalByPartionerType", ByteBufferSerializer.get()), // FIXME
LONGTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.LongType", LongSerializer.get()),
TIMEUUIDTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.TimeUUIDType", TimeUUIDSerializer.get()),
UTF8TYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.UTF8Type", StringSerializer.get()),
COMPOSITETYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.CompositeType", CompositeSerializer.get()),
DYNAMICCOMPOSITETYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.DynamicCompositeType", DynamicCompositeSerializer.get()),
UUIDTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.UUIDType", UUIDSerializer.get()),
COUNTERTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.CounterColumnType", LongSerializer.get()),
DOUBLETYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.DoubleType", DoubleSerializer.get()),
FLOATTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.FloatType", FloatSerializer.get()),
BOOLEANTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.BooleanType", BooleanSerializer.get()),
DATETYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.DateType", DateSerializer.get()),
REVERSEDTYPE(SHADED_PREFIX + "org.apache.cassandra.db.marshal.ReversedType", ReversedSerializer.get());
private final String className;
private final String typeName;
private final Serializer<?> serializer;
private ComparatorType(String className, Serializer<?> serializer) {
this.className = className;
this.typeName = getShadedTypeName(className);
this.serializer = serializer;
}
public String getClassName() {
return className;
}
public String getTypeName() {
return typeName;
}
public Serializer<?> getSerializer() {
return serializer;
}
public static ComparatorType getByClassName(String className) {
if (className == null) {
return null;
}
for (ComparatorType type : ComparatorType.values()) {
if (type.getClassName().equals(getShadedClassName(className))) {
return type;
}
}
return null;
}
public static String getShadedClassName(String className){
return ShadedTypeParser.getShadedClassName(className);
}
public static String getShadedTypeName(String typeName){
return ShadedTypeParser.getShadedTypeName(typeName);
}
}
| 7,855 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/ShortSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.IntegerType;
/**
* {@link com.netflix.astyanax.Serializer} for {@link Short}s (no pun intended).
*
*/
public final class ShortSerializer extends AbstractSerializer<Short> {
private static final ShortSerializer instance = new ShortSerializer();
public static ShortSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Short obj) {
if (obj == null) {
return null;
}
ByteBuffer b = ByteBuffer.allocate(2);
b.putShort(obj);
b.rewind();
return b;
}
@Override
public Short fromByteBuffer(ByteBuffer byteBuffer) {
if (byteBuffer == null) {
return null;
}
ByteBuffer dup = byteBuffer.duplicate();
short in = dup.getShort();
return in;
}
@Override
public ByteBuffer fromString(String str) {
// Verify value is a short
return toByteBuffer(Short.parseShort(str));
}
@Override
public String getString(ByteBuffer byteBuffer) {
return IntegerType.instance.getString(byteBuffer);
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
Short val = fromByteBuffer(byteBuffer.duplicate());
if (val == Short.MAX_VALUE) {
throw new ArithmeticException("Can't paginate past max short");
}
val++;
return toByteBuffer(val);
}
}
| 7,856 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/UnknownComparatorException.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
public class UnknownComparatorException extends Exception {
private static final long serialVersionUID = -208259105321284073L;
public UnknownComparatorException(String type) {
super(type);
}
}
| 7,857 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/GzipStringSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.UTF8Type;
import org.apache.commons.codec.binary.StringUtils;
public class GzipStringSerializer extends AbstractSerializer<String> {
private static final String UTF_8 = "UTF-8";
private static final GzipStringSerializer instance = new GzipStringSerializer();
private static final Charset charset = Charset.forName(UTF_8);
public static GzipStringSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(String obj) {
if (obj == null) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip;
try {
gzip = new GZIPOutputStream(out);
gzip.write(StringUtils.getBytesUtf8(obj));
gzip.close();
return ByteBuffer.wrap(out.toByteArray());
} catch (IOException e) {
throw new RuntimeException("Error compressing column data", e);
}
}
@Override
public String fromByteBuffer(ByteBuffer byteBuffer) {
if (byteBuffer == null) {
return null;
}
GZIPInputStream gzipInputStream = null;
ByteArrayOutputStream baos = null;
ByteBuffer dup = byteBuffer.duplicate();
try {
gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(
dup.array(), 0, dup.limit()));
baos = new ByteArrayOutputStream();
for (int value = 0; value != -1;) {
value = gzipInputStream.read();
if (value != -1) {
baos.write(value);
}
}
gzipInputStream.close();
baos.close();
return new String(baos.toByteArray(), charset);
} catch (IOException e) {
throw new RuntimeException("Error decompressing column data", e);
} finally {
if (gzipInputStream != null) {
try {
gzipInputStream.close();
} catch (IOException e) {
}
}
if (baos != null) {
try {
baos.close();
} catch (IOException e) {
}
}
}
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.BYTESTYPE;
}
@Override
public ByteBuffer fromString(String str) {
return UTF8Type.instance.fromString(str);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return UTF8Type.instance.getString(byteBuffer);
}
}
| 7,858 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/SerializerTypeInferer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.UUID;
import com.netflix.astyanax.Serializer;
/**
* Utility class that infers the concrete Serializer needed to turn a value into
* its binary representation
*
* @author Bozhidar Bozhanov
*
*/
public class SerializerTypeInferer {
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> Serializer<T> getSerializer(Object value) {
Serializer serializer = null;
if (value == null) {
serializer = ByteBufferSerializer.get();
}
else if (value instanceof UUID) {
serializer = UUIDSerializer.get();
}
else if (value instanceof String) {
serializer = StringSerializer.get();
}
else if (value instanceof Long) {
serializer = LongSerializer.get();
}
else if (value instanceof Integer) {
serializer = Int32Serializer.get();
}
else if (value instanceof Short) {
serializer = ShortSerializer.get();
}
else if (value instanceof Byte) {
serializer = ByteSerializer.get();
}
else if (value instanceof Float) {
serializer = FloatSerializer.get();
}
else if (value instanceof Double) {
serializer = DoubleSerializer.get();
}
else if (value instanceof BigInteger) {
serializer = BigIntegerSerializer.get();
}
else if (value instanceof BigDecimal) {
serializer = BigDecimalSerializer.get();
}
else if (value instanceof Boolean) {
serializer = BooleanSerializer.get();
}
else if (value instanceof byte[]) {
serializer = BytesArraySerializer.get();
}
else if (value instanceof ByteBuffer) {
serializer = ByteBufferSerializer.get();
}
else if (value instanceof Date) {
serializer = DateSerializer.get();
}
// TODO: need what to select StringCoercibleSerilizer here?
else {
serializer = ObjectSerializer.get();
}
// Add other serializers here
return serializer;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> Serializer<T> getSerializer(Class<?> valueClass) {
Serializer serializer = null;
if (valueClass.equals(UUID.class)) {
serializer = UUIDSerializer.get();
}
else if (valueClass.equals(String.class)) {
serializer = StringSerializer.get();
}
else if (valueClass.equals(Long.class) || valueClass.equals(long.class)) {
serializer = LongSerializer.get();
}
else if (valueClass.equals(Integer.class) || valueClass.equals(int.class)) {
serializer = Int32Serializer.get();
}
else if (valueClass.equals(Short.class) || valueClass.equals(short.class)) {
serializer = ShortSerializer.get();
}
else if (valueClass.equals(Byte.class) || valueClass.equals(byte.class)) {
serializer = ByteSerializer.get();
}
else if (valueClass.equals(Float.class) || valueClass.equals(float.class)) {
serializer = FloatSerializer.get();
}
else if (valueClass.equals(Double.class) || valueClass.equals(double.class)) {
serializer = DoubleSerializer.get();
}
else if (valueClass.equals(BigInteger.class)) {
serializer = BigIntegerSerializer.get();
}
else if (valueClass.equals(BigDecimal.class)) {
serializer = BigDecimalSerializer.get();
}
else if (valueClass.equals(Boolean.class) || valueClass.equals(boolean.class)) {
serializer = BooleanSerializer.get();
}
else if (valueClass.equals(byte[].class)) {
serializer = BytesArraySerializer.get();
}
else if (valueClass.equals(ByteBuffer.class)) {
serializer = ByteBufferSerializer.get();
}
else if (valueClass.equals(Date.class)) {
serializer = DateSerializer.get();
}
if (serializer == null) {
serializer = ObjectSerializer.get();
}
// Add other serializers here
return serializer;
}
}
| 7,859 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/BigDecimalSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.DecimalType;
public class BigDecimalSerializer extends AbstractSerializer<BigDecimal> {
private static final BigDecimalSerializer INSTANCE = new BigDecimalSerializer();
public static BigDecimalSerializer get() {
return INSTANCE;
}
@Override
public BigDecimal fromByteBuffer(final ByteBuffer byteBuffer) {
if (byteBuffer == null)
return null;
return DecimalType.instance.compose(byteBuffer.duplicate());
}
@Override
public ByteBuffer toByteBuffer(BigDecimal obj) {
return DecimalType.instance.decompose(obj);
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.DECIMALTYPE;
}
@Override
public ByteBuffer fromString(String str) {
return DecimalType.instance.fromString(str);
}
@Override
public String getString(final ByteBuffer byteBuffer) {
if (byteBuffer == null)
return null;
return DecimalType.instance.getString(byteBuffer.duplicate());
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
throw new RuntimeException("Not supported");
}
}
| 7,860 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/SetSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.Set;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.AbstractType;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.SetType;
import com.netflix.astyanax.serializers.AbstractSerializer;
/**
* Serializer implementation for generic sets.
*
* @author vermes
*
* @param <T>
* element type
*/
public class SetSerializer<T> extends AbstractSerializer<Set<T>> {
private final SetType<T> mySet;
/**
* @param elements
*/
public SetSerializer(AbstractType<T> elements) {
mySet = SetType.getInstance(elements);
}
@Override
public Set<T> fromByteBuffer(ByteBuffer arg0) {
return arg0 == null ? null : mySet.compose(arg0);
}
@Override
public ByteBuffer toByteBuffer(Set<T> arg0) {
return arg0 == null ? null : mySet.decompose(arg0);
}
} | 7,861 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/SerializerPackageImpl.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.CompositeType;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.ReversedType;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.ShadedTypeParser;
import org.apache.commons.lang.StringUtils;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.SerializerPackage;
import com.netflix.astyanax.ddl.ColumnDefinition;
import com.netflix.astyanax.ddl.ColumnFamilyDefinition;
/**
* Basic implementation of SerializerPackage which can be configured either from
* a ColumnFamilyDefinition or by manually setting either the ComparatorType or
* Serializer for keys, columns and values. Use this in conjunction with the CSV
* uploader to specify how values are serializer.
*
* @author elandau
*
*/
public class SerializerPackageImpl implements SerializerPackage {
private final static Serializer<?> DEFAULT_SERIALIZER = BytesArraySerializer.get();
public final static SerializerPackage DEFAULT_SERIALIZER_PACKAGE = new SerializerPackageImpl();
private Serializer<?> keySerializer = DEFAULT_SERIALIZER;
private Serializer<?> columnSerializer = DEFAULT_SERIALIZER;
private Serializer<?> defaultValueSerializer = DEFAULT_SERIALIZER;
private final Map<ByteBuffer, Serializer<?>> valueSerializers = new HashMap<ByteBuffer, Serializer<?>>();;
public SerializerPackageImpl() {
}
/**
* Construct a serializer package from a column family definition retrieved
* from the keyspace. This is the preferred method of initialing the
* serializer since it most closely matches the validators and comparator
* type set in cassandra.
*
* @param cfDef
* @param ignoreErrors
* @throws UnknownComparatorException
*/
public SerializerPackageImpl(ColumnFamilyDefinition cfDef, boolean ignoreErrors) throws UnknownComparatorException {
try {
setKeyType(cfDef.getKeyValidationClass());
}
catch (UnknownComparatorException e) {
if (!ignoreErrors)
throw e;
}
try {
setColumnType(cfDef.getComparatorType());
}
catch (UnknownComparatorException e) {
if (!ignoreErrors)
throw e;
}
try {
setDefaultValueType(cfDef.getDefaultValidationClass());
}
catch (UnknownComparatorException e) {
if (!ignoreErrors)
throw e;
}
List<ColumnDefinition> colsDefs = cfDef.getColumnDefinitionList();
if (colsDefs != null) {
for (ColumnDefinition colDef : colsDefs) {
try {
this.setValueType(colDef.getRawName(), colDef.getValidationClass());
}
catch (UnknownComparatorException e) {
if (!ignoreErrors)
throw e;
}
}
}
}
@SuppressWarnings("rawtypes")
public SerializerPackageImpl setKeyType(String keyType) throws UnknownComparatorException {
String comparatorType = StringUtils.substringBefore(keyType, "(");
ComparatorType type = ComparatorType.getByClassName(comparatorType);
if (type == null) {
throw new UnknownComparatorException(keyType);
}
if (type == ComparatorType.COMPOSITETYPE) {
try {
this.keySerializer = new SpecificCompositeSerializer((CompositeType) ShadedTypeParser.parse(keyType));
return this;
}
catch (Exception e) {
// Ignore and simply use the default serializer
}
throw new UnknownComparatorException(keyType);
}
else if (type == ComparatorType.DYNAMICCOMPOSITETYPE) {
// TODO
throw new UnknownComparatorException(keyType);
}
else if (type == ComparatorType.REVERSEDTYPE) {
try {
this.keySerializer = new SpecificReversedSerializer((ReversedType) ShadedTypeParser.parse(keyType));
return this;
}
catch (Exception e) {
// Ignore and simply use the default serializer
}
throw new UnknownComparatorException(keyType);
}
else {
this.keySerializer = type.getSerializer();
}
return this;
}
public SerializerPackageImpl setKeySerializer(Serializer<?> serializer) {
this.keySerializer = serializer;
return this;
}
@Deprecated
public SerializerPackageImpl setColumnType(String columnType) throws UnknownComparatorException {
return setColumnNameType(columnType);
}
@SuppressWarnings("rawtypes")
public SerializerPackageImpl setColumnNameType(String columnType) throws UnknownComparatorException {
// Determine the column serializer
columnType = ComparatorType.getShadedClassName(columnType);
String comparatorType = StringUtils.substringBefore(columnType, "(");
ComparatorType type = ComparatorType.getByClassName(comparatorType);
if (type == null) {
throw new UnknownComparatorException(columnType);
}
if (type == ComparatorType.COMPOSITETYPE) {
try {
this.columnSerializer = new SpecificCompositeSerializer((CompositeType) ShadedTypeParser.parse(columnType));
return this;
}
catch (Exception e) {
// Ignore and simply use the default serializer
}
throw new UnknownComparatorException(columnType);
}
else if (type == ComparatorType.DYNAMICCOMPOSITETYPE) {
// TODO
throw new UnknownComparatorException(columnType);
}
else if (type == ComparatorType.REVERSEDTYPE) {
try {
this.columnSerializer = new SpecificReversedSerializer((ReversedType) ShadedTypeParser.parse(columnType));
return this;
}
catch (Exception e) {
// Ignore and simply use the default serializer
}
throw new UnknownComparatorException(columnType);
}
else {
this.columnSerializer = type.getSerializer();
}
return this;
}
public SerializerPackageImpl setColumnNameSerializer(Serializer<?> serializer) {
this.columnSerializer = serializer;
return this;
}
public SerializerPackageImpl setDefaultValueType(String valueType) throws UnknownComparatorException {
// Determine the VALUE serializer. There is always a default serializer
// and potentially column specific serializers
ComparatorType type = ComparatorType.getByClassName(valueType);
if (type == null) {
throw new UnknownComparatorException(valueType);
}
this.defaultValueSerializer = type.getSerializer();
return this;
}
public SerializerPackageImpl setDefaultValueSerializer(Serializer<?> serializer) {
this.defaultValueSerializer = serializer;
return this;
}
public SerializerPackageImpl setValueType(String columnName, String type) throws UnknownComparatorException {
setValueType(StringSerializer.get().toByteBuffer(columnName), type);
return this;
}
public SerializerPackageImpl setValueType(ByteBuffer columnName, String valueType)
throws UnknownComparatorException {
ComparatorType type = ComparatorType.getByClassName(valueType);
if (type == null) {
throw new UnknownComparatorException(valueType);
}
this.valueSerializers.put(columnName, type.getSerializer());
return this;
}
public SerializerPackageImpl setValueSerializer(String columnName, Serializer<?> serializer) {
this.valueSerializers.put(StringSerializer.get().toByteBuffer(columnName), serializer);
return this;
}
public SerializerPackageImpl setValueSerializer(ByteBuffer columnName, Serializer<?> serializer) {
this.valueSerializers.put(columnName, serializer);
return this;
}
@Override
public Serializer<?> getKeySerializer() {
return this.keySerializer;
}
@Override
@Deprecated
public Serializer<?> getColumnSerializer() {
return getColumnNameSerializer();
}
@Override
public Serializer<?> getColumnNameSerializer() {
return this.columnSerializer;
}
@Override
@Deprecated
public Serializer<?> getValueSerializer(ByteBuffer columnName) {
return getColumnSerializer(columnName);
}
public Serializer<?> getColumnSerializer(ByteBuffer columnName) {
if (valueSerializers == null) {
return defaultValueSerializer;
}
Serializer<?> ser = valueSerializers.get(columnName);
if (ser == null) {
return defaultValueSerializer;
}
return ser;
}
@Override
public Serializer<?> getColumnSerializer(String columnName) {
return getValueSerializer(StringSerializer.get().toByteBuffer(columnName));
}
@Override
@Deprecated
public Serializer<?> getValueSerializer(String columnName) {
return getColumnSerializer(columnName);
}
@Override
public Set<ByteBuffer> getColumnNames() {
Set<ByteBuffer> set = new HashSet<ByteBuffer>();
if (valueSerializers != null) {
for (Entry<ByteBuffer, Serializer<?>> entry : valueSerializers.entrySet()) {
set.add(entry.getKey().duplicate());
}
}
return set;
}
@Override
@Deprecated
public Serializer<?> getValueSerializer() {
return getDefaultValueSerializer();
}
@Override
public Serializer<?> getDefaultValueSerializer() {
return defaultValueSerializer;
}
@Override
public String keyAsString(ByteBuffer key) {
return this.keySerializer.getString(key);
}
@Override
public String columnAsString(ByteBuffer column) {
return this.columnSerializer.getString(column);
}
@Override
public String valueAsString(ByteBuffer column, ByteBuffer value) {
Serializer<?> serializer = this.valueSerializers.get(column);
if (serializer == null) {
return this.defaultValueSerializer.getString(value);
}
else {
return serializer.getString(value);
}
}
@Override
public ByteBuffer keyAsByteBuffer(String key) {
return this.keySerializer.fromString(key);
}
@Override
public ByteBuffer columnAsByteBuffer(String column) {
return this.columnSerializer.fromString(column);
}
@Override
public ByteBuffer valueAsByteBuffer(ByteBuffer column, String value) {
Serializer<?> serializer = this.valueSerializers.get(column);
if (serializer == null) {
return this.defaultValueSerializer.fromString(value);
}
else {
return serializer.fromString(value);
}
}
@Override
public ByteBuffer valueAsByteBuffer(String column, String value) {
return valueAsByteBuffer(this.columnSerializer.fromString(column), value);
}
}
| 7,862 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/ReversedSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
public class ReversedSerializer<T> extends AbstractSerializer<T>{
@SuppressWarnings("rawtypes")
private static final ReversedSerializer instance = new ReversedSerializer() ;
@SuppressWarnings("unchecked")
public static <T> ReversedSerializer<T> get()
{
return instance;
}
@Override
public ByteBuffer toByteBuffer(T obj) {
if (obj == null)
return null;
return SerializerTypeInferer.getSerializer(obj).toByteBuffer(obj);
}
@Override
public T fromByteBuffer(ByteBuffer byteBuffer) {
throw new RuntimeException(
"ReversedSerializer.fromByteBuffer() Not Implemented.");
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.REVERSEDTYPE;
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
throw new RuntimeException(
"ReversedSerializer.getNext() Not implemented.");
}
}
| 7,863 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/CompositeSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import java.util.List;
import com.netflix.astyanax.model.Composite;
public class CompositeSerializer extends AbstractSerializer<Composite> {
private static final CompositeSerializer instance = new CompositeSerializer();
public static CompositeSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Composite obj) {
return obj.serialize();
}
@Override
public Composite fromByteBuffer(ByteBuffer byteBuffer) {
Composite composite = new Composite();
composite.setComparatorsByPosition(getComparators());
composite.deserialize(byteBuffer);
return composite;
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
throw new IllegalStateException(
"Composite columns can't be paginated this way. Use SpecificCompositeSerializer instead.");
}
@Override
public ComparatorType getComparatorType() {
return ComparatorType.COMPOSITETYPE;
}
public List<String> getComparators() {
return null;
}
}
| 7,864 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/SpecificReversedSerializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.AbstractType;
import com.netflix.astyanax.shaded.org.apache.cassandra.db.marshal.ReversedType;
import com.google.common.base.Preconditions;
@SuppressWarnings("rawtypes")
public class SpecificReversedSerializer extends ReversedSerializer {
private String reversedTypeName;
private final ComparatorType reversedComparatorType;
public SpecificReversedSerializer(ReversedType type) {
Preconditions.checkNotNull(type);
AbstractType<?> compType = type.baseType;
reversedTypeName = compType.toString();
reversedTypeName = ComparatorType.getShadedTypeName(reversedTypeName);
this.reversedComparatorType = ComparatorType.getByClassName(reversedTypeName);
}
@Override
public ByteBuffer fromString(String string) {
return this.reversedComparatorType.getSerializer().fromString(string);
}
@Override
public String getString(ByteBuffer byteBuffer) {
return this.reversedComparatorType.getSerializer().getString(byteBuffer);
}
}
| 7,865 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/serializers/Int32Serializer.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.serializers;
import java.nio.ByteBuffer;
/**
* Same as IntegerSerializer but more explicitly linked with Int32Type cmparator
* in cassandra.
*
* @author elandau
*
*/
public class Int32Serializer extends AbstractSerializer<Integer> {
private static final IntegerSerializer instance = new IntegerSerializer();
public static IntegerSerializer get() {
return instance;
}
@Override
public ByteBuffer toByteBuffer(Integer obj) {
if (obj == null) {
return null;
}
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(obj);
b.rewind();
return b;
}
@Override
public Integer fromByteBuffer(ByteBuffer byteBuffer) {
if ((byteBuffer == null) || (byteBuffer.remaining() != 4)) {
return null;
}
ByteBuffer dup = byteBuffer.duplicate();
int in = dup.getInt();
return in;
}
@Override
public Integer fromBytes(byte[] bytes) {
if ((bytes == null) || (bytes.length != 4)) {
return null;
}
ByteBuffer bb = ByteBuffer.allocate(4).put(bytes, 0, 4);
bb.rewind();
return bb.getInt();
}
@Override
public ByteBuffer fromString(String str) {
return toByteBuffer(Integer.parseInt(str));
}
@Override
public String getString(ByteBuffer byteBuffer) {
return Integer.toString(fromByteBuffer(byteBuffer));
}
@Override
public ByteBuffer getNext(ByteBuffer byteBuffer) {
Integer val = fromByteBuffer(byteBuffer.duplicate());
if (val == Integer.MAX_VALUE) {
throw new ArithmeticException("Can't paginate past max int");
}
return toByteBuffer(val + 1);
}
public ComparatorType getComparatorType() {
return ComparatorType.INT32TYPE;
}
} | 7,866 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/CompositeBuilder.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import com.netflix.astyanax.Serializer;
public interface CompositeBuilder {
CompositeBuilder addString(String value);
CompositeBuilder addLong(Long value);
CompositeBuilder addInteger(Integer value);
CompositeBuilder addBoolean(Boolean value);
CompositeBuilder addUUID(UUID value);
CompositeBuilder addTimeUUID(UUID value);
CompositeBuilder addTimeUUID(Long value, TimeUnit units);
CompositeBuilder addBytes(byte[] bytes);
CompositeBuilder addBytes(ByteBuffer bb);
<T> CompositeBuilder add(T value, Serializer<T> serializer);
CompositeBuilder greaterThanEquals();
CompositeBuilder lessThanEquals();
ByteBuffer build();
}
| 7,867 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/OrderedColumnMap.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
import com.google.common.collect.Maps;
public class OrderedColumnMap<C> implements ColumnMap<C> {
private final LinkedHashMap<C, Column<C>> columns = Maps.newLinkedHashMap();
public OrderedColumnMap() {
}
public OrderedColumnMap(Collection<Column<C>> columns) {
addAll(columns);
}
@Override
public OrderedColumnMap<C> add(Column<C> column) {
columns.put(column.getName(), column);
return this;
}
@Override
public OrderedColumnMap<C> addAll(Collection<Column<C>> columns) {
for (Column<C> column : columns){
this.columns.put(column.getName(), column);
}
return this;
}
@Override
public Iterator<Column<C>> iterator() {
return this.columns.values().iterator();
}
@Override
public Column<C> get(C columnName) {
return columns.get(columnName);
}
@Override
public String getString(C columnName, String defaultValue) {
Column<C> column = columns.get(columnName);
if (column == null)
return defaultValue;
return column.getStringValue();
}
@Override
public Integer getInteger(C columnName, Integer defaultValue) {
Column<C> column = columns.get(columnName);
if (column == null)
return defaultValue;
return column.getIntegerValue();
}
@Override
public Double getDouble(C columnName, Double defaultValue) {
Column<C> column = columns.get(columnName);
if (column == null)
return defaultValue;
return column.getDoubleValue();
}
@Override
public Long getLong(C columnName, Long defaultValue) {
Column<C> column = columns.get(columnName);
if (column == null)
return defaultValue;
return column.getLongValue();
}
@Override
public byte[] getByteArray(C columnName, byte[] defaultValue) {
Column<C> column = columns.get(columnName);
if (column == null)
return defaultValue;
return column.getByteArrayValue();
}
@Override
public Boolean getBoolean(C columnName, Boolean defaultValue) {
Column<C> column = columns.get(columnName);
if (column == null)
return defaultValue;
return column.getBooleanValue();
}
@Override
public ByteBuffer getByteBuffer(C columnName, ByteBuffer defaultValue) {
Column<C> column = columns.get(columnName);
if (column == null)
return defaultValue;
return column.getByteBufferValue();
}
@Override
public Date getDate(C columnName, Date defaultValue) {
Column<C> column = columns.get(columnName);
if (column == null)
return defaultValue;
return column.getDateValue();
}
@Override
public UUID getUUID(C columnName, UUID defaultValue) {
Column<C> column = columns.get(columnName);
if (column == null)
return defaultValue;
return column.getUUIDValue();
}
@Override
public boolean isEmpty() {
return columns.isEmpty();
}
@Override
public int size() {
return columns.size();
}
@Override
public Map<C, Column<C>> asMap() {
return columns;
}
}
| 7,868 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/AbstractComposite.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.model;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import com.netflix.astyanax.shaded.org.apache.cassandra.utils.ByteBufferUtil;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableClassToInstanceMap;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.serializers.AsciiSerializer;
import com.netflix.astyanax.serializers.BigIntegerSerializer;
import com.netflix.astyanax.serializers.BooleanSerializer;
import com.netflix.astyanax.serializers.ByteBufferOutputStream;
import com.netflix.astyanax.serializers.ByteBufferSerializer;
import com.netflix.astyanax.serializers.ComparatorType;
import com.netflix.astyanax.serializers.IntegerSerializer;
import com.netflix.astyanax.serializers.LongSerializer;
import com.netflix.astyanax.serializers.SerializerTypeInferer;
import com.netflix.astyanax.serializers.StringSerializer;
import com.netflix.astyanax.serializers.UUIDSerializer;
/**
* Parent class of Composite and DynamicComposite. Acts as a list of objects
* that get serialized into a composite column name. Unless
* setAutoDeserialize(true) is called, it's going to try to match serializers to
* Cassandra comparator types.
*
* @author edanuff
*/
@SuppressWarnings("rawtypes")
public abstract class AbstractComposite extends AbstractList<Object> implements Comparable<AbstractComposite> {
public enum ComponentEquality {
LESS_THAN_EQUAL((byte) -1), EQUAL((byte) 0), GREATER_THAN_EQUAL((byte) 1);
private final byte equality;
ComponentEquality(byte equality) {
this.equality = equality;
}
public byte toByte() {
return equality;
}
public static ComponentEquality fromByte(byte equality) {
if (equality > 0) {
return GREATER_THAN_EQUAL;
}
if (equality < 0) {
return LESS_THAN_EQUAL;
}
return EQUAL;
}
}
static final Logger logger = Logger.getLogger(AbstractComposite.class.getName());
public static final BiMap<Class<? extends Serializer>, String> DEFAULT_SERIALIZER_TO_COMPARATOR_MAPPING = new ImmutableBiMap.Builder<Class<? extends Serializer>, String>()
.put(IntegerSerializer.class, IntegerSerializer.get().getComparatorType().getTypeName())
.put(BooleanSerializer.class, BooleanSerializer.get().getComparatorType().getTypeName())
.put(AsciiSerializer.class, AsciiSerializer.get().getComparatorType().getTypeName())
.put(BigIntegerSerializer.class, BigIntegerSerializer.get().getComparatorType().getTypeName())
.put(ByteBufferSerializer.class, ByteBufferSerializer.get().getComparatorType().getTypeName())
.put(LongSerializer.class, LongSerializer.get().getComparatorType().getTypeName())
.put(StringSerializer.class, StringSerializer.get().getComparatorType().getTypeName())
.put(UUIDSerializer.class, UUIDSerializer.get().getComparatorType().getTypeName()).build();
static final ImmutableClassToInstanceMap<Serializer> SERIALIZERS = new ImmutableClassToInstanceMap.Builder<Serializer>()
.put(IntegerSerializer.class, IntegerSerializer.get())
.put(BooleanSerializer.class, BooleanSerializer.get())
.put(AsciiSerializer.class, AsciiSerializer.get())
.put(BigIntegerSerializer.class, BigIntegerSerializer.get())
.put(ByteBufferSerializer.class, ByteBufferSerializer.get())
.put(LongSerializer.class, LongSerializer.get())
.put(StringSerializer.class, StringSerializer.get())
.put(UUIDSerializer.class, UUIDSerializer.get()).build();
public static final BiMap<Byte, String> DEFAULT_ALIAS_TO_COMPARATOR_MAPPING = new ImmutableBiMap.Builder<Byte, String>()
.put((byte) 'a', ComparatorType.ASCIITYPE.getTypeName())
.put((byte) 'b', ComparatorType.BYTESTYPE.getTypeName())
.put((byte) 'i', ComparatorType.INTEGERTYPE.getTypeName())
.put((byte) 'x', ComparatorType.LEXICALUUIDTYPE.getTypeName())
.put((byte) 'l', ComparatorType.LONGTYPE.getTypeName())
.put((byte) 't', ComparatorType.TIMEUUIDTYPE.getTypeName())
.put((byte) 's', ComparatorType.UTF8TYPE.getTypeName())
.put((byte) 'u', ComparatorType.UUIDTYPE.getTypeName()).build();
BiMap<Class<? extends Serializer>, String> serializerToComparatorMapping = DEFAULT_SERIALIZER_TO_COMPARATOR_MAPPING;
BiMap<Byte, String> aliasToComparatorMapping = DEFAULT_ALIAS_TO_COMPARATOR_MAPPING;
final boolean dynamic;
List<Serializer<?>> serializersByPosition = null;
List<String> comparatorsByPosition = null;
public class Component<T> {
final Serializer<T> serializer;
final T value;
final ByteBuffer bytes;
final String comparator;
final ComponentEquality equality;
public Component(T value, ByteBuffer bytes, Serializer<T> serializer, String comparator,
ComponentEquality equality) {
this.serializer = serializer;
this.value = value;
this.bytes = bytes;
this.comparator = comparator;
this.equality = equality;
}
public Serializer<T> getSerializer() {
return serializer;
}
@SuppressWarnings("unchecked")
public <A> A getValue(Serializer<A> s) {
if (s == null) {
s = (Serializer<A>) serializer;
}
if ((value == null) && (bytes != null) && (s != null)) {
ByteBuffer cb = bytes.duplicate();
if (cb.hasRemaining()) {
return s.fromByteBuffer(cb);
}
}
if (value instanceof ByteBuffer) {
return (A) ((ByteBuffer) value).duplicate();
}
return (A) value;
}
public T getValue() {
return getValue(serializer);
}
@SuppressWarnings("unchecked")
public <A> ByteBuffer getBytes(Serializer<A> s) {
if (bytes == null) {
if (value instanceof ByteBuffer) {
return ((ByteBuffer) value).duplicate();
}
if (value == null) {
return null;
}
if (s == null) {
s = (Serializer<A>) serializer;
}
if (s != null) {
return s.toByteBuffer((A) value).duplicate();
}
}
return bytes.duplicate();
}
public ByteBuffer getBytes() {
return getBytes(serializer);
}
public String getComparator() {
return comparator;
}
public ComponentEquality getEquality() {
return equality;
}
@Override
public String toString() {
return "Component [" + getValue() + "]";
}
}
List<Component<?>> components = new ArrayList<Component<?>>();
ByteBuffer serialized = null;
public AbstractComposite(boolean dynamic) {
this.dynamic = dynamic;
}
public AbstractComposite(boolean dynamic, Object... o) {
this.dynamic = dynamic;
this.addAll(Arrays.asList(o));
}
public AbstractComposite(boolean dynamic, List<?> l) {
this.dynamic = dynamic;
this.addAll(l);
}
public List<Component<?>> getComponents() {
return components;
}
public void setComponents(List<Component<?>> components) {
serialized = null;
this.components = components;
}
public Map<Class<? extends Serializer>, String> getSerializerToComparatorMapping() {
return serializerToComparatorMapping;
}
public void setSerializerToComparatorMapping(Map<Class<? extends Serializer>, String> serializerToComparatorMapping) {
serialized = null;
this.serializerToComparatorMapping = new ImmutableBiMap.Builder<Class<? extends Serializer>, String>().putAll(
serializerToComparatorMapping).build();
}
public Map<Byte, String> getAliasesToComparatorMapping() {
return aliasToComparatorMapping;
}
public void setAliasesToComparatorMapping(Map<Byte, String> aliasesToComparatorMapping) {
serialized = null;
aliasToComparatorMapping = new ImmutableBiMap.Builder<Byte, String>().putAll(aliasesToComparatorMapping)
.build();
}
public boolean isDynamic() {
return dynamic;
}
public List<Serializer<?>> getSerializersByPosition() {
return serializersByPosition;
}
public void setSerializersByPosition(List<Serializer<?>> serializersByPosition) {
this.serializersByPosition = serializersByPosition;
}
public void setSerializersByPosition(Serializer<?>... serializers) {
serializersByPosition = Arrays.asList(serializers);
}
public void setSerializerByPosition(int index, Serializer<?> s) {
if (serializersByPosition == null) {
serializersByPosition = new ArrayList<Serializer<?>>();
}
while (serializersByPosition.size() <= index) {
serializersByPosition.add(null);
}
serializersByPosition.set(index, s);
}
public List<String> getComparatorsByPosition() {
return comparatorsByPosition;
}
public void setComparatorsByPosition(List<String> comparatorsByPosition) {
this.comparatorsByPosition = comparatorsByPosition;
}
public void setComparatorsByPosition(String... comparators) {
comparatorsByPosition = Arrays.asList(comparators);
}
public void setComparatorByPosition(int index, String c) {
if (comparatorsByPosition == null) {
comparatorsByPosition = new ArrayList<String>();
}
while (comparatorsByPosition.size() <= index) {
comparatorsByPosition.add(null);
}
comparatorsByPosition.set(index, c);
}
@Override
public int compareTo(AbstractComposite o) {
return serialize().compareTo(o.serialize());
}
private String comparatorForSerializer(Serializer<?> s) {
String comparator = serializerToComparatorMapping.get(s.getClass());
if (comparator != null) {
return comparator;
}
return ComparatorType.BYTESTYPE.getTypeName();
}
private Serializer<?> serializerForComparator(String c) {
int p = c.indexOf('(');
if (p >= 0) {
c = c.substring(0, p);
}
if (ComparatorType.LEXICALUUIDTYPE.getTypeName().equals(c)
|| ComparatorType.TIMEUUIDTYPE.getTypeName().equals(c)) {
return UUIDSerializer.get();
}
Serializer<?> s = SERIALIZERS.getInstance(serializerToComparatorMapping.inverse().get(c));
if (s != null) {
return s;
}
return ByteBufferSerializer.get();
}
private Serializer<?> serializerForPosition(int i) {
if (serializersByPosition == null) {
return null;
}
if (i >= serializersByPosition.size()) {
return null;
}
return serializersByPosition.get(i);
}
private Serializer<?> getSerializer(int i, String c) {
Serializer<?> s = serializerForPosition(i);
if (s != null) {
return s;
}
return serializerForComparator(c);
}
private String comparatorForPosition(int i) {
if (comparatorsByPosition == null) {
return null;
}
if (i >= comparatorsByPosition.size()) {
return null;
}
return comparatorsByPosition.get(i);
}
private String getComparator(int i, ByteBuffer bb) {
String name = comparatorForPosition(i);
if (name != null) {
return name;
}
if (!dynamic) {
if (bb.hasRemaining()) {
return ComparatorType.BYTESTYPE.getTypeName();
}
else {
return null;
}
}
if (bb.hasRemaining()) {
try {
int header = getShortLength(bb);
if ((header & 0x8000) == 0) {
name = ByteBufferUtil.string(getBytes(bb, header));
}
else {
byte a = (byte) (header & 0xFF);
name = aliasToComparatorMapping.get(a);
if (name == null) {
a = (byte) Character.toLowerCase((char) a);
name = aliasToComparatorMapping.get(a);
if (name != null) {
name += "(reversed=true)";
}
}
}
}
catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
}
if ((name != null) && (name.length() == 0)) {
name = null;
}
return name;
}
@Override
public void clear() {
serialized = null;
components = new ArrayList<Component<?>>();
}
@Override
public int size() {
return components.size();
}
public <T> AbstractComposite addComponent(T value, Serializer<T> s) {
addComponent(value, s, comparatorForSerializer(s));
return this;
}
public <T> AbstractComposite addComponent(T value, Serializer<T> s, ComponentEquality equality) {
addComponent(value, s, comparatorForSerializer(s), equality);
return this;
}
public <T> AbstractComposite addComponent(T value, Serializer<T> s, String comparator) {
addComponent(value, s, comparator, ComponentEquality.EQUAL);
return this;
}
public <T> AbstractComposite addComponent(T value, Serializer<T> s, String comparator, ComponentEquality equality) {
addComponent(-1, value, s, comparator, equality);
return this;
}
@SuppressWarnings("unchecked")
public <T> AbstractComposite addComponent(int index, T value, Serializer<T> s, String comparator,
ComponentEquality equality) {
serialized = null;
if (index < 0) {
index = components.size();
}
while (components.size() < index) {
components.add(null);
}
components.add(index, new Component(value, null, s, comparator, equality));
return this;
}
private static Object mapIfNumber(Object o) {
if ((o instanceof Byte) || (o instanceof Integer) || (o instanceof Short)) {
return BigInteger.valueOf(((Number) o).longValue());
}
return o;
}
@SuppressWarnings({ "unchecked" })
private static Collection<?> flatten(Collection<?> c) {
if (c instanceof AbstractComposite) {
return ((AbstractComposite) c).getComponents();
}
boolean hasCollection = false;
for (Object o : c) {
if (o instanceof Collection) {
hasCollection = true;
break;
}
}
if (!hasCollection) {
return c;
}
List newList = new ArrayList();
for (Object o : c) {
if (o instanceof Collection) {
newList.addAll(flatten((Collection) o));
}
else {
newList.add(o);
}
}
return newList;
}
@Override
public boolean addAll(Collection<? extends Object> c) {
return super.addAll(flatten(c));
}
@Override
public boolean containsAll(Collection<?> c) {
return super.containsAll(flatten(c));
}
@Override
public boolean removeAll(Collection<?> c) {
return super.removeAll(flatten(c));
}
@Override
public boolean retainAll(Collection<?> c) {
return super.retainAll(flatten(c));
}
@Override
public boolean addAll(int i, Collection<? extends Object> c) {
return super.addAll(i, flatten(c));
}
@SuppressWarnings("unchecked")
@Override
public void add(int index, Object element) {
serialized = null;
if (element instanceof Component) {
components.add(index, (Component<?>) element);
return;
}
element = mapIfNumber(element);
Serializer s = serializerForPosition(index);
if (s == null) {
s = SerializerTypeInferer.getSerializer(element);
}
String c = comparatorForPosition(index);
if (c == null) {
c = comparatorForSerializer(s);
}
components.add(index, new Component(element, null, s, c, ComponentEquality.EQUAL));
}
@Override
public Object remove(int index) {
serialized = null;
Component prev = components.remove(index);
if (prev != null) {
return prev.getValue();
}
return null;
}
public <T> AbstractComposite setComponent(int index, T value, Serializer<T> s) {
setComponent(index, value, s, comparatorForSerializer(s));
return this;
}
public <T> AbstractComposite setComponent(int index, T value, Serializer<T> s, String comparator) {
setComponent(index, value, s, comparator, ComponentEquality.EQUAL);
return this;
}
@SuppressWarnings("unchecked")
public <T> AbstractComposite setComponent(int index, T value, Serializer<T> s, String comparator,
ComponentEquality equality) {
serialized = null;
while (components.size() <= index) {
components.add(null);
}
components.set(index, new Component(value, null, s, comparator, equality));
return this;
}
@SuppressWarnings("unchecked")
@Override
public Object set(int index, Object element) {
serialized = null;
if (element instanceof Component) {
Component prev = components.set(index, (Component<?>) element);
if (prev != null) {
return prev.getValue();
}
return null;
}
element = mapIfNumber(element);
Serializer s = serializerForPosition(index);
if (s == null) {
s = SerializerTypeInferer.getSerializer(element);
}
String c = comparatorForPosition(index);
if (c == null) {
c = comparatorForSerializer(s);
}
Component prev = components.set(index, new Component(element, null, s, c, ComponentEquality.EQUAL));
if (prev != null) {
return prev.getValue();
}
return null;
}
@Override
public Object get(int i) {
Component c = components.get(i);
if (c != null) {
return c.getValue();
}
return null;
}
public <T> T get(int i, Serializer<T> s) throws ClassCastException {
T value = null;
Component<?> c = components.get(i);
if (c != null) {
value = c.getValue(s);
}
return value;
}
public Component getComponent(int i) {
if (i >= components.size()) {
return null;
}
Component c = components.get(i);
return c;
}
public Iterator<Component<?>> componentsIterator() {
return components.iterator();
}
@SuppressWarnings("unchecked")
public ByteBuffer serialize() {
if (serialized != null) {
return serialized.duplicate();
}
ByteBufferOutputStream out = new ByteBufferOutputStream();
int i = 0;
for (Component c : components) {
Serializer<?> s = serializerForPosition(i);
ByteBuffer cb = c.getBytes(s);
if (cb == null) {
cb = ByteBuffer.allocate(0);
}
if (dynamic) {
String comparator = comparatorForPosition(i);
if (comparator == null) {
comparator = c.getComparator();
}
if (comparator == null) {
comparator = ComparatorType.BYTESTYPE.getTypeName();
}
int p = comparator.indexOf("(reversed=true)");
boolean desc = false;
if (p >= 0) {
comparator = comparator.substring(0, p);
desc = true;
}
if (aliasToComparatorMapping.inverse().containsKey(comparator)) {
byte a = aliasToComparatorMapping.inverse().get(comparator);
if (desc) {
a = (byte) Character.toUpperCase((char) a);
}
out.writeShort((short) (0x8000 | a));
}
else {
out.writeShort((short) comparator.length());
out.write(ByteBufferUtil.bytes(comparator));
}
}
out.writeShort((short) cb.remaining());
out.write(cb.slice());
out.write(c.getEquality().toByte());
i++;
}
serialized = out.getByteBuffer();
return serialized.duplicate();
}
@SuppressWarnings("unchecked")
public void deserialize(ByteBuffer b) {
serialized = b.duplicate();
components = new ArrayList<Component<?>>();
String comparator = null;
int i = 0;
while ((comparator = getComparator(i, b)) != null) {
ByteBuffer data = getWithShortLength(b);
if (data != null) {
Serializer<?> s = getSerializer(i, comparator);
ComponentEquality equality = ComponentEquality.fromByte(b.get());
components.add(new Component(null, data.slice(), s, comparator, equality));
}
else {
throw new RuntimeException("Missing component data in composite type");
}
i++;
}
}
protected static int getShortLength(ByteBuffer bb) {
int length = (bb.get() & 0xFF) << 8;
return length | (bb.get() & 0xFF);
}
protected static ByteBuffer getBytes(ByteBuffer bb, int length) {
ByteBuffer copy = bb.duplicate();
copy.limit(copy.position() + length);
bb.position(bb.position() + length);
return copy;
}
protected static ByteBuffer getWithShortLength(ByteBuffer bb) {
int length = getShortLength(bb);
return getBytes(bb, length);
}
}
| 7,869 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/RangeEndpoint.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
public interface RangeEndpoint {
ByteBuffer toBytes();
RangeEndpoint append(Object value, Equality equality);
}
| 7,870 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/ColumnFamily.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.ddl.ColumnFamilyDefinition;
import com.netflix.astyanax.ddl.KeyspaceDefinition;
import com.netflix.astyanax.impl.PreparedIndexExpressionImpl;
import com.netflix.astyanax.query.PreparedIndexExpression;
import com.netflix.astyanax.serializers.ByteBufferSerializer;
/**
* Basic column family definition. The column family definition encapsulates the
* column family name as well as the type and serializers for the row keys and
* first level columns. Super column subcolumn name type and serializers are
* specified using a ColumnPath.
*
* @author elandau
*
* @param <K>
* @param <C>
*/
public class ColumnFamily<K, C> implements Comparable<ColumnFamily<K,C>>{
private final String columnFamilyName;
private final Serializer<K> keySerializer;
private final Serializer<C> columnSerializer;
private final Serializer<?> defaultValueSerializer;
private final ColumnType type;
private ColumnFamilyDefinition cfDef;
private String keyAlias = "key";
/**
* @param columnFamilyName
* @param keySerializer
* @param columnSerializer
* @param type
* @deprecated Super columns should be replaced with composite columns
*/
public ColumnFamily(String columnFamilyName, Serializer<K> keySerializer, Serializer<C> columnSerializer,
ColumnType type) {
this.columnFamilyName = columnFamilyName;
this.keySerializer = keySerializer;
this.columnSerializer = columnSerializer;
this.defaultValueSerializer = ByteBufferSerializer.get();
this.type = type;
}
public ColumnFamily(String columnFamilyName, Serializer<K> keySerializer, Serializer<C> columnSerializer) {
this(columnFamilyName, keySerializer, columnSerializer, ByteBufferSerializer.get());
}
public ColumnFamily(String columnFamilyName, Serializer<K> keySerializer, Serializer<C> columnSerializer, Serializer<?> defaultValueSerializer) {
this.columnFamilyName = columnFamilyName;
this.keySerializer = keySerializer;
this.columnSerializer = columnSerializer;
this.defaultValueSerializer = defaultValueSerializer;
this.type = ColumnType.STANDARD;
}
public String getName() {
return columnFamilyName;
}
/**
* Serializer for first level column names. This serializer does not apply
* to sub column names.
*
* @return
*/
public Serializer<C> getColumnSerializer() {
return columnSerializer;
}
/**
* Serializer used to generate row keys.
*
* @return
*/
public Serializer<K> getKeySerializer() {
return keySerializer;
}
public Serializer<?> getDefaultValueSerializer() {
return defaultValueSerializer;
}
/**
* Type of columns in this column family (Standard or Super)
*
* @deprecated Super columns should be replaced with composite columns
* @return
*/
public ColumnType getType() {
return type;
}
public void setKeyAlias(String alias) {
keyAlias = alias;
}
public String getKeyAlias() {
return keyAlias;
}
public PreparedIndexExpression<K, C> newIndexClause() {
return new PreparedIndexExpressionImpl<K, C>(this.columnSerializer);
}
public static <K, C> ColumnFamily<K, C> newColumnFamily(String columnFamilyName, Serializer<K> keySerializer,
Serializer<C> columnSerializer) {
return new ColumnFamily<K, C>(columnFamilyName, keySerializer, columnSerializer);
}
public static <K, C> ColumnFamily<K, C> newColumnFamily(String columnFamilyName, Serializer<K> keySerializer,
Serializer<C> columnSerializer, Serializer<?> defaultSerializer) {
return new ColumnFamily<K, C>(columnFamilyName, keySerializer, columnSerializer, defaultSerializer);
}
@Override
public int compareTo(ColumnFamily<K, C> other) {
return getName().compareTo(other.getName());
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof ColumnFamily))
return false;
ColumnFamily other = (ColumnFamily) obj;
return (getName() == null) ? other.getName() == null : getName().equals(other.getName());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
return result;
}
public boolean inThriftMode() {
return true;
}
public ColumnFamilyDefinition describe(Keyspace keyspace) throws ConnectionException {
KeyspaceDefinition ksDef = keyspace.describeKeyspace();
cfDef = ksDef.getColumnFamily(this.getName());
return cfDef;
}
public ColumnFamilyDefinition getColumnFamilyDefinition() {
return cfDef;
}
}
| 7,871 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/ColumnSlice.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.util.Collection;
/**
* Definition for a sub set of slices. A subset can either be a fixed set of
* columns a range of ordered columns. The slice defines the sub set of columns
* at the ColumnPath position within the row.
*
* @author elandau
*
* @param <C>
*/
public class ColumnSlice<C> {
private Collection<C> columns;
// - or -
private C startColumn;
private C endColumn;
private boolean reversed = false;
private int limit = Integer.MAX_VALUE;
public ColumnSlice(Collection<C> columns) {
this.columns = columns;
}
public ColumnSlice(C startColumn, C endColumn) {
this.startColumn = startColumn;
this.endColumn = endColumn;
}
public ColumnSlice<C> setLimit(int limit) {
this.limit = limit;
return this;
}
public ColumnSlice<C> setReversed(boolean value) {
this.reversed = value;
return this;
}
public Collection<C> getColumns() {
return columns;
}
public C getStartColumn() {
return startColumn;
}
public C getEndColumn() {
return endColumn;
}
public boolean getReversed() {
return reversed;
}
public int getLimit() {
return limit;
}
}
| 7,872 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/ConsistencyLevel.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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.
*/
/**
* ConsistencyLevel.java
* dsmirnov Mar 31, 2011
*/
package com.netflix.astyanax.model;
/**
* Consistency Level thin abstraction
*
* @author dsmirnov
*
*/
public enum ConsistencyLevel {
CL_ONE, CL_QUORUM, CL_ALL, CL_ANY, CL_EACH_QUORUM, CL_LOCAL_QUORUM, CL_TWO, CL_THREE, CL_LOCAL_ONE;
}
| 7,873 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/AbstractColumnList.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.UUID;
import com.netflix.astyanax.Serializer;
public abstract class AbstractColumnList<C> implements ColumnList<C> {
@Override
public String getStringValue(C columnName, String defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getStringValue();
}
@Override
public Integer getIntegerValue(C columnName, Integer defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getIntegerValue();
}
@Override
public Double getDoubleValue(C columnName, Double defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getDoubleValue();
}
@Override
public Long getLongValue(C columnName, Long defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getLongValue();
}
@Override
public byte[] getByteArrayValue(C columnName, byte[] defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getByteArrayValue();
}
@Override
public Boolean getBooleanValue(C columnName, Boolean defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getBooleanValue();
}
@Override
public ByteBuffer getByteBufferValue(C columnName, ByteBuffer defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getByteBufferValue();
}
@Override
public Date getDateValue(C columnName, Date defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getDateValue();
}
@Override
public UUID getUUIDValue(C columnName, UUID defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getUUIDValue();
}
@Override
public <T> T getValue(C columnName, Serializer<T> serializer, T defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getValue(serializer);
}
@Override
public String getCompressedStringValue(C columnName, String defaultValue) {
Column<C> column = getColumnByName(columnName);
if (column == null || !column.hasValue())
return defaultValue;
return column.getCompressedStringValue();
}
}
| 7,874 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/Rows.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.util.Collection;
/**
* Interface to a collection or Rows with key type K and column type C. The rows
* can be either super or standard, but not both.
*
* @author elandau
*
* @param <K>
* @param <C>
*/
public interface Rows<K, C> extends Iterable<Row<K, C>> {
/**
* Return all row keys in the set
* @return
*/
Collection<K> getKeys();
/**
* Return the row for a specific key. Will return an exception if the result
* set is a list and not a lookup.
*
* @param key
* @return
*/
Row<K, C> getRow(K key);
/**
* Return a row by it's index in the response.
*
* @param i
*/
Row<K, C> getRowByIndex(int i);
/**
* Get the number of rows in the list
*
* @return integer representing the number of rows in the list
*/
int size();
/**
* Determine if the row list has data
*
* @return
*/
boolean isEmpty();
}
| 7,875 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/CompositeParserImpl.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.UUID;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.serializers.BooleanSerializer;
import com.netflix.astyanax.serializers.IntegerSerializer;
import com.netflix.astyanax.serializers.LongSerializer;
import com.netflix.astyanax.serializers.StringSerializer;
import com.netflix.astyanax.serializers.UUIDSerializer;
public class CompositeParserImpl implements CompositeParser {
private final Composite composite;
private int position = 0;
public CompositeParserImpl(ByteBuffer bb) {
this.composite = Composite.fromByteBuffer(bb);
}
@Override
public String readString() {
return read( StringSerializer.get() );
}
@Override
public Long readLong() {
return read( LongSerializer.get() );
}
@Override
public Integer readInteger() {
return read( IntegerSerializer.get() );
}
@Override
public Boolean readBoolean() {
return read( BooleanSerializer.get() );
}
@Override
public UUID readUUID() {
return read( UUIDSerializer.get() );
}
@SuppressWarnings("unchecked")
@Override
public <T> T read(Serializer<T> serializer) {
Object obj = this.composite.get(position, serializer);
position++;
return (T) obj;
}
}
| 7,876 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/ColumnPath.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.serializers.DoubleSerializer;
import com.netflix.astyanax.serializers.IntegerSerializer;
import com.netflix.astyanax.serializers.StringSerializer;
/**
* Container for a path within a row. The path is essentially a list of columns
* in hierarchical order. Paths can have any column name type which is
* eventually converted to a ByteBuffer.
*
* When querying a super column the path must also include a serializer for the
* sub columns names. The serializer is not needed when reading a subcolumn or
* standard column.
*
* The current Cassandra implementation only supports a path depth of 2.
*
* C - Serializer for column names at the end of the path. For super columns. C2
* - Serializer for a column name that is part of the path
*
* @author elandau
*
* TODO: Add append for all serializer types
* @deprecated Super columns should be replaced with composite columns
*/
public class ColumnPath<C> implements Iterable<ByteBuffer> {
private List<ByteBuffer> path = new ArrayList<ByteBuffer>();
private Serializer<C> columnSerializer;
/**
* Construct an empty path and give it the serializer for column names at
* the end of the path. Use this constructor when performing a query
*
* @param columnSerializer
*/
public ColumnPath(Serializer<C> columnSerializer) {
this.columnSerializer = columnSerializer;
}
/**
* Construct a column path for a mutation. The serializer for the column
* names at the end of the path is not necessary.
*/
public ColumnPath() {
}
/**
* Add a depth to the path
*
* @param <C>
* @param ser
* @param name
* @return
*/
public <C2> ColumnPath<C> append(C2 name, Serializer<C2> ser) {
path.add(ByteBuffer.wrap(ser.toBytes(name)));
return this;
}
public <C2> ColumnPath<C> append(String name) {
append(name, StringSerializer.get());
return this;
}
public <C2> ColumnPath<C> append(int name) {
append(name, IntegerSerializer.get());
return this;
}
public <C2> ColumnPath<C> append(double name) {
append(name, DoubleSerializer.get());
return this;
}
@Override
public Iterator<ByteBuffer> iterator() {
return path.iterator();
}
/**
* Return the path 'depth'
*
* @return
*/
public int length() {
return path.size();
}
/**
* Get a path element from a specific depth
*
* @param index
* @return
*/
public ByteBuffer get(int index) {
return path.get(index);
}
/**
* Returns the last element in the path. This is usually the column name
* being queried or modified.
*
* @return
*/
public ByteBuffer getLast() {
return path.get(path.size() - 1);
}
/**
* Return serializer for column names at the end of the path
*
* @return
*/
public Serializer<C> getSerializer() {
return this.columnSerializer;
}
}
| 7,877 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/DynamicComposite.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.List;
public class DynamicComposite extends AbstractComposite {
public DynamicComposite() {
super(true);
}
public DynamicComposite(Object... o) {
super(true, o);
}
public DynamicComposite(List<?> l) {
super(true, l);
}
public static DynamicComposite fromByteBuffer(ByteBuffer byteBuffer) {
DynamicComposite composite = new DynamicComposite();
composite.deserialize(byteBuffer);
return composite;
}
public static ByteBuffer toByteBuffer(Object... o) {
DynamicComposite composite = new DynamicComposite(o);
return composite.serialize();
}
public static ByteBuffer toByteBuffer(List<?> l) {
DynamicComposite composite = new DynamicComposite(l);
return composite.serialize();
}
} | 7,878 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/Row.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
/**
* Instance of a row with key type K and column name type C. Child columns can
* be either standard columns or super columns
*
* @author elandau
*
* @param <K>
* @param <C>
*/
public interface Row<K, C> {
/**
* Return the key value
*
* @return
*/
K getKey();
/**
* Return the raw byte buffer for this key
*
* @return
*/
ByteBuffer getRawKey();
/**
* Child columns of the row. Note that if a ColumnPath was provided to a
* query these will be the columns at the column path location and not the
* columns at the root of the row.
*
* @return
*/
ColumnList<C> getColumns();
}
| 7,879 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/CompositeBuilderImpl.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.model.AbstractComposite.ComponentEquality;
import com.netflix.astyanax.serializers.BooleanSerializer;
import com.netflix.astyanax.serializers.ByteBufferSerializer;
import com.netflix.astyanax.serializers.IntegerSerializer;
import com.netflix.astyanax.serializers.LongSerializer;
import com.netflix.astyanax.serializers.StringSerializer;
import com.netflix.astyanax.serializers.TimeUUIDSerializer;
import com.netflix.astyanax.serializers.UUIDSerializer;
import com.netflix.astyanax.util.TimeUUIDUtils;
public class CompositeBuilderImpl implements CompositeBuilder {
private AbstractComposite composite;
private ComponentEquality equality = ComponentEquality.EQUAL;
public CompositeBuilderImpl(AbstractComposite composite) {
this.composite = composite;
}
@Override
public CompositeBuilder addString(String value) {
composite.addComponent(value, StringSerializer.get(), equality);
return this;
}
@Override
public CompositeBuilder addLong(Long value) {
composite.addComponent(value, LongSerializer.get(), equality);
return this;
}
@Override
public CompositeBuilder addInteger(Integer value) {
composite.addComponent(value, IntegerSerializer.get(), equality);
return this;
}
@Override
public CompositeBuilder addBoolean(Boolean value) {
composite.addComponent(value, BooleanSerializer.get(), equality);
return this;
}
@Override
public CompositeBuilder addUUID(UUID value) {
composite.addComponent(value, UUIDSerializer.get(), equality);
return this;
}
@Override
public <T> CompositeBuilder add(T value, Serializer<T> serializer) {
composite.addComponent(value, serializer, equality);
return this;
}
@Override
public CompositeBuilder addTimeUUID(UUID value) {
composite.addComponent(value, TimeUUIDSerializer.get(), equality);
return this;
}
@Override
public CompositeBuilder addTimeUUID(Long value, TimeUnit units) {
composite.addComponent(TimeUUIDUtils.getMicrosTimeUUID(TimeUnit.MICROSECONDS.convert(value, units)),
TimeUUIDSerializer.get(), equality);
return this;
}
@Override
public CompositeBuilder addBytes(byte[] bytes) {
composite.addComponent(ByteBuffer.wrap(bytes), ByteBufferSerializer.get(), equality);
return this;
}
@Override
public CompositeBuilder addBytes(ByteBuffer bb) {
composite.addComponent(bb, ByteBufferSerializer.get(), equality);
return this;
}
@Override
public ByteBuffer build() {
return composite.serialize();
}
@Override
public CompositeBuilder greaterThanEquals() {
equality = ComponentEquality.GREATER_THAN_EQUAL;
return this;
}
@Override
public CompositeBuilder lessThanEquals() {
equality = ComponentEquality.LESS_THAN_EQUAL;
return this;
}
}
| 7,880 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/Equality.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
public enum Equality {
LESS_THAN((byte) -1), GREATER_THAN_EQUALS((byte) -1), EQUAL((byte) 0), GREATER_THAN((byte) 1), LESS_THAN_EQUALS(
(byte) 1);
private final byte equality;
Equality(byte equality) {
this.equality = equality;
}
public byte toByte() {
return equality;
}
public static Equality fromByte(byte equality) {
if (equality > 0) {
return GREATER_THAN;
}
if (equality < 0) {
return LESS_THAN;
}
return EQUAL;
}
}
| 7,881 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/ColumnList.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Date;
import java.util.UUID;
import com.netflix.astyanax.Serializer;
/**
* Interface to a list of columns.
*
* @author elandau
*
* @param <C>
* Data type for column names
*/
public interface ColumnList<C> extends Iterable<Column<C>> {
/**
* Return the column names
*/
Collection<C> getColumnNames();
/**
* Queries column by name
*
* @param columnName
* @return an instance of a column or null if not found
* @throws Exception
*/
Column<C> getColumnByName(C columnName);
/**
* Return value as a string
*
* @return
*/
String getStringValue(C columnName, String defaultValue);
/**
* Get a string that was stored as a compressed blob
* @param columnName
* @param defaultValue
* @return
*/
String getCompressedStringValue(C columnName, String defaultValue);
/**
* Return value as an integer
*
* @return
*/
Integer getIntegerValue(C columnName, Integer defaultValue);
/**
* Return value as a double
*
* @return
*/
Double getDoubleValue(C columnName, Double defaultValue);
/**
* Return value as a long. Use this to get the value of a counter column
*
* @return
*/
Long getLongValue(C columnName, Long defaultValue);
/**
* Get the raw byte[] value
*
* @return
*/
byte[] getByteArrayValue(C columnName, byte[] defaultValue);
/**
* Get value as a boolean
*
* @return
*/
Boolean getBooleanValue(C columnName, Boolean defaultValue);
/**
* Get the raw ByteBuffer value
*
* @return
*/
ByteBuffer getByteBufferValue(C columnName, ByteBuffer defaultValue);
/**
* Get a value with optional default using a specified serializer
* @param <T>
* @param columnName
* @param serializer
* @param defaultValue
* @return
*/
<T> T getValue(C columnName, Serializer<T> serializer, T defaultValue);
/**
* Get the value as a date object
*
* @return
*/
Date getDateValue(C columnName, Date defaultValue);
/**
* Get the value as a UUID
*
* @return
*/
UUID getUUIDValue(C columnName, UUID defaultValue);
/**
* Queries column by index
*
* @param idx
* @return
* @throws NetflixCassandraException
*/
Column<C> getColumnByIndex(int idx);
/**
* Return the super column with the specified name
*
* @param <C2>
* @param columnName
* @param colSer
* @return
* @throws NetflixCassandraException
* @deprecated Super columns should be replaced with composite columns
*/
<C2> Column<C2> getSuperColumn(C columnName, Serializer<C2> colSer);
/**
* Get super column by index
*
* @param idx
* @return
* @throws NetflixCassandraException
* @deprecated Super columns should be replaced with composite columns
*/
<C2> Column<C2> getSuperColumn(int idx, Serializer<C2> colSer);
/**
* Indicates if the list of columns is empty
*
* @return
*/
boolean isEmpty();
/**
* returns the number of columns in the row
*
* @return
*/
int size();
/**
* Returns true if the columns are super columns with subcolumns. If true
* then use getSuperColumn to call children. Otherwise call getColumnByIndex
* and getColumnByName to get the standard columns in the list.
*
* @return
* @deprecated Super columns should be replaced with composite columns
*/
boolean isSuperColumn();
}
| 7,882 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/Column.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.UUID;
import com.netflix.astyanax.Serializer;
/**
* Common interface for extracting column values after a query.
*
* @author elandau
*
* TODO Add getIntValue, getDoubleValue, ...
*
* @param <C>
* Column name type
*/
public interface Column<C> {
/**
* Column or super column name
*
* @return
*/
C getName();
/**
* Return the raw byet buffer for the column name
*
* @return
*/
ByteBuffer getRawName();
/**
* Returns the column timestamp. Not to be confused with column values that
* happen to be time values.
*
* @return
*/
long getTimestamp();
/**
* Return the value
*
* @param <V>
* value type
* @return
* @throws NetflixCassandraException
*/
<V> V getValue(Serializer<V> valSer);
/**
* Return value as a string
*
* @return
*/
String getStringValue();
/**
* Return a string that was stored as a compressed blob
* @return
*/
String getCompressedStringValue();
/**
* Return value as an integer
*
* @return
*/
byte getByteValue();
/**
* Return value as an integer
*
* @return
*/
short getShortValue();
/**
* Return value as an integer
*
* @return
*/
int getIntegerValue();
/**
* Return value as a float
*
* @return
*/
float getFloatValue();
/**
* Return value as a double
*
* @return
*/
double getDoubleValue();
/**
* Return value as a long. Use this to get the value of a counter column
*
* @return
*/
long getLongValue();
/**
* Get the raw byte[] value
*
* @return
*/
byte[] getByteArrayValue();
/**
* Get value as a boolean
*
* @return
*/
boolean getBooleanValue();
/**
* Get the raw ByteBuffer value
*
* @return
*/
ByteBuffer getByteBufferValue();
/**
* Get the value as a date object
*
* @return
*/
Date getDateValue();
/**
* Get the value as a UUID
*
* @return
*/
UUID getUUIDValue();
/**
* Get columns in the case of a super column. Will throw an exception if
* this is a regular column Valid only if isCompositeColumn returns true
*
* @param <C2>
* Type of column names for sub columns
* @deprecated Super columns should be replaced with composite columns
* @return
*/
@Deprecated
<C2> ColumnList<C2> getSubColumns(Serializer<C2> ser);
/**
* Returns true if the column contains a list of child columns, otherwise
* the column contains a value.
*
* @deprecated Super columns should be replaced with composite columns
* @return
*/
@Deprecated
boolean isParentColumn();
/**
* Get the TTL for this column.
* @return TTL in seconds or 0 if no ttl was set
*/
int getTtl();
/**
* Determine whether the column has a value.
*
* @return True if column has a value or false if value is null or an empty byte array.
*/
boolean hasValue();
}
| 7,883 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/Composite.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.List;
public class Composite extends AbstractComposite {
public Composite() {
super(false);
}
public Composite(Object... o) {
super(false, o);
}
public Composite(List<?> l) {
super(false, l);
}
public static Composite fromByteBuffer(ByteBuffer byteBuffer) {
Composite composite = new Composite();
composite.deserialize(byteBuffer);
return composite;
}
public static ByteBuffer toByteBuffer(Object... o) {
Composite composite = new Composite(o);
return composite.serialize();
}
public static ByteBuffer toByteBuffer(List<?> l) {
Composite composite = new Composite(l);
return composite.serialize();
}
}
| 7,884 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/CqlResult.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
/**
* Interface for a CQL query result. The result can either be a set of rows or a
* count/number.
*
* @author elandau
*
* @param <K>
* @param <C>
*/
public interface CqlResult<K, C> {
Rows<K, C> getRows();
int getNumber();
boolean hasRows();
boolean hasNumber();
}
| 7,885 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/KeySlice.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.util.Collection;
/**
* Definition of a set of keys. The set can be either a fixed set of keys, a
* range of keys or a range of tokens.
*
* @author elandau
*
* @param <K>
*/
public class KeySlice<K> {
private Collection<K> keys;
private K startKey;
private K endKey;
private String startToken;
private String endToken;
private int size = 0;
public KeySlice(Collection<K> keys) {
this.keys = keys;
}
public KeySlice(K startKey, K endKey, String startToken, String endToken, int size) {
this.startKey = startKey;
this.endKey = endKey;
this.startToken = startToken;
this.endToken = endToken;
this.size = size;
}
public Collection<K> getKeys() {
return keys;
}
public K getStartKey() {
return startKey;
}
public K getEndKey() {
return endKey;
}
public String getStartToken() {
return startToken;
}
public String getEndToken() {
return endToken;
}
public int getLimit() {
return size;
}
}
| 7,886 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/CompositeParser.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.util.UUID;
import com.netflix.astyanax.Serializer;
public interface CompositeParser {
String readString();
Long readLong();
Integer readInteger();
Boolean readBoolean();
UUID readUUID();
<T> T read(Serializer<T> serializer);
}
| 7,887 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/ColumnMap.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
public interface ColumnMap<C> extends Iterable<Column<C>> {
/**
* Return the underlying map
* @return
*/
Map<C, Column<C>> asMap();
/**
* Queries column by name
*
* @param columnName
* @return an instance of a column or null if not found
* @throws Exception
*/
Column<C> get(C columnName);
/**
* Return value as a string
*
* @return
*/
String getString(C columnName, String defaultValue);
/**
* Return value as an integer
*
* @return
*/
Integer getInteger(C columnName, Integer defaultValue);
/**
* Return value as a double
*
* @return
*/
Double getDouble(C columnName, Double defaultValue);
/**
* Return value as a long. Use this to get the value of a counter column
*
* @return
*/
Long getLong(C columnName, Long defaultValue);
/**
* Get the raw byte[] value
*
* @return
*/
byte[] getByteArray(C columnName, byte[] defaultValue);
/**
* Get value as a boolean
*
* @return
*/
Boolean getBoolean(C columnName, Boolean defaultValue);
/**
* Get the raw ByteBuffer value
*
* @return
*/
ByteBuffer getByteBuffer(C columnName, ByteBuffer defaultValue);
/**
* Get the value as a date object
*
* @return
*/
Date getDate(C columnName, Date defaultValue);
/**
* Get the value as a UUID
*
* @return
*/
UUID getUUID(C columnName, UUID defaultValue);
/**
* Indicates if the list of columns is empty
*
* @return
*/
boolean isEmpty();
/**
* returns the number of columns in the row
*
* @return
*/
int size();
/**
* Add a single column to the collection
* @param column
* @return
*/
OrderedColumnMap<C> add(Column<C> column);
/**
* Add a set of columns to the collection
* @param columns
* @return
*/
OrderedColumnMap<C> addAll(Collection<Column<C>> columns);
}
| 7,888 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/Composites.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
public class Composites {
public static CompositeBuilder newDynamicCompositeBuilder() {
return new CompositeBuilderImpl(new DynamicComposite());
}
public static CompositeBuilder newCompositeBuilder() {
return new CompositeBuilderImpl(new Composite());
}
public static CompositeParser newCompositeParser(ByteBuffer bb) {
return new CompositeParserImpl(bb);
}
public static CompositeParser newDynamicCompositeParser(ByteBuffer bb) {
return null;
}
}
| 7,889 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/AbstractColumnImpl.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.UUID;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.serializers.BooleanSerializer;
import com.netflix.astyanax.serializers.ByteBufferSerializer;
import com.netflix.astyanax.serializers.ByteSerializer;
import com.netflix.astyanax.serializers.BytesArraySerializer;
import com.netflix.astyanax.serializers.DateSerializer;
import com.netflix.astyanax.serializers.DoubleSerializer;
import com.netflix.astyanax.serializers.FloatSerializer;
import com.netflix.astyanax.serializers.IntegerSerializer;
import com.netflix.astyanax.serializers.LongSerializer;
import com.netflix.astyanax.serializers.ShortSerializer;
import com.netflix.astyanax.serializers.StringSerializer;
import com.netflix.astyanax.serializers.UUIDSerializer;
public abstract class AbstractColumnImpl <C> implements Column<C> {
private final C name;
public AbstractColumnImpl(C name) {
this.name = name;
}
@Override
public final C getName() {
return name;
}
@Override
public final String getStringValue() {
return getValue(StringSerializer.get());
}
@Override
public final byte getByteValue() {
return getValue(ByteSerializer.get());
}
@Override
public final short getShortValue() {
return getValue(ShortSerializer.get());
}
@Override
public final int getIntegerValue() {
return getValue(IntegerSerializer.get());
}
@Override
public long getLongValue() {
return getValue(LongSerializer.get());
}
@Override
public final byte[] getByteArrayValue() {
return getValue(BytesArraySerializer.get());
}
@Override
public final boolean getBooleanValue() {
return getValue(BooleanSerializer.get());
}
@Override
public final ByteBuffer getByteBufferValue() {
return getValue(ByteBufferSerializer.get());
}
@Override
public final Date getDateValue() {
return getValue(DateSerializer.get());
}
@Override
public final UUID getUUIDValue() {
return getValue(UUIDSerializer.get());
}
@Override
public final float getFloatValue() {
return getValue(FloatSerializer.get());
}
@Override
public final double getDoubleValue() {
return getValue(DoubleSerializer.get());
}
@Override
public final String getCompressedStringValue() {
throw new UnsupportedOperationException("getCompressedString not yet implemented");
}
@Override
public <C2> ColumnList<C2> getSubColumns(Serializer<C2> ser) {
throw new UnsupportedOperationException("SimpleColumn \'" + name + "\' has no children");
}
@Override
public boolean isParentColumn() {
return false;
}
} | 7,890 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/ByteBufferRange.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
import java.nio.ByteBuffer;
/**
* Interface to get a raw byte buffer range. Subclasses of ByteBufferRange are
* usually builders that simplify their creation.
*
* @author elandau
*
*/
public interface ByteBufferRange {
ByteBuffer getStart();
ByteBuffer getEnd();
boolean isReversed();
int getLimit();
}
| 7,891 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/model/ColumnType.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.model;
/**
*
* @author elandau
* @deprecated Super columns should be replaced with composite columns
*
*/
public enum ColumnType {
STANDARD, SUPER,
}
| 7,892 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/query/PreparedIndexValueExpression.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.query;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.UUID;
import com.netflix.astyanax.Serializer;
public interface PreparedIndexValueExpression<K, C> {
PreparedIndexExpression<K, C> value(String value);
PreparedIndexExpression<K, C> value(long value);
PreparedIndexExpression<K, C> value(int value);
PreparedIndexExpression<K, C> value(boolean value);
PreparedIndexExpression<K, C> value(Date value);
PreparedIndexExpression<K, C> value(byte[] value);
PreparedIndexExpression<K, C> value(ByteBuffer value);
PreparedIndexExpression<K, C> value(double value);
PreparedIndexExpression<K, C> value(UUID value);
<V> PreparedIndexExpression<K, C> value(V value, Serializer<V> valueSerializer);
}
| 7,893 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/query/ColumnQuery.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.query;
import com.netflix.astyanax.Execution;
import com.netflix.astyanax.model.Column;
/**
* Interface to execute a column query on a single row.
*
* @author elandau
*
* @param <C>
*/
public interface ColumnQuery<C> extends Execution<Column<C>> {
}
| 7,894 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/query/PreparedIndexColumnExpression.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.query;
public interface PreparedIndexColumnExpression<K, C> {
/**
* Set the column part of the expression
*
* @param columnName
* @return
*/
PreparedIndexOperationExpression<K, C> whereColumn(C columnName);
}
| 7,895 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/query/IndexOperationExpression.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.query;
public interface IndexOperationExpression<K, C> {
IndexValueExpression<K, C> equals();
IndexValueExpression<K, C> greaterThan();
IndexValueExpression<K, C> lessThan();
IndexValueExpression<K, C> greaterThanEquals();
IndexValueExpression<K, C> lessThanEquals();
}
| 7,896 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/query/PreparedIndexOperationExpression.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.query;
public interface PreparedIndexOperationExpression<K, C> {
PreparedIndexValueExpression<K, C> equals();
PreparedIndexValueExpression<K, C> greaterThan();
PreparedIndexValueExpression<K, C> lessThan();
PreparedIndexValueExpression<K, C> greaterThanEquals();
PreparedIndexValueExpression<K, C> lessThanEquals();
}
| 7,897 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/query/IndexQuery.java | /*******************************************************************************
* Copyright 2011 Netflix
*
* 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 com.netflix.astyanax.query;
import java.nio.ByteBuffer;
import java.util.Collection;
import com.netflix.astyanax.Execution;
import com.netflix.astyanax.model.ByteBufferRange;
import com.netflix.astyanax.model.ColumnSlice;
import com.netflix.astyanax.model.Rows;
public interface IndexQuery<K, C> extends Execution<Rows<K, C>> {
/**
* Limit the number of rows in the response
*
* @param count
* @deprecated Use setRowLimit instead
*/
@Deprecated
IndexQuery<K, C> setLimit(int count);
/**
* Limits the number of rows returned
*
* @param count
*/
IndexQuery<K, C> setRowLimit(int count);
/**
* @param key
*/
IndexQuery<K, C> setStartKey(K key);
/**
* Add an expression (EQ, GT, GTE, LT, LTE) to the clause. Expressions are
* inherently ANDed
*/
IndexColumnExpression<K, C> addExpression();
/**
* Add a set of prepare index expressions.
*
* @param expressions
*/
IndexQuery<K, C> addPreparedExpressions(Collection<PreparedIndexExpression<K, C>> expressions);
/**
* Specify a non-contiguous set of columns to retrieve.
*
* @param columns
*/
IndexQuery<K, C> withColumnSlice(C... columns);
/**
* Specify a non-contiguous set of columns to retrieve.
*
* @param columns
*/
IndexQuery<K, C> withColumnSlice(Collection<C> columns);
/**
* Use this when your application caches the column slice.
*
* @param slice
*/
IndexQuery<K, C> withColumnSlice(ColumnSlice<C> columns);
/**
* Specify a range of columns to return.
*
* @param startColumn
* First column in the range
* @param endColumn
* Last column in the range
* @param reversed
* True if the order should be reversed. Note that for reversed,
* startColumn should be greater than endColumn.
* @param count
* Maximum number of columns to return (similar to SQL LIMIT)
*/
IndexQuery<K, C> withColumnRange(C startColumn, C endColumn, boolean reversed, int count);
/**
* Specify a range and provide pre-constructed start and end columns. Use
* this with Composite columns
*
* @param startColumn
* @param endColumn
* @param reversed
* @param count
*/
IndexQuery<K, C> withColumnRange(ByteBuffer startColumn, ByteBuffer endColumn, boolean reversed, int count);
/**
* Specify a range of composite columns. Use this in conjunction with the
* AnnotatedCompositeSerializer.buildRange().
*
* @param range
*/
IndexQuery<K, C> withColumnRange(ByteBufferRange range);
/**
* @deprecated autoPaginateRows()
*/
IndexQuery<K, C> setIsPaginating();
/**
* Automatically sets the next start key so that the next call to execute
* will fetch the next block of rows
*/
IndexQuery<K, C> autoPaginateRows(boolean autoPaginate);
}
| 7,898 |
0 | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax | Create_ds/astyanax/astyanax-cassandra/src/main/java/com/netflix/astyanax/query/PreparedIndexExpression.java | /**
* Copyright 2013 Netflix, Inc.
*
* 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 com.netflix.astyanax.query;
import java.nio.ByteBuffer;
public interface PreparedIndexExpression<K, C> extends PreparedIndexColumnExpression<K, C> {
public ByteBuffer getColumn();
public ByteBuffer getValue();
public IndexOperator getOperator();
}
| 7,899 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.