-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Will you consider taking the Dao/Model pattern of JDBI and SpringData? #19
Comments
It would be a good pattern to reduce the LOC for myql coding and also implemented efficiently. |
Yeah, I like the idea of the bind interface from jdbi. I'll have to ponder how it will fit in with the reactive model. Using dynamic proxies with an interface would be nicer than using the mapped class. |
👯 public class SomethingMapper implements ResultSetMapper<Something>
{
public Something map(int index, ResultSet r, StatementContext ctx) throws SQLException
{
return new Something(r.getInt("id"), r.getString("name"));
}
}
...
@SqlQuery("select id, name from something where id = :id")
@Mapper(SomethingMapper.class) // <<< Fast(better than Reflection) and ORM
Something findById(@Bind("id") int id); AND also http://jdbi.org/sql_object_api_dml/ public static interface Update
{
...
@SqlUpdate("update something set name = :name where id = :id")
int update(@BindBean Something s); // <<< @BindBean
} |
Good work!! Even cleaner code. I too was considering AutoMap Example for the @Mapper(SomethingMapper.class) Suggestion. How would that also impact the update/insert example? |
The mapper functionality to avoid reflection overhead already exists (though not with an annotation): String name = db()
.select("select name from person order by name")
.get(new Func1<ResultSet, String>() {
@Override
public String call(ResultSet rs) {
try {
return rs.getString(1);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}).first().toBlocking().single();
} Using java 8 and rxjava-extras String name = db()
.select("select name from person order by name")
.get(Checked.f1(rs -> rs.getString(1))
.first().toBlocking().single(); |
Updated docs about custom mapping: I would like to have |
rxjava-jdbc 0.5.9 will use a new This will enable usage like: Observable<Person> persons = db()
.select("select name, score from person order by name")
.get(rs -> new Person(rs.getString(1), rs.getInt(2))); |
The above progress looks good: Actually, I am new to rxjava, and like to clarify with another feature, you recommended not to use ...
Observable<Person> persons = db()
.select("select name, score from person order by name")
.get(rs -> new Person(rs.getString(1), rs.getInt(2)))
.first().toBlocking().single();
// vs
// I knows this can be run async and automatically in multithread as you
Observable<Person> persons = db()
.select("select name, score from person order by name")
.get(rs -> new Person(rs.getString(1), rs.getInt(2))); IF I have JaxRS, because of existing code base on client side: @Path("/persons")
public class PersonController {
|
|
Accidentally, closed. @path("/persons")
}
|
try { return new Person(rs.get(1), rs.get(2));} How to hide it with the this feature?? |
|
Subscriber which I can show you if you want. |
Fixed in 0.5.9 when it comes out as mentioned above. The try catch will be gone.
That's for something else. |
Please help here? @Path("/persons")
public class PersonController {
@GET
@Produces({"application/json", "application/xml"})
public List<Person> get() {
List<Person> persons= ...
// How do I use rxjava + jdbc ASYNC here???
...
return persons.toArray();
}
} You are kind! I been to Aussie(Sydney, Melbourne) many times. Missed the Harry beef pie in Sydney. Aussies are very well known for being kind. :D |
By the way, you could also use Retrofit's integration with RxJava for an endpoint like this http://square.github.io/retrofit/ |
is retrofit for server side? I had the impression it is for client side code only. Btw, This Beef Pie |
|
yep retrofit for server side, the signature of your server side method like you have can return |
Thanks, how about insert? @Path("/persons")
public class PersonController {
@POST
@Produces({"application/json", "application/xml"})
public String add(Person person) {
String primaryId="none";
// rx-java-jdbc?
return primaryId
}``` |
Ah so you are in Malaysia right, good stuff. You'd have a heart attack here, forecast is for -6 degrees tonight. |
Yes. Malaysia. Was working in Singapore. If you visit penang, let me know. I show you how to gain plenty of winter weight. With some porkchop + friedrice: forecast is for -6 degrees tonight. << Where? I experience 3-4degreess with windy Sydney. |
|
Canberra, which is 550m higher than Sydney |
I'd be delighted to meet you there, I love Malaysian food (all of its many varieties). |
Canberra? Never been there. I drove from Sydney to Melbourne(2007 Jun/july) coastline. Beautiful country. |
0.5.9 is released to Maven Central now and includes |
Also Consider Backing me up on this suggestion? It might reduce your work also: |
Such ideas are inspired from reading this URL from project lombok: |
This is new?? I was about the suggest this to you but does not want to swap the issue, : <dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java6</artifactId>
<version>2.3.2</version>
</dependency>
and you can use a Hikari database connection pool like so:
```java
Database db = Database.builder().url(url).pool(minPoolSize,maxPoolSize).build();
// Once finished with a Database that has used a connection pool you should call
db.close(); This will close the connection pool and release its resources. |
By the way, you could also use Retrofit's integration with RxJava for an endpoint like this http://square.github.io/retrofit/ <<< Trying it out today. |
Connection pools are not new no. On Thu, 4 Jun 2015 13:16 Matthew Ong notifications@github.com wrote:
|
Yes. I saw ConnectionPool. But I think I remember I did not see Hikari. Anyway, you picked the right choices. CLAPx3. |
Hi, I tried out retrofit. It is merely an JaxRS Client side JAVA api which is used for calling REST Service. |
I found out this is also not hard to use, a bit more raw than JaxRS, but workable: |
public class MyJsonTransformer implements ResponseTransformer { get("/hello", "application/json", (request, response) -> { :D x3. |
Will you please also consider taking these code pattern from JDBI or SpringData?
http://jdbi.org/
However have OPTIONS to handle the commonly used pattern in Reactive or Sync model??
The text was updated successfully, but these errors were encountered: