From df422c9673316b6a7ecdb96e314aeabd660985ad Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 29 Jun 2007 05:03:09 +0000 Subject: Fixed IllegalArgumentException with optimized join queries of the form "a.b = ? & (a.c = ? | a.d = ?)". --- .../com/amazon/carbonado/spi/TriggerManager.java | 87 +++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/amazon/carbonado/spi') diff --git a/src/main/java/com/amazon/carbonado/spi/TriggerManager.java b/src/main/java/com/amazon/carbonado/spi/TriggerManager.java index a67b134..c4caf72 100644 --- a/src/main/java/com/amazon/carbonado/spi/TriggerManager.java +++ b/src/main/java/com/amazon/carbonado/spi/TriggerManager.java @@ -32,6 +32,9 @@ import com.amazon.carbonado.Storable; import com.amazon.carbonado.Trigger; import com.amazon.carbonado.TriggerFactory; +import com.amazon.carbonado.lob.Blob; +import com.amazon.carbonado.lob.Clob; + /** * Used by Storage implementations to manage triggers and consolidate them into * single logical triggers. This class is thread-safe and ensures that changes @@ -44,6 +47,7 @@ public class TriggerManager extends Trigger { private static final int FOR_INSERT = 1; private static final int FOR_UPDATE = 2; private static final int FOR_DELETE = 4; + private static final int FOR_ADAPT_LOB = 8; private static final Method BEFORE_INSERT_METHOD, @@ -62,7 +66,10 @@ public class TriggerManager extends Trigger { BEFORE_TRY_DELETE_METHOD, AFTER_DELETE_METHOD, AFTER_TRY_DELETE_METHOD, - FAILED_DELETE_METHOD; + FAILED_DELETE_METHOD, + + ADAPT_BLOB_METHOD, + ADAPT_CLOB_METHOD; static { Class triggerClass = Trigger.class; @@ -87,6 +94,11 @@ public class TriggerManager extends Trigger { AFTER_DELETE_METHOD = triggerClass.getMethod("afterDelete", TWO_PARAMS); AFTER_TRY_DELETE_METHOD = triggerClass.getMethod("afterTryDelete", TWO_PARAMS); FAILED_DELETE_METHOD = triggerClass.getMethod("failedDelete", TWO_PARAMS); + + ADAPT_BLOB_METHOD = triggerClass + .getMethod("adaptBlob", Object.class, String.class, Blob.class); + ADAPT_CLOB_METHOD = triggerClass + .getMethod("adaptClob", Object.class, String.class, Clob.class); } catch (NoSuchMethodException e) { Error error = new NoSuchMethodError(); error.initCause(e); @@ -97,6 +109,7 @@ public class TriggerManager extends Trigger { private final ForInsert mForInsert = new ForInsert(); private final ForUpdate mForUpdate = new ForUpdate(); private final ForDelete mForDelete = new ForDelete(); + private final ForAdaptLob mForAdaptLob = new ForAdaptLob(); public TriggerManager() { } @@ -143,6 +156,18 @@ public class TriggerManager extends Trigger { return forDelete.isEmpty() ? null : forDelete; } + /** + * Returns a consolidated trigger to call for adapt LOB operations, or null + * if none. If not null, the consolidated trigger is not a snapshot -- it + * will change as the set of triggers in this manager changes. + * + * @since 1.2 + */ + public Trigger getAdaptLobTrigger() { + ForAdaptLob forAdaptLob = mForAdaptLob; + return forAdaptLob.isEmpty() ? null : forAdaptLob; + } + public boolean addTrigger(Trigger trigger) { if (trigger == null) { throw new IllegalArgumentException(); @@ -161,6 +186,9 @@ public class TriggerManager extends Trigger { if ((types & FOR_DELETE) != 0) { retValue |= mForDelete.add(trigger); } + if ((types & FOR_ADAPT_LOB) != 0) { + retValue |= mForAdaptLob.add(trigger); + } return retValue; } @@ -183,6 +211,9 @@ public class TriggerManager extends Trigger { if ((types & FOR_DELETE) != 0) { retValue |= mForDelete.remove(trigger); } + if ((types & FOR_ADAPT_LOB) != 0) { + retValue |= mForAdaptLob.remove(trigger); + } return retValue; } @@ -207,6 +238,7 @@ public class TriggerManager extends Trigger { mForInsert.localDisable(); mForUpdate.localDisable(); mForDelete.localDisable(); + mForAdaptLob.localDisable(); } /** @@ -217,6 +249,7 @@ public class TriggerManager extends Trigger { mForInsert.localEnable(); mForUpdate.localEnable(); mForDelete.localEnable(); + mForAdaptLob.localEnable(); } @Override @@ -294,6 +327,16 @@ public class TriggerManager extends Trigger { mForDelete.failedDelete(storable, state); } + @Override + public Blob adaptBlob(S storable, String name, Blob blob) { + return mForAdaptLob.adaptBlob(storable, name, blob); + } + + @Override + public Clob adaptClob(S storable, String name, Clob clob) { + return mForAdaptLob.adaptClob(storable, name, clob); + } + /** * Determines which operations the given trigger overrides. */ @@ -329,6 +372,12 @@ public class TriggerManager extends Trigger { types |= FOR_DELETE; } + if (overridesMethod(triggerClass, ADAPT_BLOB_METHOD) || + overridesMethod(triggerClass, ADAPT_CLOB_METHOD)) + { + types |= FOR_ADAPT_LOB; + } + return types; } @@ -897,4 +946,40 @@ public class TriggerManager extends Trigger { } } } + + private static class ForAdaptLob extends ForSomething { + @Override + public Blob adaptBlob(S storable, String name, Blob blob) { + if (isLocallyDisabled()) { + return blob; + } + + Trigger[] triggers = mTriggers; + + int length = triggers.length; + + for (int i=0; i[] triggers = mTriggers; + + int length = triggers.length; + + for (int i=0; i