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

way to db.update() in a single transaction taking parameterStream() input from another query result #31

Open
archieby opened this issue Oct 1, 2018 · 0 comments

Comments

@archieby
Copy link

archieby commented Oct 1, 2018

Is there any way to to db.update() in a single transaction taking parameterStream() input from another query result.
This fails in my case:

        try (final Database db = Database.test()) {
            final Flowable<String> comments = db
                .select("select name from person")
                .getAs(String.class)
                .flatMap(n -> Flowable.range(0, 10).map(i -> String.format("comment %s by %s", i, n)));

            db.update("insert into note(text) values(?)")
                .parameterStream(comments)
                .transacted()
                .transactedValuesOnly()
                .counts()
                .blockingForEach(System.out::println);
        }

with the following output:

13:13:48.019 [pool-1-thread-3] DEBUG o.d.rx.jdbc.TransactedConnection - TransactedConnection attempt close
13:13:48.021 [main] DEBUG org.davidmoten.rx.jdbc.Util - ignored exception Cannot close a connection while a transaction is still active., class java.sql.SQLException, {}
java.sql.SQLException: Cannot close a connection while a transaction is still active.
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedConnection.checkForTransactionInProgress(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedConnection.close(Unknown Source)
	at org.davidmoten.rx.jdbc.Util.closeSilently(Util.java:264)
	at org.davidmoten.rx.pool.DecoratingMember.disposeValue(DecoratingMember.java:75)
	at org.davidmoten.rx.pool.MemberSingle.disposeValues(MemberSingle.java:398)
	at org.davidmoten.rx.pool.MemberSingle.disposeAll(MemberSingle.java:391)
	at org.davidmoten.rx.pool.MemberSingle.cancel(MemberSingle.java:140)
	at org.davidmoten.rx.pool.MemberSingle.close(MemberSingle.java:384)
	at org.davidmoten.rx.pool.NonBlockingPool.close(NonBlockingPool.java:93)
	at org.davidmoten.rx.jdbc.pool.NonBlockingConnectionPool.close(NonBlockingConnectionPool.java:336)
	at org.davidmoten.rx.jdbc.Database.lambda$from$4(Database.java:72)
	at org.davidmoten.rx.jdbc.Database.close(Database.java:198)
	at TransactionTest.testSelectTransacted(TransactionTest.java:24)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.derby.iapi.error.StandardException: Cannot close a connection while a transaction is still active.
	at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source)
	... 40 common frames omitted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant