Added JPA connection provider and added basic support for multiple transactions to KeycloakSession
This commit is contained in:
1 parent
8cc7676335
commit
d625fb014c
120 files changed
+1867
-1291
No files matched your search
+7
-26
@@ -34,7 +34,6 @@ public class DefaultCacheModelProvider implements CacheModelProvider {
|
||||
protected KeycloakCache cache;
|
||||
protected KeycloakSession session;
|
||||
protected ModelProvider delegate;
|
||||
protected KeycloakTransaction transactionDelegate;
|
||||
protected boolean transactionActive;
|
||||
protected boolean setRollbackOnly;
|
||||
|
||||
@@ -54,6 +53,8 @@ public class DefaultCacheModelProvider implements CacheModelProvider {
|
||||
public DefaultCacheModelProvider(KeycloakCache cache, KeycloakSession session) {
|
||||
this.cache = cache;
|
||||
this.session = session;
|
||||
|
||||
session.getTransaction().enlist(getTransaction());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,13 +62,6 @@ public class DefaultCacheModelProvider implements CacheModelProvider {
|
||||
if (!transactionActive) throw new IllegalStateException("Cannot access delegate without a transaction");
|
||||
if (delegate != null) return delegate;
|
||||
delegate = session.getProvider(ModelProvider.class);
|
||||
transactionDelegate = delegate.getTransaction();
|
||||
if (!transactionDelegate.isActive()) {
|
||||
transactionDelegate.begin();
|
||||
if (setRollbackOnly) {
|
||||
transactionDelegate.setRollbackOnly();
|
||||
}
|
||||
}
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@@ -115,8 +109,7 @@ public class DefaultCacheModelProvider implements CacheModelProvider {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeycloakTransaction getTransaction() {
|
||||
private KeycloakTransaction getTransaction() {
|
||||
return new KeycloakTransaction() {
|
||||
@Override
|
||||
public void begin() {
|
||||
@@ -126,33 +119,21 @@ public class DefaultCacheModelProvider implements CacheModelProvider {
|
||||
@Override
|
||||
public void commit() {
|
||||
if (delegate == null) return;
|
||||
try {
|
||||
delegate.getTransaction().commit();
|
||||
if (clearAll) {
|
||||
cache.clear();
|
||||
}
|
||||
} finally {
|
||||
runInvalidations();
|
||||
if (clearAll) {
|
||||
cache.clear();
|
||||
}
|
||||
runInvalidations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() {
|
||||
setRollbackOnly = true;
|
||||
if (delegate == null) return;
|
||||
try {
|
||||
delegate.getTransaction().rollback();
|
||||
} finally {
|
||||
runInvalidations();
|
||||
}
|
||||
runInvalidations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRollbackOnly() {
|
||||
setRollbackOnly = true;
|
||||
if (delegate == null) return;
|
||||
delegate.getTransaction().setRollbackOnly();
|
||||
setRollbackOnly = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+11
-58
@@ -24,9 +24,9 @@ import java.util.Set;
|
||||
public class NoCacheModelProvider implements CacheModelProvider {
|
||||
protected KeycloakSession session;
|
||||
protected ModelProvider delegate;
|
||||
protected KeycloakTransaction transactionDelegate;
|
||||
protected boolean transactionActive;
|
||||
protected boolean setRollbackOnly;
|
||||
// protected KeycloakTransaction transactionDelegate;
|
||||
// protected boolean transactionActive;
|
||||
// protected boolean setRollbackOnly;
|
||||
|
||||
public NoCacheModelProvider(KeycloakSession session) {
|
||||
this.session = session;
|
||||
@@ -34,16 +34,16 @@ public class NoCacheModelProvider implements CacheModelProvider {
|
||||
|
||||
@Override
|
||||
public ModelProvider getDelegate() {
|
||||
if (!transactionActive) throw new IllegalStateException("Cannot access delegate without a transaction");
|
||||
// if (!transactionActive) throw new IllegalStateException("Cannot access delegate without a transaction");
|
||||
if (delegate != null) return delegate;
|
||||
delegate = session.getProvider(ModelProvider.class);
|
||||
transactionDelegate = delegate.getTransaction();
|
||||
if (!transactionDelegate.isActive()) {
|
||||
transactionDelegate.begin();
|
||||
if (setRollbackOnly) {
|
||||
transactionDelegate.setRollbackOnly();
|
||||
}
|
||||
}
|
||||
// transactionDelegate = delegate.getTransaction();
|
||||
// if (!transactionDelegate.isActive()) {
|
||||
// transactionDelegate.begin();
|
||||
// if (setRollbackOnly) {
|
||||
// transactionDelegate.setRollbackOnly();
|
||||
// }
|
||||
// }
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@@ -63,53 +63,6 @@ public class NoCacheModelProvider implements CacheModelProvider {
|
||||
public void registerOAuthClientInvalidation(String id) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeycloakTransaction getTransaction() {
|
||||
return new KeycloakTransaction() {
|
||||
@Override
|
||||
public void begin() {
|
||||
transactionActive = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() {
|
||||
if (delegate == null) return;
|
||||
try {
|
||||
delegate.getTransaction().commit();
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() {
|
||||
setRollbackOnly = true;
|
||||
if (delegate == null) return;
|
||||
try {
|
||||
delegate.getTransaction().rollback();
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRollbackOnly() {
|
||||
setRollbackOnly = true;
|
||||
if (delegate == null) return;
|
||||
delegate.getTransaction().setRollbackOnly();
|
||||
setRollbackOnly = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRollbackOnly() {
|
||||
return setRollbackOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return transactionActive;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public RealmModel createRealm(String name) {
|
||||
return getDelegate().createRealm(name);
|
||||
|
||||
Reference in new issue
Block a user