From c08e8a086133809df5526420c7d4cf40bb8cad3c Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 19 Sep 2006 07:14:05 +0000 Subject: Make toStringKeyOnly also include alternate keys. --- src/main/java/com/amazon/carbonado/Storable.java | 4 +-- .../amazon/carbonado/spi/StorableGenerator.java | 36 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/amazon/carbonado/Storable.java b/src/main/java/com/amazon/carbonado/Storable.java index f5c2248..20c7ab7 100644 --- a/src/main/java/com/amazon/carbonado/Storable.java +++ b/src/main/java/com/amazon/carbonado/Storable.java @@ -416,8 +416,8 @@ public interface Storable> { String toString(); /** - * Returns a string for debugging purposes that contains only supported - * primary key property names and values for this object. Unsupported + * Returns a string for debugging purposes that contains supported + * key property names and values for this object. Unsupported * {@link Independent independent} properties are not included. */ String toStringKeyOnly(); diff --git a/src/main/java/com/amazon/carbonado/spi/StorableGenerator.java b/src/main/java/com/amazon/carbonado/spi/StorableGenerator.java index f63a260..ecd344d 100644 --- a/src/main/java/com/amazon/carbonado/spi/StorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/spi/StorableGenerator.java @@ -3138,6 +3138,42 @@ public final class StorableGenerator { b.loadConstant('}'); invokeAppend(b, charParam); + + // For key string, also show all the alternate keys. This makes the + // FetchNoneException message more helpful. + if (keyOnly) { + int altKeyCount = mInfo.getAlternateKeyCount(); + for (int i=0; i key = mInfo.getAlternateKey(i); + + ordinal = 0; + for (OrderedProperty op : key.getProperties()) { + StorableProperty property = op.getChainedProperty().getPrimeProperty(); + + Label skipPrint = b.createLabel(); + + // Check if independent property is supported, and skip if not. + if (property.isIndependent()) { + addSkipIndependent(b, null, property, skipPrint); + } + + if (ordinal++ > 0) { + b.loadConstant(", "); + invokeAppend(b, stringParam); + } + addPropertyAppendCall(b, property, stringParam, charParam); + + skipPrint.setLocation(); + } + + b.loadConstant('}'); + invokeAppend(b, charParam); + } + } + b.invokeVirtual(stringBuilder, TO_STRING_METHOD_NAME, TypeDesc.STRING, null); b.returnValue(TypeDesc.STRING); } -- cgit v1.2.3