Quantcast

Help: I wish to contribute code

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

Help: I wish to contribute code

Antonio Sánchez
Hi all.

I wish to contribute code but I have no idea where to start, I need some
guidance.

To begin with I'd like to do some proof of concept in issue #500
regarding parameters in mappings.

http://code.google.com/p/mybatis/issues/detail?id=500

Could you help me, please?

Thank you!

Antonio.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Jeff Butler
I'm not sure what your question is exactly, but this is the general process...

1. Check out the code from SVN
2. Create your proof of concept
3. Attach a patch to the issue for everyone to review

That's about it.  Let us know if you have a more specific question.

Jeff Butler



On Mon, Feb 20, 2012 at 1:50 PM, Antonio Sánchez
<[hidden email]> wrote:

> Hi all.
>
> I wish to contribute code but I have no idea where to start, I need some
> guidance.
>
> To begin with I'd like to do some proof of concept in issue #500 regarding
> parameters in mappings.
>
> http://code.google.com/p/mybatis/issues/detail?id=500
>
> Could you help me, please?
>
> Thank you!
>
> Antonio.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Eduardo Macarron
I am afraid there is not any doc but feel free to ask specific questions.

Regarding issue #500. I would better discuss it with the rest of the
users/devs because:
- it will be hard to implement
- maybe it will not be accepted

Now we have this:

public interface SomeMapper {
    public SomeClass getWith2Params(@Param("p1") int p1, @Param("p2")
String p2);
}

<select id="getWith2Params" resultType="SomeClass">
        SELECT *
        FROM SomeTable
        WHERE p1 = #{p1} AND p2= #{p2}
</select>

And the purpose is to have this:

public interface SomeMapper {
    public SomeClass getWith2Params(int arg1, String arg2);
}

<select id="getWith2Params" parameters="int p1; string p2"
resultType="SomeClass">
        SELECT *
        FROM SomeTable
        WHERE p1 = #{p1} AND p2= #{p2}
</select>

Not a big gain. Just moved param names from one place o another.

But there are two big problems :)
1st. There is no way to get param names by introspection in java. So
you can just work by possitions, and that already works now. There is
no need to specify the type, MyBatis will work fine without that.

Parameters are automapped to param1, param2, param3... So this works right now.

public interface SomeMapper {
    public SomeClass getWith2Params(int arg1, String arg2);
}

<select id="getWith2Params" resultType="SomeClass">
        SELECT *
        FROM SomeTable
        WHERE p1 = #{param1} AND p2= #{param2}
</select>

The second big problem is that stements just get ONE parameter. When
using mappers an internal hashmap is automatically created an passed.

Something like:
Map<String, Object> map = new HashMap();
map.put(param1, value1)
map.put(param2, value2)
session.selectOne(statement, map)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Antonio Sánchez
In reply to this post by Jeff Butler
Thank you Jeff.

I was meaning what classes should I consider, which tests to pass...
anyway if I go on I'll ask more specific questions.

Antonio.

El 20/02/12 20:01, Jeff Butler escribió:
> I'm not sure what your question is exactly, but this is the general process...
>
> 1. Check out the code from SVN
> 2. Create your proof of concept
> 3. Attach a patch to the issue for everyone to review
>
> That's about it.  Let us know if you have a more specific question.
>
> Jeff Butler
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Antonio Sánchez
In reply to this post by Eduardo Macarron
This does the trick in my case:

"So you can just work by possitions, and that already works now. There is
no need to specify the type, MyBatis will work fine without that.

Parameters are automapped to param1, param2, param3... So this works right now."

I didn't know this so I guess my problem was actually no problem.

I was not concerned about the names of the parameters but about the signature of the persistence interface, which I need to keep independent from the underlying persistence technology. I'm sorry I didn't understand it when you already gave me the answer:

http://code.google.com/p/mybatis/issues/detail?id=500#c8

This means I'll then be asking about #509.

Thank you once again!


