Skip to content

Commit

Permalink
#72 more detailed exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Feb 23, 2016
1 parent 70ee588 commit 5f70721
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
26 changes: 22 additions & 4 deletions src/main/java/com/jcabi/dynamo/AwsItem.java
Expand Up @@ -124,12 +124,18 @@ public boolean has(final String attr) throws IOException {
final GetItemResult result = aws.getItem(request);
has = result.getItem().get(attrib) != null;
Logger.info(
this, "#has('%s'): %B from DynamoDB%s, in %[ms]s",
this, "#has('%s'): %B from DynamoDB, %s, in %[ms]s",
attr, has, AwsTable.print(result.getConsumedCapacity()),
System.currentTimeMillis() - start
);
} catch (final AmazonClientException ex) {
throw new IOException(ex);
throw new IOException(
String.format(
"failed to check existence of \"%s\" at \"%s\" by %s",
attr, this.name, this.keys
),
ex
);
} finally {
aws.shutdown();
}
Expand Down Expand Up @@ -161,7 +167,13 @@ public AttributeValue get(final String attr) throws IOException {
System.currentTimeMillis() - start
);
} catch (final AmazonClientException ex) {
throw new IOException(ex);
throw new IOException(
String.format(
"failed to get \"%s\" from \"%s\" by %s",
attr, this.name, this.keys
),
ex
);
} finally {
aws.shutdown();
}
Expand Down Expand Up @@ -202,7 +214,13 @@ public Map<String, AttributeValue> put(
);
return result.getAttributes();
} catch (final AmazonClientException ex) {
throw new IOException(ex);
throw new IOException(
String.format(
"failed to put %s into \"%s\" with %s",
attrs, this.name, this.keys
),
ex
);
} finally {
aws.shutdown();
}
Expand Down
29 changes: 24 additions & 5 deletions src/main/java/com/jcabi/dynamo/AwsTable.java
Expand Up @@ -108,7 +108,7 @@ public Item put(final Map<String, AttributeValue> attributes)
final PutItemResult result = aws.putItem(request);
final long start = System.currentTimeMillis();
Logger.info(
this, "#put('%[text]s'): created item in '%s'%s, in %[ms]s",
this, "#put('%[text]s'): created item in '%s', %s, in %[ms]s",
attributes, this.self,
AwsTable.print(result.getConsumedCapacity()),
System.currentTimeMillis() - start
Expand All @@ -121,7 +121,13 @@ public Item put(final Map<String, AttributeValue> attributes)
new Array<String>(this.keys())
);
} catch (final AmazonClientException ex) {
throw new IOException(ex);
throw new IOException(
String.format(
"failed to put into \"%s\" with %s",
this.self, attributes
),
ex
);
} finally {
aws.shutdown();
}
Expand Down Expand Up @@ -166,7 +172,13 @@ public Collection<String> keys() throws IOException {
);
return keys;
} catch (final AmazonClientException ex) {
throw new IOException(ex);
throw new IOException(
String.format(
"failed to describe \"%s\"",
this.self
),
ex
);
} finally {
aws.shutdown();
}
Expand Down Expand Up @@ -201,13 +213,20 @@ public void delete(final Map<String, AttributeValue> attributes)
final DeleteItemResult result = aws.deleteItem(request);
final long start = System.currentTimeMillis();
Logger.info(
this, "#delete('%[text]s'): deleted item in '%s'%s, in %[ms]s",
this,
"#delete('%[text]s'): deleted item in '%s', %s, in %[ms]s",
attributes, this.self,
AwsTable.print(result.getConsumedCapacity()),
System.currentTimeMillis() - start
);
} catch (final AmazonClientException ex) {
throw new IOException(ex);
throw new IOException(
String.format(
"failed to delete at \"%s\" by keys %s",
this.self, attributes
),
ex
);
} finally {
aws.shutdown();
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/jcabi/dynamo/QueryValve.java
Expand Up @@ -157,14 +157,20 @@ public Dosage fetch(final Credentials credentials, final String table,
final QueryResult result = aws.query(request);
Logger.info(
this,
"#items(): loaded %d item(s) from '%s' using %s%s, in %[ms]s",
"#items(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
result.getCount(), table, conditions,
AwsTable.print(result.getConsumedCapacity()),
System.currentTimeMillis() - start
);
return new QueryValve.NextDosage(credentials, request, result);
} catch (final AmazonClientException ex) {
throw new IOException(ex);
throw new IOException(
String.format(
"failed to fetch from \"%s\" by %s and %s",
table, conditions, keys
),
ex
);
} finally {
aws.shutdown();
}
Expand Down Expand Up @@ -342,7 +348,7 @@ public Dosage next() {
Logger.info(
this,
// @checkstyle LineLength (1 line)
"#next(): loaded %d item(s) from '%s' using %s%s, in %[ms]s",
"#next(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
rslt.getCount(), rqst.getTableName(),
rqst.getKeyConditions(),
AwsTable.print(rslt.getConsumedCapacity()),
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/jcabi/dynamo/ScanValve.java
Expand Up @@ -113,14 +113,20 @@ public Dosage fetch(final Credentials credentials,
final ScanResult result = aws.scan(request);
Logger.info(
this,
"#items(): loaded %d item(s) from '%s' using %s%s, in %[ms]s",
"#items(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
result.getCount(), table, conditions,
AwsTable.print(result.getConsumedCapacity()),
System.currentTimeMillis() - start
);
return new ScanValve.NextDosage(credentials, request, result);
} catch (final AmazonClientException ex) {
throw new IOException(ex);
throw new IOException(
String.format(
"failed to fetch from \"%s\" by %s and %s",
table, conditions, keys
),
ex
);
} finally {
aws.shutdown();
}
Expand Down Expand Up @@ -221,7 +227,7 @@ public Dosage next() {
Logger.info(
this,
// @checkstyle LineLength (1 line)
"#next(): loaded %d item(s) from '%s' using %s%s, in %[ms]s",
"#next(): loaded %d item(s) from '%s' using %s, %s, in %[ms]s",
rslt.getCount(), rqst.getTableName(), rqst.getScanFilter(),
AwsTable.print(rslt.getConsumedCapacity()),
System.currentTimeMillis() - start
Expand Down

0 comments on commit 5f70721

Please sign in to comment.