if (((SetType) type).getElementsType().getClass().getSimpleName().equals("UserType"))
public <T> Set<T> getFrozenSet(String column, AbstractType<T> type) { ByteBuffer raw = data.get(column); return raw == null ? null : SetType.getInstance(type, false).compose(raw); }
SetSerializer setSerializer = setType.getSerializer(); Collection outputCollection = new ArrayList(); if (useNativeProtocol2) UserType usertype = (UserType) setType.getElementsType(); Collection result = new HashSet(); Iterator collectionItems = outputCollection.iterator();
SetType setType = SetType.getInstance((AbstractType) valueClassInstance, false); return setType.decompose((Set) value).array();
valueType = SetType.getInstance(parser.parse(), true).toString();
try setType = SetType.getInstance(new TypeParser(cqlColumnMetadata.substring( cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length())));
private static AbstractType<?> expandUserTypes(AbstractType<?> original) { if (original instanceof UserType) return new TupleType(expandUserTypes(((UserType) original).fieldTypes())); if (original instanceof TupleType) return new TupleType(expandUserTypes(((TupleType) original).allTypes())); if (original instanceof ListType<?>) return ListType.getInstance(expandUserTypes(((ListType<?>) original).getElementsType()), original.isMultiCell()); if (original instanceof MapType<?,?>) { MapType<?, ?> mt = (MapType<?, ?>) original; return MapType.getInstance(expandUserTypes(mt.getKeysType()), expandUserTypes(mt.getValuesType()), mt.isMultiCell()); } if (original instanceof SetType<?>) return SetType.getInstance(expandUserTypes(((SetType<?>) original).getElementsType()), original.isMultiCell()); // this is very unlikely to ever happen, but it's better to be safe than sorry if (original instanceof ReversedType<?>) return ReversedType.getInstance(expandUserTypes(((ReversedType) original).baseType)); if (original instanceof CompositeType) return CompositeType.getInstance(expandUserTypes(original.getComponents())); return original; }
@Override public AbstractType<?> freezeNestedMulticellTypes() { if (!isMultiCell()) return this; if (elements.isFreezable() && elements.isMultiCell()) return getInstance(elements.freeze(), isMultiCell); return getInstance(elements.freezeNestedMulticellTypes(), isMultiCell); }
case SET: SetType<?> setType = (SetType<?>)type; return setType.compose(foundValue).contains(setType.getElementsType().compose(value)); case MAP: MapType<?,?> mapType = (MapType<?, ?>)type;
@Override public boolean isValueCompatibleWithFrozen(CollectionType<?> previous) { // because sets are ordered, any changes to the type must maintain the ordering return isCompatibleWithFrozen(previous); }
public static synchronized <T> SetType<T> getInstance(AbstractType<T> elements, boolean isMultiCell) { Map<AbstractType<?>, SetType> internMap = isMultiCell ? instances : frozenInstances; SetType<T> t = internMap.get(elements); if (t == null) { t = new SetType<T>(elements, isMultiCell); internMap.put(elements, t); } return t; }
@Override public String toString(boolean ignoreFreezing) { boolean includeFrozenType = !ignoreFreezing && !isMultiCell(); StringBuilder sb = new StringBuilder(); if (includeFrozenType) sb.append(FrozenType.class.getName()).append("("); sb.append(getClass().getName()); sb.append(TypeParser.stringifyTypeParameters(Collections.<AbstractType<?>>singletonList(elements), ignoreFreezing || !isMultiCell)); if (includeFrozenType) sb.append(")"); return sb.toString(); }
@Override public AbstractType<?> freeze() { if (isMultiCell) return getInstance(this.elements, false); else return this; }
private static AbstractType<?> expandUserTypes(AbstractType<?> original) { if (original instanceof UserType) return new TupleType(expandUserTypes(((UserType) original).fieldTypes())); if (original instanceof TupleType) return new TupleType(expandUserTypes(((TupleType) original).allTypes())); if (original instanceof ListType<?>) return ListType.getInstance(expandUserTypes(((ListType<?>) original).getElementsType()), original.isMultiCell()); if (original instanceof MapType<?,?>) { MapType<?, ?> mt = (MapType<?, ?>) original; return MapType.getInstance(expandUserTypes(mt.getKeysType()), expandUserTypes(mt.getValuesType()), mt.isMultiCell()); } if (original instanceof SetType<?>) return SetType.getInstance(expandUserTypes(((SetType<?>) original).getElementsType()), original.isMultiCell()); // this is very unlikely to ever happen, but it's better to be safe than sorry if (original instanceof ReversedType<?>) return ReversedType.getInstance(expandUserTypes(((ReversedType) original).baseType)); if (original instanceof CompositeType) return CompositeType.getInstance(expandUserTypes(original.getComponents())); return original; }
@Override public AbstractType<?> freezeNestedMulticellTypes() { if (!isMultiCell()) return this; if (elements.isFreezable() && elements.isMultiCell()) return getInstance(elements.freeze(), isMultiCell); return getInstance(elements.freezeNestedMulticellTypes(), isMultiCell); }
case SET: SetType<?> setType = (SetType<?>)type; return setType.compose(foundValue).contains(setType.getElementsType().compose(value)); case MAP: MapType<?,?> mapType = (MapType<?, ?>)type;
private static byte[] compose(Object value, Class clazz, Class<?> mapGenericClassses) { Class<?> valueValidationClass = CassandraValidationClassMapper.getValidationClassInstance( mapGenericClassses, true); Object valueClassInstance; try { valueClassInstance = valueValidationClass.getDeclaredField("instance").get(null); SetType setType = SetType.getInstance((AbstractType) valueClassInstance); return setType.decompose((Set) value).array(); } catch (Exception e) { log.error("Error while retrieving field{} value via CQL, Caused by: .", clazz.getSimpleName(), e); throw new PersistenceException(e); } }
@Override public boolean isValueCompatibleWithFrozen(CollectionType<?> previous) { // because sets are ordered, any changes to the type must maintain the ordering return isCompatibleWithFrozen(previous); }
public static synchronized <T> SetType<T> getInstance(AbstractType<T> elements, boolean isMultiCell) { Map<AbstractType<?>, SetType> internMap = isMultiCell ? instances : frozenInstances; SetType<T> t = internMap.get(elements); if (t == null) { t = new SetType<T>(elements, isMultiCell); internMap.put(elements, t); } return t; }
@Override public String toString(boolean ignoreFreezing) { boolean includeFrozenType = !ignoreFreezing && !isMultiCell(); StringBuilder sb = new StringBuilder(); if (includeFrozenType) sb.append(FrozenType.class.getName()).append("("); sb.append(getClass().getName()); sb.append(TypeParser.stringifyTypeParameters(Collections.<AbstractType<?>>singletonList(elements), ignoreFreezing || !isMultiCell)); if (includeFrozenType) sb.append(")"); return sb.toString(); }