• 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: Updating EOObjects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Updating EOObjects


  • Subject: Re: Updating EOObjects
  • From: Arturo PĂ©rez <email@hidden>
  • Date: Thu, 18 Aug 2005 20:53:55 -0400

Hey Jonathan,

Everybody does it, don't feel bad :-)

Remember you're dealing with objects (EOGenericRecords probably). Most of your EOF-related code should look like

// create and initialize object.
aLicense = new License();
eoEditingContext.insertObject(aLicense);
aLicense.takeValueForKey(Color.RED, "color");

// create and initialize object.
aPrincipal = new Principal();
eoEditingContext.insertObject(aPrincipal);
aPrincipal.takeValueForKey(privileges, "permissions");


// set up the relationship between the above two objects.
aLicense.addObjectToBothSidesOfRelationshipWithKey(aPrincipal, "principals");


try {
     eoEditingContext.saveChanges();
} catch (...validation exceptions...) { ... }

It'll be about 18 months before you need anything beyond takeValue..., addObjectToBothSides, saveChanges, removeObjectFrom... and EOUtilities.

-arturo

On Aug 18, 2005, at 8:12 PM, Chuck Hill wrote:


On Aug 18, 2005, at 4:18 PM, Jonathan Miller wrote:

Sorry Chuck -

Here you go-

public WOComponent insertLicense()
{
try {
aLicense.takeValueForKey(selectedCustomer.valueForKey("principalid"), "principalid");


This just looks so very, very wrong. Please tell me that princpalid is not a PK. Please. What your code _should_ look like is this:
aLicense.addObjectToBothSidesOfRelationshipWithKey(principal, "principal");


_This_ is why you are not seeing the connected objects after creation. Don't touch those PK things. Connect the objects, let EOF worry about primary keys and such nastiness. Worry about the object graph, not the database. EOF will take care of the database.


or, if you like writing code: aLicense.setPrincipal(principal); principal.addToLicenses(aLicense);


aLicense.takeValueForKey(selectedPR.valueForKey("id"), "productId");
aLicense.setProduct(selectedPR);

Isn't that just so much nicer to look at?


            ec.insertObject(aLicense);

Shriek! =8-0
Always insert first. You may see examples, even from Apple, showing otherwise, but trust me on this. It will only end in tears. Try to use EOUtilities.createAndInsertInstance(ec, "Licence") for all EO creation.



            ec.saveChanges();
        } catch(NullPointerException e) {
            NSLog.out.appendln(e.getMessage());
Don't catch that, let the Application level handler deal with it.


        } catch(NSValidation.ValidationException e) {
            validationFailedWithException(e, null, null);
        } catch(RuntimeException e) {
            NSLog.out.appendln(e.getMessage());

Don't catch that, let the Application level handler deal with it.


        }
        aLicenseString = new LicenseStrings();

Insert! And this whole way of handling new objects is a disaster waiting to happen if you only use the default editing context.


Chuck


        setPageKey("NLS");
        return null;
    }

thanks again

Jon

On Aug 18, 2005, at 12:27 PM, Chuck Hill wrote:

Where is the code that creates the License, Principal, and Product objects and related them together?

Also, unrelated to your problem,

aLicense = new License();
...
searchGroup.setObjectArray(aLicense.searchLicenses(eq, ec));



Look bad design. searchLicenses should be a static method so you can write


 searchGroup.setObjectArray(License.searchLicenses(eq, ec));


And perhaps better named and conformed the to rest of the API as


searchGroup.setObjectArray(License.licensesWithQualifier(ec, eq));



Chuck


On Aug 18, 2005, at 3:04 PM, Jonathan Miller wrote:


The relationship are created straight out of the EOModeler's Java Generation Tool so I hope this is what you are asking for

/* Excerpt from License.java */
    public String principalid() {
        return (String)storedValueForKey("principalid");
    }

    public void setPrincipalid(String value) {
        takeStoredValueForKey(value, "principalid");
    }
    public Number productId() {
        return (Number)storedValueForKey("productId");
    }

    public void setProductId(Number value) {
        takeStoredValueForKey(value, "productId");
    }

public com.VX30_ADMIN.LicenseStrings licensestrings() {
return (com.VX30_ADMIN.LicenseStrings)storedValueForKey("licensestrings");
}


public void setLicensestrings(com.VX30_ADMIN.LicenseStrings value) {
takeStoredValueForKey(value, "licensestrings");
}


public com.VX30_ADMIN.Products products() {
return (com.VX30_ADMIN.Products)storedValueForKey("products");
}


    public void setProducts(com.VX30_ADMIN.Products value) {
        takeStoredValueForKey(value, "products");
    }

public com.VX30_ADMIN.Principals principals() {
return (com.VX30_ADMIN.Principals)storedValueForKey("principals");
}


    public void setPrincipals(com.VX30_ADMIN.Principals value) {
        takeStoredValueForKey(value, "principals");
    }
 /* Excerpt from Products.java */

    public NSArray licensekeyss() {
        return (NSArray)storedValueForKey("licensekeyss");
    }

    public void setLicensekeyss(NSArray value) {
        takeStoredValueForKey(value, "licensekeyss");
    }

    public NSArray licenses() {
        return (NSArray)storedValueForKey("licenses");
    }

    public void setLicenses(NSArray value) {
        takeStoredValueForKey(value, "licenses");
    }

    public void addToLicenses(com.VX30_ADMIN.License object) {
        includeObjectIntoPropertyWithKey(object, "licenses");
    }

    public void removeFromLicenses(com.VX30_ADMIN.License object) {
        excludeObjectFromPropertyWithKey(object, "licenses");
    }
