Search in sources :

Example 1 with ComposerEntityNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData in project scout.rt by eclipse.

the class FormDataStatementBuilderWithComposerTest method testBuildComposerEntityNodeStrategyBuildConstraintsAggregationSum.

@Test
public void testBuildComposerEntityNodeStrategyBuildConstraintsAggregationSum() throws Exception {
    ComposerAttributeNodeData subAttributeNode = prepareComposer(DataModelConstants.AGGREGATION_SUM);
    ComposerEntityNodeData subEntityNode = (ComposerEntityNodeData) subAttributeNode.getParentNode();
    m_builder.getAliasMapper().setNodeAlias(subEntityNode.getParentNode(), "Table", "T");
    EntityContribution entityContribution = m_builder.buildComposerEntityNodeContribution(subEntityNode, EntityStrategy.BuildConstraints);
    assertNotNull(entityContribution);
    assertTrue(entityContribution.getSelectParts().isEmpty());
    assertTrue(entityContribution.getFromParts().isEmpty());
    assertTrue(entityContribution.getGroupByParts().isEmpty());
    assertTrue(entityContribution.getHavingParts().isEmpty());
    assertFalse(entityContribution.getWhereParts().isEmpty());
    assertEquals(1, entityContribution.getWhereParts().size());
    assertEquals("EXISTS ( SELECT 1 FROM TABLE a0001 WHERE a0001.PRIMARY_KEY=T.PRIMARY_KEY GROUP BY T.PRIMARY_KEY HAVING 1=1 AND SUM(a0001.SUB_ATTRIBUTE)=:__a2 )", StringUtility.cleanup(entityContribution.getWhereParts().get(0)));
}
Also used : ComposerEntityNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData) ComposerAttributeNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerAttributeNodeData) Test(org.junit.Test)

Example 2 with ComposerEntityNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData in project scout.rt by eclipse.

the class FormDataStatementBuilderWithComposerTest method prepareComposer.

private ComposerAttributeNodeData prepareComposer(int aggregationType) {
    IDataModelEntity entity = m_dataModel.getEntity(TestDataModel.Entity.class);
    IDataModelEntity subEntity = entity.getEntity(TestDataModel.Entity.SubEntity.class);
    IDataModelAttribute subAttribute = subEntity.getAttribute(TestDataModel.Entity.SubEntity.SubAttribute.class);
    ComposerAttributeNodeData subAttributeNode = new ComposerAttributeNodeData();
    subAttributeNode.setAggregationType(aggregationType);
    subAttributeNode.setOperator(DataModelConstants.OPERATOR_EQ);
    String attributeExternalId = DataModelUtility.attributePathToExternalId(m_dataModel, new EntityPath().addToEnd(entity).addToEnd(subEntity).addToEnd(subAttribute));
    subAttributeNode.setAttributeExternalId(attributeExternalId);
    subAttributeNode.setValues(CollectionUtility.arrayList(10L));
    ComposerEntityNodeData subEntityNode = new ComposerEntityNodeData();
    subEntityNode.setEntityExternalId(DataModelUtility.entityPathToExternalId(m_dataModel, new EntityPath().addToEnd(entity).addToEnd(subEntity)));
    subEntityNode.setChildNodes(Arrays.<TreeNodeData>asList(subAttributeNode));
    ComposerEntityNodeData entityNode = new ComposerEntityNodeData();
    entityNode.setEntityExternalId(DataModelUtility.entityPathToExternalId(m_dataModel, new EntityPath().addToEnd(entity)));
    entityNode.setChildNodes(Arrays.<TreeNodeData>asList(subEntityNode));
    return subAttributeNode;
}
Also used : IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) AbstractDataModelEntity(org.eclipse.scout.rt.shared.data.model.AbstractDataModelEntity) EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) ComposerEntityNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData) ComposerAttributeNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerAttributeNodeData) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)

Example 3 with ComposerEntityNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData in project scout.rt by eclipse.

