Quantcast

Definition of Sequences in Glorp

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Definition of Sequences in Glorp

jtuchel
Hi,

as we've seen in another post of mine yesterday, Glorp can, in principle, use a Sequence for multiple tables. This is a MUST for horizontal inheritance (Horizontal Type Resolver).

Glorp's default way of defining a Descriptor System is based on the assumption that each sequence is associated to exactly one table. 
The point where things start to fall apart is when you try to use table creation methods in GlorpSession etc. These methods try to create the sequences for each table it creates. So if two tables are defined so that they share a sequence, Glorp tries to create the sequence twice, which fails, of course.

Knowing that, I can find my way around it by using DatabaseAccessor>>#createTable:ifError: , which does not create a Sequence at all.

But this requires me to know a sequence has been created. In my special case, the new table was added to an existing db, so I had to add the new table "by hand".

Over night, I thought a bit about this and wondered how I could define a DescriptorSystem in which I declare All tables and sequences and stuff so that the sequence will only be created once (when you first need it), and it seems there is something missing here.

There are some pieces for the puzzle in place, like defining a sequence with a developer-provided name, and as I showed in my other thread, a way to reuse it in another table, but there is no mechanism for creating this sequence the first time a table is created that references it. And there is no mechanism to find out if a sequence was already created during the creation of another table.

So what could work is a new/extended API to manage sequences not as attributes of tables, but of the DescriptorSystem itself. That way you could create sequences independently form the tables by using the good old asSet trick (self sequences asSet do: [:each| self createSequence: each]). As long as Tables hold the sequences and the Descriptor system always only looks at the current table to be created (or a list thereof) and wants to create each table's sequence without taking into account that this might be a sequence somebody else is already using, this won't work in a nice way.

So either I still haven't found the right way of describing my database/mappings, or Glorp needs some work in this area.
Both is very well possible.

Any ideas?

Joachim

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Definition of Sequences in Glorp

Alan Knight-2
I think my quick and dirty approach to this would be to just call createTables:, and if a sequence already exists it will call the error block, which is just "self halt" and proceed through. There might be cleaner approaches. But I would think the simplest thing would be, after getting all the sequences of the descriptor system, put them in a set before creating them.

On 15 October 2014 23:24, jtuchel <[hidden email]> wrote:
Hi,

as we've seen in another post of mine yesterday, Glorp can, in principle, use a Sequence for multiple tables. This is a MUST for horizontal inheritance (Horizontal Type Resolver).

Glorp's default way of defining a Descriptor System is based on the assumption that each sequence is associated to exactly one table. 
The point where things start to fall apart is when you try to use table creation methods in GlorpSession etc. These methods try to create the sequences for each table it creates. So if two tables are defined so that they share a sequence, Glorp tries to create the sequence twice, which fails, of course.

Knowing that, I can find my way around it by using DatabaseAccessor>>#createTable:ifError: , which does not create a Sequence at all.

But this requires me to know a sequence has been created. In my special case, the new table was added to an existing db, so I had to add the new table "by hand".

Over night, I thought a bit about this and wondered how I could define a DescriptorSystem in which I declare All tables and sequences and stuff so that the sequence will only be created once (when you first need it), and it seems there is something missing here.

There are some pieces for the puzzle in place, like defining a sequence with a developer-provided name, and as I showed in my other thread, a way to reuse it in another table, but there is no mechanism for creating this sequence the first time a table is created that references it. And there is no mechanism to find out if a sequence was already created during the creation of another table.

So what could work is a new/extended API to manage sequences not as attributes of tables, but of the DescriptorSystem itself. That way you could create sequences independently form the tables by using the good old asSet trick (self sequences asSet do: [:each| self createSequence: each]). As long as Tables hold the sequences and the Descriptor system always only looks at the current table to be created (or a list thereof) and wants to create each table's sequence without taking into account that this might be a sequence somebody else is already using, this won't work in a nice way.

So either I still haven't found the right way of describing my database/mappings, or Glorp needs some work in this area.
Both is very well possible.

Any ideas?

Joachim

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Definition of Sequences in Glorp

