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 com.avaje.ebeaninternal.server.deploy;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.Expression;
import com.avaje.ebean.Query;
import com.avaje.ebean.SqlUpdate;
import com.avaje.ebean.Transaction;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.BeanCollection.ModifyListenMode;
import com.avaje.ebean.bean.BeanCollectionAdd;
import com.avaje.ebean.bean.BeanCollectionLoader;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.text.PathProperties;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
import com.avaje.ebeaninternal.server.deploy.id.ImportedId;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocMany;
import com.avaje.ebeaninternal.server.el.ElPropertyChainBuilder;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
import com.avaje.ebeaninternal.server.query.SqlBeanLoad;
import com.avaje.ebeaninternal.server.text.json.ReadJson;
import com.avaje.ebeaninternal.server.text.json.WriteJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.PersistenceException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Property mapped to a List Set or Map.
*/
public class BeanPropertyAssocMany extends BeanPropertyAssoc {
private static final Logger logger = LoggerFactory.getLogger(BeanPropertyAssocMany.class);
private final BeanPropertyAssocManyJsonHelp jsonHelp;
/**
* Join for manyToMany intersection table.
*/
private final TableJoin intersectionJoin;
private final String intersectionPublishTable;
private final String intersectionDraftTable;
/**
* For ManyToMany this is the Inverse join used to build reference queries.
*/
private final TableJoin inverseJoin;
/**
* Flag to indicate that this is a unidirectional relationship.
*/
private final boolean unidirectional;
/**
* Flag to indicate manyToMany relationship.
*/
private final boolean manyToMany;
/**
* 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;
/**
* The type of the many, set, list or map.
*/
private final ManyType manyType;
private final ModifyListenMode modifyListenMode;
private BeanProperty mapKeyProperty;
/**
* Derived list of exported property and matching foreignKey
*/
private ExportedProperty[] exportedProperties;
private String exportedPropertyBindProto = "?";
/**
* Property on the 'child' bean that links back to the 'master'.
*/
protected BeanPropertyAssocOne> childMasterProperty;
private String childMasterIdProperty;
private boolean embeddedExportedProperties;
private BeanCollectionHelp help;
private ImportedId importedId;
private String deleteByParentIdSql;
private String deleteByParentIdInSql;
/**
* Create this property.
*/
public BeanPropertyAssocMany(BeanDescriptor> descriptor, DeployBeanPropertyAssocMany deploy) {
super(descriptor, deploy);
this.unidirectional = deploy.isUnidirectional();
this.manyToMany = deploy.isManyToMany();
this.manyType = deploy.getManyType();
this.mapKey = deploy.getMapKey();
this.fetchOrderBy = deploy.getFetchOrderBy();
this.intersectionJoin = deploy.createIntersectionTableJoin();
if (intersectionJoin != null) {
this.intersectionPublishTable = intersectionJoin.getTable();
this.intersectionDraftTable = deploy.getIntersectionDraftTable();
} else {
this.intersectionPublishTable = null;
this.intersectionDraftTable = null;
}
this.inverseJoin = deploy.createInverseTableJoin();
this.modifyListenMode = deploy.getModifyListenMode();
this.jsonHelp = new BeanPropertyAssocManyJsonHelp(this);
}
public void initialise() {
super.initialise();
if (!isTransient) {
this.help = BeanCollectionHelpFactory.create(this);
if (manyToMany) {
// only manyToMany's have imported properties
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();
if (exportedProperties.length > 0) {
embeddedExportedProperties = exportedProperties[0].isEmbedded();
exportedPropertyBindProto = deriveExportedPropertyBindProto();
if (fetchOrderBy != null) {
// derive lazyFetchOrderBy
StringBuilder sb = new StringBuilder(50);
for (int i = 0; i < exportedProperties.length; i++) {
if (i > 0) {
sb.append(", ");
}
// these fk columns are either on the intersection (int_) or base table (t0)
String fkTableAlias = isManyToMany() ? "int_" : "t0";
sb.append(fkTableAlias).append(".").append(exportedProperties[i].getForeignDbColumn());
}
sb.append(", ").append(fetchOrderBy);
lazyFetchOrderBy = sb.toString().trim();
}
}
String delStmt;
if (manyToMany) {
delStmt = "delete from " + inverseJoin.getTable() + " where ";
} else {
delStmt = "delete from " + targetDescriptor.getBaseTable() + " where ";
}
deleteByParentIdSql = delStmt + deriveWhereParentIdSql(false, "");
deleteByParentIdInSql = delStmt + deriveWhereParentIdSql(true, "");
}
}
/**
* Initialise after the target bean descriptors have been all set.
*/
public void initialisePostTarget() {
if (childMasterProperty != null) {
BeanProperty masterId = childMasterProperty.getTargetDescriptor().getIdProperty();
childMasterIdProperty = childMasterProperty.getName() + "." + masterId.getName();
}
}
@Override
protected void docStoreIncludeByDefault(PathProperties pathProps) {
// by default not including "Many" properties in document store
}
/**
* Copy collection value if existing is empty.
*/
@Override
public void merge(EntityBean bean, EntityBean existing) {
Object existingCollection = getVal(existing);
if (existingCollection instanceof BeanCollection>) {
BeanCollection> toBC = (BeanCollection>)existingCollection;
if (!toBC.isPopulated()) {
Object fromCollection = getVal(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.
*/
public void addBeanToCollectionWithCreate(EntityBean parentBean, EntityBean detailBean, boolean withCheck) {
BeanCollection> bc = (BeanCollection>) super.getValue(parentBean);
if (bc == null) {
bc = help.createEmpty(parentBean);
setValue(parentBean, bc);
}
help.add(bc, detailBean, withCheck);
}
/**
* Return true if this is considered 'empty' from a save perspective.
*/
public boolean isEmptyBeanCollection(EntityBean bean, boolean insertedParent) {
Object val = getValue(bean);
if (val == null) {
return true;
}
if ((val instanceof BeanCollection>)) {
return ((BeanCollection>) val).isEmptyAndUntouched();
}
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 == null) {
// not expecting this - set an empty reference
createReference(bean);
} else {
// reset the collection back to empty
((BeanCollection)value).reset(bean, name);
}
}
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
}
public SqlUpdate deleteByParentId(Object parentId, List