Skip to content
Open
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-GH-4068-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data JPA Parent</name>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-envers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-GH-4068-SNAPSHOT</version>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-GH-4068-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-jpa-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-GH-4068-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-GH-4068-SNAPSHOT</version>

<name>Spring Data JPA</name>
<description>Spring Data module for JPA repositories.</description>
Expand All @@ -16,7 +16,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-GH-4068-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor;
import org.jspecify.annotations.Nullable;
import org.springframework.data.repository.config.AotRepositoryContext;

import org.springframework.data.util.Lazy;
import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypes;
import org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo;
Expand All @@ -55,19 +55,6 @@ class AotMetamodel implements Metamodel {
private final Lazy<EntityManagerFactory> entityManagerFactory;
private final Lazy<EntityManager> entityManager = Lazy.of(() -> getEntityManagerFactory().createEntityManager());

public AotMetamodel(AotRepositoryContext repositoryContext) {
this(repositoryContext.getResolvedTypes().stream().filter(AotMetamodel::isJakartaAnnotated).map(Class::getName)
.toList(), null);
}

private static boolean isJakartaAnnotated(Class<?> cls) {

return cls.isAnnotationPresent(jakarta.persistence.Entity.class)
|| cls.isAnnotationPresent(jakarta.persistence.Embeddable.class)
|| cls.isAnnotationPresent(jakarta.persistence.MappedSuperclass.class)
|| cls.isAnnotationPresent(jakarta.persistence.Converter.class);
}

public AotMetamodel(PersistenceManagedTypes managedTypes) {
this(managedTypes.getManagedClassNames(), managedTypes.getPersistenceUnitRootUrl());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@
* @author Mark Paluch
* @since 4.0
*/
class EntityGraphLookup {

private final EntityManagerFactory entityManagerFactory;

public EntityGraphLookup(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
record EntityGraphLookup(EntityManagerFactory entityManagerFactory) {

@SuppressWarnings("unchecked")
public @Nullable AotEntityGraph findEntityGraph(MergedAnnotation<EntityGraph> entityGraph,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceUnitUtil;
import jakarta.persistence.metamodel.Metamodel;
import jakarta.persistence.spi.PersistenceUnitInfo;

import java.lang.reflect.Method;
import java.util.Map;
Expand Down Expand Up @@ -61,7 +60,6 @@
import org.springframework.data.repository.query.ReturnedType;
import org.springframework.javapoet.CodeBlock;
import org.springframework.javapoet.TypeName;
import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypes;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;

Expand All @@ -77,39 +75,31 @@
*/
public class JpaRepositoryContributor extends RepositoryContributor {

private final AotRepositoryContext context;
private final PersistenceUnitContext persistenceUnit;
private final Metamodel metamodel;
private final PersistenceUnitUtil persistenceUnitUtil;
private final PersistenceProvider persistenceProvider;
private final QueriesFactory queriesFactory;
private final EntityGraphLookup entityGraphLookup;
private final AotRepositoryContext context;

public JpaRepositoryContributor(AotRepositoryContext repositoryContext) {
this(repositoryContext, new AotMetamodel(repositoryContext));
}

public JpaRepositoryContributor(AotRepositoryContext repositoryContext, PersistenceUnitInfo unitInfo) {
this(repositoryContext, new AotMetamodel(unitInfo));
}

public JpaRepositoryContributor(AotRepositoryContext repositoryContext, PersistenceManagedTypes managedTypes) {
this(repositoryContext, new AotMetamodel(managedTypes));
this(repositoryContext, PersistenceUnitContexts.from(repositoryContext));
}

public JpaRepositoryContributor(AotRepositoryContext repositoryContext, EntityManagerFactory entityManagerFactory) {
this(repositoryContext, entityManagerFactory, entityManagerFactory.getMetamodel());
this(repositoryContext, PersistenceUnitContexts.from(entityManagerFactory));
}

private JpaRepositoryContributor(AotRepositoryContext repositoryContext, AotMetamodel metamodel) {
this(repositoryContext, metamodel.getEntityManagerFactory(), metamodel);
}

private JpaRepositoryContributor(AotRepositoryContext repositoryContext, EntityManagerFactory entityManagerFactory,
Metamodel metamodel) {
public JpaRepositoryContributor(AotRepositoryContext repositoryContext, PersistenceUnitContext persistenceUnit) {

super(repositoryContext);

this.metamodel = metamodel;
this.persistenceUnit = persistenceUnit;
this.metamodel = persistenceUnit.getMetamodel();

EntityManagerFactory entityManagerFactory = persistenceUnit.getEntityManagerFactory();

this.persistenceUnitUtil = entityManagerFactory.getPersistenceUnitUtil();
this.persistenceProvider = PersistenceProvider.fromEntityManagerFactory(entityManagerFactory);
this.queriesFactory = new QueriesFactory(repositoryContext.getConfigurationSource(), entityManagerFactory,
Expand Down Expand Up @@ -258,8 +248,8 @@ private Optional<Class<QueryEnhancerSelector>> getQueryEnhancerSelectorClass() {
});
}

public Metamodel getMetamodel() {
return metamodel;
public PersistenceUnitContext getPersistenceUnit() {
return persistenceUnit;
}

record StoredProcedureMetadata(String procedure) implements QueryMetadata {
Expand All @@ -268,6 +258,7 @@ record StoredProcedureMetadata(String procedure) implements QueryMetadata {
public Map<String, Object> serialize() {
return Map.of("procedure", procedure());
}

}

record NamedStoredProcedureMetadata(String procedureName) implements QueryMetadata {
Expand All @@ -276,6 +267,7 @@ record NamedStoredProcedureMetadata(String procedureName) implements QueryMetada
public Map<String, Object> serialize() {
return Map.of("procedure-name", procedureName());
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2025 the original author or authors.
*
* 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 org.springframework.data.jpa.repository.aot;

import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.metamodel.Metamodel;

/**
* Strategy interface representing a JPA PersistenceUnit providing access to {@link EntityManagerFactory} and
* {@link Metamodel} for AOT repository generation.
*/
public interface PersistenceUnitContext {

/**
* @return the entity manager factory.
*/
EntityManagerFactory getEntityManagerFactory();

/**
* @return metamodel describing managed types used in the persistence unit.
*/
Metamodel getMetamodel();
}
Loading