NEW: PersistVisitor

This commit is contained in:
Roland Praml
2022-01-05 10:26:29 +01:00
parent f045d5e1b0
commit 50c612f8ec
8 changed files with 282 additions and 2 deletions
+13
View File
@@ -477,6 +477,19 @@ public final class DB {
public static int saveAll(Object... beans) throws OptimisticLockException {
return getDefault().saveAll(beans);
}
/**
* This will visit all beans in the persist graph on a given object
* <code>start</code>. It will call the visitor for each dirty bean that would
* be saved with {@link #save(Object)} or {@link #saveAll(Collection)}. You can
* use this method to implement custom validations.
*
* @param start could be a bean, a list of beans or a map of beans.
* @param visitor the visitor
*/
public static void visitSave(Object start, PersistVisitor visitor) {
getDefault().visitSave(start, visitor);
}
/**
* This method checks the uniqueness of a bean. I.e. if the save will work. It will return the
@@ -1017,6 +1017,17 @@ public interface Database {
* Save all the beans.
*/
int saveAll(Object... beans) throws OptimisticLockException;
/**
* This will visit all beans in the persist graph on a given object
* <code>start</code>. It will call the visitor for each dirty bean that would
* be saved with {@link #save(Object)} or {@link #saveAll(Collection)}. You can
* use this method to implement custom validations.
*
* @param start could be a bean, a list of beans or a map of beans.
* @param visitor the visitor
*/
void visitSave(Object start, PersistVisitor visitor);
/**
* Delete the bean.
@@ -0,0 +1,29 @@
package io.ebean;
import java.util.Collection;
import java.util.Map;
import io.ebean.bean.EntityBean;
import io.ebean.plugin.Property;
@FunctionalInterface
public interface PersistVisitor {
PersistVisitor visitBean(EntityBean bean);
default PersistVisitor visitProperty(Property prop) {
return this;
};
default PersistVisitor visitCollection(Collection<?> collection) {
return this;
};
default PersistVisitor visitMap(Map<?, ?> map) {
return this;
};
default void visitEnd() {
}
}