use of org.apache.ofbiz.entity.model.ModelRelation in project ofbiz-framework by apache.
the class EntityArtifactInfo method populateAll.
public void populateAll() throws GeneralException {
List<ModelRelation> relationOneList = modelEntity.getRelationsOneList();
for (ModelRelation relationOne : relationOneList) {
this.entitiesRelatedOne.add(this.aif.getEntityArtifactInfo(relationOne.getRelEntityName()));
}
List<ModelRelation> relationManyList = modelEntity.getRelationsManyList();
for (ModelRelation relationMany : relationManyList) {
this.entitiesRelatedMany.add(this.aif.getEntityArtifactInfo(relationMany.getRelEntityName()));
}
}
use of org.apache.ofbiz.entity.model.ModelRelation in project ofbiz-framework by apache.
the class GenericDelegator method getRelatedOne.
/* (non-Javadoc)
* @see org.apache.ofbiz.entity.Delegator#getRelatedOne(java.lang.String, org.apache.ofbiz.entity.GenericValue, boolean)
*/
@Override
public GenericValue getRelatedOne(String relationName, GenericValue value, boolean useCache) throws GenericEntityException {
ModelRelation relation = value.getModelEntity().getRelation(relationName);
if (relation == null) {
throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value);
}
if (!"one".equals(relation.getType()) && !"one-nofk".equals(relation.getType())) {
throw new GenericModelException("Relation is not a 'one' or a 'one-nofk' relation: " + relationName + " of entity " + value.getEntityName());
}
Map<String, Object> fields = new HashMap<>();
for (ModelKeyMap keyMap : relation.getKeyMaps()) {
fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName()));
}
return this.findOne(relation.getRelEntityName(), fields, useCache);
}
use of org.apache.ofbiz.entity.model.ModelRelation in project ofbiz-framework by apache.
the class GenericDelegator method removeRelated.
/* (non-Javadoc)
* @see org.apache.ofbiz.entity.Delegator#removeRelated(java.lang.String, org.apache.ofbiz.entity.GenericValue)
*/
@Override
public int removeRelated(String relationName, GenericValue value) throws GenericEntityException {
ModelEntity modelEntity = value.getModelEntity();
ModelRelation relation = modelEntity.getRelation(relationName);
if (relation == null) {
throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value);
}
Map<String, Object> fields = new HashMap<>();
for (ModelKeyMap keyMap : relation.getKeyMaps()) {
fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName()));
}
return this.removeByAnd(relation.getRelEntityName(), fields);
}
use of org.apache.ofbiz.entity.model.ModelRelation in project ofbiz-framework by apache.
the class GenericDelegator method getMultiRelation.
/* (non-Javadoc)
* @see org.apache.ofbiz.entity.Delegator#getMultiRelation(org.apache.ofbiz.entity.GenericValue, java.lang.String, java.lang.String, java.util.List)
*/
@Override
public List<GenericValue> getMultiRelation(GenericValue value, String relationNameOne, String relationNameTwo, List<String> orderBy) throws GenericEntityException {
boolean beganTransaction = false;
try {
if (alwaysUseTransaction) {
beganTransaction = TransactionUtil.begin();
}
// TODO: add eca eval calls
// traverse the relationships
ModelEntity modelEntity = value.getModelEntity();
ModelRelation modelRelationOne = modelEntity.getRelation(relationNameOne);
ModelEntity modelEntityOne = getModelEntity(modelRelationOne.getRelEntityName());
ModelRelation modelRelationTwo = modelEntityOne.getRelation(relationNameTwo);
ModelEntity modelEntityTwo = getModelEntity(modelRelationTwo.getRelEntityName());
GenericHelper helper = getEntityHelper(modelEntity);
List<GenericValue> result = helper.findByMultiRelation(value, modelRelationOne, modelEntityOne, modelRelationTwo, modelEntityTwo, orderBy);
TransactionUtil.commit(beganTransaction);
return result;
} catch (GenericEntityException e) {
String errMsg = "Failure in getMultiRelation operation for entity [" + value.getEntityName() + "]: " + e.toString() + ". Rolling back transaction.";
Debug.logError(e, errMsg, module);
TransactionUtil.rollback(beganTransaction, errMsg, e);
throw new GenericEntityException(e);
}
}
use of org.apache.ofbiz.entity.model.ModelRelation in project ofbiz-framework by apache.
the class GenericDelegator method getRelatedDummyPK.
/* (non-Javadoc)
* @see org.apache.ofbiz.entity.Delegator#getRelatedDummyPK(java.lang.String, java.util.Map, org.apache.ofbiz.entity.GenericValue)
*/
@Override
public GenericPK getRelatedDummyPK(String relationName, Map<String, ? extends Object> byAndFields, GenericValue value) throws GenericEntityException {
ModelEntity modelEntity = value.getModelEntity();
ModelRelation relation = modelEntity.getRelation(relationName);
if (relation == null) {
throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value);
}
ModelEntity relatedEntity = getModelReader().getModelEntity(relation.getRelEntityName());
// put the byAndFields (if not null) into the hash map first,
// they will be overridden by value's fields if over-specified this is important for security and cleanliness
Map<String, Object> fields = new HashMap<>();
if (byAndFields != null) {
fields.putAll(byAndFields);
}
for (ModelKeyMap keyMap : relation.getKeyMaps()) {
fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName()));
}
return GenericPK.create(this, relatedEntity, fields);
}
Aggregations