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

Java 9 TODO Automapped interface #22

Open
sorinpepelea opened this issue Mar 8, 2018 · 5 comments
Open

Java 9 TODO Automapped interface #22

sorinpepelea opened this issue Mar 8, 2018 · 5 comments

Comments

@sorinpepelea
Copy link

This is not an issue, but had no idea where to drop suggestions

Automapped interface with default methods currentluy does not work in Java 9

In order to work in Java 9, folowing changes should be made :

in org.davidmoten.rx.jdbc.Util#ProxyService

class add additional method

@SuppressWarnings("unchecked")
public T newInstance(ResultSet rs, Class cls) {
return (T) Proxy.newProxyInstance(cls.getClassLoader(), new Class[] { cls }, new ProxyInstance(cls, values()));
}

in org.davidmoten.rx.jdbc.Util class

alter original method that works with java8

static T autoMap(ResultSet rs, Class cls, ProxyService proxyService) {
return proxyService.newInstance();
}

to a modified version that works with java 9

static T autoMap(ResultSet rs, Class cls, ProxyService proxyService) {
return proxyService.newInstance(rs, cls);
}

Testing example that worked in Java 9

Database
.test()
.select(Person.class)
.get()
.map(Person::name)
.blockingForEach(System.out::println);

Not related to this example - another suggestion - make annotation work with sql field aliases
I would be happy to share more ideas for this great great api.

@davidmoten
Copy link
Owner

Great, thanks! I'll have a look soon.

@davidmoten
Copy link
Owner

I tried this and did not work for me but I would be happy to review a PR if you can make one. One of the current tests is below. Once your fix is in place uncomment the version check in the test and we'll see if it works!

    @Test
    public void testAutomappedObjectsWhenDefaultMethodInvoked() {
        // only run test if java 8
      if (System.getProperty("java.version").startsWith("1.8.")) {
            PersonWithDefaultMethod p = Database.test() //
                    .select("select name, score from person where name=?") //
                    .parameters("FRED") //
                    .autoMap(PersonWithDefaultMethod.class) //
                    .blockingFirst();
            assertEquals("fred", p.nameLower());
      }
    }

@sorinpepelea
Copy link
Author

Sorry for delay. I have no java 8 installed, and my project is set to java 9.04 - source/binary, compile ..
i will post a project that works on java9 with all the changes i made.

@sorinpepelea
Copy link
Author

Here is one of my prj . cropped to minimum for testing.
All you need to do is to adjust setting.ini file to fill your need
adjust query line in com.atlas.sql.Q.java interface
and run com.atlas.java9.DBTEST.java

I use postgresql database .. works like a charm ..but i tested also with mysql, mssql, oracle,
gridx.zip

@davidmoten
Copy link
Owner

Hi, if you can make a PR on this with unit test it would be very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants