Search in sources :

Example 56 with ObjEntity

use of org.apache.cayenne.map.ObjEntity 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)

Example 57 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class ObjPathProcessorIT2 method prepareTranslationContext.

@Before
public void prepareTranslationContext() {
    TranslatorContext translatorContext = new TranslatorContext(new FluentSelectWrapper(ObjectSelect.query(Object.class)), Mockito.mock(DbAdapter.class), context.getEntityResolver(), null);
    ObjEntity entity = context.getEntityResolver().getObjEntity("CompoundFkTestEntity");
    pathProcessor = new ObjPathProcessor(translatorContext, entity, null);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbAdapter(org.apache.cayenne.dba.DbAdapter) Before(org.junit.Before)

Example 58 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class CAY_743Test method testLoad2MapsWithCrossMapInheritance.

@Test
public void testLoad2MapsWithCrossMapInheritance() throws Exception {
    Injector injector = DIBootstrap.createInjector(new ServerModule() {

        @Override
        public void configure(Binder binder) {
            super.configure(binder);
            ServerModule.contributeProjectLocations(binder).add("cay743/cayenne-domain.xml");
        }
    });
    try {
        DataDomain domain = injector.getInstance(DataDomain.class);
        assertEquals(2, domain.getDataMaps().size());
        DataMap m1 = domain.getDataMap("map1");
        DataMap m2 = domain.getDataMap("map2");
        ObjEntity oe11 = m1.getObjEntity("Entity11");
        ObjEntity oe12 = m1.getObjEntity("Entity12");
        ObjEntity oe21 = m2.getObjEntity("Entity21");
        ObjEntity oe22 = m2.getObjEntity("Entity22");
        // this causes StackOverflow per CAY-743
        ObjEntity oe21Super = oe21.getSuperEntity();
        ObjEntity oe12Super = oe12.getSuperEntity();
        assertSame(oe12Super, oe22);
        assertSame(oe21Super, oe11);
    } finally {
        injector.shutdown();
    }
}
Also used : Binder(org.apache.cayenne.di.Binder) ObjEntity(org.apache.cayenne.map.ObjEntity) DataDomain(org.apache.cayenne.access.DataDomain) Injector(org.apache.cayenne.di.Injector) ServerModule(org.apache.cayenne.configuration.server.ServerModule) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 59 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class ObjEntityTab method setClientSuperClassName.

void setClientSuperClassName(String text) {
    if (text != null && text.trim().length() == 0) {
        text = null;
    }
    ObjEntity ent = mediator.getCurrentObjEntity();
    if (ent != null && !Util.nullSafeEquals(ent.getClientSuperClassName(), text)) {
        ent.setClientSuperClassName(text);
        mediator.fireObjEntityEvent(new EntityEvent(this, ent));
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 60 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class ObjEntityTab method initController.

private void initController() {
    // initialize events processing and tracking of UI updates...
    mediator.addObjEntityDisplayListener(this);
    dbEntityCombo.addActionListener(e -> {
        // Change DbEntity for current ObjEntity
        ObjEntity entity = mediator.getCurrentObjEntity();
        DbEntity dbEntity = (DbEntity) dbEntityCombo.getSelectedItem();
        if (dbEntity != entity.getDbEntity()) {
            entity.setDbEntity(dbEntity);
            mediator.fireObjEntityEvent(new EntityEvent(ObjEntityTab.this, entity));
        }
    });
    superEntityCombo.addActionListener(e -> {
        // Change super-entity
        ObjEntity superEntity = (ObjEntity) superEntityCombo.getSelectedItem();
        String name = (superEntity == null || superEntity == NO_INHERITANCE) ? null : superEntity.getName();
        ObjEntity entity = mediator.getCurrentObjEntity();
        if (!Util.nullSafeEquals(name, entity.getSuperEntityName())) {
            List<ObjAttribute> duplicateAttributes = null;
            if (name != null) {
                duplicateAttributes = getDuplicatedAttributes(superEntity);
            }
            if (duplicateAttributes != null && duplicateAttributes.size() > 0) {
                DuplicatedAttributesDialog.showDialog(Application.getFrame(), duplicateAttributes, superEntity, entity);
                if (DuplicatedAttributesDialog.getResult().equals(DuplicatedAttributesDialog.CANCEL_RESULT)) {
                    superEntityCombo.setSelectedItem(entity.getSuperEntity());
                    superClassName.setText(entity.getSuperClassName());
                    return;
                }
            }
            entity.setSuperEntityName(name);
            // drop not valid dbAttributePath
            if (name == null) {
                for (ObjAttribute objAttribute : entity.getAttributes()) {
                    if (objAttribute.getDbAttribute() == null) {
                        objAttribute.setDbAttributePath(null);
                    }
                }
            }
            if (name == null) {
                dbEntityCombo.setEnabled(true);
            } else {
                dbEntityCombo.setEnabled(false);
                dbEntityCombo.getModel().setSelectedItem(null);
            }
            // if a super-entity selected, disable table selection
            // and also update parent DbEntity selection...
            toggleEnabled(name == null, !serverOnly.isSelected());
            dbEntityCombo.getModel().setSelectedItem(entity.getDbEntity());
            superClassName.setText(entity.getSuperClassName());
            // fire both EntityEvent and EntityDisplayEvent;
            // the later is to update attribute and relationship display
            DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
            DataMap map = mediator.getCurrentDataMap();
            mediator.fireObjEntityEvent(new EntityEvent(this, entity));
            mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, entity, map, domain));
        }
    });
    tableLabel.addActionListener(e -> {
        // Jump to DbEntity of the current ObjEntity
        DbEntity entity = mediator.getCurrentObjEntity().getDbEntity();
        if (entity != null) {
            DataChannelDescriptor dom = (DataChannelDescriptor) mediator.getProject().getRootNode();
            mediator.fireDbEntityDisplayEvent(new EntityDisplayEvent(this, entity, entity.getDataMap(), dom));
        }
    });
    readOnly.addItemListener(e -> {
        ObjEntity entity = mediator.getCurrentObjEntity();
        if (entity != null) {
            entity.setReadOnly(readOnly.isSelected());
            mediator.fireObjEntityEvent(new EntityEvent(this, entity));
        }
    });
    optimisticLocking.addItemListener(e -> {
        ObjEntity entity = mediator.getCurrentObjEntity();
        if (entity != null) {
            entity.setDeclaredLockType(optimisticLocking.isSelected() ? ObjEntity.LOCK_TYPE_OPTIMISTIC : ObjEntity.LOCK_TYPE_NONE);
            mediator.fireObjEntityEvent(new EntityEvent(this, entity));
        }
    });
    serverOnly.addItemListener(e -> {
        ObjEntity entity = mediator.getCurrentObjEntity();
        if (entity != null) {
            entity.setServerOnly(serverOnly.isSelected());
            toggleEnabled(dbEntityCombo.isEnabled(), !serverOnly.isSelected());
            mediator.fireObjEntityEvent(new EntityEvent(this, entity));
        }
    });
    isAbstract.addItemListener(e -> {
        ObjEntity entity = mediator.getCurrentObjEntity();
        if (entity != null) {
            entity.setAbstract(isAbstract.isSelected());
            mediator.fireObjEntityEvent(new EntityEvent(this, entity));
        }
    });
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) DbEntity(org.apache.cayenne.map.DbEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) EntityEvent(org.apache.cayenne.map.event.EntityEvent) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

ObjEntity (org.apache.cayenne.map.ObjEntity)294 Test (org.junit.Test)110 DbEntity (org.apache.cayenne.map.DbEntity)72 ObjAttribute (org.apache.cayenne.map.ObjAttribute)68 ObjRelationship (org.apache.cayenne.map.ObjRelationship)62 DataMap (org.apache.cayenne.map.DataMap)57 DbAttribute (org.apache.cayenne.map.DbAttribute)37 DbRelationship (org.apache.cayenne.map.DbRelationship)29 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)27 ObjectId (org.apache.cayenne.ObjectId)26 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)22 ArrayList (java.util.ArrayList)19 Embeddable (org.apache.cayenne.map.Embeddable)18 EntityResolver (org.apache.cayenne.map.EntityResolver)17 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)16 Expression (org.apache.cayenne.exp.Expression)15 Persistent (org.apache.cayenne.Persistent)12 EntityEvent (org.apache.cayenne.map.event.EntityEvent)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 Entity (org.apache.cayenne.map.Entity)11