You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by li...@apache.org on 2018/04/13 12:38:53 UTC

[13/32] trafodion git commit: [TRAFODION-2704]close unused statment in JDBC regression

[TRAFODION-2704]close unused statment in JDBC regression


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/808c8745
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/808c8745
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/808c8745

Branch: refs/heads/master
Commit: 808c87450f343e6df3dcc82e0799919581958513
Parents: 42b2b0b
Author: Weiqing Xu <we...@esgyn.cn>
Authored: Wed Sep 20 05:49:28 2017 +0000
Committer: Weiqing Xu <we...@esgyn.cn>
Committed: Wed Sep 20 05:49:28 2017 +0000

----------------------------------------------------------------------
 .../org/trafodion/jdbc_test/JdbcCommon.java     | 27 ++++++---
 .../org/trafodion/jdbc_test/TestForeignKey.java | 62 +++++++++++++-------
 2 files changed, 59 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/808c8745/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
----------------------------------------------------------------------
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
index 6ab5fca..ec68443 100644
--- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/JdbcCommon.java
@@ -117,8 +117,11 @@ public class JdbcCommon {
         StringBuilder buf = new StringBuilder(ddl);
         ddl = buf.toString();
 
-        try {
-            _conn.createStatement().execute(ddl);
+        try (
+            Statement stmt = _conn.createStatement();
+        )
+        {
+            stmt.execute(ddl);
         } catch (Exception e) { 
             System.out.println(e.getMessage());
             fail("Failed to create table");
@@ -154,8 +157,11 @@ public class JdbcCommon {
         if (commConn == null)
             commConn = getConnection();
 
-        try {
-            commConn.createStatement().execute("create schema " + _catalog + "." + _schema);
+        try (
+            Statement stmt = commConn.createStatement();
+        )
+        {
+            stmt.execute("create schema " + _catalog + "." + _schema);
         } catch (Exception e) {
             // Do nothing, the schema may already exist.
         }
@@ -165,8 +171,11 @@ public class JdbcCommon {
         if (commConn == null)
             commConn = getConnection();
 
-        try {
-            commConn.createStatement().execute("drop schema " + _catalog + "." + _schema + " cascade");
+        try (
+            Statement stmt = commConn.createStatement();
+        )
+        {
+            stmt.execute("drop schema " + _catalog + "." + _schema + " cascade");
         } catch (Exception e) {
             // Do nothing, the schema may not exist.  
         }
@@ -184,8 +193,10 @@ public class JdbcCommon {
 
         for (String objname : objDropList) {
             for (int i = 0; i < 3; i++) {
-                try {
-                    commConn.createStatement().executeUpdate("drop " + objname + " cascade");
+                try (
+                    Statement stmt = commConn.createStatement();
+                ){
+                    stmt.executeUpdate("drop " + objname + " cascade");
                     break; // no execption, break out here
                 } catch (Exception e) {
                     String msg = e.getMessage();

http://git-wip-us.apache.org/repos/asf/trafodion/blob/808c8745/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java
----------------------------------------------------------------------
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java
index d6c2175..9c87e9e 100644
--- a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestForeignKey.java
@@ -74,12 +74,15 @@ public class TestForeignKey {
 	public static void doTestSuiteSetup() throws Exception {
 		try{
 			_conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd);
-			Statement stmt = _conn.createStatement();
-			
-			stmt.execute(strCreatePKTABLE1Query);
-			stmt.execute(strCreatePKTABLE2Query);
-			stmt.execute(strCreateFKTABLE1Query);
-			stmt.execute(strCreateFKTABLE2Query);
+            try (
+			    Statement stmt = _conn.createStatement();
+            )
+		    {	
+                stmt.execute(strCreatePKTABLE1Query);
+                stmt.execute(strCreatePKTABLE2Query);
+                stmt.execute(strCreateFKTABLE1Query);
+                stmt.execute(strCreateFKTABLE2Query);
+            }
 		}
 		catch (Exception e) {
 			System.out.println(e.getMessage());
@@ -96,12 +99,19 @@ public class TestForeignKey {
 		
 		try {
 			DatabaseMetaData metaData = _conn.getMetaData();
-			ResultSet rs = metaData.getImportedKeys("TRAFODION", Utils.schema, FKTABLE1);
 			int rowNum = 0;
-			while(rs.next()) {
-				compareForeignkeyWithExp("testGetImportedKeys", rowNum + 1, rs, expFkInfo[rowNum]);
-				rowNum += 1;
-			}
+            try (
+                 ResultSet rs = metaData.getImportedKeys("TRAFODION", Utils.schema, FKTABLE1);
+            )
+            {
+                while(rs.next()) {
+                    compareForeignkeyWithExp("testGetImportedKeys", rowNum + 1, rs, expFkInfo[rowNum]);
+                    rowNum += 1;
+                }
+            }
+            catch (Exception e) {
+                fail(e.getMessage());
+            }
 			assertEquals(rowNum, 2);
 		} catch (Exception e) {
 			e.printStackTrace();
@@ -117,12 +127,16 @@ public class TestForeignKey {
 		
 		try {
 			DatabaseMetaData metaData = _conn.getMetaData();
-			ResultSet rs = metaData.getExportedKeys("TRAFODION", Utils.schema, PKTABLE1);
-			int rowNum = 0;
-			while(rs.next()) {
-				compareForeignkeyWithExp("testGetExportedKeys", rowNum + 1, rs, expFkInfo[rowNum]);
-				rowNum += 1;
-			}
+            int rowNum = 0;
+            try (
+			    ResultSet rs = metaData.getExportedKeys("TRAFODION", Utils.schema, PKTABLE1);
+            )
+            {
+			    while(rs.next()) {
+			    	compareForeignkeyWithExp("testGetExportedKeys", rowNum + 1, rs, expFkInfo[rowNum]);
+			    	rowNum += 1;
+			    }
+            }
 			assertEquals(rowNum, 2);
 		} catch (Exception e) {
 			e.printStackTrace();
@@ -137,12 +151,16 @@ public class TestForeignKey {
 		
 		try {
 			DatabaseMetaData metaData = _conn.getMetaData();
-			ResultSet rs = metaData.getCrossReference("TRAFODION", Utils.schema, PKTABLE1, "TRAFODION", Utils.schema, FKTABLE1);
 			int rowNum = 0;
-			while(rs.next()) {
-				compareForeignkeyWithExp("testGetCrossReference", rowNum + 1, rs, expFkInfo[rowNum]);
-				rowNum += 1;
-			}
+            try (
+			    ResultSet rs = metaData.getCrossReference("TRAFODION", Utils.schema, PKTABLE1, "TRAFODION", Utils.schema, FKTABLE1);
+            )
+            {
+			    while(rs.next()) {
+			    	compareForeignkeyWithExp("testGetCrossReference", rowNum + 1, rs, expFkInfo[rowNum]);
+			    	rowNum += 1;
+			    }
+            }
 			assertEquals(rowNum, 1);
 		} catch (Exception e) {
 			e.printStackTrace();