the class FormDataStatementBuilder method buildComposerEntityNodeContribution.

public EntityContribution buildComposerEntityNodeContribution(ComposerEntityNodeData node, EntityStrategy entityStrategy) {
    if (getDataModel() == null) {
        throw new ProcessingException("there is no data model set, call FormDataStatementBuilder.setDataModel to set one");
    }
    EntityPath entityPath = DataModelUtility.externalIdToEntityPath(getDataModel(), node.getEntityExternalId());
    IDataModelEntity entity = (entityPath != null ? entityPath.lastElement() : null);
    if (entity == null) {
        LOG.warn("no entity for external id: {}", node.getEntityExternalId());
        return null;
    }
    DataModelEntityPartDefinition def = m_dataModelEntMap.get(entity.getClass());
    if (def == null) {
        LOG.warn("no PartDefinition for entity: {}", entity);
        return null;
    }
    ComposerEntityNodeData parentEntityNode = getParentNodeOfType(node, ComposerEntityNodeData.class);
    Map<String, String> parentAliasMap = (parentEntityNode != null ? m_aliasMapper.getNodeAliases(parentEntityNode) : m_aliasMapper.getRootAliases());
    String baseStm;
    switch(entityStrategy) {
        case BuildQuery:
            {
                baseStm = def.getSelectClause();
                break;
            }
        case BuildConstraints:
            {
                baseStm = def.getWhereClause();
                break;
            }
        default:
            {
                baseStm = null;
            }
    }
    String stm = null;
    if (baseStm != null) {
        stm = def.createInstance(this, node, entityStrategy, baseStm, parentAliasMap);
    }
    if (stm == null) {
        return null;
    }
    m_aliasMapper.addAllNodeEntitiesFrom(node, stm);
    stm = m_aliasMapper.replaceMarkersByAliases(stm, m_aliasMapper.getNodeAliases(node), parentAliasMap);
    switch(entityStrategy) {
        case BuildQuery:
            {
                EntityContribution resultContrib = buildComposerEntityUnitContribution(node, entityStrategy, stm, node.getChildNodes(), isConsumeChildContributions(entityPath));
                return resultContrib;
            }
        case BuildConstraints:
            {
                String s = buildComposerEntityEitherOrSplit(entityStrategy, stm, node.isNegative(), node.getChildNodes());
                EntityContribution resultContrib = (s != null ? EntityContribution.create(s) : new EntityContribution());
                return resultContrib;
            }
        default:
            {
                return null;
            }
    }
}
Also used : EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) ComposerEntityNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 4 with ComposerEntityNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData in project scout.rt by eclipse.

the class FormDataStatementBuilder method buildComposerAttributeNode.

