Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ERXPartialInitializer handle locking and class property settings correctly #804

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.webobjects.eoaccess.EOEntity;
import com.webobjects.eoaccess.EOModel;
import com.webobjects.eoaccess.EOModelGroup;
import com.webobjects.eoaccess.EOProperty;
import com.webobjects.eoaccess.EORelationship;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSDictionary;
Expand Down Expand Up @@ -38,6 +39,7 @@
*
* @property er.extensions.partials.enabled
* @author mschrag
* @author jtabert
*/
public class ERXPartialInitializer {
private static final Logger log = LoggerFactory.getLogger(ERXModelGroup.class);
Expand Down Expand Up @@ -83,6 +85,7 @@ public void initializePartialEntities(EOModelGroup modelGroup) {
Enumeration modelsEnum = modelGroup.models().objectEnumerator();
while (modelsEnum.hasMoreElements()) {
EOModel model = (EOModel) modelsEnum.nextElement();
// TODO: merge userInfo from model
Enumeration entitiesEnum = model.entities().objectEnumerator();
while (entitiesEnum.hasMoreElements()) {
EOEntity partialExtensionEntity = (EOEntity) entitiesEnum.nextElement();
Expand All @@ -103,18 +106,33 @@ public void initializePartialEntities(EOModelGroup modelGroup) {
NSMutableDictionary<String, Object> attributePropertyList = new NSMutableDictionary<String, Object>();
partialAttribute.encodeIntoPropertyList(attributePropertyList);
String factoryMethodArgumentType = (String) attributePropertyList.objectForKey("factoryMethodArgumentType");
// OFFICIALLY THE DUMBEST DAMN THING I'VE EVER
// SEEN
// OFFICIALLY THE DUMBEST DAMN THING I'VE EVER SEEN
if ("EOFactoryMethodArgumentIsString".equals(factoryMethodArgumentType)) {
attributePropertyList.setObjectForKey("EOFactoryMethodArgumentIsNSString", "factoryMethodArgumentType");
}
EOAttribute primaryAttribute = new EOAttribute(attributePropertyList, partialEntity);
primaryAttribute.awakeWithPropertyList(attributePropertyList);
partialEntity.addAttribute(primaryAttribute);
// check if the attribute is a class property
if (!partialExtensionEntity.classPropertyNames().contains(partialAttribute.name())) {
EOProperty p = partialEntity.propertyNamed(partialAttribute.name());
if (p != null) {
partialEntity.classProperties().remove(p);
log.debug("Removing partial attribute {}.{} from {}.classProperties because it is not defined as class property.", partialExtensionEntity.name(), partialAttribute.name(), partialEntity.name());
}
}
// check if the attribute is used for locking
if (!partialExtensionEntity.attributesUsedForLocking().contains(partialAttribute)) {
EOAttribute a = partialEntity.attributeNamed(partialAttribute.name());
if (a != null) {
partialEntity.attributesUsedForLocking().remove(a);
log.debug("Removing partial attribute {}.{} from {} attributesUsedForLocking because it is not defined as locking attribute.", partialExtensionEntity.name(), partialAttribute.name(), partialEntity.name());
}
}
}
else {
log.debug("Skipping partial attribute {}.{} because {} already has an attribute of the same name.",
partialExtensionEntity.name(), partialAttribute.name(), partialEntity.name());
// TODO: merge userInfo from attribute
log.debug("Skipping partial attribute {}.{} because {} already has an attribute of the same name.", partialExtensionEntity.name(), partialAttribute.name(), partialEntity.name());
}
}

Expand All @@ -128,10 +146,18 @@ public void initializePartialEntities(EOModelGroup modelGroup) {
EORelationship primaryRelationship = new EORelationship(relationshipPropertyList, partialEntity);
primaryRelationship.awakeWithPropertyList(relationshipPropertyList);
partialEntity.addRelationship(primaryRelationship);
// check if the relationship is a class property
if (!partialExtensionEntity.classPropertyNames().contains(partialRelationship.name())) {
EOProperty p = partialEntity.propertyNamed(partialRelationship.name());
if (p != null) {
partialEntity.classProperties().remove(p);
log.debug("Removing partial relationship {}.{} from {} classProperties because it is not defined as class property.", partialExtensionEntity.name(), partialRelationship.name(), partialEntity.name());
}
}
}
else {
log.debug("Skipping partial relationship {}.{} because {} already has a relationship of the same name.",
partialExtensionEntity.name(), partialRelationship.name(), partialEntity.name());
// TODO: merge userInfo from relationship
log.debug("Skipping partial relationship {}.{} because {} already has a relationship of the same name.", partialExtensionEntity.name(), partialRelationship.name(), partialEntity.name());
}
}

Expand Down