Search in sources :

Example 1 with DefaultValueComparisonStrategyFactory

use of org.apache.cayenne.reflect.generic.DefaultValueComparisonStrategyFactory in project cayenne by apache.

the class DescriptorColumnExtractorTest method testExtractNoPrefix.

@Test
public void testExtractNoPrefix() {
    DbEntity mockDbEntity = createMockDbEntity("mock");
    TranslatableQueryWrapper wrapper = new MockQueryWrapperBuilder().withMetaData(new MockQueryMetadataBuilder().withDbEntity(mockDbEntity).build()).build();
    TranslatorContext context = new MockTranslatorContext(wrapper);
    DataMap dataMap = new DataMap();
    dataMap.addDbEntity(mockDbEntity);
    ObjEntity entity = new ObjEntity();
    entity.setName("mock");
    entity.setDataMap(dataMap);
    entity.setDbEntity(mockDbEntity);
    ObjAttribute attribute = new ObjAttribute();
    attribute.setName("not_name");
    attribute.setDbAttributePath("name");
    attribute.setType("java.lang.Integer");
    entity.addAttribute(attribute);
    dataMap.addObjEntity(entity);
    EntityResolver resolver = new EntityResolver();
    resolver.addDataMap(dataMap);
    resolver.setValueComparisionStrategyFactory(new DefaultValueComparisonStrategyFactory(mock(ValueObjectTypeRegistry.class)));
    DescriptorColumnExtractor extractor = new DescriptorColumnExtractor(context, resolver.getClassDescriptor("mock"));
    extractor.extract();
    assertEquals(2, context.getResultNodeList().size());
    ResultNodeDescriptor descriptor0 = context.getResultNodeList().get(0);
    ResultNodeDescriptor descriptor1 = context.getResultNodeList().get(1);
    assertNull(descriptor0.getProperty());
    assertNotNull(descriptor0.getNode());
    assertThat(descriptor0.getNode(), instanceOf(ColumnNode.class));
    assertFalse(descriptor0.isAggregate());
    assertTrue(descriptor0.isInDataRow());
    assertNotNull(descriptor0.getDbAttribute());
    assertEquals("name", descriptor0.getDataRowKey());
    assertEquals(Types.VARBINARY, descriptor0.getJdbcType());
    assertEquals("java.lang.Integer", descriptor0.getJavaType());
    assertNull(descriptor1.getProperty());
    assertNotNull(descriptor1.getNode());
    assertThat(descriptor1.getNode(), instanceOf(ColumnNode.class));
    assertFalse(descriptor1.isAggregate());
    assertTrue(descriptor1.isInDataRow());
    assertEquals("id", descriptor1.getDataRowKey());
    assertNotNull(descriptor1.getDbAttribute());
    assertEquals(Types.BIGINT, descriptor1.getJdbcType());
}
Also used : ObjAttribute(org.apache.cayenne.map.ObjAttribute) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) EntityResolver(org.apache.cayenne.map.EntityResolver) DataMap(org.apache.cayenne.map.DataMap) DefaultValueComparisonStrategyFactory(org.apache.cayenne.reflect.generic.DefaultValueComparisonStrategyFactory) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Test(org.junit.Test)

Aggregations

ColumnNode (org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode)1 DataMap (org.apache.cayenne.map.DataMap)1 DbEntity (org.apache.cayenne.map.DbEntity)1 EntityResolver (org.apache.cayenne.map.EntityResolver)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 DefaultValueComparisonStrategyFactory (org.apache.cayenne.reflect.generic.DefaultValueComparisonStrategyFactory)1 Test (org.junit.Test)1