public AnnotatedCompositeSerializer<T> clone() { AnnotatedCompositeSerializer<T> clone = new AnnotatedCompositeSerializer<T>(this.clazz, this.bufferSize, false); return clone; }
@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); } }
private static ByteBuffer getWithShortLength(ByteBuffer bb) { int length = getShortLength(bb); return getBytes(bb, length); }
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); }
} else { AnnotatedCompositeSerializer compositeSerializer = (AnnotatedCompositeSerializer) serializer; CompositeRangeBuilder rangeBuilder = compositeSerializer.buildRange(); List<ComponentField> componentFields = componentFieldsForClass(start.getClass()); List<ComponentField> nonNullFields = new ArrayList<ComponentField>();
private void testReadSingleRowColumnRange(boolean rowDeleted) throws Exception { AnnotatedCompositeSerializer<Population> compSerializer = new AnnotatedCompositeSerializer<Population>(Population.class); .withColumnRange(compSerializer.buildRange() .withPrefix("CA") .build()) .withColumnRange(compSerializer.buildRange() .withPrefix("CA") .greaterThan("San Diego") .withColumnRange(compSerializer.buildRange() .withPrefix("WA") .withPrefix("Seattle")
List<MessageContext> entries = Lists.newArrayList(); RangeEndpoint re = ShardedDistributedMessageQueue.entrySerializer .makeEndpoint((byte) MessageQueueEntryType.Message.ordinal(), Equality.EQUAL) .append((byte) 0, Equality.EQUAL); if(lockColumn!=null) { try { ColumnList<MessageMetadataEntry> columns = queue.keyspace.prepareQuery(queue.keyIndexColumnFamily).getRow(groupRowKey).withColumnRange(ShardedDistributedMessageQueue.metadataSerializer.buildRange().greaterThanEquals((byte) MessageMetadataEntryType.MessageId.ordinal()).lessThanEquals((byte) MessageMetadataEntryType.MessageId.ordinal()).build()).execute().getResult(); MessageMetadataEntry mostRecentMessageMetadata = null; long mostRecentTriggerTime = 0;
private static Object getCompositeColumn(Row row, AnnotatedCompositeSerializer<?> compositeSerializer, ColumnFamily<?,?> cf) { Class<?> clazz = compositeSerializer.getClazz(); Object obj = null; try { obj = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } CqlColumnFamilyDefinitionImpl cfDef = (CqlColumnFamilyDefinitionImpl) cf.getColumnFamilyDefinition(); List<ColumnDefinition> cluseringKeyList = cfDef.getClusteringKeyColumnDefinitionList(); int componentIndex = 0; for (ComponentSerializer<?> component : compositeSerializer.getComponents()) { Object value = getDynamicColumn(row, component.getSerializer(), cluseringKeyList.get(componentIndex).getName(), cf); try { component.setFieldValueDirectly(obj, value); componentIndex++; } catch (Exception e) { throw new RuntimeException(e); } } return obj; } }
@Override public BoundStatement bindValues(PreparedStatement pStatement, CqlColumnQueryImpl<?> columnQuery) { List<Object> values = new ArrayList<Object>(); values.add(columnQuery.getRowKey()); ColumnFamily<?,?> cf = columnQuery.getCF(); AnnotatedCompositeSerializer<?> compSerializer = (AnnotatedCompositeSerializer<?>) cf.getColumnSerializer(); List<ComponentSerializer<?>> components = compSerializer.getComponents(); Object columnName = columnQuery.getColumnName(); for (ComponentSerializer<?> component : components) { values.add(component.getFieldValueDirectly(columnName)); } return pStatement.bind(values.toArray()); } };
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; }
.withColumnRange(compSerializer.buildRange() .withPrefix("CA") .build()) .withColumnRange(compSerializer.buildRange() .withPrefix("CA") .greaterThan("San Diego") .withColumnRange(compSerializer.buildRange() .withPrefix("WA") .withPrefix("Seattle")
private void processCompositeComparator() { int colIndex = 1; for (ComponentSerializer<?> componentSerializer : compositeSerializer.getComponents()) { String typeName = componentSerializer.getSerializer().getComparatorType().getTypeName(); ColumnDefinition column = new CqlColumnDefinitionImpl().setName("column" + colIndex++).setValidationClass(typeName); clusteringKeyList.add(column); } }
.withColumnRange(compSerializer.buildRange() .withPrefix("CA") .build()) .withColumnRange(compSerializer.buildRange() .withPrefix("CA") .greaterThan("San Diego") .withColumnRange(compSerializer.buildRange() .withPrefix("WA") .withPrefix("Seattle")
serializer = new AnnotatedCompositeSerializer(valueClass); } else { serializer = ObjectSerializer.get();
@Override public BoundStatement bindValues(PreparedStatement pStatement, CqlColumnMutationImpl<?, ?> mutation) { int size = 1 + cfDef.getPartitionKeyColumnDefinitionList().size() + cfDef.getClusteringKeyColumnDefinitionList().size(); Object[] arr = new Object[size]; int index = 0; arr[index++] = mutation.columnValue; arr[index++] = mutation.getRowKey(); ColumnFamily<?,?> cf = mutation.cfContext.getColumnFamily(); boolean isCompositeColumn = cf.getColumnSerializer().getComparatorType() == ComparatorType.COMPOSITETYPE; if (isCompositeColumn) { AnnotatedCompositeSerializer<?> compSerializer = (AnnotatedCompositeSerializer<?>) cf.getColumnSerializer(); for (ComponentSerializer<?> component : compSerializer.getComponents()) { try { arr[index++] = component.getFieldValueDirectly(mutation.columnName); } catch (Exception e) { throw new RuntimeException(e); } } } else { arr[index++] = mutation.columnName; } return pStatement.bind(arr); } };
.withColumnRange(compSerializer.buildRange() .withPrefix("CA") .build()) .withColumnRange(compSerializer.buildRange() .withPrefix("CA") .greaterThan("San Diego") .withColumnRange(compSerializer.buildRange() .withPrefix("WA") .withPrefix("Seattle")
AnnotatedCompositeSerializer<Population> compSerializer = new AnnotatedCompositeSerializer<Population>(Population.class); ColumnFamily<String, Population> CF_POPULATION = new ColumnFamily<String, Population>("population", StringSerializer.get(), compSerializer);
for (ComponentSerializer<?> component : compSerializer.getComponents()) { try { arr[index++] = component.getFieldValueDirectly(colMutation.columnName);
.withColumnRange(compSerializer.buildRange() .withPrefix("CA") .build()) .withColumnRange(compSerializer.buildRange() .withPrefix("CA") .greaterThan("San Diego") .withColumnRange(compSerializer.buildRange() .withPrefix("WA") .withPrefix("Seattle")
@Override public Placement newPlacement(String placement) throws ConnectionException { String[] parsed = PlacementUtil.parsePlacement(placement); String keyspaceName = parsed[0]; String cfPrefix = parsed[1]; CassandraKeyspace keyspace = _keyspaceMap.get(keyspaceName); if (keyspace == null) { throw new UnknownPlacementException(format( "Placement string refers to unknown or non-local Cassandra keyspace: %s", keyspaceName), placement); } KeyspaceDefinition keyspaceDef = keyspace.getAstyanaxKeyspace().describeKeyspace(); AnnotatedCompositeSerializer<DeltaKey> deltaKeySerializer = new AnnotatedCompositeSerializer<DeltaKey>(DeltaKey.class); // DDL's are not actually configurable due to the way we abstract the names from the placements here. // In the future, we should either phase out the DDL config or change the implementation here to conform to it. ColumnFamily<ByteBuffer, UUID> deltaCf = getColumnFamily(keyspaceDef, cfPrefix, "delta", placement, TimeUUIDSerializer.get()); ColumnFamily<ByteBuffer, DeltaKey> blockedDeltaCf = getColumnFamily(keyspaceDef, cfPrefix, "delta_v2", placement, deltaKeySerializer); ColumnFamily<ByteBuffer, UUID> deltaHistoryCf = getColumnFamily(keyspaceDef, cfPrefix, "history", placement, TimeUUIDSerializer.get()); // Calculate the data centers on demand since they may change in a live system. return new DeltaPlacement(placement, keyspace, deltaCf, blockedDeltaCf, deltaHistoryCf); }