Just updated to the new version

Posts   
 
    
netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 10-Mar-2004 11:12:23   

Good work, couple of issues though...

  • Oracle Stored Procs I still have a problem with the stored proc i mentioned before - see below for url - the proc definition is now being generated with a System.Decimal parameter. I'm not sure if there will be a way around this, as oracle does not allow you to define the size of the parameter, oracle works it out depending on how it's used in the sproc.
  • OnSaveEntity of DataAccessAdapter At what point is this called? I'm overriding this to set some values like amended date before saving, but the values don't seem to be sticking, when i refetch the data the values haven't changed. This worked as expected before when i had overriden SaveEntity and called my own OnBeforeSave and OnAfterSave methods.

stored proc thread

p.s. there seems to be a problem with the list tag if you have other tags embedded in a list item.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 10-Mar-2004 11:29:38   

netclectic wrote:

Good work, couple of issues though...

  • Oracle Stored Procs I still have a problem with the stored proc i mentioned before - see below for url - the proc definition is now being generated with a System.Decimal parameter. I'm not sure if there will be a way around this, as oracle does not allow you to define the size of the parameter, oracle works it out depending on how it's used in the sproc.
  • OnSaveEntity of DataAccessAdapter At what point is this called? I'm overriding this to set some values like amended date before saving, but the values don't seem to be sticking, when i refetch the data the values haven't changed. This worked as expected before when i had overriden SaveEntity and called my own OnBeforeSave and OnAfterSave methods.

Right before the actual query is executed, which is IMHO the right spot to call it.


// flag we're going to save an entity
OnSaveEntity(saveQuery, entityToSave);

// execute the query
saveSucceeded = (ExecuteActionQuery(saveQuery) > 0);

// flag save action was completed
OnSaveEntityComplete(saveQuery, entityToSave);

The save method is still virtual, so you can still override those if you want. The problem with overriding just the SaveEntity() method is that it might first decide to save dependent entities instead of the entity passed to the SaveEntity() method. So OnBeforeSave() called from a derived SaveEntity() right before you call base.SaveEntity() is not that precise. OnSaveEntity() is.

p.s. there seems to be a problem with the list tag if you have other tags embedded in a list item.

Could you please elaborate on this a bit, because I'm a little confused what you mean with list tag and in what context? simple_smile

Frans Bouma | Lead developer LLBLGen Pro
netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 10-Mar-2004 11:43:17   

Otis wrote:

OnSaveEntity of DataAccessAdapter At what point is this called? I'm overriding this to set some values like amended date before saving, but the values don't seem to be sticking, when i refetch the data the values haven't changed. This worked as expected before when i had overriden SaveEntity and called my own OnBeforeSave and OnAfterSave methods.

Right before the actual query is executed, which is IMHO the right spot to call it.


// flag we're going to save an entity
OnSaveEntity(saveQuery, entityToSave);

// execute the query
saveSucceeded = (ExecuteActionQuery(saveQuery) > 0);

// flag save action was completed
OnSaveEntityComplete(saveQuery, entityToSave);

Strange, i can see it going through my OnSaveEntity method and setting the values but they aren't saved to the database.

The save method is still virtual, so you can still override those if you want. The problem with overriding just the SaveEntity() method is that it might first decide to save dependent entities instead of the entity passed to the SaveEntity() method. So OnBeforeSave() called from a derived SaveEntity() right before you call base.SaveEntity() is not that precise. OnSaveEntity() is.

I've reverted to this for the time being, i'll be sure to watch out for strange behaviour.

p.s. there seems to be a problem with the list tag if you have other tags embedded in a list item.

Could you please elaborate on this a bit, because I'm a little confused what you mean with list tag and in what context? simple_smile

in the context of the forums, try this:

[ list][*]some text [urldescription="a desription"]http://www.a-url.com[/url] some more text[/*][/list ]

remove the spaces from the [ list] and [/list ] tags, as the code tag doesn't seem to like them wink

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 10-Mar-2004 12:30:58   

netclectic wrote:

Otis wrote:

OnSaveEntity of DataAccessAdapter At what point is this called? I'm overriding this to set some values like amended date before saving, but the values don't seem to be sticking, when i refetch the data the values haven't changed. This worked as expected before when i had overriden SaveEntity and called my own OnBeforeSave and OnAfterSave methods.

Right before the actual query is executed, which is IMHO the right spot to call it.


// flag we're going to save an entity
OnSaveEntity(saveQuery, entityToSave);

// execute the query
saveSucceeded = (ExecuteActionQuery(saveQuery) > 0);

// flag save action was completed
OnSaveEntityComplete(saveQuery, entityToSave);

Strange, i can see it going through my OnSaveEntity method and setting the values but they aren't saved to the database.

Setting values in fields in the OnSaveEntity() method is too late, as the saveQuery contains the query already. You can only change parameter values in there.

p.s. there seems to be a problem with the list tag if you have other tags embedded in a list item.

Could you please elaborate on this a bit, because I'm a little confused what you mean with list tag and in what context? simple_smile

in the context of the forums, try this:

[ list][*]some text [urldescription="a desription"]http://www.a-url.com[/url] some more text[/*][/list ]

remove the spaces from the [ list] and [/list ] tags, as the code tag doesn't seem to like them wink

Hmm. simple_smile The LR(1) parser which parses the tags is indeed somewhat flawed in some areas. I wrote an LR(1) parser generator which generates the parser tables for this UBB syntax, and there are some shift-reduce conflicts in the grammar. (UBB isn't an LR(1) grammar). I've to rewrite the parser to use LL(1) techniques instead (the template parser uses this technique): 1 handler routine per grammar rule (non-ternimal). This can then handle better conflicts with what to do with the seen tokens: accept it as a known non-terminal or scan further so another non-terminal will match the stream of tokens. I've no idea when I'll have time for this though. I'll check if I can remove the shift-reduce conflict in the grammar.

Frans Bouma | Lead developer LLBLGen Pro
netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 10-Mar-2004 12:51:51   

Otis wrote:

Setting values in fields in the OnSaveEntity() method is too late, as the saveQuery contains the query already. You can only change parameter values in there.

Of course, that's why it has a paremeter with the query. Doh! flushed

netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 10-Mar-2004 14:27:01   

Does the query at that point only contain fields & parameters for fields that have changed?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 10-Mar-2004 14:42:16   

netclectic wrote:

Does the query at that point only contain fields & parameters for fields that have changed?

Yes it's the query which will be executed on the database. So if you want to change a field and then make it end up in the query, you should override SaveEntity() and alter the fields there, then call base.SaveEntity() which will process the entity as planned simple_smile

Frans Bouma | Lead developer LLBLGen Pro
netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 10-Mar-2004 14:54:30   

As i suspected, that's what i've been doing anyway, so that's cool.

Cheers.

wojo
User
Posts: 69
Joined: 10-Mar-2004
# Posted on: 10-Mar-2004 18:13:10   

Ah, I ran into some similar issues when trying to automatically set some columns when entities are saved (UpdateBy, UpdateTime, etc).

I've been playing around with ways to do this automatically, and the way I'm thinking now is to dynamically check for the fields named "UpdateBy", "UpdateTime" and set the IEntityField2 values in my own DataAccessAdapter during save/updates/etc.

The place I initially though of doing it was in SaveEntity. However, of the four SaveEntity overloads, only two are virtual (marked with *).

bool SaveEntity(IEntity2) bool SaveEntity(IEntity2, bool) * bool SaveEntity(IEntity2, bool, IPredicateExpression) * bool SaveEntity(IEntity2, bool, IPredicateExpression, bool)

So I tried overriding the fourth one, thinking that all the rest of them eventually called that one with default params, but it looks like I have to override both of the virtual ones for some reason (which I did, and it catches all four overloads with my code now).

What is the recommend way of hooking into the save process? This could also apply to SaveEntityCollection and many other methods, too.

Maybe a OnBeforeSaveEntity() virtual method would be nice, which would happen before the IActionQuery was built?

Or maybe I'm going about this all wrong? simple_smile

netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 11-Mar-2004 10:17:31   

wojo wrote:

The place I initially though of doing it was in SaveEntity. However, of the four SaveEntity overloads, only two are virtual (marked with *).

bool SaveEntity(IEntity2) bool SaveEntity(IEntity2, bool) * bool SaveEntity(IEntity2, bool, IPredicateExpression) * bool SaveEntity(IEntity2, bool, IPredicateExpression, bool)

So I tried overriding the fourth one, thinking that all the rest of them eventually called that one with default params, but it looks like I have to override both of the virtual ones for some reason (which I did, and it catches all four overloads with my code now).

Interesting, i've only overriden the fourth one and I've not encountered a problem yet. But looking at the source for DataAccessAdapterBase, it appears they do all call the fourth method with default params.

wojo wrote:

Maybe a OnBeforeSaveEntity() virtual method would be nice, which would happen before the IActionQuery was built?

I knocked up a basic interface which any overriden entities that need to provide OnBeforeSave type events implement. Then in my OnBeforeSave of my DataAccessAdapter i check to see if they implement this interface and if so then i call their OnBeforeSave methods.

wojo
User
Posts: 69
Joined: 10-Mar-2004
# Posted on: 11-Mar-2004 14:23:25   

netclectic wrote:

Interesting, i've only overriden the fourth one and I've not encountered a problem yet. But looking at the source for DataAccessAdapterBase, it appears they do all call the fourth method with default params.

Yep, you're right. I must have been on something when I was doing my testing.

I also didn't realize the source was available for the ORM support classes and the DQEs. Cool, this helps a lot! Thanks Frans for providing the the source! smile

I guess it is still odd that only two of them are virtual. Should probably be all of them, or just the fourth one (the latter would be a fine I'm sure).

netclectic wrote:

I knocked up a basic interface which any overriden entities that need to provide OnBeforeSave type events implement. Then in my OnBeforeSave of my DataAccessAdapter i check to see if they implement this interface and if so then i call their OnBeforeSave methods.

That sounds like a good idea. I wanted to do it without modifying the generated entities, so I just have it checking the field names at runtime, which I'm sure is slower... but a little easier.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 11-Mar-2004 14:38:23   

There are 2 virtual and not one, because the 4th was added in 1.0.2003.3 and the other was already virtual.

I first made the 3rd non-virtual again, but this might break code so I kept it virtual simple_smile

You can just override the 4th (the one all the other methods are calling).

Frans Bouma | Lead developer LLBLGen Pro
OddurMag avatar
OddurMag
User
Posts: 17
Joined: 21-Oct-2003
# Posted on: 11-Mar-2004 15:05:23   

I've ran into some major problems with oracle stored procs and parameters, for instance the decimal type, I've had to change it's size everywhere from 0 to 22. String params were not working either. I think the oracle templates need some work, maybe I should contribute wink

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 11-Mar-2004 16:28:33   

OddurMag wrote:

I've ran into some major problems with oracle stored procs and parameters, for instance the decimal type, I've had to change it's size everywhere from 0 to 22. String params were not working either. I think the oracle templates need some work, maybe I should contribute wink

Is this related to the NUMBER type not having a length specified?

I check if the type is a NUMBER, then I check if the precision is 0. If so, I set it to 38.

So I'm a bit lost where the 0 pops up, as it should use the precision of 38.

If you have more info for me on this, please let me know simple_smile

Frans Bouma | Lead developer LLBLGen Pro