db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mamta A. Satoor (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (DERBY-6053) Client should use a prepared statement rather than regular statement for Connection.setTransactionIsolation
Date Fri, 01 Feb 2013 22:52:13 GMT

    [ https://issues.apache.org/jira/browse/DERBY-6053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13569184#comment-13569184
] 

Mamta A. Satoor edited comment on DERBY-6053 at 2/1/13 10:52 PM:
-----------------------------------------------------------------

I have made the changes to use PreparedStatement vs Statement(attached a patch DERBY6053_patch1_diff.txt
for it) so that we do not compile the statements for isolation level change every single time.
When I compile this code though, I get following error from ant all
    [javac] Note: C:\p4clients\svnmain\client3\trunk\java\client\org\apache\derby\client\am\Connection.java
uses unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
The subsequent compile doesn't show this error anymore. I have a feeling this has to do with
using Hashtable and Iterator objects, but not 100% yet. Am I correct about that assumption?
If so, can this compile time error be ignored since the subsequent compile doesn't give that
error again? Thanks
                
      was (Author: mamtas):
    I have made the changes to use PreparedStatement vs Statement so that we do not compile
the statements for isolation level change every single time. When I compile this code though,
I get following error from ant all
    [javac] Note: C:\p4clients\svnmain\client3\trunk\java\client\org\apache\derby\client\am\Connection.java
uses unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
The subsequent compile doesn't show this error anymore. I have a feeling this has to do with
using Hashtable and Iterator objects, but not 100% yet. Am I correct about that assumption?
If so, can this compile time error be ignored since the subsequent compile doesn't give that
error again? Thanks
                  
> Client should use a prepared statement rather than regular statement for Connection.setTransactionIsolation
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-6053
>                 URL: https://issues.apache.org/jira/browse/DERBY-6053
>             Project: Derby
>          Issue Type: Improvement
>          Components: Network Client
>            Reporter: Kathey Marsden
>         Attachments: DERBY6053_patch1_diff.txt
>
>
> o.a.d.client.am.Connection setTransactionIsolation() uses a Statement which  it builds
up each time for setTransactionIsolation()  is called.
> private Statement setTransactionIsolationStmt = null;
> ...
> setTransactionIsolationStmt =
>                     createStatementX(java.sql.ResultSet.TYPE_FORWARD_ONLY,
>                             java.sql.ResultSet.CONCUR_READ_ONLY,
>                             holdability());
> ....
>  private void setTransactionIsolationX(int level)
> ...
>             setTransactionIsolationStmt.executeUpdate(
>                 "SET CURRENT ISOLATION = " + levelString);
> It would be better for performance and also for avoid possible garbage collection issues,
to have a single prepared statement with a parameter marker. 
> The program below shows repeated calls to setTransactionIsolation.
> import java.sql.*;
> import java.net.*;
> import java.io.*;
> import org.apache.derby.drda.NetworkServerControl;
> /**
>  * Client template starts its own NetworkServer and runs some SQL against it.
>  * The SQL or JDBC API calls can be modified to reproduce issues
>  * 
>  */public class SetTransactionIsolation {
>     public static Statement s;
>     
>     public static void main(String[] args) throws Exception {
>         try {
>             // Load the driver. Not needed for network server.
>             
>             Class.forName("org.apache.derby.jdbc.ClientDriver");
>             // Start Network Server
>             startNetworkServer();
>             // If connecting to a customer database. Change the URL
>             Connection conn = DriverManager
>                     .getConnection("jdbc:derby://localhost:1527/wombat;create=true");
>             // clean up from a previous run
>             s = conn.createStatement();
>             try {
>                 s.executeUpdate("DROP TABLE T");
>             } catch (SQLException se) {
>                 if (!se.getSQLState().equals("42Y55"))
>                     throw se;
>             }
>             for (int i = 0; i < 50000; i++) {
> 		conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
> 		conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
> 	    }
>             
>             // rs.close();
>             // ps.close();
>             runtimeInfo();
>             conn.close();
>             // Shutdown the server
>             shutdownServer();
>         } catch (SQLException se) {
>             while (se != null) {
>                 System.out.println("SQLState=" + se.getSQLState()
>                         + se.getMessage());
>                 se.printStackTrace();
>                 se = se.getNextException();
>             }
>         }
>     }
>     
>     /**
>      * starts the Network server
>      * 
>      */
>     public static void startNetworkServer() throws SQLException {
>         Exception failException = null;
>         try {
>             
>             NetworkServerControl networkServer = new NetworkServerControl(
>                     InetAddress.getByName("localhost"), 1527);
>             
>             networkServer.start(new PrintWriter(System.out));
>             
>             // Wait for the network server to start
>             boolean started = false;
>             int retries = 10; // Max retries = max seconds to wait
>             
>             while (!started && retries > 0) {
>                 try {
>                     // Sleep 1 second and then ping the network server
>                     Thread.sleep(1000);
>                     networkServer.ping();
>                     
>                     // If ping does not throw an exception the server has
>                     // started
>                     started = true;
>                 } catch (Exception e) {
>                     retries--;
>                     failException = e;
>                 }
>                 
>             }
>             
>             // Check if we got a reply on ping
>             if (!started) {
>                 throw failException;
>             }
>         } catch (Exception e) {
>             SQLException se = new SQLException("Error starting network  server");
>             se.initCause(failException);
>             throw se;
>         }
>     }
>     
>     public static void shutdownServer() throws Exception {
>         NetworkServerControl networkServer = new NetworkServerControl(
>                 InetAddress.getByName("localhost"), 1527);
>         networkServer.shutdown();
>     }
>     
>     public static void runtimeInfo() throws Exception {
>         NetworkServerControl networkServer = new NetworkServerControl(
>                 InetAddress.getByName("localhost"), 1527);
>         System.out.println(networkServer.getRuntimeInfo());
>     }
>     
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message