Skip to content

Commit

Permalink
Merge pull request #28095 from njr-11/27748-EntityDefining
Browse files Browse the repository at this point in the history
EntityDefining from Jakarta Data
  • Loading branch information
njr-11 authored Apr 5, 2024
2 parents 742ca76 + 6836639 commit 065300e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ IBM-API-Package: \
jakarta.data.metamodel.impl; type="spec",\
jakarta.data.page; type="spec",\
jakarta.data.page.impl; type="spec",\
jakarta.data.repository; type="spec"
jakarta.data.repository; type="spec",\
jakarta.data.spi; type="spec"
Subsystem-Name: Jakarta Data 1.0
#TODO io.openliberty.jakartaeePlatform-11.0
-features=\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import jakarta.data.repository.Repository;
import jakarta.data.repository.Save;
import jakarta.data.repository.Update;
import jakarta.data.spi.EntityDefining;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.spi.AfterBeanDiscovery;
Expand Down Expand Up @@ -595,7 +596,8 @@ private boolean supportsEntity(Class<?> entityClass, AnnotatedType<?> repository
Class<? extends Annotation> annoClass = anno.annotationType();
if (annoClass.equals(Entity.class))
return true;
else if (annoClass.getSimpleName().endsWith("Entity"))
else if (annoClass.getSimpleName().endsWith("Entity") // also covers Jakarta NoSQL entity
|| annoClass.isAnnotationPresent(EntityDefining.class))
hasEntityAnnos = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public void afterTypeDiscovery(@Observes AfterTypeDiscovery event, BeanManager b
if (entityClass == null)
throw new MappingException("Did not find the entity class for " + repositoryInterface);

PalindromicEntity entityAnno = entityClass.getAnnotation(PalindromicEntity.class);
Palindromic entityAnno = entityClass.getAnnotation(Palindromic.class);

if (entityAnno == null) {
Repository repository = repositoryType.getAnnotation(Repository.class);
if (!Repository.ANY_PROVIDER.equals(repository.provider()))
throw new MappingException("The Palindrome mock Jakarta Data provider cannot provide the " +
repositoryType.getJavaClass().getName() + " repository because the repository's " +
entityClass.getName() + " entity class is not annotated with " + PalindromicEntity.class.getName());
entityClass.getName() + " entity class is not annotated with " + Palindromic.class.getName());
} else {
BeanAttributes<?> attrs = beanMgr.createBeanAttributes(repositoryType);
Bean<?> bean = beanMgr.createBean(attrs, repositoryInterface, new PalindromeRepositoryProducer.Factory<>());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 IBM Corporation and others.
* Copyright (c) 2023,2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -17,10 +17,13 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.data.spi.EntityDefining;

/**
* Fake entity annotation.
*/
@EntityDefining
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface PalindromicEntity {
public @interface Palindromic {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022,2023 IBM Corporation and others.
* Copyright (c) 2022,2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -13,12 +13,12 @@

package test.jakarta.data.inmemory.web;

import test.jakarta.data.inmemory.provider.PalindromicEntity;
import test.jakarta.data.inmemory.provider.Palindromic;

/**
* Entity class for tests
*/
@PalindromicEntity
@Palindromic
public class Palindrome {
public long id;
public String letters;
Expand Down
3 changes: 2 additions & 1 deletion dev/io.openliberty.jakarta.data.1.0/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Export-Package: \
jakarta.data.metamodel.impl;version="1.0.0",\
jakarta.data.page;version="1.0.0",\
jakarta.data.page.impl;version="1.0.0",\
jakarta.data.repository;version="1.0.0"
jakarta.data.repository;version="1.0.0",\
jakarta.data.spi;version="1.0.0"

instrument.classesExcludes: jakarta/data/*.class

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package jakarta.data.spi;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Method signatures are copied from Jakarta Data.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface EntityDefining {
}

0 comments on commit 065300e

Please sign in to comment.