private ColumnFamilyModel mapXmlColumnFamilyToColumnFamilyModel( org.cassandraunit.dataset.xml.ColumnFamily xmlColumnFamily) { ColumnFamilyModel columnFamily = new ColumnFamilyModel(); /* structure information */ columnFamily.setName(xmlColumnFamily.getName()); if (xmlColumnFamily.getType() != null) { columnFamily.setType(ColumnType.valueOf(xmlColumnFamily.getType().toString())); } columnFamily.setComment(xmlColumnFamily.getComment()); if (xmlColumnFamily.getCompactionStrategy() != null) { columnFamily.setCompactionStrategy(xmlColumnFamily.getCompactionStrategy()); } if (xmlColumnFamily.getCompactionStrategyOptions() != null) { List<CompactionStrategyOptionModel> compactionStrategyOptionModels = new ArrayList<CompactionStrategyOptionModel>(); for (CompactionStrategyOption compactionStrategyOption : xmlColumnFamily.getCompactionStrategyOptions().getCompactionStrategyOption()) { compactionStrategyOptionModels.add( new CompactionStrategyOptionModel( compactionStrategyOption.getName(), compactionStrategyOption.getValue())); } columnFamily.setCompactionStrategyOptions(compactionStrategyOptionModels); } if (xmlColumnFamily.getGcGraceSeconds() != null) { columnFamily.setGcGraceSeconds(xmlColumnFamily.getGcGraceSeconds()); } if (xmlColumnFamily.getMaxCompactionThreshold() != null) { columnFamily.setMaxCompactionThreshold(xmlColumnFamily.getMaxCompactionThreshold()); } if (xmlColumnFamily.getMinCompactionThreshold() != null) { columnFamily.setMinCompactionThreshold(xmlColumnFamily.getMinCompactionThreshold()); } if (xmlColumnFamily.getReadRepairChance() != null) { columnFamily.setReadRepairChance(xmlColumnFamily.getReadRepairChance()); } if (xmlColumnFamily.getReplicationOnWrite() != null) { columnFamily.setReplicationOnWrite(xmlColumnFamily.getReplicationOnWrite()); } GenericTypeEnum[] typesBelongingCompositeTypeForKeyType = null; if (xmlColumnFamily.getKeyType() != null) { ComparatorType keyType = ComparatorTypeHelper.verifyAndExtract(xmlColumnFamily.getKeyType()); columnFamily.setKeyType(keyType); if (ComparatorType.COMPOSITETYPE.getTypeName().equals(keyType.getTypeName())) { String keyTypeAlias = StringUtils.removeStart( xmlColumnFamily.getKeyType(), ComparatorType.COMPOSITETYPE.getTypeName()); columnFamily.setKeyTypeAlias(keyTypeAlias); typesBelongingCompositeTypeForKeyType = ComparatorTypeHelper.extractGenericTypesFromTypeAlias(keyTypeAlias); } } GenericTypeEnum[] typesBelongingCompositeTypeForComparatorType = null; if (xmlColumnFamily.getComparatorType() != null) { ComparatorType comparatorType = ComparatorTypeHelper.verifyAndExtract(xmlColumnFamily.getComparatorType()); columnFamily.setComparatorType(comparatorType); if (ComparatorType.COMPOSITETYPE.getTypeName().equals(comparatorType.getTypeName())) { String comparatorTypeAlias = StringUtils.removeStart( xmlColumnFamily.getComparatorType(), ComparatorType.COMPOSITETYPE.getTypeName()); columnFamily.setComparatorTypeAlias(comparatorTypeAlias); typesBelongingCompositeTypeForComparatorType = ComparatorTypeHelper.extractGenericTypesFromTypeAlias(comparatorTypeAlias); } } if (xmlColumnFamily.getSubComparatorType() != null) { columnFamily.setSubComparatorType( ComparatorType.getByClassName(xmlColumnFamily.getSubComparatorType().value())); } if (xmlColumnFamily.getDefaultColumnValueType() != null) { columnFamily.setDefaultColumnValueType( ComparatorType.getByClassName(xmlColumnFamily.getDefaultColumnValueType().value())); } columnFamily.setColumnsMetadata( mapXmlColumsMetadataToColumnsMetadata(xmlColumnFamily.getColumnMetadata())); /* data information */ columnFamily.setRows( mapXmlRowsToRowsModel( xmlColumnFamily, columnFamily.getKeyType(), typesBelongingCompositeTypeForKeyType, columnFamily.getComparatorType(), typesBelongingCompositeTypeForComparatorType, columnFamily.getSubComparatorType(), columnFamily.getDefaultColumnValueType())); return columnFamily; }
private ColumnFamilyModel mapParsedColumnFamilyToColumnFamilyModel( ParsedColumnFamily parsedColumnFamily) { ColumnFamilyModel columnFamily = new ColumnFamilyModel(); /* structure information */ if (parsedColumnFamily == null || parsedColumnFamily.getName() == null) { throw new ParseException("Column Family Name is missing"); } columnFamily.setName(parsedColumnFamily.getName()); if (parsedColumnFamily.getType() != null) { columnFamily.setType(ColumnType.valueOf(parsedColumnFamily.getType().toString())); } columnFamily.setComment(parsedColumnFamily.getComment()); if (parsedColumnFamily.getCompactionStrategy() != null) { columnFamily.setCompactionStrategy(parsedColumnFamily.getCompactionStrategy()); } if (parsedColumnFamily.getCompactionStrategyOptions() != null && !parsedColumnFamily.getCompactionStrategyOptions().isEmpty()) { List<CompactionStrategyOptionModel> compactionStrategyOptionModels = new ArrayList<CompactionStrategyOptionModel>(); for (ParsedCompactionStrategyOption parsedCompactionStrategyOption : parsedColumnFamily.getCompactionStrategyOptions()) { compactionStrategyOptionModels.add( new CompactionStrategyOptionModel( parsedCompactionStrategyOption.getName(), parsedCompactionStrategyOption.getValue())); } columnFamily.setCompactionStrategyOptions(compactionStrategyOptionModels); } if (parsedColumnFamily.getGcGraceSeconds() != null) { columnFamily.setGcGraceSeconds(parsedColumnFamily.getGcGraceSeconds()); } if (parsedColumnFamily.getMaxCompactionThreshold() != null) { columnFamily.setMaxCompactionThreshold(parsedColumnFamily.getMaxCompactionThreshold()); } if (parsedColumnFamily.getMinCompactionThreshold() != null) { columnFamily.setMinCompactionThreshold(parsedColumnFamily.getMinCompactionThreshold()); } if (parsedColumnFamily.getReadRepairChance() != null) { columnFamily.setReadRepairChance(parsedColumnFamily.getReadRepairChance()); } if (parsedColumnFamily.getReplicationOnWrite() != null) { columnFamily.setReplicationOnWrite(parsedColumnFamily.getReplicationOnWrite()); } /* keyType */ GenericTypeEnum[] typesBelongingCompositeTypeForKeyType = null; if (parsedColumnFamily.getKeyType() != null) { ComparatorType keyType = ComparatorTypeHelper.verifyAndExtract(parsedColumnFamily.getKeyType()); columnFamily.setKeyType(keyType); if (ComparatorType.COMPOSITETYPE.getTypeName().equals(keyType.getTypeName())) { String keyTypeAlias = StringUtils.removeStart( parsedColumnFamily.getKeyType(), ComparatorType.COMPOSITETYPE.getTypeName()); columnFamily.setKeyTypeAlias(keyTypeAlias); typesBelongingCompositeTypeForKeyType = ComparatorTypeHelper.extractGenericTypesFromTypeAlias(keyTypeAlias); } } /* comparatorType */ GenericTypeEnum[] typesBelongingCompositeTypeForComparatorType = null; if (parsedColumnFamily.getComparatorType() != null) { ComparatorType comparatorType = ComparatorTypeHelper.verifyAndExtract(parsedColumnFamily.getComparatorType()); columnFamily.setComparatorType(comparatorType); if (ComparatorType.COMPOSITETYPE.getTypeName().equals(comparatorType.getTypeName())) { String comparatorTypeAlias = StringUtils.removeStart( parsedColumnFamily.getComparatorType(), ComparatorType.COMPOSITETYPE.getTypeName()); columnFamily.setComparatorTypeAlias(comparatorTypeAlias); typesBelongingCompositeTypeForComparatorType = ComparatorTypeHelper.extractGenericTypesFromTypeAlias(comparatorTypeAlias); } } /* subComparatorType */ if (parsedColumnFamily.getSubComparatorType() != null) { columnFamily.setSubComparatorType( ComparatorType.getByClassName(parsedColumnFamily.getSubComparatorType().name())); } if (parsedColumnFamily.getDefaultColumnValueType() != null) { columnFamily.setDefaultColumnValueType( ComparatorType.getByClassName(parsedColumnFamily.getDefaultColumnValueType().name())); } columnFamily.setColumnsMetadata( mapParsedColumsMetadataToColumnsMetadata( parsedColumnFamily.getColumnsMetadata(), columnFamily.getComparatorType(), typesBelongingCompositeTypeForComparatorType)); /* data information */ columnFamily.setRows( mapParsedRowsToRowsModel( parsedColumnFamily, columnFamily.getKeyType(), typesBelongingCompositeTypeForKeyType, columnFamily.getComparatorType(), typesBelongingCompositeTypeForComparatorType, columnFamily.getSubComparatorType(), columnFamily.getDefaultColumnValueType())); return columnFamily; }