Allow to use prefixless getters or setters to map DB data to Java POJOs

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

Allow to use prefixless getters or setters to map DB data to Java POJOs

Alexander Vasiljev
Hello

I'd like to propose a new way to map DB data from and into Java POJOs -- without get- or set- prefixes

e.g. one should be able to use POJO

class A {
  private Long id;

  public Long id() {
    return id;
  }

  public A id(Long id) {
     this.id = id;
     return this;
  }
}

to map data from ResultSet to POJO or from POJO into velocity template. What do you think about this?
I've created a pull request for the feature:
https://github.com/mybatis/mybatis-3/pull/722

--
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
|  
Report Content as Inappropriate

Re: Allow to use prefixless getters or setters to map DB data to Java POJOs

Guy Rouillier-2
Groovy can do this with MyBatis.  Also, you may want to look at Project Lombok (https://projectlombok.org/), which can transparently generate getters and setters.  I haven't used Lombok together with MyBatis to verify that it works.
 
--
Guy Rouillier
 
 
 
------ Original Message ------
From: "Alexander Vasiljev" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 7/1/2016 4:06:52 AM
Subject: Allow to use prefixless getters or setters to map DB data to Java POJOs
 
Hello

I'd like to propose a new way to map DB data from and into Java POJOs -- without get- or set- prefixes

e.g. one should be able to use POJO

class A {
  private Long id;

  public Long id() {
    return id;
  }

  public A id(Long id) {
     this.id = id;
     return this;
  }
}

to map data from ResultSet to POJO or from POJO into velocity template. What do you think about this?
I've created a pull request for the feature:
https://github.com/mybatis/mybatis-3/pull/722

--
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
|  
Report Content as Inappropriate

Re: Allow to use prefixless getters or setters to map DB data to Java POJOs

Alexander Vasiljev
Sure, there are ways to overcome these limitations. The patch is about removing limitations.

MyBatis itself is rather flexible framework. E.g. instead of using external datasource, sql connection might be provided manually when creating MyBatis' SqlSession, so integration with legacy code is possible. Prefix-less way of writing getters and setters does not concern core functionality, just codestyle, yet it is a nice option to have. Take for example googler's AutoValue library (it works together with MyBatis) - there are two equally supported options: either to use get- or set- prefixed getters and setters or prefix-less ones. At the moment in MyBatis one could use either get- and set- getters and setters or just class fields to bind data from POJO into prepared statement and bind data back from ResultSet into POJO. The patch is adding the third option.

My personal goal was to integrate AutoValue-generated prefix-less code with MyBatis, to make it possible to inject prefix-less POJO's data into prepared statement. New version of the patch is available here:
https://github.com/mybatis/mybatis-3/pull/730

суббота, 2 июля 2016 г., 11:09:52 UTC+6 пользователь Guy Rouillier написал:
Groovy can do this with MyBatis.  Also, you may want to look at Project Lombok (<a href="https://projectlombok.org/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fprojectlombok.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHlq-SEVLRZq9F9xMLW-6ijUSWo0w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fprojectlombok.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHlq-SEVLRZq9F9xMLW-6ijUSWo0w&#39;;return true;">https://projectlombok.org/), which can transparently generate getters and setters.  I haven't used Lombok together with MyBatis to verify that it works.
 
--
Guy Rouillier
 
 
 
------ Original Message ------
From: "Alexander Vasiljev" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="yjzje0PTCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">a.a.va...@...>
To: "mybatis-user" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="yjzje0PTCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybati...@...>
Sent: 7/1/2016 4:06:52 AM
Subject: Allow to use prefixless getters or setters to map DB data to Java POJOs
 
Hello

I'd like to propose a new way to map DB data from and into Java POJOs -- without get- or set- prefixes

e.g. one should be able to use POJO

class A {
  private Long id;

  public Long id() {
    return id;
  }

  public A id(Long id) {
     <a href="http://this.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fthis.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFGLoPFD_d9JTTNqfqZ6geUV4-xjw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fthis.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFGLoPFD_d9JTTNqfqZ6geUV4-xjw&#39;;return true;">this.id = id;
     return this;
  }
}

to map data from ResultSet to POJO or from POJO into velocity template. What do you think about this?
I've created a pull request for the feature:
<a href="https://github.com/mybatis/mybatis-3/pull/722" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fpull%2F722\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEGsOlpwk2v059-CCvO8AhwGf2OJA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fpull%2F722\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEGsOlpwk2v059-CCvO8AhwGf2OJA&#39;;return true;">https://github.com/mybatis/mybatis-3/pull/722

--
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="yjzje0PTCgAJ" 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.
Loading...