• 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
Re: Need To Get PrimaryKey ID - Extended
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need To Get PrimaryKey ID - Extended


  • Subject: Re: Need To Get PrimaryKey ID - Extended
  • From: "Jonathan Fleming" <email@hidden>
  • Date: Wed, 26 Mar 2003 01:20:10 +0000

Hi Jonathan and the rest of you Dev Kings,

Thanks Jonathan, but I've solved this now with this code placed in my EOModel EOCustomObject class thanks to Jacky Gagnon.

public String sTb_ClientID() {
try{
NSDictionary primaryKey = EOUtilities.primaryKeyForObject(this.editingContext(), this);
return String.valueOf( (Integer) primaryKey.objectForKey("tbClientID") );
} catch (Exception e){
NSLog.out.appendln("\n*** Exception thrown by sTb_ClientID(): " + e + "\n");
}
return null;
}


However, I have this Problem (probably because I don't fully understand the editing context... probably)
These are the classes/java files that are involved:
TbJobPicture tbJobPicture, TbJob tbJob, TbClient tbClient


THIS IS THE SENARIO:
TbJobPicture is really where everything goes on, so when adding a new image, the class will -- if it does not already exist -- creates a CLIENT directory which holds a JOB directory which holds the images for the specified Client's job. The image file is sent to the folder using a fileOutputStream and saves, no problem. So far so good...


Bare in mind that the primary key is used to give the directories a reference within the directory name that will indicate which EO it links to, for example; Haydon_334.dir, Jones_8.dir or Haydon_4545.dir And back relationships are used to get the "lastName" from tbClient which is reached through tbJob where I get the "jobRefNo" which is used in the JOB directory name as well as the tbJobID, Eg. Job_Ahm001_17_Dta

If I go to update any images I can do so with no problem, but if I attempt to delete any image file I can only do so if I click on the edit button/link in my app first, if I don't I get a NullPointerException.
Now, I have a good idea that this is due to my filePath statement not holding value in either the PK or lastNameOr jobRefNO, but I don't know why this is happening. For convienience, here's an example of one of those filePath statements:
public String sPortfolioPixDirPath() {
return "/AppleJavaProjects/JandMBuildingServices/JandMGeneralMaintenance/JandMGeneralMaintenance.woa/Contents/WebServerResources/images_dir/PortfolioPix/";
}
public String sClientDtaDirPath() {
return sPortfolioPixDirPath() + sClientLastName() + "_" + tbJob.tbClient().sTb_ClientID() + "/";
}


THE INTERFACE SETUP:
I have a WORepetition which is bound to method sortedJobList
public NSArray sortedJobPictures() {
NSMutableArray sortedJobPictureList = new NSMutableArray(tbJob().tbJobPictures());
//*** Rest of code... etc.


In the WORepetition's table row I have an edit button and a delete button, the edit button is linked to this:
public WOComponent dbEditTbJobPicture() {
// set the tbClient to edit to the one the user selected
tbJobPicture = tbJobPictureItem;
setReadyNewJobPicture("Edit This Picture's Details");


NSLog.out.appendln( "===\r The Client Directory ID For " + sClientLastName() + " is: " + tbJob.tbClient().sTb_ClientID() + " from dbEditTbJobPicture()" );
NSLog.out.appendln( "===\r The Job Directory ID For " + sJobRefNo() + " is: " + tbJob.sTb_JobID() + " from dbEditTbJobPicture()\r" );


       return null;
   }

Delete is linked to this:
/*---------------------- 2 x delete methods -------------------------*/


   public WOComponent deleteTbJobPicture() {
       setRequiredButtons("showSaveRevertButtonsInListView");
       setClickedButton("Delete Button");

       // get editing context from tbJobPicture object
       EOEditingContext ec = tbJobPictureItem.editingContext();

// delete tbJobPicture from its editing context
ec.deleteObject(tbJobPictureItem);
// remove object from relationship
tbJob.removeObjectFromBothSidesOfRelationshipWithKey(tbJobPictureItem,
"tbJobPictures");
((Session)session()).setDeleteVar("deleted");
NSLog.out.appendln("App Delete iVar set to " + ((Session)session()).deleteVar() + "");
setAnchor("DELETEWARNING");


NSLog.out.appendln( "===\r The Client Directory ID For " + sClientLastName() + " is: " + tbJob.tbClient().sTb_ClientID() + " from deleteTbJobPicture()" );
NSLog.out.appendln( "===\r The Job Directory ID For " + sJobRefNo() + " is: " + tbJob.sTb_JobID() + " from deleteTbJobPicture()\r" );
return null;
}
/*------------------*/


   public WOComponent OkFullDeletion() {

       // get editing context
       EOEditingContext ec = session().defaultEditingContext();

boolean deleteThumbnail = (new File(sJobDtaDirPath() + tbJobPicture.picThumbRef())).delete();
NSLog.out.appendln( "\n=== Thumbnail deleted" + tbJobPicture.picThumbnail() );
if (!deleteThumbnail) {
// Deletion of thumbnail failed
NSLog.out.appendln( "=== Deletion of thumbnail named " + tbJobPicture.picThumbnail() + "failed " );
}


boolean deleteJpeg = (new File(sJobDtaDirPath() + tbJobPicture.picLrgRef())).delete();
NSLog.out.appendln( "\n=== Jpeg deleted" + tbJobPicture.picLrg() );
if (!deleteJpeg) {
// Deletion of jpeg failed
NSLog.out.appendln( "=== Deletion of jpeg named " + tbJobPicture.picLrg() + "failed " );
}


       // save changes made in editing context to object store
       ec.saveChanges();
       ((Session)session()).setDeleteVar(null);

NSLog.out.appendln("\nThe ec saved on a full deletion was: " + ec + "\n");
NSLog.out.appendln( "===\r The Client Directory ID For " + sClientLastName() + " is: " + tbJob.tbClient().sTb_ClientID() + " from OkFullDeletion()" );
NSLog.out.appendln( "===\r The Job Directory ID For " + sJobRefNo() + " is: " + tbJob.sTb_JobID() + " from OkFullDeletion()\r" );


       return null;
   }

THE PROBLEM:
whenever i come into the tbJobPicture interface and click the delete button immediately without having clicked the update button I will be warned that I am about to delete an item, I have the option to "Revert" or "Really Delete", when i click "Really Delete" I get the NullPointerException. Obviously the delete button is linked to a conditional element so that I am warned before I trully delete.
However, if I do click the edit button which will show a form (again, through a conditional where I can still see my list too) containing all that is needed to upload the image and it's data and I attempt to delete an item, the delete button works fine, only this time the EO is deleted but the image files don't, they remain on the server.
Moreover, if I change the delete methods above so that the statements, boolean deleteThumbnail and boolean deleteJpeg are in the; deleteTbJobPicture() method rather than where they are as you see them now, when I click on delete after having clicked on the update button first, I am able to get my warning panel but my files will have already been deleted so if i "Revert" i will only get back my EO. If I continue on to "Really Delete", the EO disappears from the database as well, no problem.


I have spent days trying to figure this out how to come into the page and simply delete an item having fist being warned before I delete and be able to delete with no problems like I've been having, but i have no idea now how to fix it because my brain is fried to a crisp, well over done like a tough slab of meat...

Please help
Jonathan
Ps. I hope I've explained myself good enough on this one... this was one of the reason's i've tried so hard to find a solution to this; because i knew it was going to take some explaining.


_________________________________________________________________
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: ip address in log file
  • Next by Date: Newbie: Client object updates
  • Previous by thread: RE:ip address in log file
  • Next by thread: Newbie: Client object updates
  • Index(es):
    • Date
    • Thread