-
1. Re: Teiid JDBC setting the readonly flag throws an exception
rareddy Jan 24, 2016 10:27 PM (in response to cgausub)Typically autoCommit flag is set to true on JDBC connections, if you are using any client tools, they some times change the default behavior. Otherwise check your client code, where you might be setting this to false.
-
2. Re: Teiid JDBC setting the readonly flag throws an exception
cgausub Jan 25, 2016 9:33 AM (in response to rareddy)I can understand the reasons for the autoCommit flag to be true by default but why should it be set to true for setting the readOnly property on the connection.
-
3. Re: Teiid JDBC setting the readonly flag throws an exception
shawkins Jan 25, 2016 9:39 AM (in response to cgausub)That is part of the spec - https://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#setReadOnly(boolean)
autoCommit false means that you are in a local transaction. Ramesh is saying that along the line somewhere setAutoCommit(false) is being called to start a transaction and then later setReadOnly is being called
-
4. Re: Teiid JDBC setting the readonly flag throws an exception
cgausub Jan 25, 2016 9:53 AM (in response to shawkins)What I am trying to argue is that setting autoCommit to false does not automatically start a transaction. I still need to start the transaction explicitly.
Hence based on the spec the readonly flag should throw an exception only if a transaction is active and for no other reason.
-
5. Re: Teiid JDBC setting the readonly flag throws an exception
rareddy Jan 25, 2016 10:09 AM (in response to cgausub)A local transaction starts when the autocommit flag is set to "false" in Teiid. So, yes transaction is implicitly already started. I would like to know how you are explicitly starting a transaction? Are you using XA driver to participate in global transaction?
-
6. Re: Teiid JDBC setting the readonly flag throws an exception
shawkins Jan 25, 2016 10:28 AM (in response to cgausub)> What I am trying to argue is that setting autoCommit to false does not automatically start a transaction. I still need to start the transaction explicitly.
By explicit you mean that the transaction will be started by any statement executed against the server, or do you mean something else?
It is correct that if you are in autoCommit false and have not executed a statement that the transaction will not be started (inLocalTxn will be false initially). setReadOnly is not aware of the difference between inLocalTxn and the autoCommitFlag, however that seems like a fairly narrow case. Also it seems like there is very little adherence to the spec with regards to this flag as other drivers will simply ignore the call or allow it even in a transaction, so there may not be too much of point in being a stickler.
We probably shouldn't be setting the read only flag at all, since it doesn't appear that the value is used - although it would be fairly straight-forward to use it.
-
7. Re: Teiid JDBC setting the readonly flag throws an exception
cgausub Jan 28, 2016 1:22 AM (in response to shawkins)Just to confirm do you mean that a transaction will be started even if I execute a simple Select statement even if auto-commit is false?
> We probably shouldn't be setting the read only flag at all, since it doesn't appear that the value is used - although it would be fairly straight-forward to use it.
Also, does setting the readOnly flag to true have no effect , in that case I can skip setting this flag on the connection.
-
8. Re: Teiid JDBC setting the readonly flag throws an exception
shawkins Jan 28, 2016 7:42 AM (in response to cgausub)> Just to confirm do you mean that a transaction will be started even if I execute a simple Select statement even if auto-commit is false?
In most circumstances yes. To ensure isolation even reads may need to be transactional.
> Also, does setting the readOnly flag to true have no effect , in that case I can skip setting this flag on the connection.
Yes, and I've logged [TEIID-3939] Refined Behavior of Connection.setReadOnly - JBoss Issue Tracker to improve this behavior.
-
9. Re: Teiid JDBC setting the readonly flag throws an exception
cgausub Jan 28, 2016 8:10 AM (in response to shawkins)Thanks that should help.