El 20/02/12 20:06, Eduardo Macarron escribió:

> I am afraid there is not any doc but feel free to ask specific questions.
>
> Regarding issue #500. I would better discuss it with the rest of the
> users/devs because:
> - it will be hard to implement
> - maybe it will not be accepted
>
> Now we have this:
>
> public interface SomeMapper {
>      public SomeClass getWith2Params(@Param("p1") int p1, @Param("p2")
> String p2);
> }
>
> <select id="getWith2Params" resultType="SomeClass">
>          SELECT *
>          FROM SomeTable
>          WHERE p1 = #{p1} AND p2= #{p2}
> </select>
>
> And the purpose is to have this:
>
> public interface SomeMapper {
>      public SomeClass getWith2Params(int arg1, String arg2);
> }
>
> <select id="getWith2Params" parameters="int p1; string p2"
> resultType="SomeClass">
>          SELECT *
>          FROM SomeTable
>          WHERE p1 = #{p1} AND p2= #{p2}
> </select>
>
> Not a big gain. Just moved param names from one place o another.
>
> But there are two big problems :)
> 1st. There is no way to get param names by introspection in java. So
> you can just work by possitions, and that already works now. There is
> no need to specify the type, MyBatis will work fine without that.
>
> Parameters are automapped to param1, param2, param3... So this works right now.
>
> public interface SomeMapper {
>      public SomeClass getWith2Params(int arg1, String arg2);
> }
>
> <select id="getWith2Params" resultType="SomeClass">
>          SELECT *
>          FROM SomeTable
>          WHERE p1 = #{param1} AND p2= #{param2}
> </select>
>
> The second big problem is that stements just get ONE parameter. When
> using mappers an internal hashmap is automatically created an passed.
>
> Something like:
> Map<String, Object>  map = new HashMap();
> map.put(param1, value1)
> map.put(param2, value2)
> session.selectOne(statement, map)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Antonio Sánchez
In reply to this post by Jeff Butler
Now that #500 issue is done I wish to contribute #509:

Provide a way to reference the parent instances in parent-child-parent
relationships inside the result map

http://code.google.com/p/mybatis/issues/detail?id=509

First, please let me know if you believe this one is feasible and
acceptable. If it is and if you agree please let me know which packages,
classes and test should I start reviewing and coding in order to begin
with some POC.

Antonio.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Eduardo Macarron
This one is possible, and It would be great to get it fixed!! :)

#509 is the same as #8: detect circular references and resolve them properly.

That already works for nested selects but not for nested result maps.

As an starting point have a look at PermissionsTest, it is a good
sample of how joined results are processed. All the interesting stuff
happens inside NestedResultSetHandler. Pass throught it with the
debugger and you will figure out how it works.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Antonio Sánchez
What do you think about the suggested approach?

It's just an easy suggestion, I'm interested in your opinion before
coding anything.

El lun 20 feb 2012 21:47:49 CET, Eduardo Macarron escribió:

> This one is possible, and It would be great to get it fixed!! :)
>
> #509 is the same as #8: detect circular references and resolve them properly.
>
> That already works for nested selects but not for nested result maps.
>
> As an starting point have a look at PermissionsTest, it is a good
> sample of how joined results are processed. All the interesting stuff
> happens inside NestedResultSetHandler. Pass throught it with the
> debugger and you will figure out how it works.



