From 87804809f306e8b93587ce22a36a709b9f88a6c3 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 19 Jul 2021 11:27:31 +0200 Subject: [PATCH] [New] Added tx.getPolicy(Class clazz, ...) overrides Old version are deprecated. This is to help the compiler know what we really want as result. This is a stop gap till we can make PolicyDef be typed, but this requires moving StrolchPolicy to model. --- .../persistence/api/AbstractTransaction.java | 14 ++++++- .../persistence/api/StrolchTransaction.java | 39 ++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java index b2c1387db..732a6f9f9 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java @@ -317,7 +317,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { } @Override - public void releaseLock(Locator locator) throws StrolchLockException { + public void releaseLock(Locator locator) throws StrolchLockException { this.realm.releaseLock(locator); this.lockedElements.remove(locator); } @@ -419,15 +419,27 @@ public abstract class AbstractTransaction implements StrolchTransaction { } @Override + @Deprecated public T getPolicy(PolicyDef policyDef) { return getContainer().getComponent(PolicyHandler.class).getPolicy(policyDef, this); } @Override + public T getPolicy(Class clazz, PolicyDef policyDef) { + return getContainer().getComponent(PolicyHandler.class).getPolicy(policyDef, this); + } + + @Override + @Deprecated public T getPolicy(PolicyDef policyDef, PolicyDef defaultDef) { return getContainer().getComponent(PolicyHandler.class).getPolicy(policyDef, defaultDef, this); } + @Override + public T getPolicy(Class clazz, PolicyDef policyDef, PolicyDef defaultDef) { + return getContainer().getComponent(PolicyHandler.class).getPolicy(policyDef, defaultDef, this); + } + private void assertQueryAllowed(StrolchQuery query) { try { getPrivilegeContext().validateAction(query); diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java index 20b090670..2495f508a 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java @@ -238,9 +238,26 @@ public interface StrolchTransaction extends AutoCloseable { * the type of policy to return * * @return the policy + * + * @deprecated use {@link #getPolicy(Class, PolicyDef)} instead */ + @Deprecated T getPolicy(PolicyDef policyDef); + /** + * Instantiates the policy using the given {@link PolicyDef} + * + * @param clazz + * the type of policy to return + * @param policyDef + * the policy definition + * @param + * the type of policy to return + * + * @return the policy + */ + T getPolicy(Class clazz, PolicyDef policyDef); + /** * Instantiates the policy using the given {@link PolicyDef}, or if not available, the default policy * @@ -252,9 +269,28 @@ public interface StrolchTransaction extends AutoCloseable { * the type of policy to return * * @return the policy + * + * @deprecated user {@link #getPolicy(Class, PolicyDef, PolicyDef)} instead */ + @Deprecated T getPolicy(PolicyDef policyDef, PolicyDef defaultDef); + /** + * Instantiates the policy using the given {@link PolicyDef}, or if not available, the default policy + * + * @param clazz + * the type of policy to return + * @param policyDef + * the policy definition + * @param defaultDef + * the default policy definition if the given policy definition is unavailable + * @param + * the type of policy to return + * + * @return the policy + */ + T getPolicy(Class clazz, PolicyDef policyDef, PolicyDef defaultDef); + /** * Returns the currently set {@link TransactionCloseStrategy} * @@ -324,6 +360,7 @@ public interface StrolchTransaction extends AutoCloseable { * StrolchTransactionException} which can be thrown by the caller to stop the exception * * @param exceptionMessage + * the message with which this TX has failed * * @return a {@link StrolchTransactionException} to be thrown by the caller */ @@ -505,7 +542,7 @@ public interface StrolchTransaction extends AutoCloseable { * @throws StrolchLockException * if something goes wrong while unlocking */ - void releaseLock(Locator locator) throws StrolchLockException; + void releaseLock(Locator locator) throws StrolchLockException; /** * Adds the given {@link Command} to the transaction. Using this method guarantees that a {@link Command} is