Search in sources :

Example 1 with ModelRelation

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

Example 2 with ModelRelation

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);
}
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)

Example 3 with ModelRelation

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);
}
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 4 with ModelRelation

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

Example 5 with ModelRelation

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);
}
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)

Aggregations

ModelRelation (org.apache.ofbiz.entity.model.ModelRelation)14 ModelEntity (org.apache.ofbiz.entity.model.ModelEntity)10 HashMap (java.util.HashMap)7 ModelKeyMap (org.apache.ofbiz.entity.model.ModelKeyMap)7 ModelViewEntity (org.apache.ofbiz.entity.model.ModelViewEntity)6 UtilObject (org.apache.ofbiz.base.util.UtilObject)4 ModelField (org.apache.ofbiz.entity.model.ModelField)3 ModelFieldType (org.apache.ofbiz.entity.model.ModelFieldType)3 SQLException (java.sql.SQLException)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)2 ModelIndex (org.apache.ofbiz.entity.model.ModelIndex)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1