? jdbcstartcommand.patch
Index: src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java,v
retrieving revision 1.50.2.2
diff -u -r1.50.2.2 JDBCStartCommand.java
--- src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java	29 Oct 2005 05:06:52 -0000	1.50.2.2
+++ src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java	9 Jan 2006 14:22:10 -0000
@@ -106,6 +106,11 @@
          {
             SQLUtil.OldColumns oldColumns = SQLUtil.getOldColumns(entity.getQualifiedTableName(), entity.getDataSource());
             ArrayList oldNames = oldColumns.getColumnNames();
+            int len = oldNames.size();
+            for(int i = 0; i < len; i++)
+            {
+              oldNames.set(i, ((String) oldNames.get(i)).toUpperCase());
+            }
             ArrayList oldTypes = oldColumns.getTypeNames();
             ArrayList oldSizes = oldColumns.getColumnSizes();
             SQLUtil.OldIndexes oldIndexes = null;
@@ -170,7 +175,7 @@
 
                // see if we have to add an index for the field
                JDBCCMPFieldMetaData fieldMD = entity.getMetaData().getCMPFieldByName(field.getFieldName());
-               if(fieldMD.isIndexed())
+               if(fieldMD != null && fieldMD.isIndexed())
                {
                   if(oldIndexes == null)
                   {
@@ -260,6 +265,11 @@
                if(relationMetaData.getAlterTable())
                {
                   ArrayList oldNames = SQLUtil.getOldColumns(cmrField.getQualifiedTableName(), dataSource).getColumnNames();
+                  int len = oldNames.size();
+                  for(int k = 0; k < len; k++)
+                  {
+                    oldNames.set(k, ((String) oldNames.get(k)).toUpperCase());
+                  }
                   ArrayList newNames = new ArrayList();
                   JDBCFieldBridge[] leftKeys = cmrField.getTableKeyFields();
                   JDBCFieldBridge[] rightKeys = cmrField.getRelatedCMRField().getTableKeyFields();
@@ -391,48 +401,33 @@
     *
     * @param oldIndexes list of existing indexes
     * @param field      field for we test the existence of an index
-    * @return
+    * @return True if the field has an index; otherwise false
     */
    private boolean hasIndex(SQLUtil.OldIndexes oldIndexes, JDBCFieldBridge field)
    {
-      JDBCType jdbcType = field.getJDBCType();
-      String[] columns = jdbcType.getColumnNames();
-      ArrayList idxNames = oldIndexes.getIndexNames();
+      String[] columns = field.getJDBCType().getColumnNames();
       ArrayList idxColumns = oldIndexes.getColumnNames();
-      ArrayList idxAscDesc = oldIndexes.getColumnAscDesc();
 
-      // search for for column in index
-      for(int i = 0; i < idxColumns.size(); i++)
+      for(int i = 0; i < columns.length; i++)
       {
-         // only match ascending columns
-         if(idxAscDesc.get(i).equals("A"))
+         String name = columns[i];
+         boolean found = false;
+         for(int j = 0; !found && j < idxColumns.size(); j++)
          {
-            String name = columns[0];
-            String testCol = (String) idxColumns.get(i);
-            if(testCol.equalsIgnoreCase(name))
+            String testCol = (String)idxColumns.get(j);
+
+            if(testCol.indexOf(name) != -1)
             {
-               // first column matches, now check the others
-               String idxName = (String) idxNames.get(i);
-               int j = 1;
-               for(; j < columns.length; j++)
-               {
-                  name = columns[j];
-                  testCol = (String) idxColumns.get(i + j);
-                  String testName = (String) idxNames.get(i + j);
-                  if(!(testName.equals(idxName)
-                     &&
-                     testCol.equalsIgnoreCase(name)
-                     && idxAscDesc.get(i + j).equals("A")))
-                  {
-                     break;
-                  }
-               }
-               // if they all matched -> found
-               if(j == columns.length) return true;
+               found = true;
             }
          }
+         if(!found)
+         {
+            return false;
+         }
       }
-      return false;
+
+      return true;
    }
 
    private void alterTable(DataSource dataSource, JDBCFunctionMappingMetaData mapping, String tableName, String fieldName, String fieldStructure)
@@ -464,7 +459,7 @@
          {
             con = dataSource.getConnection();
             statement = con.createStatement();
-            statement.executeUpdate(sql.toString());
+            statement.executeUpdate(sql);
          }
          finally
          {
