parent
c49c4f80a2
commit
af7a040d54
1 changed files with 21 additions and 16 deletions
|
@ -24,6 +24,8 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
|
@ -80,10 +82,11 @@ public class JpaMapStorageProviderFactory implements
|
||||||
EnvironmentDependentProviderFactory {
|
EnvironmentDependentProviderFactory {
|
||||||
|
|
||||||
public static final String PROVIDER_ID = "jpa-map-storage";
|
public static final String PROVIDER_ID = "jpa-map-storage";
|
||||||
|
private static final Logger logger = Logger.getLogger(JpaMapStorageProviderFactory.class);
|
||||||
|
|
||||||
private volatile EntityManagerFactory emf;
|
private volatile EntityManagerFactory emf;
|
||||||
|
private final Set<Class<?>> validatedModels = ConcurrentHashMap.newKeySet();
|
||||||
private Config.Scope config;
|
private Config.Scope config;
|
||||||
private static final Logger logger = Logger.getLogger(JpaMapStorageProviderFactory.class);
|
|
||||||
|
|
||||||
public final static DeepCloner CLONER = new DeepCloner.Builder()
|
public final static DeepCloner CLONER = new DeepCloner.Builder()
|
||||||
//client
|
//client
|
||||||
|
@ -144,6 +147,7 @@ public class JpaMapStorageProviderFactory implements
|
||||||
if (emf != null) {
|
if (emf != null) {
|
||||||
emf.close();
|
emf.close();
|
||||||
}
|
}
|
||||||
|
this.validatedModels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lazyInit() {
|
private void lazyInit() {
|
||||||
|
@ -231,15 +235,15 @@ public class JpaMapStorageProviderFactory implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validateAndUpdateSchema(KeycloakSession session, Class<?> modelType) {
|
public void validateAndUpdateSchema(KeycloakSession session, Class<?> modelType) {
|
||||||
|
if (this.validatedModels.add(modelType)) {
|
||||||
Connection connection = getConnection();
|
Connection connection = getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (logger.isDebugEnabled()) printOperationalInfo(connection);
|
if (logger.isDebugEnabled()) printOperationalInfo(connection);
|
||||||
|
|
||||||
MapJpaUpdaterProvider updater = session.getProvider(MapJpaUpdaterProvider.class);
|
MapJpaUpdaterProvider updater = session.getProvider(MapJpaUpdaterProvider.class);
|
||||||
MapJpaUpdaterProvider.Status status = updater.validate(modelType, connection, config.get("schema"));
|
MapJpaUpdaterProvider.Status status = updater.validate(modelType, connection, config.get("schema"));
|
||||||
|
|
||||||
if (! status.equals(VALID)) {
|
if (!status.equals(VALID)) {
|
||||||
update(modelType, connection, session);
|
update(modelType, connection, session);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -252,6 +256,7 @@ public class JpaMapStorageProviderFactory implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Connection getConnection() {
|
private Connection getConnection() {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue