try {
// Create an RPC request to begin a new transaction.
BeginTransactionRequest.Builder treq = BeginTransactionRequest.newBuilder();
// Execute the RPC synchronously.
BeginTransactionResponse tres = datastore.beginTransaction(treq.build());
// Get the transaction handle from the response.
ByteString tx = tres.getTransaction();
// Create an RPC request to get entities by key.
LookupRequest.Builder lreq = LookupRequest.newBuilder();