diff options
| author | Jesse Morgan <jesse@jesterpm.net> | 2018-03-25 18:10:14 -0700 | 
|---|---|---|
| committer | Jesse Morgan <jesse@jesterpm.net> | 2018-03-26 07:45:31 -0700 | 
| commit | 8fa81b2885d2597cb90e31294595a09ce62ffa44 (patch) | |
| tree | 094e7d95933d3da91c98c859bb72476fd42d2464 /src/test/java/com/amazon/carbonado/TestStorables.java | |
| parent | e9133156ea8dcefbd4b19d89c15ad6e2c01cf86d (diff) | |
Fix load by alternate key with Automatic primary keyfix-automatic-and-alt-key
Storables ignore @Automatic properties when checking if the primary key
is initialized. This makes sense for insert, because the Repository is
responsible for populating the @Automatic property. However, this doesn't
work for load--when the @Automatic property is also the primary key--
because it won't attempt to load by alternate key when it must.
Diffstat (limited to 'src/test/java/com/amazon/carbonado/TestStorables.java')
| -rw-r--r-- | src/test/java/com/amazon/carbonado/TestStorables.java | 27 | 
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/java/com/amazon/carbonado/TestStorables.java b/src/test/java/com/amazon/carbonado/TestStorables.java index b5b4fa8..e08e2ee 100644 --- a/src/test/java/com/amazon/carbonado/TestStorables.java +++ b/src/test/java/com/amazon/carbonado/TestStorables.java @@ -3513,6 +3513,33 @@ public class TestStorables extends TestCase {          }      } +    public void test_loadByAltKeyWithAutomatic() throws Exception { +        Storage<AutomaticAndAltKey> storage = +                getRepository().storageFor(AutomaticAndAltKey.class); + +        // Insert a couple of records, starting with id=1. +        // Note: manually set the Automatic ID property because not every +        //       Repository type will set it automatically. +        for (int i=1; i <= 2; i++) { +            AutomaticAndAltKey record = storage.prepare(); +            record.setID(i); +            record.setName("row" + i); +            record.insert(); +        } + +        // Load an existing record. +        AutomaticAndAltKey record = storage.prepare(); +        record.setName("row2"); +        assertTrue(record.tryLoad()); +        assertEquals(2, record.getID()); +        assertEquals("row2", record.getName()); + +        // Load a non-existent record. +        record = storage.prepare(); +        record.setName("row3"); +        assertFalse(record.tryLoad()); +    } +      private void assertUninitialized(boolean expected, Storable storable, String... properties) {          for (String property : properties) {              assertEquals(expected, storable.isPropertyUninitialized(property));  | 
