• 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: Derived attribute problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Derived attribute problem


  • Subject: Re: Derived attribute problem
  • From: David Avendasora <email@hidden>
  • Date: Tue, 25 Mar 2014 09:07:15 -0400

Hey Angelo, 

As far as your statement:

1) I prefer to implement my business logic in my custom classes rather than in SQL code that will often be hard to maintain and that will almost certainly be tailored for a specific RDBMS. Anyway, what is the point in having custom classes and the power of Enterprise Objects if I must rely on custom-tailored SQL code?

Amen, brother! You are 100% right. If you are not forced into working with a legacy database, you should **not** be doing a bunch of work-around, hacky BS with derived attributes/relationships or read/write formatters. Store the data in the DB how you want to use it. Why have an ORM if you are still forced to write SQL? And even if you are forced to use an existing column, there are ways to do what you want using Java instead. See the “boolean” erprototype. It is an example of using a “Custom" Data Type in Entity Modeler which you can use specify your own Java class to do the read/write transformations instead of writing db-specific SQL.

As far as the rest of the issues you describe, there is something very wrong. The things you describe in point 2 and 3 below should not be happening.

How have you modeled these three entities? (Party, Person, Organization)

What type of Inheritance are you using? (SingleTable, Vertical, Horizontal)

How are the entities represented in the database? (one table, two tables, three tables)

With EOF the EOModel is EVERYTHING. If you don’t get it right, you will be writing a huge amount of code to try to make EOF do what you really want and it will likely still not do it every time. 

If you get the EOModel right, then the code will seem to write itself and all this work you are doing will just go away.

I’m going to be in-and-out all day today, but if you can zip and attach your .eomodeld file, I’ll look it over to see if I (or anybody else) can spot where things have gone wrong for you.


Dave


On Mar 24, 2014, at 5:16 PM, Ângelo Andrade Cirino <email@hidden> wrote:

Hi Dave,

It is a minor bug, but still a bug. When I have time I will give it a look.

I am working with the derived attributes with no major complaints now. Still, there are some problems with EO and derived attributes.

1) I prefer to implement my business logic in my custom classes rather than in SQL code that will often be hard to maintain and that will almost certainly be tailored for a specific RDBMS. Anyway, what is the point in having custom classes and the power of Enterprise Objects if I must rely on custom-tailored SQL code?
So, I simply create a derived attribute and then I override it in my custom class, and then forget the existence of the derived attribute. To make my typing shorter I tried to include dummies for the SQL statement, as simple as returning an empty string, ''. But EO did not interpret correctly my reasoning and tried to use it with an error. I ended using a very stupid dummy for all my derived attributes, since I want the model to be database agnostic. I use if(TRUE,NULL,NULL) and then override the derived attributes with my custom logic in my custom classes. I am currently not concerned with database performance, I am just trying to develop a valid programming technique for the context of D2W applications.

2) I implemented two derived classes, Person and Organization, since both are a Party. The subclasses are differentiated by the type attribute. Up to a point EO will deal with the Party entity very well, essentially when I try to access only the attributes or derived attributes that are common to both subclasses. When I needed the equivalent of this SQL statement

select distinct party.id, party.created, party.lastmodified, if(party.status = 0,'Active','Inactive') as status, if(party.type = 0, 'Natural Person', 'Legal person') as type,
(
   case party.type
        when 0 then concat(person.firstName, ' ', person.lastName)
        when 1 then organization.name
    end
) as fullName from party inner join person, organization where (party.personID = person.id or party.organizationID = organization.id);

EO returned an empty set, because it used party.personID = person.id AND party.organizationID = organization.id instead of OR as my SQL statement. Whenever I constructed a derived attribute with columns from both tables EO generates the SQL inner join clause with an AND instead of an OR. I found no way to solve this problem and that's one of the reasons I moved to dummy derived attributes statements.

3) In simple listings for the base class, Party, EO will generate a very similar SQL statement but will effectively lack the DISTINCT clause doubling the result set. This happens for queries too. For the listings I circumvented the problem by creating a allParties fetch specification in my Party entity

type = 0 OR type = 1

and then implementing the list page this way

public WOComponent listPartyAction() {
        ListPageInterface newListPage = (ListPageInterface)D2W.factory().pageForConfigurationNamed("List" + Party.ENTITY_NAME, session());
        EODataSource ds = new ERXDatabaseDataSource(ERXEC.newEditingContext(), Party.ENTITY_NAME, "allParties");
        newListPage.setDataSource(ds);
        return (WOComponent) newListPage;
}

This way my list page displays the correct set of EO objects. I still have to work on the query issue with an adequate delegate implementing an additional fetch specification, but I deferred the solution to a later moment since it is already identified and easily implemented.

I am not sure if I am being naive or using EO in a very stupid way (or both perhaps, since stupidity comes after naivety). I would appreciate any sincere and frank comments and criticisms, since I am doing all this in a huge effort to deepen my understanding of EO and Wonder and then become a better WO developer, hoping to contribute to the community instead of only asking silly questions.

Regards,

Angelo


2014-03-24 10:12 GMT-03:00 David Avendasora <email@hidden>:
Hi Angelo,

The question is, why does EO expect a column for a derived attribute for a custom class and not for a ERXGenericRecord?


It doesn’t. You’ve found a EntityModeler bug I just found last week as well. A derived attribute should not have a value for “columnName” in the .plist - regardless if it has a specific custom/generic class or not. It should either be an empty string (columnName = "";) or just remove the entry all together. 

I don’t think EOF will even look at the definition entry if there is a value for columnName.

Your entry of:

definition = "case code when 0 then 'Active' when 1 then 'Inactive' end";

Should work correctly if that would be a valid SQL clause in a MySQL select statement.

I think if you just get rid of the columnName entry it should work.

Dave



On Mar 23, 2014, at 1:50 PM, Ângelo Andrade Cirino <email@hidden> wrote:

Hi Aaron,

1) You are right, I am using Eclipse and WOlips, so, forgive me for the old times lingo, but I am really using Eclipse's (WOlips) Entity Modeler.

2) Since I am dedicating some time to deepen my understanding of Wonder I decided to do it with a new Eclipse (Kepler) install. I am using Kepler and the latest WOlips 4.3 stable build. After finishing installation I just forgot to turn off generate bundles...

3) Unfortunately we need to live with the Eclipse problems. But Apple's PB and EOModeler weren't free of problems too…

Angelo


2014-03-23 14:32 GMT-03:00 Aaron Rosenzweig <email@hidden>:
Hi Angelo,

Glad you got it working in the end. A couple things though:

1) You keep saying “EOModeler.” Technically that is an Apple product that requires the Objective-C to Java bridge which has not worked since probably Mac OS X Tiger. Is that what you are using or are you using “EntityModeler” that runs in Eclipse?

2) Are you using the “bundle-less build” in Eclipse? If you are not, some of these problems could be related to that. Since it has been possible to run without generating a bundle, I doubt anyone has tested the older way much. 

3) Eclipse just sucks… in general. I mean, it’s a tall order, taking all those “dead” files on disk and then puffing them up like the “living dead” in a cool IDE so that you can see “who calls who” and “refactor” etc. But It’s easy to get out of sync or just to have problems. If you are running EntityModeler on its own (Can you do that? I know RuleModeler can… I’m not sure about EntityModeler) then you better “refresh” all your projects and “clean” all your projects after you make an edit and save from EntityModeler. It’s what I have to do when using any external tool. And sometimes, even when I’m totally in the Eclipse universe something invariably will screw the pooch and I need to “refresh” “clean all” and sometimes restart Eclipse. I call it the “Eclipse dance."
AARON ROSENZWEIG / Chat 'n Bike

e:  email@hidden  t:  (301) 956-2319
Chat 'n BikeChat 'n Bike

On Mar 23, 2014, at 11:58 AM, Ângelo Andrade Cirino <email@hidden> wrote:

Hi Aaron,

Thank you for your prompt answer. Unfortunately none of the suggestions worked.

1) I can't find any combination of double or single apostrophe that will work. A similar MySQL SELECT statement is as simple as this

select Party.id as partyID, (case status
when 0 then 'Active'
when 1 then 'Inactive'
    end) as fullStatus from Party;

Even this simple derived attribute that returns a constant won't work (from the plist entity file):

{
columnName = fullStatus; 
definition = "'Full Status'"; 
name = fullStatus; 
prototypeName = varchar16; 
}, 

with the following error:

IllegalStateException: sqlStringForAttribute: attempt to generate SQL for attribute 'fullStatus' on entity 'Party' with undefined column name. You must define a column name for this attribute before attempting a database operation.

2) The read format option didn't work either since the attribute is an integer number and the return value is a string. I attempted this format:

if(%P,'Active','Inactive')

and it resulted in this error:

JDBCAdaptorException: Invalid value for getInt() - 'Inactive'

However, this works just fine as a read format:

if(%P,2*%P,5*%P)

But I am stubborn and think that a derived attribute is a desirable attribute. I would like to use it for more complex operations, for example involving concatenation of strings in related entities.

Anyway, trying to figure out what is happening, it occurred to me that my Party entity is a custom class, so I tried a non-custom class with a simple entity to see if the derived attribute would work. And it worked. My simple tentative entity is this:

{
    attributes = (
        {columnName = code; name = code; prototypeName = intNumber; }, 
        {
            columnName = fullStatus; 
            definition = "case code when 0 then 'Active' when 1 then 'Inactive' end"; 
            isReadOnly = Y; 
            name = fullStatus; 
            prototypeName = varchar16; 
            userInfo = {"_EntityModeler" = {generateSource = NO; }; }; 
        }, 
        {allowsNull = N; name = id; prototypeName = id; }
    ); 
    attributesUsedForLocking = (code, id); 
    className = "er.extensions.eof.ERXGenericRecord"; 
    classProperties = (code, fullStatus); 
    externalName = Status; 
    fetchSpecificationDictionary = {}; 
    name = Status; 
    primaryKeyAttributes = (id); 
}

But this isn't a solution for me, since my entity will have a lot of business logic that demands a custom class. Perhaps I should set my Party entity as a ERXGenericRecord and then subclass it to implement the business logic.

The question is, why does EO expect a column for a derived attribute for a custom class and not for a ERXGenericRecord?

By the way, the original Apple EOModeler User Guide doesn't state that a derived attribute will not work for a custom class nor does the documentation states that a derived attribute should be modeled for a generic record.

Angelo

2014-03-23 1:01 GMT-03:00 Aaron Rosenzweig <email@hidden>:
Hi Angelo,

Couple things to try:

1) Remove the single apostrophes surrounding “status” and try again. It is possible that it isn’t parsing properly… don’t column names need to have “double apostrophes” ??? Perhaps MySQL is lax about that but still… Either use no apostrophe or use a “double apostrophe” meaning a single character the shift-apostrophe key. If it is a single apostrophe that is a String in SQL. 

2) Try a different way. Remove all the code you have in the derived part and make this a normal EOAttribute. Put “STATUS” in there by itself. Now go to the “advanced” tab and type what you want in the “Read Format” and check the “read only” box. In the read format you want to use %P for your columnName so you’ll want something like this:

case %P when 0 then 'Active' when 1 then 'Inactive’ end

Honestly, I almost always use the #2 way and never the “derived” way because it is more flexible. I like the idea that I define the column in one box and in another I write something complex but refer to it with %P. 

Try it out and report back.
AARON ROSENZWEIG / Chat 'n Bike

e:  email@hidden  t:  (301) 956-2319







-- 
Ângelo Andrade Cirino
email@hidden
31-3494-8642
31-9303-0695
MSN email@hidden
Skype aacirino
_______________________________________________
Do not post admin requests to the list. They will be ignored.

This email sent to email@hidden


—————————————————————————————
WebObjects - so easy that even Dave Avendasora can do it!™
—————————————————————————————
David Avendasora
Senior Software Abuser
Nekesto, Inc.








--
Ângelo Andrade Cirino
email@hidden
31-3494-8642
31-9303-0695
MSN email@hidden
Skype aacirino


—————————————————————————————
WebObjects - so easy that even Dave Avendasora can do it!™
—————————————————————————————
David Avendasora
Senior Software Abuser
Nekesto, Inc.





 _______________________________________________
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: Derived attribute problem
      • From: Ângelo Andrade Cirino <email@hidden>
References: 
 >Derived attribute problem (From: Ângelo Andrade Cirino <email@hidden>)
 >Re: Derived attribute problem (From: Aaron Rosenzweig <email@hidden>)
 >Re: Derived attribute problem (From: Ângelo Andrade Cirino <email@hidden>)
 >Re: Derived attribute problem (From: Aaron Rosenzweig <email@hidden>)
 >Re: Derived attribute problem (From: Ângelo Andrade Cirino <email@hidden>)
 >Re: Derived attribute problem (From: David Avendasora <email@hidden>)
 >Re: Derived attribute problem (From: Ângelo Andrade Cirino <email@hidden>)

  • Prev by Date: RE: Saving NSDictionary to DB
  • Next by Date: WOLips gives WO Template Problems (keypaths) even if not real problems!
  • Previous by thread: Re: Derived attribute problem
  • Next by thread: Re: Derived attribute problem
  • Index(es):
    • Date
    • Thread