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.
/**
* Copyright (C) 2006 Robin Bygrave
*
* This file is part of Ebean.
*
* Ebean is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Ebean is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Ebean; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.avaje.ebeaninternal.server.deploy;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.persistence.PersistenceException;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.Expression;
import com.avaje.ebean.InvalidValue;
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.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.lib.util.StringHelper;
import com.avaje.ebeaninternal.server.query.SqlBeanLoad;
import com.avaje.ebeaninternal.server.text.json.ReadJsonContext;
import com.avaje.ebeaninternal.server.text.json.ReadJsonContext.ReadBeanState;
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
/**
* Property mapped to a List Set or Map.
*/
public class BeanPropertyAssocMany extends BeanPropertyAssoc {
/**
* Join for manyToMany intersection table.
*/
final TableJoin intersectionJoin;
/**
* For ManyToMany this is the Inverse join used to build reference queries.
*/
final TableJoin inverseJoin;
/**
* Flag to indicate that this is a unidirectional relationship.
*/
final boolean unidirectional;
/**
* Flag to indicate manyToMany relationship.
*/
final boolean manyToMany;
final String fetchOrderBy;
final String mapKey;
/**
* The type of the many, set, list or map.
*/
final ManyType manyType;
final String serverName;
final ModifyListenMode modifyListenMode;
BeanProperty mapKeyProperty;
/**
* Derived list of exported property and matching foreignKey
*/
ExportedProperty[] exportedProperties;
/**
* Property on the 'child' bean that links back to the 'master'.
*/
BeanProperty childMasterProperty;
boolean embeddedExportedProperties;
BeanCollectionHelp help;
ImportedId importedId;
String deleteByParentIdSql;
String deleteByParentIdInSql;
final CollectionTypeConverter typeConverter;
/**
* Create this property.
*/
public BeanPropertyAssocMany(BeanDescriptorMap owner, BeanDescriptor> descriptor, DeployBeanPropertyAssocMany deploy) {
super(owner, descriptor, deploy);
this.unidirectional = deploy.isUnidirectional();
this.manyToMany = deploy.isManyToMany();
this.serverName = descriptor.getServerName();
this.manyType = deploy.getManyType();
this.typeConverter = manyType.getTypeConverter();
this.mapKey = deploy.getMapKey();
this.fetchOrderBy = deploy.getFetchOrderBy();
this.intersectionJoin = deploy.createIntersectionTableJoin();
this.inverseJoin = deploy.createInverseTableJoin();
this.modifyListenMode = deploy.getModifyListenMode();
}
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 (mapKey != null){
mapKeyProperty = initMapKeyProperty();
}
exportedProperties = createExported();
if (exportedProperties.length > 0){
embeddedExportedProperties = exportedProperties[0].isEmbedded();
}
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);
}
}
/**
* Get the underlying List Set or Map.
* For unwrapping scala collection types etc.
*/
public Object getValueUnderlying(Object bean) {
Object value = getValue(bean);
if (typeConverter != null){
value = typeConverter.toUnderlying(value);
}
return value;
}
@Override
public Object getValue(Object bean) {
return super.getValue(bean);
}
@Override
public Object getValueIntercept(Object bean) {
return super.getValueIntercept(bean);
}
@Override
public void setValue(Object bean, Object value) {
if (typeConverter != null){
value = typeConverter.toWrapped(value);
}
super.setValue(bean, value);
}
@Override
public void setValueIntercept(Object bean, Object value) {
if (typeConverter != null){
value = typeConverter.toWrapped(value);
}
super.setValueIntercept(bean, value);
}
public ElPropertyValue buildElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) {
return createElPropertyValue(propName, remainder, chain, propertyDeploy);
}
@Override
public void copyProperty(Object sourceBean, Object destBean, CopyContext ctx, int maxDepth){
Object sourceCollection = getValueUnderlying(sourceBean);
if (sourceCollection != null){
Object copyCollection = help.copyCollection(sourceCollection, ctx, maxDepth, destBean);
setValue(destBean, copyCollection);
}
}
public SqlUpdate deleteByParentId(Object parentId, List