jtuchel
Alan,

I also had that trick in mind.
That only works for creating all tables. But if you already have a table that uses a sequence that a single, newly to add table also wants to reference, the asSet trick doesn't work, because the createTable: method asks the table for its sequence and ignores anything else.

The only thing that I think would work is to move sequences into their own Collection (like tables) in the DescriptorSystem. That is the only way to make sure a descriptor has a clear picture of what sequences are there and who (=which table) references which sequence.

That way, a DescriptorSystem wouldn't have to ask all tables for "their" sequence (see #allSequences). It could just look into its collection. So #allSequences would be removed and there would be #sequences which holds the list of all sequences. That way, #tableForXXX methods could look up existing sequences by #sequenceNamed' and you could create new ones by using "platform newSequenceNamed:". This could even be hidden in the descriptor by a lookup that lazily creates new sequences if none of that name exists yet. This would, however, pave the way for troubles in case you misspell a sequence name...


Joachim





Am Montag, 20. Oktober 2014 05:48:24 UTC+2 schrieb Alan Knight:
I think my quick and dirty approach to this would be to just call createTables:, and if a sequence already exists it will call the error block, which is just "self halt" and proceed through. There might be cleaner approaches. But I would think the simplest thing would be, after getting all the sequences of the descriptor system, put them in a set before creating them.

On 15 October 2014 23:24, jtuchel <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="zUuAbt28768J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">jtu...@...> wrote:
Hi,

as we've seen in another <a href="https://groups.google.com/d/msg/glorp-group/0yFMZeRBuYo/nOeLKLYuBWkJ" target="_blank" onmousedown="this.href='https://groups.google.com/d/msg/glorp-group/0yFMZeRBuYo/nOeLKLYuBWkJ';return true;" onclick="this.href='https://groups.google.com/d/msg/glorp-group/0yFMZeRBuYo/nOeLKLYuBWkJ';return true;">post of mine yesterday, Glorp can, in principle, use a Sequence for multiple tables. This is a MUST for horizontal inheritance (Horizontal Type Resolver).

Glorp's default way of defining a Descriptor System is based on the assumption that each sequence is associated to exactly one table. 
The point where things start to fall apart is when you try to use table creation methods in GlorpSession etc. These methods try to create the sequences for each table it creates. So if two tables are defined so that they share a sequence, Glorp tries to create the sequence twice, which fails, of course.

Knowing that, I can find my way around it by using DatabaseAccessor>>#createTable:ifError: , which does not create a Sequence at all.

But this requires me to know a sequence has been created. In my special case, the new table was added to an existing db, so I had to add the new table "by hand".

Over night, I thought a bit about this and wondered how I could define a DescriptorSystem in which I declare All tables and sequences and stuff so that the sequence will only be created once (when you first need it), and it seems there is something missing here.

There are some pieces for the puzzle in place, like defining a sequence with a developer-provided name, and as I showed in my other thread, a way to reuse it in another table, but there is no mechanism for creating this sequence the first time a table is created that references it. And there is no mechanism to find out if a sequence was already created during the creation of another table.

So what could work is a new/extended API to manage sequences not as attributes of tables, but of the DescriptorSystem itself. That way you could create sequences independently form the tables by using the good old asSet trick (self sequences asSet do: [:each| self createSequence: each]). As long as Tables hold the sequences and the Descriptor system always only looks at the current table to be created (or a list thereof) and wants to create each table's sequence without taking into account that this might be a sequence somebody else is already using, this won't work in a nice way.

So either I still haven't found the right way of describing my database/mappings, or Glorp needs some work in this area.
Both is very well possible.

Any ideas?

Joachim

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="zUuAbt28768J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">glorp-group...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="zUuAbt28768J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">glorp...@....
Visit this group at <a href="http://groups.google.com/group/glorp-group" target="_blank" onmousedown="this.href='http://groups.google.com/group/glorp-group';return true;" onclick="this.href='http://groups.google.com/group/glorp-group';return true;">http://groups.google.com/group/glorp-group.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/d/optout.
Loading...