Is Adding EOAttribute to EOEntity Thread Safe?
Is Adding EOAttribute to EOEntity Thread Safe?
- Subject: Is Adding EOAttribute to EOEntity Thread Safe?
- From: Dov Rosenberg <email@hidden>
- Date: Sun, 30 Mar 2008 17:43:45 -0400
- Thread-topic: Is Adding EOAttribute to EOEntity Thread Safe?
Title: Is Adding EOAttribute to EOEntity Thread Safe?
We have some code that we are using from Project Wonder (I think) that adds an attribute programmatically to an EOEntity to do things like count, max, etc. (See below). We were doing a load test on our application and started throwing errors because a different query was submitted using the extra attribute. It seems that making changes to the EOModel is not thread safe. If that is the case is there anything we can do to use this code? Or should we dump this and build a regular fetch for the aggregate data. Any thooughts or insights would be a huge help.
Query that was generated in error – notice the COUNT() attribute embedded in the query incorrectly
"SELECT t0.ACTUALRATING, t0.BODY, t0.CLOSED, t0.DATEADDED, t0.DATEMODIFIED, t0.FORUMID, t0.IPADDRESS, t0.LOCALEID, t0.MODERATE, COUNT(t0.RECORDID), t0.PUBLISHED, t0.RECORDID, t0.STATUS, t0.TITLE, t0.TYPE, t0.USERID, t0.USERNAME, t0.USERNICKNAME, t0.WEIGHTEDRATING FROM DBTOPIC t0 WHERE t0.RECORDID = ?" withBindings: 1:"0032274bc94901122623a943007f46"(recordID)>:
Next exception:SQL State:42000 -- error code: 937 -- msg: ORA-00937: not a single-group group function
This is the code that we use to add the temporary attribute.
public static Number aggregateNumberFunctionWithQualifier(EOEditingContext ec, String entityName, String attributeName, String function, EOQualifier qualifier) {
EOEntity entity = EOUtilities.entityNamed(ec, entityName);
NSArray results = null;
EOAttribute attribute = createAggregateAttribute(ec, function, attributeName, entityName, "java.lang.Number", "i");
EOQualifier schemaBasedQualifier = entity.schemaBasedQualifier(qualifier);
EOFetchSpecification fs = new EOFetchSpecification(entityName, schemaBasedQualifier, null);
synchronized (entity) {
entity.addAttribute(attribute);
try{
fs.setFetchesRawRows(true);
fs.setRawRowKeyPaths(new NSArray(attribute.name()));
results = ec.objectsWithFetchSpecification(fs);
}finally{
entity.removeAttribute(attribute);
}
}
if ((results != null) && (results.count() == 1)) {
NSDictionary row = (NSDictionary) results.lastObject();
if (row.objectForKey(attribute.name()) != null && row.objectForKey(attribute.name()) instanceof Number) {
return (Number) row.objectForKey(attribute.name());
}
}
return null;
}
Dov Rosenberg
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden