/** * Compose and add. * * @param entity * the entity * @param cqlMetadata * the cql metadata * @param thriftColumnValue * the thrift column value * @param thriftColumnName * the thrift column name */ private void composeAndAdd(HashMap entity, CqlMetadata cqlMetadata, Object thriftColumnValue, String thriftColumnName) { byte[] columnName = thriftColumnName.getBytes(); Map<ByteBuffer, String> schemaTypes = this.clientBase.getCqlMetadata().getValue_types(); AbstractType<?> type = null; try { type = TypeParser.parse(schemaTypes.get(ByteBuffer.wrap((byte[]) columnName))); } catch (SyntaxException | ConfigurationException e) { log.error(e.getMessage()); throw new KunderaException("Error while parsing CQL Type " + e); } entity.put(thriftColumnName, type.compose(ByteBuffer.wrap((byte[]) thriftColumnValue))); }
/** * Parse a string containing an type definition. */ public static AbstractType<?> parse(String str) throws SyntaxException, ConfigurationException { if (str == null) return BytesType.instance; AbstractType<?> type = cache.get(str); if (type != null) return type; // This could be simplier (i.e. new TypeParser(str).parse()) but we avoid creating a TypeParser object if not really necessary. int i = 0; i = skipBlank(str, i); int j = i; while (!isEOS(str, i) && isIdentifierChar(str.charAt(i))) ++i; if (i == j) return BytesType.instance; String name = str.substring(j, i); i = skipBlank(str, i); if (!isEOS(str, i) && str.charAt(i) == '(') type = getAbstractType(name, new TypeParser(str, i)); else type = getAbstractType(name); // We don't really care about concurrency here. Worst case scenario, we do some parsing unnecessarily cache.put(str, type); return type; }
if (validation_class.equals(ListType.class)) TypeParser parser = new TypeParser(getValidationClass(genericClasses.get(0), isCql3Enabled)); valueType = ListType.getInstance(parser.parse(), true).toString(); TypeParser parser = new TypeParser(getValidationClass(genericClasses.get(0), isCql3Enabled)); valueType = SetType.getInstance(parser.parse(), true).toString();
/** * Parse an AbstractType from current position of this parser. */ public AbstractType<?> parse() throws SyntaxException, ConfigurationException { skipBlank(); String name = readNextIdentifier(); skipBlank(); if (!isEOS() && str.charAt(idx) == '(') return getAbstractType(name, this); else return getAbstractType(name); }
public Pair<Pair<String, ByteBuffer>, List<Pair<ByteBuffer, AbstractType>>> getUserTypeParameters() throws SyntaxException, ConfigurationException if (isEOS() || str.charAt(idx) != '(') throw new IllegalStateException(); skipBlankAndComma(); String keyspace = readNextIdentifier(); skipBlankAndComma(); ByteBuffer typeName = fromHex(readNextIdentifier()); List<Pair<ByteBuffer, AbstractType>> defs = new ArrayList<>(); while (skipBlankAndComma()) ByteBuffer name = fromHex(readNextIdentifier()); skipBlank(); if (str.charAt(idx) != ':') throwSyntaxError("expecting ':' token"); ++idx; skipBlank(); try AbstractType type = parse(); defs.add(Pair.create(name, type));
public static TupleType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException { List<AbstractType<?>> types = parser.getTypeParameters(); for (int i = 0; i < types.size(); i++) types.set(i, types.get(i).freeze()); return new TupleType(types); }
private static AbstractType<?> getAbstractType(String compareWith) throws ConfigurationException { String className = compareWith.contains(".") ? compareWith : "org.apache.cassandra.db.marshal." + compareWith; Class<? extends AbstractType<?>> typeClass = FBUtilities.<AbstractType<?>>classForName(className, "abstract-type"); try { Field field = typeClass.getDeclaredField("instance"); return (AbstractType<?>) field.get(null); } catch (NoSuchFieldException e) { // Trying with empty parser return getRawAbstractType(typeClass, EMPTY_PARSER); } catch (IllegalAccessException e) { // Trying with empty parser return getRawAbstractType(typeClass, EMPTY_PARSER); } }
public static AbstractType<?> parseDefaultParameters(AbstractType<?> baseType, TypeParser parser) throws SyntaxException { Map<String, String> parameters = parser.getKeyValueParameters(); String reversed = parameters.get("reversed"); if (reversed != null && (reversed.isEmpty() || reversed.equals("true"))) { return ReversedType.getInstance(baseType); } else { return baseType; } }
public static ColumnToCollectionType getInstance(TypeParser parser) throws SyntaxException, ConfigurationException { return getInstance(parser.getCollectionsParameters()); }
public static synchronized DynamicCompositeType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException { return getInstance(parser.getAliasParameters()); }
public static UserType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException { Pair<Pair<String, ByteBuffer>, List<Pair<ByteBuffer, AbstractType>>> params = parser.getUserTypeParameters(); String keyspace = params.left.left; ByteBuffer name = params.left.right; List<FieldIdentifier> columnNames = new ArrayList<>(params.right.size()); List<AbstractType<?>> columnTypes = new ArrayList<>(params.right.size()); for (Pair<ByteBuffer, AbstractType> p : params.right) { columnNames.add(new FieldIdentifier(p.left)); columnTypes.add(p.right); } return new UserType(keyspace, name, columnNames, columnTypes, true); }
try listType = ListType.getInstance(new TypeParser(cqlColumnMetadata.substring( cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length()))); try setType = SetType.getInstance(new TypeParser(cqlColumnMetadata.substring( cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length()))); try mapType = MapType.getInstance(new TypeParser(cqlColumnMetadata.substring( cqlColumnMetadata.indexOf("("), cqlColumnMetadata.length())));
public Pair<Pair<String, ByteBuffer>, List<Pair<ByteBuffer, AbstractType>>> getUserTypeParameters() throws SyntaxException, ConfigurationException if (isEOS() || str.charAt(idx) != '(') throw new IllegalStateException(); skipBlankAndComma(); String keyspace = readNextIdentifier(); skipBlankAndComma(); ByteBuffer typeName = fromHex(readNextIdentifier()); List<Pair<ByteBuffer, AbstractType>> defs = new ArrayList<>(); while (skipBlankAndComma()) ByteBuffer name = fromHex(readNextIdentifier()); skipBlank(); if (str.charAt(idx) != ':') throwSyntaxError("expecting ':' token"); ++idx; skipBlank(); try AbstractType type = parse(); defs.add(Pair.create(name, type));
/** * Parse an AbstractType from current position of this parser. */ public AbstractType<?> parse() throws SyntaxException, ConfigurationException { skipBlank(); String name = readNextIdentifier(); skipBlank(); if (!isEOS() && str.charAt(idx) == '(') return getAbstractType(name, this); else return getAbstractType(name); }
public static MapType<?, ?> getInstance(TypeParser parser) throws ConfigurationException, SyntaxException { List<AbstractType<?>> l = parser.getTypeParameters(); if (l.size() != 2) throw new ConfigurationException("MapType takes exactly 2 type parameters"); return getInstance(l.get(0), l.get(1), true); }
private static AbstractType<?> getAbstractType(String compareWith) throws ConfigurationException { String className = compareWith.contains(".") ? compareWith : "org.apache.cassandra.db.marshal." + compareWith; Class<? extends AbstractType<?>> typeClass = FBUtilities.<AbstractType<?>>classForName(className, "abstract-type"); try { Field field = typeClass.getDeclaredField("instance"); return (AbstractType<?>) field.get(null); } catch (NoSuchFieldException | IllegalAccessException e) { // Trying with empty parser return getRawAbstractType(typeClass, EMPTY_PARSER); } }
public static AbstractType<?> parseDefaultParameters(AbstractType<?> baseType, TypeParser parser) throws SyntaxException { Map<String, String> parameters = parser.getKeyValueParameters(); String reversed = parameters.get("reversed"); if (reversed != null && (reversed.isEmpty() || reversed.equals("true"))) { return ReversedType.getInstance(baseType); } else { return baseType; } }
public static ColumnToCollectionType getInstance(TypeParser parser) throws SyntaxException, ConfigurationException { return getInstance(parser.getCollectionsParameters()); }
public static synchronized DynamicCompositeType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException { return getInstance(parser.getAliasParameters()); }
public static UserType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException { Pair<Pair<String, ByteBuffer>, List<Pair<ByteBuffer, AbstractType>>> params = parser.getUserTypeParameters(); String keyspace = params.left.left; ByteBuffer name = params.left.right; List<FieldIdentifier> columnNames = new ArrayList<>(params.right.size()); List<AbstractType<?>> columnTypes = new ArrayList<>(params.right.size()); for (Pair<ByteBuffer, AbstractType> p : params.right) { columnNames.add(new FieldIdentifier(p.left)); columnTypes.add(p.right); } return new UserType(keyspace, name, columnNames, columnTypes, true); }