Inserting a column value map

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

Inserting a column value map

Vishal Pandya
I have multiple tables(can grow in future) which I Insert into at a high rate. The tables have different number of columns with basic data types and along with it a timestamp and binary datatype.  Am trying to come up with a generic SQL statement using mybatis for the same. I store the values to be inserted into a key value structure in java using a map. However, am not successful in creating a dynamic SQL using an InsertProvider. I am new to mybatis. 

My SQLBuilder pseudocode is something like this.

(Map<String, Object> Params) { //One of the parameter to the builder is the map containing the column names and their corresponding values)

INSERT INTO(TABLE_NAME);
VALUES((column, {#value})

}

How do I a manage a generalized statement which can take care of mapping the column names to the value and also ensuring that the correct JDBC data type is being used? Please note that my number of columns do change across different tables, however the timestamp and binary columns do exist in all of them. Appreciate any help here. Thank you!!

--
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: Inserting a column value map

Iwao AVE!
Hi Vishal,

The pseudocode does not make much sense.
Consider providing MCVE instead : https://stackoverflow.com/help/mcve

It should look similar to the following test, I think.
https://github.com/mybatis/mybatis-3/blob/67a1c4ea5726c605d297398a8ab9a42ab7d4ebf1/src/test/java/org/apache/ibatis/submitted/mapper_type_parameter/BaseMapper.java#L64-L79

Regards,
Iwao
On Fri, Nov 9, 2018 at 1:26 AM Vishal Pandya <[hidden email]> wrote:

>
> I have multiple tables(can grow in future) which I Insert into at a high rate. The tables have different number of columns with basic data types and along with it a timestamp and binary datatype.  Am trying to come up with a generic SQL statement using mybatis for the same. I store the values to be inserted into a key value structure in java using a map. However, am not successful in creating a dynamic SQL using an InsertProvider. I am new to mybatis.
>
> My SQLBuilder pseudocode is something like this.
>
> (Map<String, Object> Params) { //One of the parameter to the builder is the map containing the column names and their corresponding values)
>
> INSERT INTO(TABLE_NAME);
> VALUES((column, {#value})
>
> }
>
> How do I a manage a generalized statement which can take care of mapping the column names to the value and also ensuring that the correct JDBC data type is being used? Please note that my number of columns do change across different tables, however the timestamp and binary columns do exist in all of them. Appreciate any help here. Thank you!!
>
> --
> 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: Inserting a column value map

Vishal Pandya
Thanks Iwao for the pointers! I was able to get around the problem(was not aware of the complete capabilities and did it through trial and error). However, in future will ensure following MCVE. Helpful hint.

Regards,
Vishal

On Wednesday, 14 November 2018 10:08:03 UTC+5:30, Iwao AVE! wrote:
Hi Vishal,

The pseudocode does not make much sense.
Consider providing MCVE instead : <a href="https://stackoverflow.com/help/mcve" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fhelp%2Fmcve\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFwcq7Sejdz7IFSTp_pnKLUbct2CQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fhelp%2Fmcve\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFwcq7Sejdz7IFSTp_pnKLUbct2CQ&#39;;return true;">https://stackoverflow.com/help/mcve

It should look similar to the following test, I think.
<a href="https://github.com/mybatis/mybatis-3/blob/67a1c4ea5726c605d297398a8ab9a42ab7d4ebf1/src/test/java/org/apache/ibatis/submitted/mapper_type_parameter/BaseMapper.java#L64-L79" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fblob%2F67a1c4ea5726c605d297398a8ab9a42ab7d4ebf1%2Fsrc%2Ftest%2Fjava%2Forg%2Fapache%2Fibatis%2Fsubmitted%2Fmapper_type_parameter%2FBaseMapper.java%23L64-L79\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEv0PZ7CPCY760TJz8c3vLArLLzOA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fblob%2F67a1c4ea5726c605d297398a8ab9a42ab7d4ebf1%2Fsrc%2Ftest%2Fjava%2Forg%2Fapache%2Fibatis%2Fsubmitted%2Fmapper_type_parameter%2FBaseMapper.java%23L64-L79\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEv0PZ7CPCY760TJz8c3vLArLLzOA&#39;;return true;">https://github.com/mybatis/mybatis-3/blob/67a1c4ea5726c605d297398a8ab9a42ab7d4ebf1/src/test/java/org/apache/ibatis/submitted/mapper_type_parameter/BaseMapper.java#L64-L79

Regards,
Iwao
On Fri, Nov 9, 2018 at 1:26 AM Vishal Pandya <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="RbT-8uhUAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">vishal...@...> wrote:

>
> I have multiple tables(can grow in future) which I Insert into at a high rate. The tables have different number of columns with basic data types and along with it a timestamp and binary datatype.  Am trying to come up with a generic SQL statement using mybatis for the same. I store the values to be inserted into a key value structure in java using a map. However, am not successful in creating a dynamic SQL using an InsertProvider. I am new to mybatis.
>
> My SQLBuilder pseudocode is something like this.
>
> (Map<String, Object> Params) { //One of the parameter to the builder is the map containing the column names and their corresponding values)
>
> INSERT INTO(TABLE_NAME);
> VALUES((column, {#value})
>
> }
>
> How do I a manage a generalized statement which can take care of mapping the column names to the value and also ensuring that the correct JDBC data type is being used? Please note that my number of columns do change across different tables, however the timestamp and binary columns do exist in all of them. Appreciate any help here. Thank you!!
>
> --
> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="RbT-8uhUAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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.