Re: Saving WOCheckboxes in a Repetition into a database
Re: Saving WOCheckboxes in a Repetition into a database
- Subject: Re: Saving WOCheckboxes in a Repetition into a database
- From: Alexander Spohr <email@hidden>
- Date: Fri, 6 Oct 2006 10:18:48 +0200
david,
1. switch off Artifacts relationship favouriteArtifacts.
2. any delete rules firing database-checks?
atze
Am 06.10.2006 um 03:13 schrieb David Holt:
The following code derived from mmalc's article on Stepwise is what
I have been using to store "favourites" to the database. I show the
items that have been marked as favourites when the page loads. When
I submit, the code loops through every artifact in the database
(some 20,000) and is dog slow. The inefficiency didn't show up
until I connected to the production database. Does anyone have any
suggestions for how I might make this code more efficient?
Thanks,
David
/** @TypeInfo Artifact */
public NSArray favourites() {
if (favourites == null) {
favourites = favAppPermission.favouriteArtifacts(); //get
favourites from the database
}
return favourites;
}
/** @TypeInfo Artifact */
public NSMutableArray selectionList() {
if (selectionList == null) {
selectionList = new NSMutableArray(favourites.mutableClone
()); // set the UI the same as the contents of the database
}
return selectionList;
}
public boolean artifactChecked()
{
return selectionList.containsObject(anArtifact); // is the
item checked in the UI?
}
public void setArtifactChecked(boolean newArtifactChecked) {
if ( newArtifactChecked) {
if (!selectionList.containsObject(anArtifact)) {
selectionList.addObject(anArtifact);
}
} else
if (selectionList.containsObject(anArtifact)) {
selectionList.removeObject(anArtifact);
mostRecentRemoval.addObject(anArtifact);
}
}
public WOComponent submit()
{
Session session = (Session)session();
EOEditingContext ec = session.defaultEditingContext();
int y = 0;
while (mostRecentRemoval.count() != y) {
anArtifact = (Artifact)mostRecentRemoval.objectAtIndex(y);
favAppPermission.removeObjectFromBothSidesOfRelationshipWithKey
(anArtifact, "favouriteArtifacts");
++y;
}
int z = 0;
while (selectionList.count() != z) {
anArtifact = (Artifact)selectionList.objectAtIndex(z);
favAppPermission.addObjectToBothSidesOfRelationshipWithKey
(anArtifact, "favouriteArtifacts");
++z;
}
ec.saveChanges();
return null;
}
CheckBox1: WOCheckBox {
checked = artifactChecked;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40freeport.de
This email sent to email@hidden
Freeport & Soliversum
Alexander Spohr
email@hidden
www.freeport.de
_______________________________________________
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