Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions jmix-bom/bom.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ dependencies {
api "io.jmix.dynattr:jmix-dynattr-flowui-kit:$freeVersion"
api "io.jmix.dynattr:jmix-dynattr-flowui-starter:$freeVersion"

api "io.jmix.dynmodel:jmix-dynmodel:$premiumVersion"
api "io.jmix.dynmodel:jmix-dynmodel-starter:$premiumVersion"
api "io.jmix.dynmodel:jmix-dynmodel-flowui:$premiumVersion"
api "io.jmix.dynmodel:jmix-dynmodel-flowui-starter:$premiumVersion"

api "io.jmix.email:jmix-email:$freeVersion"
api "io.jmix.email:jmix-email-flowui:$freeVersion"
api "io.jmix.email:jmix-email-starter:$freeVersion"
Expand Down Expand Up @@ -350,6 +355,7 @@ dependencies {
api "com.vaadin:vaadin-spreadsheet-flow:$vaadinFlowVersion"
api "com.vaadin:vaadin-dashboard-flow:$vaadinFlowVersion"
api "com.vaadin:flow-server:$vaadinFlowVersion"
api "com.vaadin:vaadin-dev:$vaadinFlowVersion"

api 'org.spockframework:spock-core:2.4-groovy-5.0'
api 'org.spockframework:spock-spring:2.4-groovy-5.0'
Expand Down
24 changes: 18 additions & 6 deletions jmix-core/core/src/main/java/io/jmix/core/CoreConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import io.jmix.core.annotation.JmixModule;
import io.jmix.core.impl.logging.LogMdcFilter;
import io.jmix.core.impl.metadata.MetadataGenerationFilter;
import io.jmix.core.impl.metadata.MetadataGenerationManager;
import io.jmix.core.impl.validation.JmixLocalValidatorFactoryBean;
import io.jmix.core.impl.validation.ValidationTraversableResolver;
import io.jmix.core.security.CurrentAuthentication;
Expand All @@ -29,12 +31,7 @@
import org.springframework.boot.validation.autoconfigure.ValidationConfigurationCustomizer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

Expand Down Expand Up @@ -96,4 +93,19 @@ public FilterRegistrationBean<LogMdcFilter> logMdcFilterFilterRegistrationBean(C
filterRegistration.setUrlPatterns(Set.of("/*"));
return filterRegistration;
}

/**
* Registers the servlet filter that pins a single metadata generation to each HTTP request.
*
* @return filter registration bean for metadata generation pinning
*/
@Bean("core_MetadataGenerationFilterRegistrationBean")
@Order(JmixOrder.HIGHEST_PRECEDENCE + 310)
public FilterRegistrationBean<MetadataGenerationFilter> metadataGenerationFilterRegistrationBean(
MetadataGenerationManager metadataGenerationManager) {
FilterRegistrationBean<MetadataGenerationFilter> filterRegistration =
new FilterRegistrationBean<>(new MetadataGenerationFilter(metadataGenerationManager));
filterRegistration.setUrlPatterns(Set.of("/*"));
return filterRegistration;
}
}
95 changes: 91 additions & 4 deletions jmix-core/core/src/main/java/io/jmix/core/ExtendedEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import io.jmix.core.common.datastruct.Pair;
import io.jmix.core.entity.annotation.ReplaceEntity;
import io.jmix.core.entity.annotation.ReplacedByEntity;
import io.jmix.core.impl.MetadataImpl;
import io.jmix.core.impl.metadata.MetadataGenerationManager;
import io.jmix.core.impl.keyvalue.KeyValueMetaClass;
import io.jmix.core.metamodel.model.MetaClass;
import io.jmix.core.metamodel.model.MetaProperty;
Expand All @@ -29,11 +31,14 @@
import io.jmix.core.metamodel.model.impl.MetaClassImpl;
import io.jmix.core.metamodel.model.impl.MetaPropertyImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Component;

import org.jspecify.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -47,15 +52,26 @@ public class ExtendedEntities {
protected Metadata metadata;

protected Map<Class<?>, MetaClass> replacedMetaClasses = new HashMap<>();
protected volatile ExtendedEntitiesState currentState = ExtendedEntitiesState.of(replacedMetaClasses);

@Autowired
protected ObjectProvider<MetadataGenerationManager> metadataGenerationManagerProvider;

@Autowired
public ExtendedEntities(Metadata metadata) {
this.metadata = metadata;
replaceExtendedMetaClasses();
replaceExtendedMetaClasses(getBootstrapSession());
currentState = ExtendedEntitiesState.of(replacedMetaClasses);
}

protected Session getBootstrapSession() {
if (metadata instanceof MetadataImpl metadataImpl) {
return metadataImpl.getRawSession();
}
return metadata.getSession();
}

protected void replaceExtendedMetaClasses() {
Session session = metadata.getSession();
protected void replaceExtendedMetaClasses(Session session) {
List<Pair<MetaClass, MetaClass>> replaceMap = new ArrayList<>();
for (MetaClass metaClass : session.getClasses()) {
MetaClass effectiveMetaClass = session.getClass(getEffectiveClass(metaClass));
Expand Down Expand Up @@ -198,7 +214,7 @@ public MetaClass getOriginalMetaClass(MetaClass extendedMetaClass) {
return null;
}

MetaClass metaClass = replacedMetaClasses.get(originalClass);
MetaClass metaClass = getState().getReplacedMetaClasses().get(originalClass);
if (metaClass != null) {
return metaClass;
}
Expand Down Expand Up @@ -231,5 +247,76 @@ public MetaClass getOriginalOrThisMetaClass(MetaClass metaClass) {
@Internal
public void registerReplacedMetaClass(MetaClass metaClass) {
replacedMetaClasses.put(metaClass.getJavaClass(), metaClass);
currentState = ExtendedEntitiesState.of(replacedMetaClasses);
}

/**
* Returns the extended-entities state visible to the current metadata generation.
*
* <p>Intended for infrastructure that needs a stable replacement map for the whole request or data operation.</p>
*/
public ExtendedEntitiesState getCurrentStateSnapshot() {
MetadataGenerationManager metadataGenerationManager = metadataGenerationManagerProvider.getIfAvailable();
if (metadataGenerationManager != null) {
return metadataGenerationManager.getPinnedOrCurrentGeneration().getExtendedEntitiesState();
}
return currentState;
}

/**
* Returns the extended-entities state built from the bootstrap metadata session.
*
* <p>Intended for initialization of the first published metadata generation.</p>
*/
public ExtendedEntitiesState getBootstrapState() {
return currentState;
}

protected ExtendedEntitiesState getState() {
MetadataGenerationManager metadataGenerationManager = metadataGenerationManagerProvider.getIfAvailable();
if (metadataGenerationManager != null) {
return metadataGenerationManager.getPinnedOrCurrentGeneration().getExtendedEntitiesState();
}
return currentState;
}

public static class ExtendedEntitiesState {

protected final Map<Class<?>, MetaClass> replacedMetaClasses;

protected ExtendedEntitiesState(Map<Class<?>, MetaClass> replacedMetaClasses) {
this.replacedMetaClasses = Collections.unmodifiableMap(replacedMetaClasses);
}

/**
* Creates an immutable snapshot of replaced meta classes.
*
* @param replacedMetaClasses replacement mapping to snapshot
* @return immutable state snapshot
*/
public static ExtendedEntitiesState of(Map<Class<?>, MetaClass> replacedMetaClasses) {
return new ExtendedEntitiesState(new LinkedHashMap<>(replacedMetaClasses));
}

/**
* Returns replaced meta classes keyed by original Java type.
*/
public Map<Class<?>, MetaClass> getReplacedMetaClasses() {
return replacedMetaClasses;
}

/**
* Rebuilds the state for a cloned metadata session.
*
* @param metaClassMap mapping from source meta classes to cloned meta classes
* @return state remapped to the cloned session
*/
public ExtendedEntitiesState remap(Map<MetaClass, MetaClass> metaClassMap) {
Map<Class<?>, MetaClass> remapped = new LinkedHashMap<>();
for (Map.Entry<Class<?>, MetaClass> entry : replacedMetaClasses.entrySet()) {
remapped.put(entry.getKey(), metaClassMap.get(entry.getValue()));
}
return new ExtendedEntitiesState(remapped);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ public interface InstanceNameProvider {
* @return collection of the name pattern properties
*/
Collection<MetaProperty> getInstanceNameRelatedProperties(MetaClass metaClass, boolean useOriginal);

/**
* Evicts cached instance name metadata for all entities.
*/
default void evictInstanceNameCache() {
}
}
2 changes: 1 addition & 1 deletion jmix-core/core/src/main/java/io/jmix/core/LoadContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public Sort getSort() {
* @param sort query sort
* @return this query instance for chaining
*/
public Query setSort(Sort sort) {
public Query setSort(@Nullable Sort sort) {
this.sort = sort;
return this;
}
Expand Down
9 changes: 6 additions & 3 deletions jmix-core/core/src/main/java/io/jmix/core/MetadataTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class MetadataTools {
public static final String SYSTEM_ANN_NAME = "jmix.system";
public static final String STORE_ANN_NAME = "jmix.storeName";
public static final String LENGTH_ANN_NAME = "jmix.length";
public static final String LOB_ANN_NAME = "jmix.lob";
public static final String INCLUDE_IN_FETCH_PLAN_ANN_NAME = "jmix.includeInFetchPlan";
public static final String CASCADE_TYPES_ANN_NAME = "jmix.cascadeTypes";
public static final String CASCADE_PROPERTIES_ANN_NAME = "jmix.cascadeProperties";
public static final String EMBEDDED_PROPERTIES_ANN_NAME = "jmix.embeddedProperties";
Expand Down Expand Up @@ -418,7 +420,8 @@ public boolean isJpa(MetaPropertyPath metaPropertyPath) {
*/
public boolean isJpa(MetaProperty metaProperty) {
Objects.requireNonNull(metaProperty, "metaProperty is null");
return metaProperty.getStore().getDescriptor().isJpa();
return metaProperty.getStore().getDescriptor().isJpa()
&& metaProperty.getDeclaringClass() != null; // not a dynamic property
}

/**
Expand All @@ -436,8 +439,8 @@ public boolean isMethodBased(MetaProperty metaProperty) {
*/
public boolean isLob(MetaProperty metaProperty) {
Objects.requireNonNull(metaProperty, "metaProperty is null");
return metaProperty.getAnnotatedElement() != null
&& metaProperty.getAnnotatedElement().isAnnotationPresent(Lob.class);
return metaProperty.getAnnotatedElement().isAnnotationPresent(Lob.class)
|| Boolean.TRUE.equals(metaProperty.getAnnotations().get(LOB_ANN_NAME));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public Sort getSort() {
* @param sort query sort
* @return this query instance for chaining
*/
public Query setSort(Sort sort) {
public Query setSort(@Nullable Sort sort) {
this.sort = sort;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
Expand All @@ -39,13 +40,36 @@
*/
public final class ReflectionHelper {

private static final Set<ClassLoader> classLoaders = new CopyOnWriteArraySet<>();

private static final LoadingCache<Class<?>, Map<String, Field>> fieldsCache = CacheBuilder.newBuilder()
.weakKeys()
.build(CacheLoader.from(ReflectionHelper::getDeclaredFields));

private ReflectionHelper() {
}

/**
* Add an additional class loader to be used by {@link #loadClass(String)}.
*/
public static void addClassLoader(ClassLoader classLoader) {
classLoaders.add(classLoader);
}

/**
* Remove an additional class loader.
*/
public static void removeClassLoader(ClassLoader classLoader) {
classLoaders.remove(classLoader);
}

/**
* Clear all additional class loaders.
*/
public static void clearClassLoaders() {
classLoaders.clear();
}

/**
* Load class by name.
*
Expand Down Expand Up @@ -78,7 +102,18 @@ public static Class<?> loadClass(String name) throws ClassNotFoundException {
"Consider setting it in a new thread using 'Thread.currentThread().setContextClassLoader()' " +
"to the classloader of the parent thread or executing class.");
}
return contextClassLoader.loadClass(name);
try {
return contextClassLoader.loadClass(name);
} catch (ClassNotFoundException e) {
for (ClassLoader classLoader : classLoaders) {
try {
return classLoader.loadClass(name);
} catch (ClassNotFoundException e1) {
// ignore
}
}
throw e;
}
}

/**
Expand Down
Loading