Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Propel event handler

propel
Discussion topic

Back to topic list

Propel event handler

Reply

Author Ron Rademaker <r dot rademaker at virtualbuilding dot nl>
Full name Ron Rademaker <r dot rademaker at virtualbuilding dot nl>
Date 2007-11-15 02:45:32 PST
Message Hi all,

Last week I told you about my idea to create a backup function in propel
based on sql triggers. I've been working on this a bit this week only to
find out sql triggers and procedures have some very annoying properties.
This would result in having to redefine all triggers whenever you change
your schema, and often no errors if you forget to do this (and I *know*
I would something forget it and I would be *very* surprised if the other
developers here wouldn't). I don't think this is a good idea so I've
come up with a different, much more flexible, database independent
solution. The only drawback I see is that performance would be better if
the backup functionality was implemented in sql.

The basic idea is that you can add event to tables and columns (and
databases, though I haven't though of a useful example for that yet). An
example schema (I think the first event is obvious, I'll explain the
second later) could be:

<table name='foo'>
    <column name='id' primaryKey='true' type='INTEGER'
autoIncrement='true'/>
    <column name='date' type='TIMESTAMP'/>
    <column name='bar' type='VARCHAR'/>
    <event occasion='onChange'> <!-- this is now defined on the table,
but could also be defined on the bar column -->
       <handler name='setcolumn'>
          <parameter name='column' value='date'/>
          <parameter name='value' type='phpfunction'>
             <function name='date'>
                 <parameter value='"now"'/>
             </function>
          </parameter>
       </handler>
    </event>
    <event occasion='onCreate'>
       <handler name='saver' function='registerSave'/>
    </event>
    <event occasion='onSave'>
       <handler name='saver' function='triggerSave'/>
    </event>
</table>
<table name='bar'>
    <column name='id' primaryKey='true' type='INTEGER'
autoIncrement='true'/>
    <column name='bar' type='VARCHAR'/>
    <event occasion='onCreate'>
       <handler name='saver' function='registerSave'/>
    </event>
    <event occasion='onSave'>
       <handler name='saver' function='triggerSave'/>
    </event>
</table>

Both table foo and bar have the saver handler for the onCreate and
onSave event. I intent to implement the event / handler structure using
the observer pattern, Propel objects being Observables and event
handlers being Observers. The saver handler (observer) would be an
example where the onCreate event registers the propel object with the
handler and the onSave triggers save on all registered objects. This way
you can save multiple objects with a single save() call, potentially
this means you could tweak things so that you would add or update many
objects in a single sql query.
I know many of the things this will make possible are already possible
by overriding functions in the propel classes. I do believe however,
that this mechanism would prove to be very flexible and easier to
maintain than implementations in propel classes (I still have a whole
lot of classes where I need to change save(PDO $con = nul) to
save(PropelPDO $con = null)).
I'll be starting to build this shortly, anyone having suggestions,
improvements, seeing upfront bottlenecks, just let me know and if I
think it makes sense I'll try to do something useful with it ;)

Ron

« Previous message in topic | 1 of 19 | Next message in topic »

Messages

Show all messages in topic

Propel event handler Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2007-11-15 02:45:32 PST
     Re: [propel-dev] Propel event handler hlellelid Hans Lellelid 2007-11-15 15:28:03 PST
         Re: [propel-dev] Propel event handler Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2007-11-16 00:28:50 PST
             Re: [propel-dev] Propel event handler Bert-Jan <info at bert-jan dot com> Bert-Jan <info at bert-jan dot com> 2007-11-16 02:34:57 PST
             Re: [propel-dev] Propel event handler hlellelid Hans Lellelid 2007-11-16 04:02:10 PST
                 Re: [propel-dev] Propel event handler Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2007-11-16 04:15:58 PST
                     Re: [propel-dev] Propel event handler hlellelid Hans Lellelid 2007-11-16 05:21:35 PST
                         Re: [propel-dev] Propel event handler Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2007-11-16 05:58:30 PST
                             Re: [propel-dev] Propel event handler =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> 2007-11-16 06:36:22 PST
                                 Re: [propel-dev] Propel event handler hlellelid Hans Lellelid 2007-11-16 06:44:57 PST
                                     Re: [propel-dev] Propel event handler =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> 2007-11-16 07:22:12 PST
     Re: [propel-dev] Propel event handler Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2008-05-05 07:16:33 PDT
         Re: [propel-dev] Propel event handler hlellelid Hans Lellelid 2008-05-05 09:53:00 PDT
             Re: [propel-dev] Propel event handler Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2008-05-06 00:15:41 PDT
                 Re: [propel-dev] Propel event handler hlellelid Hans Lellelid 2008-05-06 06:39:12 PDT
                     Re: [propel-dev] Propel event handler Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2008-05-06 06:47:08 PDT
                         Re: [propel-dev] Propel event handler hlellelid Hans Lellelid 2008-05-06 06:49:51 PDT
                             Re: [propel-dev] Propel event handler Ron Rademaker <r dot rademaker at virtualbuilding dot nl> Ron Rademaker <r dot rademaker at virtualbuilding dot nl> 2008-05-06 08:51:25 PDT
                                 Re: [propel-dev] Propel event handler hlellelid Hans Lellelid 2008-05-06 09:48:07 PDT
Messages per page: