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