[jboss-svn-commits] JBL Code SVN: r26376 - in labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa: JDBCResources02Setups and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue May 5 07:21:07 EDT 2009


Author: jhalliday
Date: 2009-05-05 07:21:07 -0400 (Tue, 05 May 2009)
New Revision: 26376

Modified:
   labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/JDBCResources01Setups/Setup02.java
   labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/JDBCResources02Setups/Setup02.java
   labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/JDBCProfileStore.java
Log:
Added index naming fix to JDBC tests. JBTM-390


Modified: labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/JDBCResources01Setups/Setup02.java
===================================================================
--- labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/JDBCResources01Setups/Setup02.java	2009-05-05 11:20:23 UTC (rev 26375)
+++ labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/JDBCResources01Setups/Setup02.java	2009-05-05 11:21:07 UTC (rev 26376)
@@ -36,9 +36,7 @@
 import org.jboss.jbossts.qa.Utils.OAInterface;
 import org.jboss.jbossts.qa.Utils.ORBInterface;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.Statement;
+import java.sql.*;
 import java.util.Properties;
 
 public class Setup02
@@ -96,7 +94,7 @@
 			Statement statement = connection.createStatement();
 
             String tableName = JDBCProfileStore.getTableName(databaseUser, "Infotable");
-            
+
 			try
 			{
 				System.err.println("DROP TABLE " + tableName);
@@ -121,13 +119,32 @@
             if(useShortIndexNames && tableName.length() > 14) {
                 indexName = tableName.substring(0, 14);
             }
-            
+
 			// Create an Index for the table just created. Microsoft SQL requires an index for Row Locking.
 			System.err.println("CREATE UNIQUE INDEX " + indexName+"_idx " +
 					"ON " + tableName + " (Name) ");
-			statement.executeUpdate("CREATE UNIQUE INDEX " + indexName + "_idx " +
+
+            try
+            {
+                statement.executeUpdate("CREATE UNIQUE INDEX " + indexName + "_idx " +
 					"ON " + tableName + " (Name) ");
+            }
+            catch(SQLException s)
+            {
+                if(!useShortIndexNames) {
+                    throw s;
+                }
 
+                // the shortening of the name may have made in non-uniq. Try a different name...
+                s.printStackTrace(System.err);
+                indexName = "x"+Integer.toHexString(tableName.hashCode());
+                System.err.println("CREATE INDEX failed, retrying with hashcode in the hope it's a name collision problem");
+                System.err.println("CREATE UNIQUE INDEX " + indexName+"_idx " +"ON " + tableName + " (Name) ");
+                statement.executeUpdate("CREATE UNIQUE INDEX " + indexName + "_idx " +
+					"ON " + tableName + " (Name) ");
+            }
+
+
             // sybase uses coarse grained locking by default and XA tx branches appear to be loose coupled i.e. do not share locks.
             // Unlike MSSQL, the presence of an index is not enough to cause the db to use row level locking. We need to configure
             // it explicitly instead. Without this the tests that use more than one server i.e. db conn/branch may block.

Modified: labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/JDBCResources02Setups/Setup02.java
===================================================================
--- labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/JDBCResources02Setups/Setup02.java	2009-05-05 11:20:23 UTC (rev 26375)
+++ labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/JDBCResources02Setups/Setup02.java	2009-05-05 11:21:07 UTC (rev 26376)
@@ -39,6 +39,7 @@
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.Statement;
+import java.sql.SQLException;
 import java.util.Properties;
 
 public class Setup02
@@ -96,7 +97,7 @@
 			Statement statement = connection.createStatement();
 
             String tableName = JDBCProfileStore.getTableName(databaseUser, "Infotable");
-            
+
 			try
 			{
 				System.err.println("DROP TABLE " + tableName);
@@ -120,13 +121,32 @@
             if(useShortIndexNames && tableName.length() > 14) {
                 indexName = tableName.substring(0, 14);
             }
-            
+
 			// Create an Index for the table just created. Microsoft SQL requires an index for Row Locking.
 			System.err.println("CREATE UNIQUE INDEX " + indexName+"_idx " +
 					"ON " + tableName + " (Name) ");
-			statement.executeUpdate("CREATE UNIQUE INDEX " + indexName + "_idx " +
+
+            try
+            {
+                statement.executeUpdate("CREATE UNIQUE INDEX " + indexName + "_idx " +
 					"ON " + tableName + " (Name) ");
+            }
+            catch(SQLException s)
+            {
+                if(!useShortIndexNames) {
+                    throw s;
+                }
 
+                // the shortening of the name may have made in non-uniq. Try a different name...
+                s.printStackTrace(System.err);
+                indexName = "x"+Integer.toHexString(tableName.hashCode());
+                System.err.println("CREATE INDEX failed, retrying with hashcode in the hope it's a name collision problem");
+                System.err.println("CREATE UNIQUE INDEX " + indexName+"_idx " +"ON " + tableName + " (Name) ");
+                statement.executeUpdate("CREATE UNIQUE INDEX " + indexName + "_idx " +
+					"ON " + tableName + " (Name) ");
+            }
+
+
             // sybase uses coarse grained locking by default and XA tx branches appear to be loose coupled i.e. do not share locks.
             // Unlike MSSQL, the presence of an index is not enough to cause the db to use row level locking. We need to configure
             // it explicitly instead. Without this the tests that use more than one server i.e. db conn/branch may block.

Modified: labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/JDBCProfileStore.java
===================================================================
--- labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/JDBCProfileStore.java	2009-05-05 11:20:23 UTC (rev 26375)
+++ labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/JDBCProfileStore.java	2009-05-05 11:21:07 UTC (rev 26376)
@@ -144,7 +144,7 @@
 	}
 
     public static String getTableName(String username, String suffix) throws UnknownHostException {
-        // read JBTM- before messing with this function.
+        // read JBTM-390 before messing with this function.
         // previously this would have been: username + "_" + suffix as in "DROP TABLE " + databaseUser + "_InfoTable");
         String value = username+"_"+getLocalHostNameForTables()+"_"+suffix;
         // in addition to the problems with the valid characters, there are issues with the max length.
@@ -155,14 +155,14 @@
         }
         return value;
     }
-    
-    private static String getLocalHostNameForTables() throws UnknownHostException { 
+
+    private static String getLocalHostNameForTables() throws UnknownHostException {
         String hostName = java.net.InetAddress.getLocalHost().getHostName();
         hostName = stripHostName(hostName); // strip to local portion, force lower case.
         hostName = hostName.replace("-", "_"); // some db's don't like hyphens in identifiers
         return hostName;
     }
-    
+
 	private static void loadProfile()
 			throws Exception
 	{
@@ -177,9 +177,9 @@
 			}
 
 			_profile = new Properties();
-            
+
             File file = new File(baseDir + File.separator + stripHostName(hostName) + File.separator + "JDBCProfiles");
-            
+
             if(!file.exists()) {
                 // no host specific profile, fallback to a default one
                 file = new File(baseDir + File.separator + "default" + File.separator + "JDBCProfiles");
@@ -190,9 +190,9 @@
 			profileFileInputStream.close();
 		}
 	}
-    
 
 
+
 	private static String stripHostName(String hostName)
 	{
 		hostName = hostName.toLowerCase();




More information about the jboss-svn-commits mailing list