mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1221 - ENH: Add a merge(bean) and merge(bean, paths)
This commit is contained in:
1 parent
607cf3156c
commit
afead2da41
37 files changed
+1804
-66
No files matched your search
@@ -0,0 +1,74 @@
|
||||
package io.ebeaninternal.server.persist;
|
||||
|
||||
import io.ebean.Query;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
import io.ebeaninternal.server.deploy.BeanPropertyAssoc;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Base class for merge nodes.
|
||||
*/
|
||||
abstract class MergeNode {
|
||||
|
||||
protected final String fullPath;
|
||||
protected final BeanDescriptor<?> targetDescriptor;
|
||||
protected Map<String,MergeNode> children;
|
||||
|
||||
MergeNode(String fullPath, BeanPropertyAssoc<?> property) {
|
||||
this.fullPath = fullPath;
|
||||
this.targetDescriptor = property.getTargetDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the merge processing.
|
||||
*/
|
||||
abstract void merge(MergeRequest request);
|
||||
|
||||
/**
|
||||
* Add a child node given the fullPath and relative path.
|
||||
*/
|
||||
MergeNode addChild(String fullPath, String path) {
|
||||
MergeNode childNode = MergeHandler.createMergeNode(fullPath, targetDescriptor, path);
|
||||
if (children == null) {
|
||||
children = new LinkedHashMap<>();
|
||||
}
|
||||
children.put(path, childNode);
|
||||
return childNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the node given the relative path.
|
||||
*/
|
||||
MergeNode get(String path) {
|
||||
if (children != null) {
|
||||
return children.get(path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to the query to fetch the Ids values for the foreign keys basically.
|
||||
*/
|
||||
void addSelectId(Query<?> query) {
|
||||
|
||||
BeanProperty idProperty = targetDescriptor.getIdProperty();
|
||||
query.fetch(fullPath, idProperty.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cascade the merge processing if this has child nodes.
|
||||
*/
|
||||
protected void cascade(EntityBean entityBean, EntityBean outlineBean, MergeRequest request) {
|
||||
|
||||
if (children != null && !children.isEmpty()) {
|
||||
MergeRequest sub = request.sub(entityBean, outlineBean);
|
||||
for (MergeNode node : children.values()) {
|
||||
node.merge(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user