mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
NEW: PersistVisitor
This commit is contained in:
@@ -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() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user