Generating tables with relations

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Generating tables with relations

bumjvr
I'm trying write a plugin to support a specific use case we have that requires obtaining information from tables in the relations, but the plugins are called with is IntrospectedTable, which is the meta data about an individual table. 

Is there anyway to write a plugin or extension that generates the mappers for a table, but also uses information from the tables in the relations?

Given a strict naming  convention I could do with out the relational information, if it was possible for one instance of IntrospectedTable to obtain the instance for another?

Basically I need to generate something like:

   INSERT INTO table (id, remote_fk) VALUES (#{id}, SELECT id FROM remote WHERE <key> = #{value})

where the value of <key> is determined by introspecting the constraints on the remote table.

Otherwise I'd have to write a generator from scratch, which seems like a waste given the existing generator has done so much of the work already!

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

Re: Generating tables with relations

Jeff Butler
The generator does not obtain any relationship information from the database currently, and there's no good way to hook into the database introspection code.  I wonder if it would be easier to write your plugin where you just added a few properties on the <table> element for each table where you needed to generate something like this?

Other than that, this will be difficult with the current code in the generator.

Jeff Butler


On Mon, May 15, 2017 at 2:22 PM <[hidden email]> wrote:
I'm trying write a plugin to support a specific use case we have that requires obtaining information from tables in the relations, but the plugins are called with is IntrospectedTable, which is the meta data about an individual table. 

Is there anyway to write a plugin or extension that generates the mappers for a table, but also uses information from the tables in the relations?

Given a strict naming  convention I could do with out the relational information, if it was possible for one instance of IntrospectedTable to obtain the instance for another?

Basically I need to generate something like:

   INSERT INTO table (id, remote_fk) VALUES (#{id}, SELECT id FROM remote WHERE <key> = #{value})

where the value of <key> is determined by introspecting the constraints on the remote table.

Otherwise I'd have to write a generator from scratch, which seems like a waste given the existing generator has done so much of the work already!

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

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

Re: Generating tables with relations

Mark vanRossum
The generator does not obtain any relationship information from the database currently, and there's no good way to hook into the database introspection code. 

If it was even possible to obtain the underlying JDBC connection from a plugin that would provide the info needed using Connection.getMetadata(), but Context.getConnection() is private.
 
I wonder if it would be easier to write your plugin where you just added a few properties on the <table> element for each table where you needed to generate something like this?

I was afraid that was the case!  It seems a shame to need to repeat information that is available within the database, but that is probably my only option.

Thanks anyway!
mark

On Mon, May 15, 2017 at 2:22 PM <[hidden email]> wrote:
I'm trying write a plugin to support a specific use case we have that requires obtaining information from tables in the relations, but the plugins are called with is IntrospectedTable, which is the meta data about an individual table. 

Is there anyway to write a plugin or extension that generates the mappers for a table, but also uses information from the tables in the relations?

Given a strict naming  convention I could do with out the relational information, if it was possible for one instance of IntrospectedTable to obtain the instance for another?

Basically I need to generate something like:

   INSERT INTO table (id, remote_fk) VALUES (#{id}, SELECT id FROM remote WHERE <key> = #{value})

where the value of <key> is determined by introspecting the constraints on the remote table.

Otherwise I'd have to write a generator from scratch, which seems like a waste given the existing generator has done so much of the work already!

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

--
You received this message because you are subscribed to a topic in the Google Groups "mybatis-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mybatis-user/kzYUxQZT1P0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

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

Re: Generating tables with relations

Jeff Butler
I can make Context.getConnection() method public if it will help.

Jeff Butler


On Mon, May 15, 2017 at 6:22 PM Mark vanRossum <[hidden email]> wrote:
The generator does not obtain any relationship information from the database currently, and there's no good way to hook into the database introspection code. 

If it was even possible to obtain the underlying JDBC connection from a plugin that would provide the info needed using Connection.getMetadata(), but Context.getConnection() is private.
 
I wonder if it would be easier to write your plugin where you just added a few properties on the <table> element for each table where you needed to generate something like this?

I was afraid that was the case!  It seems a shame to need to repeat information that is available within the database, but that is probably my only option.

Thanks anyway!
mark

On Mon, May 15, 2017 at 2:22 PM <[hidden email]> wrote:
I'm trying write a plugin to support a specific use case we have that requires obtaining information from tables in the relations, but the plugins are called with is IntrospectedTable, which is the meta data about an individual table. 

Is there anyway to write a plugin or extension that generates the mappers for a table, but also uses information from the tables in the relations?

Given a strict naming  convention I could do with out the relational information, if it was possible for one instance of IntrospectedTable to obtain the instance for another?

Basically I need to generate something like:

   INSERT INTO table (id, remote_fk) VALUES (#{id}, SELECT id FROM remote WHERE <key> = #{value})

where the value of <key> is determined by introspecting the constraints on the remote table.

Otherwise I'd have to write a generator from scratch, which seems like a waste given the existing generator has done so much of the work already!

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

--
You received this message because you are subscribed to a topic in the Google Groups "mybatis-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mybatis-user/kzYUxQZT1P0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].

For more options, visit https://groups.google.com/d/optout.

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

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