Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package io.ebeaninternal.server.deploy;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.ebean.SqlUpdate;
import io.ebean.Transaction;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.BeanCollection.ModifyListenMode;
import io.ebean.bean.BeanCollectionAdd;
import io.ebean.bean.EntityBean;
import io.ebean.bean.PersistenceContext;
import io.ebean.plugin.PropertyAssocMany;
import io.ebean.text.PathProperties;
import io.ebeaninternal.api.*;
import io.ebeaninternal.api.json.SpiJsonReader;
import io.ebeaninternal.api.json.SpiJsonWriter;
import io.ebeaninternal.server.deploy.id.ImportedId;
import io.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocMany;
import io.ebeaninternal.server.el.ElPropertyChainBuilder;
import io.ebeaninternal.server.el.ElPropertyValue;
import io.ebeaninternal.server.query.STreePropertyAssocMany;
import io.ebeaninternal.server.query.SqlBeanLoad;
import jakarta.persistence.PersistenceException;
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;
import static java.lang.System.Logger.Level.ERROR;
import static java.lang.System.Logger.Level.WARNING;
/**
* Property mapped to a List Set or Map.
*/
public class BeanPropertyAssocMany extends BeanPropertyAssoc implements STreePropertyAssocMany, PropertyAssocMany {
private final BeanPropertyAssocManyJsonHelp jsonHelp;
/**
* Join for manyToMany intersection table.
*/
private final TableJoin intersectionJoin;
private final boolean orphanRemoval;
private IntersectionTable intersectionTable;
/**
* For ManyToMany this is the Inverse join used to build reference queries.
*/
final TableJoin inverseJoin;
/**
* Flag to indicate that this is a unidirectional relationship.
*/
private final boolean unidirectional;
private final boolean o2mJoinTable;
/**
* Flag to indicate that the target has a order column to auto populate.
*/
private final boolean hasOrderColumn;
/**
* Flag to indicate manyToMany relationship.
*/
private final boolean manyToMany;
private final boolean elementCollection;
/**
* Descriptor for the 'target' when the property maps to an element collection.
*/
final BeanDescriptor elementDescriptor;
/**
* Order by used when fetch joining the associated many.
*/
private final String fetchOrderBy;
/**
* Order by used when lazy loading the associated many.
*/
private String lazyFetchOrderBy;
private final String mapKey;
private final ManyType manyType;
private final ModifyListenMode modifyListenMode;
private BeanProperty mapKeyProperty;
private BeanPropertyAssocOne> childMasterProperty;
private String childMasterIdProperty;
private boolean embeddedExportedProperties;
private BeanCollectionHelp help;
private ImportedId importedId;
private BeanPropertyAssocManySqlHelp sqlHelp;
/**
* Create this property.
*/
public BeanPropertyAssocMany(BeanDescriptor> descriptor, DeployBeanPropertyAssocMany deploy) {
super(descriptor, deploy);
this.unidirectional = deploy.isUnidirectional();
this.orphanRemoval = deploy.isOrphanRemoval();
this.o2mJoinTable = deploy.isO2mJoinTable();
this.hasOrderColumn = deploy.hasOrderColumn();
this.manyToMany = deploy.isManyToMany();
this.elementCollection = deploy.isElementCollection();
this.elementDescriptor = deploy.getElementDescriptor();
this.manyType = deploy.getManyType();
this.mapKey = deploy.getMapKey();
this.fetchOrderBy = deploy.getFetchOrderBy();
this.intersectionJoin = deploy.createIntersectionTableJoin();
this.inverseJoin = deploy.createInverseTableJoin();
this.modifyListenMode = deploy.getModifyListenMode();
this.jsonHelp = descriptor.isJacksonCorePresent() ? new BeanPropertyAssocManyJsonHelp(this) : null;
}
@Override
public void initialise(BeanDescriptorInitContext initContext) {
super.initialise(initContext);
initialiseAssocMany();
if (elementCollection) {
// initialise all non-id properties (we don't have an Id property)
elementDescriptor.initialiseOther(initContext);
}
}
@Override
void initialiseTargetDescriptor(BeanDescriptorInitContext initContext) {
if (elementCollection) {
targetDescriptor = elementDescriptor;
} else {
super.initialiseTargetDescriptor(initContext);
}
}
private void initialiseAssocMany() {
if (!isTransient) {
this.help = BeanCollectionHelpFactory.create(this);
if (hasJoinTable() || elementCollection) {
importedId = createImportedId(this, targetDescriptor, tableJoin);
} else {
// find the property in the many that matches
// back to the master (Order in the OrderDetail bean)
childMasterProperty = initChildMasterProperty();
if (childMasterProperty != null) {
childMasterProperty.setRelationshipProperty(this);
}
}
if (mapKey != null) {
mapKeyProperty = initMapKeyProperty();
}
exportedProperties = createExported();
this.sqlHelp = new BeanPropertyAssocManySqlHelp<>(this, exportedProperties);
if (exportedProperties.length > 0) {
embeddedExportedProperties = exportedProperties[0].isEmbedded();
if (fetchOrderBy != null) {
lazyFetchOrderBy = sqlHelp.lazyFetchOrderBy(fetchOrderBy);
}
}
}
}
String targetTable() {
return beanTable.getBaseTable();
}
/**
* Initialise after the target bean descriptors have been all set.
*/
void initialisePostTarget() {
if (childMasterProperty != null) {
BeanProperty masterId = childMasterProperty.targetDescriptor().idProperty();
if (masterId != null) { // in docstore only, the master-id may be not available
childMasterIdProperty = childMasterProperty.name() + "." + masterId.name();
}
}
}
@Override
public BeanPropertyAssocMany> asMany() {
return this;
}
@Override
public boolean isManyToManyWithHistory() {
return manyToMany && !excludedFromHistory && descriptor.isHistorySupport();
}
@Override
public void registerColumn(BeanDescriptor> desc, String prefix) {
if (targetDescriptor != null) {
desc.registerTable(targetDescriptor.baseTable(), this);
}
}
/**
* Return the underlying collection of beans.
*/
@SuppressWarnings("rawtypes")
public Collection rawCollection(EntityBean bean) {
return help.underlying(getValue(bean));
}
/**
* Copy collection value if existing is empty.
*/
@Override
public void merge(EntityBean bean, EntityBean existing) {
Object existingCollection = getValue(existing);
if (existingCollection instanceof BeanCollection>) {
BeanCollection> toBC = (BeanCollection>) existingCollection;
if (!toBC.isPopulated()) {
Object fromCollection = getValue(bean);
if (fromCollection instanceof BeanCollection>) {
BeanCollection> fromBC = (BeanCollection>) fromCollection;
if (fromBC.isPopulated()) {
toBC.loadFrom(fromBC);
}
}
}
}
}
/**
* Add the bean to the appropriate collection on the parent bean.
*/
@Override
public void addBeanToCollectionWithCreate(EntityBean parentBean, EntityBean detailBean, boolean withCheck) {
BeanCollection> bc = beanCollection(parentBean);
if (bc == null) {
bc = help.createEmpty(parentBean);
setValue(parentBean, bc);
}
help.add(bc, detailBean, withCheck);
}
private BeanCollection> beanCollection(EntityBean parentBean) {
try {
return (BeanCollection>) super.getValue(parentBean);
} catch (ClassCastException e) {
// fetching element collection, ok for now
return null;
}
}
/**
* Return true if this is considered 'empty' from a save perspective.
*/
public boolean isSkipSaveBeanCollection(EntityBean bean, boolean insertedParent) {
Object val = getValue(bean);
if (val == null) {
return true;
}
if ((val instanceof BeanCollection>)) {
return ((BeanCollection>) val).isSkipSave();
}
if (insertedParent) {
// check 'vanilla' collection types
if (val instanceof Collection>) {
return ((Collection>) val).isEmpty();
}
if (val instanceof Map, ?>) {
return ((Map, ?>) val).isEmpty();
}
}
return false;
}
/**
* Reset the many properties to be empty and ready for reloading.
*
* Used in bean refresh.
*/
public void resetMany(EntityBean bean) {
Object value = getValue(bean);
if (value instanceof BeanCollection) {
// reset the collection back to empty
((BeanCollection>) value).reset(bean, name);
} else {
createReference(bean);
}
}
@Override
public ElPropertyValue buildElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) {
return createElPropertyValue(propName, remainder, chain, propertyDeploy);
}
@Override
public void buildRawSqlSelectChain(String prefix, List selectChain) {
// do not add to the selectChain at the top level of the Many bean
}
@Override
public SpiSqlUpdate deleteByParentId(Object parentId) {
return sqlHelp.deleteByParentId(parentId);
}
@Override
public SpiSqlUpdate deleteByParentIdList(List