@Test(expected = MongoValidationException.class) public void buildMalformedPKTest() throws MongoValidationException { TableMetadataBuilder tableMetaBuilder = new TableMetadataBuilder(DB_NAME, COLLECTION_NAME, CLUSTER_NAME); tableMetaBuilder.addColumn(ROW_NAME, VARCHAR_COLUMN_TYPE).addColumn(OTHER_ROW_NAME, new ColumnType(DataType.SET)); tableMetaBuilder.withPartitionKey(OTHER_ROW_NAME); TableMetadata tableMetadata = tableMetaBuilder.build(); Row row = new Row(); row.addCell(OTHER_ROW_NAME, new Cell(Collections.EMPTY_SET)); StorageUtils.buildPK(tableMetadata, row); }
public static Object buildPK(TableMetadata tableMetadata, Row row) throws MongoValidationException { Object pk = null; DBObject bsonPK = null; Object cellValue; List<ColumnName> primaryKeyList = tableMetadata.getPrimaryKey(); if (!primaryKeyList.isEmpty()) { if (primaryKeyList.size() == 1) { cellValue = row.getCell(primaryKeyList.get(0).getName()).getValue(); validatePKDataType(tableMetadata.getColumns().get(primaryKeyList.get(0)).getColumnType()); pk = cellValue; } else { bsonPK = new BasicDBObject(); for (ColumnName columnName : primaryKeyList) { cellValue = row.getCell(columnName.getName()).getValue(); validatePKDataType(tableMetadata.getColumns().get(columnName).getColumnType()); bsonPK.put(columnName.getName(), cellValue); } pk = bsonPK; } } return pk; }
StorageUtils { public static Object buildPK(TableMetadata tableMetadata, Row row) throws MongoValidationException { Object pk = null; DBObject bsonPK = null; Object cellValue; List<ColumnName> primaryKeyList = tableMetadata.getPrimaryKey(); if (!primaryKeyList.isEmpty()) { if (primaryKeyList.size() == 1) { cellValue = row.getCell(primaryKeyList.get(0).getName()).getValue(); validatePKDataType(tableMetadata.getColumns().get(primaryKeyList.get(0)).getColumnType()); pk = cellValue; } else { bsonPK = new BasicDBObject(); for (ColumnName columnName : primaryKeyList) { cellValue = row.getCell(columnName.getName()).getValue(); validatePKDataType(tableMetadata.getColumns().get(columnName).getColumnType()); bsonPK.put(columnName.getName(), cellValue); } pk = bsonPK; } } return pk; } }
StorageUtils { public static Object buildPK(TableMetadata tableMetadata, Row row) throws MongoValidationException { Object pk = null; DBObject bsonPK = null; Object cellValue; List<ColumnName> primaryKeyList = tableMetadata.getPrimaryKey(); if (!primaryKeyList.isEmpty()) { if (primaryKeyList.size() == 1) { cellValue = row.getCell(primaryKeyList.get(0).getName()).getValue(); validatePKDataType(tableMetadata.getColumns().get(primaryKeyList.get(0)).getColumnType()); pk = cellValue; } else { bsonPK = new BasicDBObject(); for (ColumnName columnName : primaryKeyList) { cellValue = row.getCell(columnName.getName()).getValue(); validatePKDataType(tableMetadata.getColumns().get(columnName).getColumnType()); bsonPK.put(columnName.getName(), cellValue); } pk = bsonPK; } } return pk; } private  StorageUtils(); }
StorageUtils { public static Object buildPK(TableMetadata tableMetadata, Row row) throws MongoValidationException { Object pk = null; DBObject bsonPK = null; Object cellValue; List<ColumnName> primaryKeyList = tableMetadata.getPrimaryKey(); if (!primaryKeyList.isEmpty()) { if (primaryKeyList.size() == 1) { cellValue = row.getCell(primaryKeyList.get(0).getName()).getValue(); validatePKDataType(tableMetadata.getColumns().get(primaryKeyList.get(0)).getColumnType()); pk = cellValue; } else { bsonPK = new BasicDBObject(); for (ColumnName columnName : primaryKeyList) { cellValue = row.getCell(columnName.getName()).getValue(); validatePKDataType(tableMetadata.getColumns().get(columnName).getColumnType()); bsonPK.put(columnName.getName(), cellValue); } pk = bsonPK; } } return pk; } private  StorageUtils(); static Object buildPK(TableMetadata tableMetadata, Row row); }
StorageUtils { public static Object buildPK(TableMetadata tableMetadata, Row row) throws MongoValidationException { Object pk = null; DBObject bsonPK = null; Object cellValue; List<ColumnName> primaryKeyList = tableMetadata.getPrimaryKey(); if (!primaryKeyList.isEmpty()) { if (primaryKeyList.size() == 1) { cellValue = row.getCell(primaryKeyList.get(0).getName()).getValue(); validatePKDataType(tableMetadata.getColumns().get(primaryKeyList.get(0)).getColumnType()); pk = cellValue; } else { bsonPK = new BasicDBObject(); for (ColumnName columnName : primaryKeyList) { cellValue = row.getCell(columnName.getName()).getValue(); validatePKDataType(tableMetadata.getColumns().get(columnName).getColumnType()); bsonPK.put(columnName.getName(), cellValue); } pk = bsonPK; } } return pk; } private  StorageUtils(); static Object buildPK(TableMetadata tableMetadata, Row row);  }