--
Antonio Sánchez.
------------------------------------------------------------------------
IMPORTANTE: Por favor, si reenvías este mensaje te ruego
encarecidamente
que respetes la privacidad de mi identidad eliminando mi dirección de
correo electrónico en tu reenvío así como mi nombre o cualquier otra
referencia a mi identidad. Así mismo te ruego que todos aquellos
mensajes que me quieras enviar como co-destinatario lo hagas con un
envío de copia oculta, es decir poniendo mi dirección en el campo CCO
del mensaje.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Eduardo Macarron
Just my personal opinion but using parent, grandparent... looks more
like a workaround than a solution. :(
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Eduardo Macarron
Just a hint. If during filling an object tree an instance is found
that is equal to an ancestor (equal means that it is defined in the
same resultmap, read from the same columns and obtained the same
values), then the ancestor should be used instead of creating a new
one.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Antonio Sánchez
In reply to this post by Eduardo Macarron
The notation

<parent property="parent" level="1">

is just a POC for illustrating the issue.

Indeed I wish to know what MyBatis users and developers think there
would be the best notation.

So, what notation or approach do you suggest?


El 20/02/12 22:05, Eduardo Macarron escribió:
> Just my personal opinion but using parent, grandparent... looks more
> like a workaround than a solution. :(

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Eduardo Macarron
I am -1 for an specific notation to refer ancestors (parent,
grandparent, grandgrandparent...)

Technically it is possible to solve the cycles with no DTD changes.

NestedResultSetHandler produces trees. If there is a repeated object
with a different parent a new instance is created.

suppose this table and data:
resource, user, action
resource1, user1, create
resource1, user1, read
resource2, user1, update
resource2, user1, delete

This will create 2 resources, 2 users and 4 actions

resource1 -> user1 (instance 1)-> (create, read)
resource2 -> user1 (instance 2)-> (update, delete)

All these objects are held in a map. Each instace has key composed by
its own information (values, columns) and its parent's id.

Note the problem, if a loop is detected, remember there are no foreing
keys in nested resultmaps.
resource -> user -> action -> user

which user? We have two instances of user1!

We may just allow referring to ancestors to solve this problem. Which
user1? the one you will find climbing upwards to the root.

So I suppose we could just keep the track of all he ancestors and
search that collection to resolve loops.

I am not sure if this will resolve all cases but it will resolve the
link to parent problem.

The only problem I see with this approach is performance. Right now,
the main problem with performance is key calculation so all this
should be done trying not to increase key calculations.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Eduardo Macarron
Antonio I could not resitst doing some code and results are promising.

Apply the patch I attached to 509 and run the PermissionsTest. You
will see there is a loop defined in result maps
(resource->user->permission->resource) and it seems to work!

The problem is that... I doubled the key calculations and than is
paying too much for this. But, if the tests go fine we may work in
optimizing it.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Antonio Sánchez
Fantastic! You've almost done it!

I have downloaded your patch and it is working.

Sadly I'm afraid I won't be able to work on this for the next couple of
days, luckily until tomorrow afternoon.

I'll try to:

1. Review/understand/enhance your code, if that is possible for me :)
2. Focus on performance.
3. Provide some testing with massive data for testing performance.

I'll be watching on this anyway.

Kind regards.

Antonio.

El sáb 25 feb 2012 19:32:03 CET, Eduardo Macarron escribió:
> Antonio I could not resitst doing some code and results are promising.
>
> Apply the patch I attached to 509 and run the PermissionsTest. You
> will see there is a loop defined in result maps
> (resource->user->permission->resource) and it seems to work!
>
> The problem is that... I doubled the key calculations and than is
> paying too much for this. But, if the tests go fine we may work in
> optimizing it.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Eduardo Macarron
Hi Antonio.

I changed the first version to avoid the extra calculation so no need
to worry about performance, it will be ok.

But I would like to know if this is what you were expecting :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Antonio Sánchez
I think it is but I'd like to take a closer look at it before giving a solid answer. I'll do some hard testing, you know :) Please give me some time, I hope to put my hands on it next wednesday, at most.

But it seems that you have done it, not almost but fully. I think this is a great feature that MyBatis users will wellcome.

Kind regards.

2012/2/27 Eduardo Macarron <[hidden email]>

But I would like to know if this is what you were expecting :)

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Help: I wish to contribute code

Eduardo Macarron
2012/2/27 Antonio Sánchez <[hidden email]>:
> I'll do some hard testing, you know :)

I know :)

You are doing a great work Antonio, keep it up!
Loading...