use of org.apache.ofbiz.entity.model.ModelEntity in project ofbiz-framework by apache.
the class GenericDelegator method makeValue.
/* (non-Javadoc)
* @see org.apache.ofbiz.entity.Delegator#makeValue(java.lang.String)
*/
@Override
public GenericValue makeValue(String entityName) {
ModelEntity entity = this.getModelEntity(entityName);
if (entity == null) {
throw new IllegalArgumentException("[GenericDelegator.makeValue] could not find entity for entityName: " + entityName);
}
GenericValue value = GenericValue.create(entity);
value.setDelegator(this);
return value;
}
use of org.apache.ofbiz.entity.model.ModelEntity in project ofbiz-framework by apache.
the class GenericDelegator method getModelEntityMapByGroup.
/* (non-Javadoc)
* @see org.apache.ofbiz.entity.Delegator#getModelEntityMapByGroup(java.lang.String)
*/
@Override
public Map<String, ModelEntity> getModelEntityMapByGroup(String groupName) throws GenericEntityException {
Set<String> entityNameSet = getModelGroupReader().getEntityNamesByGroup(delegatorBaseName, groupName);
if (this.delegatorInfo.getDefaultGroupName().equals(groupName)) {
// add all entities with no group name to the Set
Set<String> allEntityNames = this.getModelReader().getEntityNames();
for (String entityName : allEntityNames) {
if (this.delegatorInfo.getDefaultGroupName().equals(getModelGroupReader().getEntityGroupName(entityName, this.delegatorBaseName))) {
entityNameSet.add(entityName);
}
}
}
Map<String, ModelEntity> entities = new HashMap<>();
if (UtilValidate.isEmpty(entityNameSet)) {
return entities;
}
int errorCount = 0;
for (String entityName : entityNameSet) {
try {
ModelEntity entity = getModelReader().getModelEntity(entityName);
if (entity != null) {
entities.put(entity.getEntityName(), entity);
} else {
throw new IllegalStateException("Could not find entity with name " + entityName);
}
} catch (GenericEntityException ex) {
errorCount++;
Debug.logError("Entity [" + entityName + "] named in Entity Group with name " + groupName + " are not defined in any Entity Definition file", module);
}
}
if (errorCount > 0) {
Debug.logError(errorCount + " entities were named in ModelGroup but not defined in any EntityModel", module);
}
return entities;
}
use of org.apache.ofbiz.entity.model.ModelEntity 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.ModelEntity in project ofbiz-framework by apache.
the class GenericDelegator method create.
/* (non-Javadoc)
* @see org.apache.ofbiz.entity.Delegator#create(java.lang.String, java.util.Map)
*/
@Override
public GenericValue create(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException {
if (entityName == null || fields == null) {
return null;
}
ModelEntity entity = this.getModelReader().getModelEntity(entityName);
GenericValue genericValue = GenericValue.create(this, entity, fields);
return this.create(genericValue);
}
use of org.apache.ofbiz.entity.model.ModelEntity 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);
}
}
Aggregations