Question 39 of 179 from exam AZ-204: Developing Solutions for Microsoft Azure

Question 39 of 179 from exam AZ-204: Developing Solutions for Microsoft Azure

Question

HOTSPOT - A company develops a series of mobile games.

All games use a single leaderboard service.

You have the following requirements: -> Code must be scalable and allow for growth.

-> Each record must consist of a playerId, gameId, score, and time played.

-> When users reach a new high score, the system will save the new score using the SaveScore function below.

-> Each game is assigned an Id based on the series title.

You plan to store customer information in Azure Cosmos DB.

The following data already exists in the database:

PartitionKey RowKey Email
Harp Walter wharp@contoso.com
Smith Steve ssmith@contoso.com
Smith Jeff ismith@contoso.com

You develop the following code to save scores in the data store.

(Line numbers are included for reference only.)

o1
02
03
04
05
06
07
08
09
10

public void SaveScore(string gameId, string playerId, int score, long timePlayed)
{

CloudStorageAccount storageAccount = CloudStorageAccount . Parse (connectionstring) ;
CloudTableClient tableClient = storageAccount.CreateCloudTableClient ();
CloudTable table = tableClient.GetTableReference ("scoreTable") ;
table.CreateI£NotExists ();

var scoreRecord = new PlayerScore(gameId, playerId, score, timePlayed) ;
TableOperation insertOperation = TableOperation. Insert (scoreRecord) ;

table. Execute (insertOperation) ;

t

You develop the following code to query the database.

(Line numbers are included for reference only.)

CloudfableClient tableClient = account.CreateCloudTableClient () ;

CloudTable table = tableClient.GetTableReference ("people");

TableQuery < CustomerEntity> query = new TableQuery <CustomerEntity >( )

-Where( TableQuery.CombineFilters (

TableQuery.GenerateFilterCondition (PartitionKey, QueryComparisons.Equal , "Smith"),

TableOperators.And , TableQuery.GenerateFilterCondition (Email, QueryComparisons.Equal, "ssmith@contoso.com")
Ye

await table.ExecuteQuerySegmentedAsync< CustomerEntity>(query, null);

For each of the following statements, select Yes if the statement is true.

Otherwise, select No.

NOTE: Each correct selection is worth one point.

Hot Area:

Answer Area

Statements

SaveScore will work with Cosmos DB.

SaveScore will update and replace a record if one already exists
with the same playerld and gameld.

Leader board data for the game will be automatically partitioned
using gameld.

SaveScore will store the values for the gameld and playerld
parameters in the database.

oO jo |

Oo jo |O

Explanations

Answer Area

Statements

SaveScore will work with Cosmos DB.

SaveScore will update and replace a record if one already exists
with the same playerld and gameld.

Leader board data for the game will be automatically partitioned
using gameld.

SaveScore will store the values for the gameld and playerld
parameters in the database.

eS co oO B

oOo @ Bo

Box 1: Yes - Create a table.

A CloudTableClient object lets you get reference objects for tables and entities.

The following code creates a CloudTableClient object and uses it to create a new CloudTable object, which represents a table // Retrieve storage account from connection-string.

CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); // Create the table client.

CloudTableClient tableClient = storageAccount.createCloudTableClient(); // Create the table if it doesn't exist.

String tableName = "people"; CloudTable cloudTable = tableClient.getTableReference(tableName); cloudTable.createIfNotExists(); Box 2: No - New records are inserted with TableOperation.insert.

Old records are not updated.

To update old records TableOperation.insertOrReplace should be used instead.

Box 3: No - Box 4: Yes - Reference: https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-java.