Skip to content

Commit

Permalink
Remove exception cause in Cayenne Modeler (#582)
Browse files Browse the repository at this point in the history
* Remove exception cause in Cayenne Modeler

* Fix creation of EmbeddedAttribute in Modeler

---------

Co-authored-by: Nikita Timofeev <[email protected]>
  • Loading branch information
aperaverzeu and stariy95 committed Jun 18, 2024
1 parent 3594caf commit 91e768a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,26 @@ private String getDBAttribute(ObjAttributeWrapper attribute, DbAttribute dbAttri

private String getDBAttributeType(ObjAttributeWrapper attribute, DbAttribute dbAttribute) {
int type;
if (dbAttribute == null) {
if (!(attribute.getValue() instanceof EmbeddedAttribute)) {
if (dbAttribute != null) {
type = dbAttribute.getType();
} else {
if (attribute.getValue() instanceof EmbeddedAttribute) {
return null;
} else {
try {
type = TypesMapping.getSqlTypeByJava(attribute.getJavaClass());
Class<?> objAttributeClass;
try {
objAttributeClass = attribute.getObjAttributeClass();
} catch (DIRuntimeException e) {
return null;
}
type = TypesMapping.getSqlTypeByJava(objAttributeClass);
// have to catch the exception here to make sure that exceptional situations
// (class doesn't exist, for example) don't prevent the gui from properly updating.
} catch (CayenneRuntimeException | DIRuntimeException cre) {
} catch (CayenneRuntimeException cre) {
return null;
}
} else {
return null;
}
} else {
type = dbAttribute.getType();
}
return TypesMapping.getSqlNameByType(type);
}
Expand Down Expand Up @@ -274,32 +280,23 @@ private void setObjAttribute(ObjAttributeWrapper attribute, Object value) {
}

private void setObjAttributeType(ObjAttributeWrapper attribute, Object value) {
String oldType = attribute.getType();
String newType = value != null ? value.toString() : null;

attribute.setType(newType);
if (oldType == null || newType == null) {
return;
}

String[] registeredTypes = ModelerUtil.getRegisteredTypeNames();
Collection<String> registeredTypesList = Arrays.asList(registeredTypes);
if (registeredTypesList.contains(oldType) == registeredTypesList.contains(newType)) {
if (Arrays.asList(ModelerUtil.getRegisteredTypeNames()).contains(newType) || newType == null) {
return;
}

ObjEntity entity = attribute.getEntity();

ObjAttribute attributeNew;
if (registeredTypesList.contains(newType) ||
!mediator.getEmbeddableNamesInCurrentDataDomain().contains(newType)) {
attributeNew = new ObjAttribute();
attributeNew.setDbAttributePath(attribute.getDbAttributePath());
} else {
if (mediator.getEmbeddableNamesInCurrentDataDomain().contains(newType)) {
attributeNew = new EmbeddedAttribute();
attributeNew.setDbAttributePath((String)null);
} else {
attributeNew = new ObjAttribute();
attributeNew.setDbAttributePath(attribute.getDbAttributePath());
}

ObjEntity entity = attribute.getEntity();
attributeNew.setName(attribute.getName());
attributeNew.setEntity(entity);
attributeNew.setParent(attribute.getParent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void setParent(Object parent) {
objAttribute.setParent(parent);
}

public Class<?> getJavaClass() {
public Class<?> getObjAttributeClass() {
return objAttribute.getJavaClass();
}

Expand Down

0 comments on commit 91e768a

Please sign in to comment.