Search in sources :

Example 6 with ModelEntity

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;
}
Also used : ModelEntity(org.apache.ofbiz.entity.model.ModelEntity)

Example 7 with ModelEntity

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;
}
Also used : HashMap(java.util.HashMap) ModelEntity(org.apache.ofbiz.entity.model.ModelEntity)

Example 8 with ModelEntity

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);
}
Also used : ModelKeyMap(org.apache.ofbiz.entity.model.ModelKeyMap) HashMap(java.util.HashMap) ModelRelation(org.apache.ofbiz.entity.model.ModelRelation) UtilObject(org.apache.ofbiz.base.util.UtilObject) ModelEntity(org.apache.ofbiz.entity.model.ModelEntity)

Example 9 with ModelEntity

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);
}
Also used : ModelEntity(org.apache.ofbiz.entity.model.ModelEntity)

Example 10 with ModelEntity

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);
    }
}
Also used : ModelRelation(org.apache.ofbiz.entity.model.ModelRelation) ModelEntity(org.apache.ofbiz.entity.model.ModelEntity) GenericHelper(org.apache.ofbiz.entity.datasource.GenericHelper)

Aggregations

ModelEntity (org.apache.ofbiz.entity.model.ModelEntity)102 GenericValue (org.apache.ofbiz.entity.GenericValue)37 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)29 ModelField (org.apache.ofbiz.entity.model.ModelField)28 HashMap (java.util.HashMap)22 Delegator (org.apache.ofbiz.entity.Delegator)17 ModelViewEntity (org.apache.ofbiz.entity.model.ModelViewEntity)16 LinkedList (java.util.LinkedList)14 Locale (java.util.Locale)12 ModelKeyMap (org.apache.ofbiz.entity.model.ModelKeyMap)11 ArrayList (java.util.ArrayList)10 ModelRelation (org.apache.ofbiz.entity.model.ModelRelation)10 IOException (java.io.IOException)8 TreeSet (java.util.TreeSet)8 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)8 Map (java.util.Map)7 GeneralRuntimeException (org.apache.ofbiz.base.util.GeneralRuntimeException)7 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)7 ModelFieldType (org.apache.ofbiz.entity.model.ModelFieldType)7 GenericTransactionException (org.apache.ofbiz.entity.transaction.GenericTransactionException)7