Re: Snapshot problems
Re: Snapshot problems
- Subject: Re: Snapshot problems
- From: Chuck Hill <email@hidden>
- Date: Fri, 20 Apr 2007 15:16:36 -0700
On Apr 20, 2007, at 3:12 PM, Steven Mark McCraw wrote:
Ok, I jumped the gun. When you asked if I had custom attributes, I
thought you meant "do you have instance variables within your
custom classes of type 'NSMutable...'". After looking at page 43
of my shiny new PWO eBook, I see you were actually talking about
custom attributes specified in the EOModel. The answer to that is,
"Good Lord, no".
Oh, darn. There goes that neat and tidy theory. :-(
Here is what I meant (and thought you meant at first):
public class CatalogItem extends _CatalogItem {
/**
* Temporarily holds the sale prices and quantities so we don't
have to fetch them over
* and over (since we don't want to use a relationship to
saleItem, because
* there may be many relationships to sale items which are for
different sales
* than the one we are concerned with.).
*/
public NSMutableDictionary saleInfo;
public NSMutableArray sortedSaleQuantities;
private boolean saleItemsFetched;
public CatalogItem() {
super();
saleInfo = null;
saleItemsFetched = false;
configurableKit = false;
}
...
Or was I right the first time, and the code I added above is
problematic? Sorry for all the confusion / false hope.
As long as saleInfo, sortedSaleQuantities, and saleItemsFetched do
not match any attribute or relationship names that should be safe.
What else can it be....?
Chuck
On Apr 20, 2007, at 5:41 PM, Chuck Hill wrote:
On Apr 20, 2007, at 2:28 PM, Steven Mark McCraw wrote:
Another explanation occurred to me. Do you have any custom
attributes in any of the objects? Are any of them mutable (e.g.
NSMutableDictionary, NSMutableArray, a custom class that you
wrote)?
Yes, many of my classes have custom attributes. CatalogItem has
an NSMutableDictionary and an NSMutableArray as custom attributes.
DING DING DING! We have a winner!
I believe some of my EOs also have attributes that are
references to custom classes that I have written. Could this be
problematic?
Mutable attributes are death to EOF. That is your problem. Or at
least one of them. If you really, really work at it you can
probably get it to work, but it is really not worth the effort
IMO. Make them immutable. Add cover methods to modify these
values: make a mutable clone of the attribute, modify it, make an
immutable clone and replace the attribute value. See page 43 of
PWO if you have it. If you don't have it, can pretty much assure
that you want it!
Chuck
Are you doing anything else, anywhere, that might be a departure
from plain jane EOF? You may be doing something that appears
innocent and unrelated which is actually hammering EOF. I am
just trying to prod your memory.
It's hard to know. What is an example of something you would
consider not plain jane EOF? In InventoryItem, I'm overridding
the 'set' methods for a couple of attributes that are likely to
change frequently underneath EOF so that it can automatically
handle Optimistic locking exceptions. An example of something
like that is below. Yesterday after some of our email, I got
worried that this may be doing something terrible with regards to
EOF, and commented it all out so that everything was using the
default implementation (and of course this was also the case when
I commented out the entire body of each custom class), but it had
no impact whatsoever on the test case that started all of this,
so I felt more secure that it was ok to do this kind of thing.
public void setShelfQuantity( Number newValue ) {
Integer existingShelf = (Integer) shelfQuantity();
if ( shelfQuantity() != null && availableQuantity() != null
&& rawPrimaryKey() != null ) {
int difference = newValue.intValue() - shelfQuantity
().intValue();
if ( difference >= 0 ) {
increaseShelfQuantityBy( difference );
increaseAvailableQuantityBy( difference );
} else {
reduceAvailableQuantityBy( difference * -1 );
reduceShelfQuantityBy( difference * -1 );
}
} else {
super.setShelfQuantity( newValue );
setAvailableQuantity( newValue );
}
if ( ( existingShelf == null || existingShelf.intValue() ==
0 ) && newValue != null
&& newValue.intValue() > 0 ) {
Enumeration catalogEnum = catalogItems().objectEnumerator();
CatalogItem catalog = null;
while ( catalogEnum.hasMoreElements() ) {
catalog = (CatalogItem) catalogEnum.nextElement();
if ( catalog.futureRelease().intValue() == 1 ) {
catalog.setFutureRelease( new Integer( 0 ) );
}
}
}
}
public void increaseShelfQuantityBy( int numberSold ) {
super.setShelfQuantity( new Integer( shelfQuantity().intValue
() + numberSold ) );
// try to save changes but check for conflicts
try {
successfulChangeSave();
} catch ( EOGeneralAdaptorException e ) {
// conflict!! try again on the refaulted object
super.setShelfQuantity( new Integer( shelfQuantity
().intValue() + numberSold ) );
try {
successfulChangeSave();
} catch ( EOGeneralAdaptorException f ) {
NSLog.out.appendln( "Multiple conflicts increasing shelf
qty!: " + "shelf: "
+ shelfQuantity() + ", avail: " +
availableQuantity() + "\n"
+ ErrorStackTrace.toString( f ) );
}
}
}
public void refresh() {
editingContext().invalidateObjectsWithGlobalIDs(new NSArray
(editingContext().globalIDForObject(this)));
}
public void successfulChangeSave() throws
EOGeneralAdaptorException {
try {
editingContext().saveChanges();
} catch ( EOGeneralAdaptorException f ) {
refresh();
throw f;
}
if ( editingContext().parentObjectStore() instanceof
EOEditingContext ) {
try {
( (EOEditingContext) editingContext().parentObjectStore
() ).saveChanges();
} catch (EOGeneralAdaptorException f) {
refresh();
throw f;
}
}
}
Chuck
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve
specific problems.
http://www.global-village.net/products/practical_webobjects
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
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