Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,8 @@ public MetaClass getOriginalOrThisMetaClass(MetaClass metaClass) {
public void registerReplacedMetaClass(MetaClass metaClass) {
replacedMetaClasses.put(metaClass.getJavaClass(), metaClass);
}

public void unregisterReplacedMetaClass(MetaClass metaClass) {

}
}
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() {
}
}
8 changes: 5 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,7 @@ 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 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 +419,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 +438,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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ public Set<?> save(SaveContext context) {
fireEvent(deletingEvent);

beforeSaveTransactionCommit(context, savedEntities, deletedEntities);
DataStoreBeforeSaveCommitEvent beforeSaveCommitEvent =
new DataStoreBeforeSaveCommitEvent(context, savedEntities, deletedEntities, saveState);
fireEvent(beforeSaveCommitEvent);
commitTransaction(transaction);
} finally {
beforeSaveTransactionRollback(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2026 Haulmont.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.jmix.core.datastore;

import io.jmix.core.metamodel.model.StoreDescriptor;

public interface AdditionalStoreDescriptorProvider {

String getStoreName();

StoreDescriptor getStoreDescriptor();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2026 Haulmont.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.jmix.core.datastore;

import io.jmix.core.SaveContext;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class DataStoreBeforeSaveCommitEvent extends BaseDataStoreEvent {
private static final long serialVersionUID = -6940314788251718595L;

protected final EventSharedState eventState;
protected final List<Object> savedEntities;
protected final List<Object> removedEntities;

public DataStoreBeforeSaveCommitEvent(SaveContext saveContext, Collection<Object> savedEntities,
Collection<Object> removedEntities, EventSharedState eventState) {
super(saveContext);
this.eventState = eventState;
this.savedEntities = new ArrayList<>(savedEntities);
this.removedEntities = new ArrayList<>(removedEntities);
}

public SaveContext getSaveContext() {
return (SaveContext) getSource();
}

public EventSharedState getEventState() {
return eventState;
}

public List<Object> getSavedEntities() {
return savedEntities;
}

public List<Object> getRemovedEntities() {
return removedEntities;
}

@Override
public void sendTo(DataStoreEventListener listener) {
listener.beforeSaveCommit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ default void entitySaving(DataStoreEntitySavingEvent event) {
default void entityDeleting(DataStoreEntityDeletingEvent event) {
}

default void beforeSaveCommit(DataStoreBeforeSaveCommitEvent event) {
}

default void entityReload(DataStoreEntityReloadEvent event) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ public Collection<MetaProperty> getInstanceNameRelatedProperties(MetaClass metaC
return optional.map(instanceNameRec -> Arrays.asList(instanceNameRec.nameProperties)).orElse(Collections.emptyList());
}

@Override
public void evictInstanceNameCache() {
instanceNameRecCache.invalidateAll();
}

protected Collection<MetaProperty> getInstanceNameProperties(MetaClass metaClass, @Nullable Method nameMethod, @Nullable MetaProperty nameProperty) {
final Collection<MetaProperty> properties = new HashSet<>();
if (nameMethod != null) {
Expand Down Expand Up @@ -278,7 +283,7 @@ public InstanceNameRec parseNamePattern(MetaClass metaClass) {
.filter(m -> AnnotatedElementUtils.findMergedAnnotation(m, InstanceName.class) != null)
.collect(Collectors.toList());
List<MetaProperty> nameProperties = metaClass.getProperties().stream()
.filter(p -> p.getAnnotatedElement().getAnnotation(InstanceName.class) != null)
.filter(this::isInstanceNameProperty)
.filter(p -> !metadataTools.isMethodBased(p))
.collect(Collectors.toList());
if (!instanceNameMethods.isEmpty()) {
Expand Down Expand Up @@ -317,6 +322,13 @@ public InstanceNameRec parseNamePattern(MetaClass metaClass) {
.toArray(MetaProperty[]::new));
}

protected boolean isInstanceNameProperty(MetaProperty metaProperty) {
if (metaProperty.getAnnotatedElement().getAnnotation(InstanceName.class) != null) {
return true;
}
return Boolean.TRUE.equals(metadataTools.getMetaAnnotationValue(metaProperty, InstanceName.class));
}

private void validateInstanceNameAnnotation(MetaClass metaClass,
List<Method> instanceNameMethods,
List<MetaProperty> nameProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
import com.google.common.collect.Sets;
import io.jmix.core.CoreProperties;
import io.jmix.core.TimeSource;
import io.jmix.core.common.util.ReflectionHelper;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import org.apache.commons.io.FileUtils;
import jakarta.annotation.PreDestroy;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import org.springframework.beans.factory.annotation.Autowired;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
Expand Down Expand Up @@ -73,6 +74,7 @@ public JavaClassLoader(CoreProperties coreProperties) {
for (String dir : this.rootDirs) {
this.classFilesProviders.put(dir, new ClassFilesProvider(dir));
}
ReflectionHelper.addClassLoader(this);
}

//Please use this constructor only in tests
Expand All @@ -88,12 +90,18 @@ public JavaClassLoader(CoreProperties coreProperties) {
for (String dir : this.rootDirs) {
this.classFilesProviders.put(dir, new ClassFilesProvider(dir));
}
ReflectionHelper.addClassLoader(this);
}

public void clearCache() {
loaded.clear();
}

@PreDestroy
public void destroy() {
ReflectionHelper.removeClassLoader(this);
}

@Override
public Class loadClass(final String fullClassName, boolean resolve) throws ClassNotFoundException {
String containerClassName = StringUtils.substringBefore(fullClassName, "$");
Expand All @@ -107,6 +115,10 @@ public Class loadClass(final String fullClassName, boolean resolve) throws Class
for (ClassFilesProvider classFilesProvider : classFilesProviders.values()) {
File classFile = classFilesProvider.getClassFile(containerClassName);
if (classFile.exists()) {
TimestampClass timestampClass = loaded.get(containerClassName);
if (timestampClass != null && classFile.lastModified() <= timestampClass.timestamp.getTime()) {
return timestampClass.clazz;
}
return loadClassFromClassFile(fullClassName, containerClassName, classFile);
}
}
Expand All @@ -121,10 +133,6 @@ public Class loadClass(final String fullClassName, boolean resolve) throws Class
}

protected Class loadClassFromClassFile(String fullClassName, String containerClassName, File classFile) {
TimestampClass timestampClass = loaded.get(containerClassName);
if (timestampClass != null && !FileUtils.isFileNewer(classFile, timestampClass.timestamp)) {
return timestampClass.clazz;
}
Map<String, Class> loadedClasses = new HashMap<>();
Map<String, String> modifiedClassFiles = new HashMap<>();
Map<String, FileClassLoader> fileClassLoaders = new HashMap<>();
Expand All @@ -144,7 +152,16 @@ protected Class loadClassFromClassFile(String fullClassName, String containerCla
throw new RuntimeException("Class not found", e);
}
loadedClasses.put(fqn, clazz);
loaded.put(fqn, new TimestampClass(clazz, getCurrentTimestamp()));

Date timestamp = getCurrentTimestamp();
for (ClassFilesProvider classFilesProvider : classFilesProviders.values()) {
File file = classFilesProvider.getClassFile(fqn);
if (file.exists()) {
timestamp = new Date(file.lastModified());
break;
}
}
loaded.put(fqn, new TimestampClass(clazz, timestamp));
}
springBeanLoader.updateContext(loadedClasses.values());
return loadedClasses.get(fullClassName);
Expand All @@ -165,7 +182,8 @@ protected Set<String> collectModifiedClassFiles(String rootDir) {
String fqn = root.relativize(path).toString();
fqn = fqn.substring(0, fqn.length() - 6).replace(File.separator, ".");
TimestampClass timeStampClass = getTimestampClass(fqn);
if (timeStampClass == null || FileUtils.isFileNewer(path.toFile(), timeStampClass.timestamp)) {
long lastModified = path.toFile().lastModified();
if (timeStampClass == null || lastModified > timeStampClass.timestamp.getTime()) {
result.add(fqn);
}
});
Expand Down
Loading