/** * map an xml column to a column * * @param xmlColumn xml column * @param typesBelongingCompositeTypeForComparatorType * @return column */ private ColumnModel mapXmlColumnToColumnModel( ColumnMetadata metaData, Column xmlColumn, ComparatorType comparatorType, GenericTypeEnum[] typesBelongingCompositeTypeForComparatorType, ComparatorType defaultColumnValueType) { ColumnModel columnModel = new ColumnModel(); if (comparatorType == null) { columnModel.setName(new GenericType(xmlColumn.getName(), GenericTypeEnum.BYTES_TYPE)); } else if (ComparatorType.COMPOSITETYPE.getTypeName().equals(comparatorType.getTypeName())) { /* composite type */ try { columnModel.setName( new GenericType( StringUtils.split(xmlColumn.getName(), ":"), typesBelongingCompositeTypeForComparatorType)); } catch (IllegalArgumentException e) { throw new ParseException( xmlColumn.getName() + " doesn't fit with the schema declaration of your composite type"); } } else { /* simple type */ columnModel.setName( new GenericType( xmlColumn.getName(), GenericTypeEnum.fromValue(comparatorType.getTypeName()))); } if (defaultColumnValueType != null && ComparatorType.COUNTERTYPE.getClassName().equals(defaultColumnValueType.getClassName()) && TypeExtractor.containFunctions(xmlColumn.getValue())) { throw new ParseException("Impossible to override Column value into a Counter column family"); } GenericType columnValue = null; if (metaData != null) { GenericTypeEnum genTypeEnum = GenericTypeEnum.valueOf(metaData.getValidationClass().name()); columnValue = new GenericType(xmlColumn.getValue(), genTypeEnum); } else { columnValue = TypeExtractor.extract(xmlColumn.getValue(), defaultColumnValueType); } columnModel.setValue(columnValue); String timestamp = xmlColumn.getTimestamp(); if (timestamp != null) { columnModel.setTimestamp(Long.valueOf(timestamp)); } else { columnModel.setTimestamp(null); } return columnModel; }
/** * map an xml super colmun to a super column * * @param xmlSuperColumn xml super column * @param subComparatorType * @param comparatorType * @return supercolumn */ private SuperColumnModel mapXmlSuperColumnToSuperColumnModel( List<ColumnMetadata> columnMetaData, SuperColumn xmlSuperColumn, ComparatorType comparatorType, ComparatorType subComparatorType, ComparatorType defaultColumnValueType) { SuperColumnModel superColumnModel = new SuperColumnModel(); superColumnModel.setName( new GenericType( xmlSuperColumn.getName(), GenericTypeEnum.fromValue(comparatorType.getTypeName()))); superColumnModel.setColumns( mapXmlColumnsToColumnsModel( columnMetaData, xmlSuperColumn.getColumn(), subComparatorType, null, defaultColumnValueType)); return superColumnModel; }
private SuperColumnModel mapParsedSuperColumnToSuperColumnModel( List<ParsedColumnMetadata> metaData, ParsedSuperColumn parsedSuperColumn, ComparatorType comparatorType, ComparatorType subComparatorType, ComparatorType defaultColumnValueType) { SuperColumnModel superColumnModel = new SuperColumnModel(); superColumnModel.setName( new GenericType( parsedSuperColumn.getName(), GenericTypeEnum.fromValue(comparatorType.getTypeName()))); superColumnModel.setColumns( mapParsedColumnsToColumnsModel( metaData, parsedSuperColumn.getColumns(), subComparatorType, null, defaultColumnValueType)); return superColumnModel; }
private ColumnModel mapParsedColumnToColumnModel( ParsedColumnMetadata metaData, ParsedColumn parsedColumn, ComparatorType comparatorType, GenericTypeEnum[] typesBelongingCompositeTypeForComparatorType, ComparatorType defaultColumnValueType) { ColumnModel columnModel = new ColumnModel(); columnModel.setName( TypeExtractor.constructGenericType( parsedColumn.getName(), comparatorType, typesBelongingCompositeTypeForComparatorType)); if (ComparatorType.COUNTERTYPE.getClassName().equals(defaultColumnValueType.getClassName()) && TypeExtractor.containFunctions(parsedColumn.getValue())) { throw new ParseException("Impossible to override Column value into a Counter column family"); } GenericType columnValue = null; if (parsedColumn.getValue() != null) { if (metaData != null && !TypeExtractor.containFunctions(parsedColumn.getValue())) { GenericTypeEnum genTypeEnum = GenericTypeEnum.fromValue(metaData.getValidationClass().name()); columnValue = new GenericType(parsedColumn.getValue(), genTypeEnum); } else { columnValue = TypeExtractor.extract(parsedColumn.getValue(), defaultColumnValueType); } } columnModel.setValue(columnValue); String timestamp = parsedColumn.getTimestamp(); if (timestamp != null) { columnModel.setTimestamp(Long.valueOf(timestamp)); } else { columnModel.setTimestamp(null); } return columnModel; }