summaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2010-03-11 01:24:57 +0000
committerBrian S. O'Neill <bronee@gmail.com>2010-03-11 01:24:57 +0000
commitdc375a085d7689ba541d573181d31816c5d1dd9e (patch)
treecaea63ecbf1d9f0d4dcd0bf11b2400fcec5ab1a3 /src/main/java/com
parente426204e204463aaf2229a6d69e34360c346b1ed (diff)
Support partition key when loading by alternate key.
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/amazon/carbonado/gen/CommonMethodNames.java1
-rw-r--r--src/main/java/com/amazon/carbonado/gen/StorableGenerator.java74
2 files changed, 57 insertions, 18 deletions
diff --git a/src/main/java/com/amazon/carbonado/gen/CommonMethodNames.java b/src/main/java/com/amazon/carbonado/gen/CommonMethodNames.java
index ba20e31..5356fba 100644
--- a/src/main/java/com/amazon/carbonado/gen/CommonMethodNames.java
+++ b/src/main/java/com/amazon/carbonado/gen/CommonMethodNames.java
@@ -73,6 +73,7 @@ public class CommonMethodNames {
public static final String
LOAD_ONE_METHOD_NAME = "loadOne",
TRY_LOAD_ONE_METHOD_NAME = "tryLoadOne",
+ AND_METHOD_NAME = "and",
WITH_METHOD_NAME = "with",
FETCH_METHOD_NAME = "fetch";
diff --git a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
index 0aeb541..6fd19fc 100644
--- a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
+++ b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java
@@ -1021,12 +1021,15 @@ public final class StorableGenerator<S extends Storable> {
CodeBuilder b = new CodeBuilder(mi);
- // Add empty method that will be overrriden if there is a partition key to check that it is initialized
+ // Add empty method that will be overrriden if there is a partition
+ // key to check that it is initialized
b.loadThis();
- b.invokeVirtual(CHECK_PK_FOR_LOAD_METHOD_NAME, null, null);
- CodeBuilder b1 = new CodeBuilder(mClassFile.addMethod(Modifiers.PROTECTED, CHECK_PK_FOR_LOAD_METHOD_NAME, null, null));
- b1.loadThis();
- b1.returnVoid();
+ b.invokeVirtual(CHECK_PK_FOR_LOAD_METHOD_NAME, null, null);
+ CodeBuilder b1 = new CodeBuilder
+ (mClassFile.addMethod
+ (Modifiers.PROTECTED, CHECK_PK_FOR_LOAD_METHOD_NAME, null, null));
+ b1.loadThis();
+ b1.returnVoid();
// Check that primary key is initialized.
b.loadThis();
@@ -1083,6 +1086,41 @@ public final class StorableGenerator<S extends Storable> {
new TypeDesc[]{bindType});
}
+ StorableKey<S> parKey = mInfo.getPartitionKey();
+ if (parKey != null) {
+ // Transfer set partition key properties to query.
+ for (OrderedProperty<S> op : parKey.getProperties()) {
+ if (altKey.getProperties().contains(op)) {
+ // Was already supplied to query.
+ continue;
+ }
+
+ StorableProperty<S> prop = op.getChainedProperty().getPrimeProperty();
+
+ Label skip = b.createLabel();
+
+ if (!prop.isDerived()) {
+ int num = prop.getNumber();
+ b.loadThis();
+ b.loadField(PROPERTY_STATE_FIELD_NAME + (num >> 4), TypeDesc.INT);
+ b.loadConstant(PROPERTY_STATE_MASK << ((num & 0xf) * 2));
+ b.math(Opcode.IAND);
+ b.ifZeroComparisonBranch(skip, "==");
+ }
+
+ b.loadConstant(prop.getName() + " = ?");
+ b.invokeInterface(queryType, AND_METHOD_NAME, queryType,
+ new TypeDesc[]{TypeDesc.STRING});
+ loadThisProperty(b, prop);
+ TypeDesc bindType = CodeBuilderUtil.bindQueryParam(prop.getType());
+ CodeBuilderUtil.convertValue(b, prop.getType(), bindType.toClass());
+ b.invokeInterface(queryType, WITH_METHOD_NAME, queryType,
+ new TypeDesc[]{bindType});
+
+ skip.setLocation();
+ }
+ }
+
b.branch(runQuery);
noAltKey.setLocation();
@@ -1714,19 +1752,19 @@ public final class StorableGenerator<S extends Storable> {
addIsInitializedMethod
(IS_PK_INITIALIZED_METHOD_NAME, mInfo.getPrimaryKeyProperties());
- {
- // Define protected isPartitionKeyInitialized method
- // It will return true if there are no Partition keys
- final Map<String, StorableProperty<S>> partitionProperties = new LinkedHashMap<String, StorableProperty<S>>();
- for (StorableProperty<S> property : mAllProperties.values()) {
- if (!property.isDerived() && property.isPartitionKeyMember()) {
- partitionProperties.put(property.getName(), property);
- }
- }
-
- // Add methods to check that the partition key is defined
- addIsInitializedMethod(IS_PARTITION_KEY_INITIALIZED_METHOD_NAME, partitionProperties);
- }
+ {
+ // Define protected isPartitionKeyInitialized method
+ // It will return true if there are no Partition keys
+ final Map<String, StorableProperty<S>> partitionProperties = new LinkedHashMap<String, StorableProperty<S>>();
+ for (StorableProperty<S> property : mAllProperties.values()) {
+ if (!property.isDerived() && property.isPartitionKeyMember()) {
+ partitionProperties.put(property.getName(), property);
+ }
+ }
+
+ // Add methods to check that the partition key is defined
+ addIsInitializedMethod(IS_PARTITION_KEY_INITIALIZED_METHOD_NAME, partitionProperties);
+ }
// Define protected methods to check if alternate key is initialized.
addAltKeyMethods: