@Test public void buildCompoundPKTest() throws MongoValidationException { TableMetadataBuilder tableMetaBuilder = new TableMetadataBuilder(DB_NAME, COLLECTION_NAME, CLUSTER_NAME); tableMetaBuilder.addColumn(ROW_NAME, VARCHAR_COLUMN_TYPE).addColumn(OTHER_ROW_NAME, INT_COLUMN_TYPE); tableMetaBuilder.withPartitionKey(ROW_NAME); tableMetaBuilder.withClusterKey(OTHER_ROW_NAME); TableMetadata tableMetadata = tableMetaBuilder.build(); Row row = new Row(); row.addCell(ROW_NAME, new Cell(CELL_VALUE)); row.addCell(OTHER_ROW_NAME, new Cell(INTEGER_CELL_VALUE)); DBObject pk = (DBObject) StorageUtils.buildPK(tableMetadata, row); assertTrue("The primary key must contain " + ROW_NAME, pk.containsField(ROW_NAME)); assertTrue("The primary key must contain " + OTHER_ROW_NAME, pk.containsField(OTHER_ROW_NAME)); assertEquals("The string value is not the expected", CELL_VALUE, pk.get(ROW_NAME)); assertEquals("The integer value is not the expected", INTEGER_CELL_VALUE, pk.get(OTHER_ROW_NAME)); }
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);  }