public EntityContribution buildComposerAttributeNode(final ComposerAttributeNodeData node, AttributeStrategy attributeStrategy) {
    if (getDataModel() == null) {
        throw new ProcessingException("there is no data model set, call FormDataStatementBuilder.setDataModel to set one");
    }
    AttributePath attPath = DataModelUtility.externalIdToAttributePath(getDataModel(), node.getAttributeExternalId());
    IDataModelAttribute attribute = (attPath != null ? attPath.getAttribute() : null);
    if (attribute == null) {
        LOG.warn("no attribute for external id: {}", node.getAttributeExternalId());
        return new EntityContribution();
    }
    DataModelAttributePartDefinition def = m_dataModelAttMap.get(attribute.getClass());
    if (def == null) {
        Integer agg = node.getAggregationType();
        if (agg != null && agg == AGGREGATION_COUNT) {
            def = new DataModelAttributePartDefinition(null, "1", false);
        }
    }
    if (def == null) {
        LOG.warn("no PartDefinition for attribute: {}", attribute);
        return new EntityContribution();
    }
    List<Object> bindValues = new ArrayList<Object>();
    if (node.getValues() != null) {
        bindValues.addAll(node.getValues());
    }
    List<String> bindNames = new ArrayList<String>(bindValues.size());
    for (int i = 0; i < bindValues.size(); i++) {
        bindNames.add("" + (char) (((int) 'a') + i));
    }
    AliasMapper aliasMap = getAliasMapper();
    ComposerEntityNodeData parentEntityNode = FormDataStatementBuilder.getParentNodeOfType(node, ComposerEntityNodeData.class);
    Map<String, String> parentAliasMap = parentEntityNode != null ? aliasMap.getNodeAliases(parentEntityNode) : aliasMap.getRootAliases();
    String stm = null;
    switch(attributeStrategy) {
        case BuildConstraintOfAttribute:
        case BuildConstraintOfContext:
        case BuildConstraintOfAttributeWithContext:
            {
                stm = def.getWhereClause();
                break;
            }
        case BuildQueryOfAttributeAndConstraintOfContext:
            {
                stm = def.getSelectClause();
                break;
            }
    }
    EntityContribution contrib = null;
    if (stm != null) {
        contrib = def.createInstance(this, node, attributeStrategy, stm, bindNames, bindValues, parentAliasMap);
    }
    if (contrib == null) {
        contrib = new EntityContribution();
    }
    switch(attributeStrategy) {
        case BuildQueryOfAttributeAndConstraintOfContext:
            {
                if (contrib.getSelectParts().isEmpty()) {
                    contrib.getSelectParts().add("NULL");
                    contrib.getGroupByParts().add("NULL");
                }
                break;
            }
    }
    if (hasInjections()) {
        injectPostBuildAttribute(node, attributeStrategy, contrib);
    }
    return contrib;
}
Also used : ArrayList(java.util.ArrayList) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComposerEntityNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) AttributePath(org.eclipse.scout.rt.shared.data.model.AttributePath)

Example 5 with ComposerEntityNodeData

use of org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData in project scout.rt by eclipse.

the class FormDataStatementBuilderWithComposerTest method testBuildComposerEntityNodeStrategyBuildConstraintsAggregationNone.

@Test
public void testBuildComposerEntityNodeStrategyBuildConstraintsAggregationNone() throws Exception {
    ComposerAttributeNodeData subAttributeNode = prepareComposer(DataModelConstants.AGGREGATION_NONE);
    ComposerEntityNodeData subEntityNode = (ComposerEntityNodeData) subAttributeNode.getParentNode();
    m_builder.getAliasMapper().setNodeAlias(subEntityNode.getParentNode(), "Table", "T");
    EntityContribution entityContribution = m_builder.buildComposerEntityNodeContribution(subEntityNode, EntityStrategy.BuildConstraints);
    assertNotNull(entityContribution);
    assertTrue(entityContribution.getSelectParts().isEmpty());
    assertTrue(entityContribution.getFromParts().isEmpty());
    assertTrue(entityContribution.getGroupByParts().isEmpty());
    assertTrue(entityContribution.getHavingParts().isEmpty());
    assertFalse(entityContribution.getWhereParts().isEmpty());
    assertEquals(1, entityContribution.getWhereParts().size());
    assertEquals("EXISTS ( SELECT 1 FROM TABLE a0001 WHERE a0001.PRIMARY_KEY=T.PRIMARY_KEY AND a0001.SUB_ATTRIBUTE=:__a2 )", StringUtility.cleanup(entityContribution.getWhereParts().get(0)));
}
Also used : ComposerEntityNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData) ComposerAttributeNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerAttributeNodeData) Test(org.junit.Test)

Aggregations

ComposerEntityNodeData (org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData)5 ComposerAttributeNodeData (org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerAttributeNodeData)3 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)2 EntityPath (org.eclipse.scout.rt.shared.data.model.EntityPath)2 IDataModelAttribute (org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)2 IDataModelEntity (org.eclipse.scout.rt.shared.data.model.IDataModelEntity)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AbstractDataModelEntity (org.eclipse.scout.rt.shared.data.model.AbstractDataModelEntity)1 AttributePath (org.eclipse.scout.rt.shared.data.model.AttributePath)1