• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Saving WOCheckboxes in a Repetition into a database
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Saving WOCheckboxes in a Repetition into a database


  • Subject: Saving WOCheckboxes in a Repetition into a database
  • From: David Holt <email@hidden>
  • Date: Thu, 5 Oct 2006 18:13:33 -0700

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Saving WOCheckboxes in a Repetition into a database
      • From: Alexander Spohr <email@hidden>
    • Re: Saving WOCheckboxes in a Repetition into a database
      • From: David LeBer <email@hidden>
  • Prev by Date: Re: Doing something when a WOSession terminates
  • Next by Date: Re: Saving WOCheckboxes in a Repetition into a database
  • Previous by thread: Re: Doing something when a WOSession terminates
  • Next by thread: Re: Saving WOCheckboxes in a Repetition into a database
  • Index(es):
    • Date
    • Thread