/*Excerpt from Principals.java */
    public NSArray licenses() {
        return (NSArray)storedValueForKey("licenses");
    }

    public void setLicenses(NSArray value) {
        takeStoredValueForKey(value, "licenses");
    }

    public void addToLicenses(com.VX30_ADMIN.License object) {
        includeObjectIntoPropertyWithKey(object, "licenses");
    }

    public void removeFromLicenses(com.VX30_ADMIN.License object) {
        excludeObjectFromPropertyWithKey(object, "licenses");
    }


If there is a more code you need please let me know.

Jon



On Aug 18, 2005, at 11:48 AM, Chuck Hill wrote:


Please post the code from where you create these objects and set the relations. That is where your mistake is.

Chuck

On Aug 18, 2005, at 2:43 PM, Jonathan Miller wrote:



Chuck-

Thanks for the quick response.

I guess I'm still stuck in an old mind site and I'm "trying" to explain it as my brain understands it. Having said that I'm leaving everything up to WebObjects and I'm letting EO do all the magic.

I have an entity that is called License. License has a relationship to another entity called Products and another relationship to an entity called Principals (each relationship is two way and are created by using EOModeler). When a license object is added all the values representing a license object are there. However when I display the license objects from a search I can see that the new license object exists however the information from the relationship's doesn't appear.

The search returns a WODisplayGroup and it iterates a license object. I reconstruct both those objects before doing the search (see code below). There is another action that occurs after the license is created that emails the license to a user. I can see from that action that the information from the relationship does not there appear as well.

Thanks for your humor and help.

Johnny.

p.s. I don't think this helps but here is the code from the search action:

    public WOComponent licenseSearch()
    {
        StringBuffer sb = new StringBuffer();
        aLicense = new License();
        searchGroup = new WODisplayGroup();

        if(selectedField.equals("Username")) {
            sb.append("principalid");
        } else {
            sb.append("principals.company");
        }

        if(selectedQualifier.equals("IS")) {
            sb.append(" =  %s");
        }else if(selectedQualifier.equals("LIKE")) {
            sb.append(" caseInsensitiveLike %@");
            searchString = searchString + "*";
        }

EOQualifier eq = EOQualifier.qualifierWithQualifierFormat(sb.toString(), new NSArray(new Object[] {searchString}));
searchGroup.setObjectArray(aLicense.searchLicenses(eq, ec));
setPageKey("VL");
return null;
}


On Aug 18, 2005, at 11:25 AM, Chuck Hill wrote:




On Aug 18, 2005, at 2:14 PM, Jonathan Miller wrote:




I have a two step form where the first step represents information in one table and the second step represents information in a second table. The two tables share a relationship where table one's Primary key is a foreign key in table 2.





Tables? Primary keys? What is that? We don't use those words in polite company here, those are dirty little implementation details best left in the dark corner of the closet. You have one instance (object) each of two entities (classes). Object A knows about (has a relationship to Object B. Does Object B know about Object A?





I am able to properly insert both sets of information into their respective tables.




That is EOF's job. Insert into tables? Who worries about low level details like that?






However when I go to view the information from inside a web page the information that should be displayed through the relationship does not appear.




Well, OK. Probably you have done something wrong. How are you creating the two objects? How are you establishing the relationship between them (telling A about B and / or B about A)? What does your code look like?






What is even more confusing is when I rebuild the project the information that didn't appear before appears now. I've tried reconstructing all my objects (i.e. the display group, the entity objects etc...) but that doesn't seem to help.




Sounds like you are relating the objects incorrectly. You are not actually, shudder, touching primary keys with your bare hands, are you?

Chuck

(only slightly in jest)


-- Practical WebObjects - a book for intermediate WebObjects developers who want to increase their overall knowledge of WebObjects, or those who are trying to solve specific application development problems.
http://www.global-village.net/products/practical_webobjects












-- Practical WebObjects - a book for intermediate WebObjects developers who want to increase their overall knowledge of WebObjects, or those who are trying to solve specific application development problems.
http://www.global-village.net/products/practical_webobjects










-- Practical WebObjects - a book for intermediate WebObjects developers who want to increase their overall knowledge of WebObjects, or those who are trying to solve specific application development problems.
http://www.global-village.net/products/practical_webobjects








-- Practical WebObjects - a book for intermediate WebObjects developers who want to increase their overall knowledge of WebObjects, or those who are trying to solve specific application development 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:
email@hidden


This email sent to email@hidden


_______________________________________________ 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: Updating EOObjects
      • From: Jonathan Miller <email@hidden>
References: 
 >Updating EOObjects (From: Jonathan Miller <email@hidden>)
 >Re: Updating EOObjects (From: Chuck Hill <email@hidden>)
 >Re: Updating EOObjects (From: Jonathan Miller <email@hidden>)
 >Re: Updating EOObjects (From: Jonathan Miller <email@hidden>)
 >Re: Updating EOObjects (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: Updating EOObjects
  • Next by Date: Re: Runtime.getRuntime().exec()
  • Previous by thread: Re: Updating EOObjects
  • Next by thread: Re: Updating EOObjects
  • Index(es):
    • Date
    • Thread