Skip to content

Commit

Permalink
[Enhancement #124] Skip classes annotated with NonEntity when loading…
Browse files Browse the repository at this point in the history
… entities.
  • Loading branch information
ledsoft committed Dec 13, 2022
1 parent af93268 commit 4018118
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
@NonJPA
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface NotEntity {
public @interface NonEntity {
}
24 changes: 12 additions & 12 deletions jopa-impl/src/main/java/cz/cvut/kbss/jopa/loaders/EntityLoader.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
* <p>
* 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.
* <p>
* 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
* <http://www.gnu.org/licenses/>.
*/
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;
Expand All @@ -33,7 +32,8 @@ public Set<Class<?>> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 4018118

Please sign in to comment.