I am trying to implement a function that given a DynamoDB and the name of a table I know exists in the database, determines whether this table is empty or not.
I expect the signature to look like the following in Java:
public Boolean isEmpty(DynamoDB database, String tableName) = ???
Assume for the purposes of this question that the table has a primary key consisting of a single Integer type attribute called "UserId".
I'm aware that one can use a scan to look at a table, but I (a) don't know what the expression would look like, and (b) need it to be limited to a single item, so that we don't have to scan the entire table (which may be large) in the case that it is non-empty.
EDIT:
Should I perhaps be using an AmazonDynamoDB in my constructor instead, rather than a DynamoDB? The former has a scan method which takes a ScanRequest - for which you can easily set a limit using .limit(1) - whereas for the latter I would do something like database.getTable(tableName).scan(...), but this scan takes a ScanSpec for which it is not clear to me how to set a limit for.