From 61051ed2b80a0f8407fbb6a0c27883a49c997721 Mon Sep 17 00:00:00 2001 From: Francesco Date: Tue, 24 Oct 2023 09:33:50 +0200 Subject: [PATCH] @Disable annotation to ignore entity (#24) --- .../tech/ailef/dbadmin/external/DbAdmin.java | 11 +++++- .../dbadmin/external/annotations/Disable.java | 35 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/main/java/tech/ailef/dbadmin/external/annotations/Disable.java diff --git a/src/main/java/tech/ailef/dbadmin/external/DbAdmin.java b/src/main/java/tech/ailef/dbadmin/external/DbAdmin.java index 38f94fd..026d816 100644 --- a/src/main/java/tech/ailef/dbadmin/external/DbAdmin.java +++ b/src/main/java/tech/ailef/dbadmin/external/DbAdmin.java @@ -47,6 +47,7 @@ import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; +import tech.ailef.dbadmin.external.annotations.Disable; import tech.ailef.dbadmin.external.annotations.DisplayFormat; import tech.ailef.dbadmin.external.dbmapping.CustomJpaRepository; import tech.ailef.dbadmin.external.dbmapping.DbField; @@ -107,7 +108,10 @@ public class DbAdmin { logger.debug("Found " + beanDefs.size() + " candidate @Entity classes"); for (BeanDefinition bd : beanDefs) { - schemas.add(processBeanDefinition(bd)); + // This can return null if the Entity has the @Disable annotation + DbObjectSchema schema = processBeanDefinition(bd); + if (schema != null) + schemas.add(schema); } logger.info("Scanned package '" + currentPackage + "'. Loaded " + beanDefs.size() + " schemas."); @@ -185,6 +189,11 @@ public class DbAdmin { try { Class klass = Class.forName(fullClassName); + + Disable disabled = klass.getAnnotation(Disable.class); + if (disabled != null) + return null; + DbObjectSchema schema = new DbObjectSchema(klass, this); CustomJpaRepository simpleJpaRepository = new CustomJpaRepository(schema, entityManager); schema.setJpaRepository(simpleJpaRepository); diff --git a/src/main/java/tech/ailef/dbadmin/external/annotations/Disable.java b/src/main/java/tech/ailef/dbadmin/external/annotations/Disable.java new file mode 100644 index 0000000..2f1a8ec --- /dev/null +++ b/src/main/java/tech/ailef/dbadmin/external/annotations/Disable.java @@ -0,0 +1,35 @@ +/* + * Spring Boot Database Admin - An automatically generated CRUD admin UI for Spring Boot apps + * Copyright (C) 2023 Ailef (http://ailef.tech) + * + * 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 tech.ailef.dbadmin.external.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Disables Spring Boot Database Admin on this table. + * This means it is ignored during the initialization phase and not analyzed + * at all. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Disable { +} \ No newline at end of file