diff --git a/jopa-api/src/main/java/cz/cvut/kbss/jopa/model/annotations/util/NotEntity.java b/jopa-api/src/main/java/cz/cvut/kbss/jopa/model/annotations/util/NonEntity.java similarity index 94% rename from jopa-api/src/main/java/cz/cvut/kbss/jopa/model/annotations/util/NotEntity.java rename to jopa-api/src/main/java/cz/cvut/kbss/jopa/model/annotations/util/NonEntity.java index f4932cefb..9afa5ded4 100644 --- a/jopa-api/src/main/java/cz/cvut/kbss/jopa/model/annotations/util/NotEntity.java +++ b/jopa-api/src/main/java/cz/cvut/kbss/jopa/model/annotations/util/NonEntity.java @@ -15,5 +15,5 @@ @NonJPA @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -public @interface NotEntity { +public @interface NonEntity { } diff --git a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/EntityLoader.java b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/EntityLoader.java index 08584ff73..3c568e6d4 100644 --- a/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/EntityLoader.java +++ b/jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/EntityLoader.java @@ -1,20 +1,19 @@ /** * Copyright (C) 2022 Czech Technical University in Prague - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. You should have received a copy of the GNU General Public License - * along with this program. If not, see . + *

+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. + *

+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License along with this program. If not, see + * . */ package cz.cvut.kbss.jopa.loaders; import cz.cvut.kbss.jopa.model.annotations.OWLClass; +import cz.cvut.kbss.jopa.model.annotations.util.NonEntity; import java.util.HashSet; import java.util.Set; @@ -33,7 +32,8 @@ public Set> getEntities() { @Override public void accept(Class cls) { - if (cls.getAnnotation(OWLClass.class) != null && !cls.isInterface()) { + if (cls.getAnnotation(OWLClass.class) != null + && cls.getAnnotation(NonEntity.class) == null && !cls.isInterface()) { entities.add(cls); } } diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/NonPersistentClass.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/NonPersistentClass.java new file mode 100644 index 000000000..140833644 --- /dev/null +++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/environment/NonPersistentClass.java @@ -0,0 +1,35 @@ +package cz.cvut.kbss.jopa.environment; + +import cz.cvut.kbss.jopa.model.annotations.Id; +import cz.cvut.kbss.jopa.model.annotations.OWLClass; +import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty; +import cz.cvut.kbss.jopa.model.annotations.util.NonEntity; + +import java.net.URI; + +@NonEntity +@OWLClass(iri = Vocabulary.c_OwlClassA) +public class NonPersistentClass { + + @Id(generated = true) + private URI uri; + + @OWLDataProperty(iri = Vocabulary.p_a_stringAttribute) + private String stringAttribute; + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + public String getStringAttribute() { + return stringAttribute; + } + + public void setStringAttribute(String stringAttribute) { + this.stringAttribute = stringAttribute; + } +} diff --git a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/EntityLoaderTest.java b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/EntityLoaderTest.java index 83fba704c..22b41348e 100644 --- a/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/EntityLoaderTest.java +++ b/jopa-impl/src/test/java/cz/cvut/kbss/jopa/loaders/EntityLoaderTest.java @@ -14,6 +14,7 @@ */ package cz.cvut.kbss.jopa.loaders; +import cz.cvut.kbss.jopa.environment.NonPersistentClass; import cz.cvut.kbss.jopa.environment.OWLClassA; import cz.cvut.kbss.jopa.environment.Vocabulary; import cz.cvut.kbss.jopa.model.annotations.OWLClass; @@ -47,4 +48,10 @@ public void entityLoaderIgnoresInterfaceWithOwlClassAnnotation() { @OWLClass(iri = Vocabulary.CLASS_BASE + "interface") interface AnnotatedInterface { } + + @Test + void entityLoaderIgnoresClassAnnotatedWithNonEntity() { + sut.accept(NonPersistentClass.class); + assertFalse(sut.getEntities().contains(NonPersistentClass.class)); + } } \ No newline at end of file