Skip to content
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

querydsl-collection doesn't support Joda Time #128

Closed
Vladislav-Hloboshin opened this issue Apr 16, 2012 · 14 comments
Closed

querydsl-collection doesn't support Joda Time #128

Vladislav-Hloboshin opened this issue Apr 16, 2012 · 14 comments

Comments

@Vladislav-Hloboshin
Copy link

@Vladislav-Hloboshin Vladislav-Hloboshin commented Apr 16, 2012

Hello,
please add support Joda Time in com.mysema.query.collections.ColQueryFunctions. At now I see only support for java.util.Date.
I manualy add this code in local source for my task:


public static int getMonth(DateTime dt){
        return dt.getMonthOfYear();
    }
public static int getYear(DateTime dt){
        return dt.getYear();
    }

And I would glad to see this code in next version

Sorry for my English.

@timowest
Copy link
Member

@timowest timowest commented Apr 19, 2012

I don't want to add a Joda Time dependency to Querydsl Collections, but you can easily support JodaTime in your queries by extending ColQueryTemplates and redefining the operations you need

add(Ops.DateTimeOps.MONTH, "{0}.getMonthOfYear()");
add(Ops.DateTimeOps.YEAR, "{0}.getYear()");

Let me know if that works

@timowest
Copy link
Member

@timowest timowest commented Apr 24, 2012

Did you have the chance to try this out?

@Vladislav-Hloboshin
Copy link
Author

@Vladislav-Hloboshin Vladislav-Hloboshin commented Apr 24, 2012

Sorry, there was no time to try this out.

ColQueryTemplates is a final class. How I can extend it?
And if I extend ColQueryTemplates class, how I can link it to existing querydsl package library?

At first I tried:

ColQueryTemplates.DEFAULT.add(Ops.DateTimeOps.MONTH, "{0}.getMonthOfYear()");

but 'add' method is private or protected, and I can't call it when my application initialized

Please, explain me what am I doing wrong.

Sorry for my English.

@timowest
Copy link
Member

@timowest timowest commented Apr 27, 2012

Now it should work. Here is an example

    ColQueryTemplates templates = new ColQueryTemplates() {{
        add(Ops.DateTimeOps.MONTH, "{0}.getMonthOfYear()");
        add(Ops.DateTimeOps.YEAR, "{0}.getYear()");
    }};
    ColQuery query = new ColQueryImpl(templates);
@Vladislav-Hloboshin
Copy link
Author

@Vladislav-Hloboshin Vladislav-Hloboshin commented Apr 27, 2012

Thanks, but I review code and saw this:

public ColQueryImpl(ColQueryTemplates templates) {
        this(new DefaultQueryEngine(new DefaultEvaluatorFactory(ColQueryTemplates.DEFAULT)));
    }

I don't see where is used 'templates' param. I think must be like this:

        this(new DefaultQueryEngine(new DefaultEvaluatorFactory(templates)));

Correct me if I wrong

Thanks, for your help. And sorry for my English again:)

@timowest
Copy link
Member

@timowest timowest commented Apr 27, 2012

Yes, you are right. And no need to apologize for your English. It's good enough ;)

timowest added a commit that referenced this issue Apr 27, 2012
@timowest
Copy link
Member

@timowest timowest commented Apr 27, 2012

Fixed

@Vladislav-Hloboshin
Copy link
Author

@Vladislav-Hloboshin Vladislav-Hloboshin commented Apr 27, 2012

Thanks.
I'll try to check it out tomorrow

timowest added a commit that referenced this issue Apr 27, 2012
@timowest
Copy link
Member

@timowest timowest commented Apr 27, 2012

I just implemented JodaTime support for you. Use it like this

ColQuery query = new ColQueryImpl(JodaTimeTemplates.DEFAULT);

This implementation doesn't have a compile time dependency on Joda Time

@Vladislav-Hloboshin
Copy link
Author

@Vladislav-Hloboshin Vladislav-Hloboshin commented Apr 28, 2012

Sorry for off-topic, but when I can find last build with this commit?
Or I need to complile querydsl myself?

@timowest
Copy link
Member

@timowest timowest commented Apr 28, 2012

I just deployed the latest version 2.5.0.BUILD-SNAPSHOT to our snapshot repository https://source.mysema.com/maven2/snapshots

@Vladislav-Hloboshin
Copy link
Author

@Vladislav-Hloboshin Vladislav-Hloboshin commented May 1, 2012

It works!
Thanks for the fix and great library

@timowest
Copy link
Member

@timowest timowest commented May 1, 2012

Good to hear. Thanks!

@timowest
Copy link
Member

@timowest timowest commented May 25, 2012

Released in 2.6.0

@timowest timowest closed this May 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants