incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1221538 - in /incubator/lcf/trunk: ./ connectors/jdbc/ framework/ framework/core/src/main/java/org/apache/manifoldcf/core/database/ framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/
Date Wed, 21 Dec 2011 00:34:15 GMT
Author: kwright
Date: Wed Dec 21 00:34:15 2011
New Revision: 1221538

URL: http://svn.apache.org/viewvc?rev=1221538&view=rev
Log:
Part of CONNECTORS-334.  Incorporate changes from CONNECTORS-314 into the ant build, so that
MySQL is usable as a database driver, for everything except reports.

Modified:
    incubator/lcf/trunk/build.xml
    incubator/lcf/trunk/connectors/jdbc/build.xml
    incubator/lcf/trunk/framework/build.xml
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/BaseTable.java
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java

Modified: incubator/lcf/trunk/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/build.xml?rev=1221538&r1=1221537&r2=1221538&view=diff
==============================================================================
--- incubator/lcf/trunk/build.xml (original)
+++ incubator/lcf/trunk/build.xml Wed Dec 21 00:34:15 2011
@@ -172,6 +172,7 @@
                 <include name="postgresql*.jar"/>
                 <include name="derby*.jar"/>
                 <include name="hsqldb*.jar"/>
+                <include name="mysql*.jar"/>
             </fileset>
         </copy>
       </target>
@@ -1212,7 +1213,7 @@
         <mkdir dir="build/example"/>
         <manifest file="build/example/manifest">
             <attribute name="Main-Class" value="org.apache.manifoldcf.jettyrunner.ManifoldCFJettyRunner"/>
-            <attribute name="Class-Path" value="lib/commons-codec.jar lib/commons-collections.jar
lib/commons-el.jar lib/commons-fileupload.jar lib/commons-httpclient-mcf.jar lib/commons-io.jar
lib/commons-logging.jar lib/hsqldb.jar lib/derbyclient.jar lib/derby.jar lib/derbyLocale_cs.jar
lib/derbyLocale_de_DE.jar lib/derbyLocale_es.jar lib/derbyLocale_fr.jar lib/derbyLocale_hu.jar
lib/derbyLocale_it.jar lib/derbyLocale_ja_JP.jar lib/derbyLocale_ko_KR.jar lib/derbyLocale_pl.jar
lib/derbyLocale_pt_BR.jar lib/derbyLocale_ru.jar lib/derbyLocale_zh_CN.jar lib/derbyLocale_zh_TW.jar
lib/derbynet.jar lib/derbyrun.jar lib/derbytools.jar lib/eclipse-ecj.jar lib/jasper-6.0.24.jar
lib/jasper-el-6.0.24.jar lib/jdbcpool-0.99.jar lib/jetty-6.1.26-patched-JETTY-1340.jar lib/jetty-util-6.1.26-patched-JETTY-1340.jar
lib/jsp-api-2.1-glassfish-2.1.v20091210.jar lib/json.jar lib/mcf-agents.jar lib/mcf-core.jar
lib/mcf-jetty-runner.jar lib/mcf-pull-agent.jar lib/mcf-ui-core.jar lib/log4j-1.2.jar
  lib/postgresql.jar lib/serializer.jar lib/servlet-api-2.5-20081211.jar lib/tomcat-juli-6.0.24.jar
lib/xalan2.jar lib/xercesImpl-mcf.jar lib/xml-apis.jar"/>
+            <attribute name="Class-Path" value="lib/commons-codec.jar lib/commons-collections.jar
lib/commons-el.jar lib/commons-fileupload.jar lib/commons-httpclient-mcf.jar lib/commons-io.jar
lib/commons-logging.jar lib/hsqldb.jar lib/derbyclient.jar lib/derby.jar lib/derbyLocale_cs.jar
lib/derbyLocale_de_DE.jar lib/derbyLocale_es.jar lib/derbyLocale_fr.jar lib/derbyLocale_hu.jar
lib/derbyLocale_it.jar lib/derbyLocale_ja_JP.jar lib/derbyLocale_ko_KR.jar lib/derbyLocale_pl.jar
lib/derbyLocale_pt_BR.jar lib/derbyLocale_ru.jar lib/derbyLocale_zh_CN.jar lib/derbyLocale_zh_TW.jar
lib/derbynet.jar lib/derbyrun.jar lib/derbytools.jar lib/eclipse-ecj.jar lib/jasper-6.0.24.jar
lib/jasper-el-6.0.24.jar lib/jdbcpool-0.99.jar lib/jetty-6.1.26-patched-JETTY-1340.jar lib/jetty-util-6.1.26-patched-JETTY-1340.jar
lib/jsp-api-2.1-glassfish-2.1.v20091210.jar lib/json.jar lib/mcf-agents.jar lib/mcf-core.jar
lib/mcf-jetty-runner.jar lib/mcf-pull-agent.jar lib/mcf-ui-core.jar lib/log4j-1.2.jar
  lib/postgresql.jar lib/mysql-connector-java-5.1.18-bin.jar lib/serializer.jar lib/servlet-api-2.5-20081211.jar
lib/tomcat-juli-6.0.24.jar lib/xalan2.jar lib/xercesImpl-mcf.jar lib/xml-apis.jar"/>
         </manifest>
         <jar destfile="dist/example/start.jar" manifest="build/example/manifest"/>
     </target>
@@ -3703,7 +3704,11 @@ Use Apache Forrest version forrest-0.9-d
         </java>
     </target>
 
-    <target name="download-dependencies">
+    <target name="download-mysql">
+        <get src="http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.18/mysql-connector-java-5.1.18.jar"
dest="lib"/>
+    </target>
+
+    <target name="download-dependencies" depends="download-mysql">
         <ant dir="connectors/jcifs" target="download-dependencies"/>
         <ant dir="connectors/jdbc" target="download-dependencies"/>
         <ant dir="connectors/sharepoint" target="download-dependencies"/>

Modified: incubator/lcf/trunk/connectors/jdbc/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/connectors/jdbc/build.xml?rev=1221538&r1=1221537&r2=1221538&view=diff
==============================================================================
--- incubator/lcf/trunk/connectors/jdbc/build.xml (original)
+++ incubator/lcf/trunk/connectors/jdbc/build.xml Wed Dec 21 00:34:15 2011
@@ -70,10 +70,6 @@
         <get src="http://repo1.maven.org/maven2/net/sourceforge/jtds/jtds/1.2.4/jtds-1.2.4.jar"
dest="jdbc-drivers"/>
     </target>
 
-    <target name="download-mysql">
-        <get src="http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.18/mysql-connector-java-5.1.18.jar"
dest="jdbc-drivers"/>
-    </target>
-    
-    <target name="download-dependencies" depends="download-ojdbc,download-jtds,download-mysql"/>
+    <target name="download-dependencies" depends="download-ojdbc,download-jtds"/>
     
 </project>

Modified: incubator/lcf/trunk/framework/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/build.xml?rev=1221538&r1=1221537&r2=1221538&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/build.xml (original)
+++ incubator/lcf/trunk/framework/build.xml Wed Dec 21 00:34:15 2011
@@ -253,6 +253,7 @@
                 <include name="postgresql*.jar"/>
                 <include name="derby*.jar"/>
                 <include name="hsqldb*.jar"/>
+                <include name="mysql*.jar"/>
             </fileset>
         </copy>
         <copy todir="build/webapp/authority-service/WEB-INF/lib">
@@ -288,6 +289,7 @@
                 <include name="postgresql*.jar"/>
                 <include name="derby*.jar"/>
                 <include name="hsqldb*.jar"/>
+                <include name="mysql*.jar"/>
             </fileset>
         </copy>
         <copy todir="build/webapp/api-service/WEB-INF/lib">
@@ -329,6 +331,7 @@
                 <include name="postgresql*.jar"/>
                 <include name="derby*.jar"/>
                 <include name="hsqldb*.jar"/>
+                <include name="mysql*.jar"/>
             </fileset>
         </copy>
         <copy todir="build/webapp/crawler-ui/WEB-INF/lib">
@@ -404,6 +407,7 @@
                 <include name="postgresql*.jar"/>
                 <include name="derby*.jar"/>
                 <include name="hsqldb*.jar"/>
+                <include name="mysql*.jar"/>
             </fileset>
             <fileset dir="build/jar">
                 <include name="mcf-core.jar"/>
@@ -494,6 +498,7 @@
                 <include name="postgresql*.jar"/>
                 <include name="derby*.jar"/>
                 <include name="hsqldb*.jar"/>
+                <include name="mysql*.jar"/>
             </fileset>
             <fileset dir="build/jar">
                 <include name="mcf-core.jar"/>

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/BaseTable.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/BaseTable.java?rev=1221538&r1=1221537&r2=1221538&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/BaseTable.java
(original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/BaseTable.java
Wed Dec 21 00:34:15 2011
@@ -153,7 +153,7 @@ public class BaseTable
   public void performRemoveIndex(String indexName)
     throws ManifoldCFException
   {
-    dbInterface.performRemoveIndex(indexName);
+    dbInterface.performRemoveIndex(indexName,tableName);
   }
 
   /** Analyze this table.
@@ -318,6 +318,17 @@ public class BaseTable
     return CacheKeyFactory.makeTableKey(null,tableName,dbInterface.getDatabaseName());
   }
 
+  /** Construct a count clause.
+  * On most databases this will be COUNT(col), but on some the count needs to be cast to
a BIGINT, so
+  * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+  *@param column is the column string to be counted.
+  *@return the query chunk needed.
+  */
+  public String constructCountClause(String column)
+  {
+    return dbInterface.constructCountClause(column);
+  }
+
   /** Construct a regular-expression match clause.
   * This method builds both the text part of a regular-expression match.
   *@param column is the column specifier string.

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java?rev=1221538&r1=1221537&r2=1221538&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
(original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
Wed Dec 21 00:34:15 2011
@@ -538,8 +538,9 @@ public class DBInterfaceDerby extends Da
 
   /** Remove an index.
   *@param indexName is the name of the index to remove.
+  *@param tableName is the table the index belongs to.
   */
-  public void performRemoveIndex(String indexName)
+  public void performRemoveIndex(String indexName, String tableName)
     throws ManifoldCFException
   {
     performModification("DROP INDEX "+indexName,null,null);
@@ -672,7 +673,7 @@ public class DBInterfaceDerby extends Da
           {
             String indexName = iter.next();
             IndexDescription id = x.get(indexName);
-            performRemoveIndex(indexName);
+            performRemoveIndex(indexName,tableName);
             performAddIndex(indexName,tableName,id);
           }
           break;
@@ -1027,6 +1028,17 @@ public class DBInterfaceDerby extends Da
     }
   }
 
+  /** Construct a count clause.
+  * On most databases this will be COUNT(col), but on some the count needs to be cast to
a BIGINT, so
+  * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+  *@param column is the column string to be counted.
+  *@return the query chunk needed.
+  */
+  public String constructCountClause(String column)
+  {
+    return "CAST(COUNT("+column+") AS bigint)";
+  }
+
   /** Construct a regular-expression match clause.
   * This method builds both the text part of a regular-expression match.
   *@param column is the column specifier string.

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java?rev=1221538&r1=1221537&r2=1221538&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
(original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
Wed Dec 21 00:34:15 2011
@@ -546,8 +546,9 @@ public class DBInterfaceHSQLDB extends D
 
   /** Remove an index.
   *@param indexName is the name of the index to remove.
+  *@param tableName is the table the index belongs to.
   */
-  public void performRemoveIndex(String indexName)
+  public void performRemoveIndex(String indexName, String tableName)
     throws ManifoldCFException
   {
     performModification("DROP INDEX "+indexName,null,null);
@@ -978,6 +979,17 @@ public class DBInterfaceHSQLDB extends D
     }
   }
 
+  /** Construct a count clause.
+  * On most databases this will be COUNT(col), but on some the count needs to be cast to
a BIGINT, so
+  * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+  *@param column is the column string to be counted.
+  *@return the query chunk needed.
+  */
+  public String constructCountClause(String column)
+  {
+    return "CAST(COUNT("+column+") AS bigint)";
+  }
+
   /** Construct a regular-expression match clause.
   * This method builds both the text part of a regular-expression match.
   *@param column is the column specifier string.

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java?rev=1221538&r1=1221537&r2=1221538&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
(original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
Wed Dec 21 00:34:15 2011
@@ -19,24 +19,35 @@
 package org.apache.manifoldcf.core.database;
 
 import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.core.system.ManifoldCF;
 import java.util.*;
 
 public class DBInterfaceMySQL extends Database implements IDBInterface
 {
   public static final String _rcsid = "@(#)$Id: DBInterfaceMySQL.java 999670 2010-09-21 22:18:19Z
kwright $";
 
-  private static final String _url = "jdbc:mysql://localhost/";
-  private static final String _driver = "org.gjt.mm.mysql.Driver";
+  /** MySQL server property */
+  public static final String mysqlServerProperty = "org.apache.manifoldcf.mysql.server";
 
+  private static final String _driver = "com.mysql.jdbc.Driver";
+  
   protected String cacheKey;
 
   public DBInterfaceMySQL(IThreadContext tc, String databaseName, String userName, String
password)
     throws ManifoldCFException
   {
-    super(tc,_url+databaseName,_driver,databaseName,userName,password);
+    super(tc,getJdbcUrl(databaseName),_driver,databaseName,userName,password);
     cacheKey = CacheKeyFactory.makeDatabaseKey(this.databaseName);
   }
 
+  private static String getJdbcUrl(String theDatabaseName)
+  {
+    String server =  ManifoldCF.getProperty(mysqlServerProperty);
+    if (server == null || server.length() == 0)
+      server = "localhost";
+    return "jdbc:mysql://"+server+"/"+theDatabaseName;
+  }
+
   /** Initialize.  This method is called once per JVM instance, in order to set up
   * database communication.
   */
@@ -69,7 +80,7 @@ public class DBInterfaceMySQL extends Da
   public void performLock(String tableName)
     throws ManifoldCFException
   {
-    performModification("LOCK TABLE "+tableName+" IN EXCLUSIVE MODE",null,null);
+    //performModification("LOCK TABLE "+tableName+" IN EXCLUSIVE MODE",null,null);
   }
 
   /** Perform an insert operation.
@@ -239,32 +250,35 @@ public class DBInterfaceMySQL extends Da
         queryBuffer.append(',');
       else
         first = false;
-      queryBuffer.append(columnName);
-      queryBuffer.append(' ');
-      queryBuffer.append(cd.getTypeString());
-      if (cd.getIsNull())
-        queryBuffer.append(" NULL");
-      else
-        queryBuffer.append(" NOT NULL");
-      if (cd.getIsPrimaryKey())
-        queryBuffer.append(" PRIMARY KEY");
-      if (cd.getReferenceTable() != null)
-      {
-        queryBuffer.append(" REFERENCES ");
-        queryBuffer.append(cd.getReferenceTable());
-        queryBuffer.append('(');
-        queryBuffer.append(cd.getReferenceColumn());
-        queryBuffer.append(") ON DELETE");
-        if (cd.getReferenceCascade())
-          queryBuffer.append(" CASCADE");
-        else
-          queryBuffer.append(" RESTRICT");
-      }
+      appendDescription(queryBuffer,columnName,cd,false);
     }
     queryBuffer.append(')');
-
     performModification(queryBuffer.toString(),null,invalidateKeys);
+  }
 
+  protected static void appendDescription(StringBuilder queryBuffer, String columnName, ColumnDescription
cd, boolean forceNull)
+  {
+    queryBuffer.append(columnName);
+    queryBuffer.append(' ');
+    queryBuffer.append(cd.getTypeString());
+    if (forceNull || cd.getIsNull())
+      queryBuffer.append(" NULL");
+    else
+      queryBuffer.append(" NOT NULL");
+    if (cd.getIsPrimaryKey())
+      queryBuffer.append(" PRIMARY KEY");
+    if (cd.getReferenceTable() != null)
+    {
+      queryBuffer.append(" REFERENCES ");
+      queryBuffer.append(cd.getReferenceTable());
+      queryBuffer.append('(');
+      queryBuffer.append(cd.getReferenceColumn());
+      queryBuffer.append(") ON DELETE");
+      if (cd.getReferenceCascade())
+        queryBuffer.append(" CASCADE");
+      else
+        queryBuffer.append(" RESTRICT");
+    }
   }
 
   /** Perform a table alter operation.
@@ -282,7 +296,61 @@ public class DBInterfaceMySQL extends Da
     StringSet invalidateKeys)
     throws ManifoldCFException
   {
-    // MHL
+    beginTransaction(TRANSACTION_ENCLOSING);
+    try
+    {
+      if (columnDeleteList != null)
+      {
+        int i = 0;
+        while (i < columnDeleteList.size())
+        {
+          String columnName = columnDeleteList.get(i++);
+          performModification("ALTER TABLE "+tableName+" DROP "+columnName,null,invalidateKeys);
+        }
+      }
+
+      // Do the modifies.  This involves renaming each column to a temp column, then creating
a new one, then copying
+      if (columnModifyMap != null)
+      {
+        Iterator<String> iter = columnModifyMap.keySet().iterator();
+        while (iter.hasNext())
+        {
+          String columnName = iter.next();
+          ColumnDescription cd = columnModifyMap.get(columnName);
+          StringBuilder sb = new StringBuilder();
+          appendDescription(sb,columnName,cd,false);
+          performModification("ALTER TABLE "+tableName+" MODIFY "+sb.toString(),null,invalidateKeys);
+        }
+      }
+
+      // Now, do the adds
+      if (columnMap != null)
+      {
+        Iterator<String> iter = columnMap.keySet().iterator();
+        while (iter.hasNext())
+        {
+          String columnName = iter.next();
+          ColumnDescription cd = columnMap.get(columnName);
+          StringBuilder sb = new StringBuilder();
+          appendDescription(sb,columnName,cd,false);
+          performModification("ALTER TABLE "+tableName+" ADD "+sb.toString(),null,invalidateKeys);
+        }
+      }
+    }
+    catch (ManifoldCFException e)
+    {
+      signalRollback();
+      throw e;
+    }
+    catch (Error e)
+    {
+      signalRollback();
+      throw e;
+    }
+    finally
+    {
+      endTransaction();
+    }
   }
 
   /** Add an index to a table.
@@ -343,11 +411,12 @@ public class DBInterfaceMySQL extends Da
 
   /** Remove an index.
   *@param indexName is the name of the index to remove.
+  *@param tableName is the table the index belongs to.
   */
-  public void performRemoveIndex(String indexName)
+  public void performRemoveIndex(String indexName, String tableName)
     throws ManifoldCFException
   {
-    performModification("DROP INDEX "+indexName,null,null);
+    performModification("DROP INDEX "+indexName+" ON "+tableName,null,null);
   }
 
   /** Analyze a table.
@@ -387,19 +456,34 @@ public class DBInterfaceMySQL extends Da
     throws ManifoldCFException
   {
     // Connect to super database
+
     Database masterDatabase = new DBInterfaceMySQL(context,"mysql",adminUserName,adminPassword);
+
     List list = new ArrayList();
-    list.add("utf8");
-    masterDatabase.executeQuery("CREATE DATABASE "+databaseName+" CHARACTER SET ?",list,
-      null,invalidateKeys,null,false,0,null,null);
-    if (userName != null)
+    try
     {
-      list.clear();
-      list.add(userName);
-      list.add("localhost");
-      list.add(password);
-      masterDatabase.executeQuery("GRANT ALL ON "+databaseName+".* TO ?@? IDENTIFIED BY ?",list,
+      list.add("utf8");
+      masterDatabase.executeQuery("CREATE DATABASE "+databaseName+" CHARACTER SET ?",list,
         null,invalidateKeys,null,false,0,null,null);
+    } catch (ManifoldCFException e){
+      if (e.getErrorCode() != 4)
+	throw new ManifoldCFException(e.getMessage());
+    }
+    if (userName != null)
+    {
+      try {
+        list.clear();
+        list.add(userName);
+        list.add("localhost");
+        list.add(password);
+        masterDatabase.executeQuery("GRANT ALL ON "+databaseName+".* TO ?@? IDENTIFIED BY
?",list,
+          null,invalidateKeys,null,false,0,null,null);
+      } catch (ManifoldCFException e){
+        if (e.getErrorCode() != 4)
+          throw new ManifoldCFException(e.getMessage());
+      }
+      //masterDatabase.executeQuery("USE " + databaseName,null,
+      //  null,invalidateKeys,null,false,0,null,null);
     }
   }
 
@@ -414,6 +498,8 @@ public class DBInterfaceMySQL extends Da
     // Connect to super database
     Database masterDatabase = new DBInterfaceMySQL(context,"mysql",adminUserName,adminPassword);
     masterDatabase.executeQuery("DROP DATABASE "+databaseName,null,null,invalidateKeys,null,false,0,null,null);
+    //masterDatabase.executeQuery("USE mysql",null,
+    //  null,invalidateKeys,null,false,0,null,null);
   }
 
   /** Perform a general database modification query.
@@ -436,17 +522,48 @@ public class DBInterfaceMySQL extends Da
   public Map<String,ColumnDescription> getTableSchema(String tableName, StringSet cacheKeys,
String queryClass)
     throws ManifoldCFException
   {
-    IResultSet set = performQuery("DESCRIBE "+tableName,null,cacheKeys,queryClass);
+    StringBuilder query = new StringBuilder();
+    List list = new ArrayList();
+    list.add(databaseName.toUpperCase());
+    list.add(tableName.toUpperCase());
+    query.append("SELECT column_name, is_nullable, data_type, character_maximum_length ")
+      .append("FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=? AND TABLE_NAME=?");
+    IResultSet set = performQuery(query.toString(),list,cacheKeys,queryClass);
+    if (set.getRowCount() == 0)
+      return null;
+
+    query = new StringBuilder();
+    query.append("SELECT t1.column_name ")
+      .append("FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE t1, INFORMATION_SCHEMA.TABLE_CONSTRAINTS
t2 ")
+      .append("WHERE t1.CONSTRAINT_NAME=t2.CONSTRAINT_NAME AND t1.TABLE_NAME=t2.TABLE_NAME
AND ")
+      .append("t1.TABLE_SCHEMA=t2.TABLE_SCHEMA AND ")
+      .append("t1.TABLE_SCHEMA=? AND t1.TABLE_NAME=? AND t2.CONSTRAINT_TYPE='PRIMARY KEY'");
+    IResultSet primarySet = performQuery(query.toString(),list,cacheKeys,queryClass);
+    String primaryKey = null;
+    if (primarySet.getRowCount() != 0)
+      primaryKey = ((String)primarySet.getRow(0).getValue("column_name")).toLowerCase();
+    if (primaryKey == null)
+      primaryKey = "";
+    
     // Digest the result
     Map<String,ColumnDescription> rval = new HashMap<String,ColumnDescription>();
     int i = 0;
     while (i < set.getRowCount())
     {
       IResultRow row = set.getRow(i++);
-      String fieldName = row.getValue("Field").toString();
-      String type = row.getValue("Type").toString();
-      boolean isNull = row.getValue("Null").toString().equals("YES");
-      boolean isPrimaryKey = row.getValue("Key").toString().equals("PRI");
+      String fieldName = ((String)row.getValue("column_name")).toLowerCase();
+      String type = (String)row.getValue("data_type");
+      Long width = (Long)row.getValue("character_maximum_length");
+      String isNullable = (String)row.getValue("is_nullable");
+      boolean isPrimaryKey = primaryKey.equals(fieldName);
+      boolean isNull = isNullable.equals("YES");
+      String dataType;
+      if (type.equals("CHARACTER VARYING"))
+        dataType = "VARCHAR("+width.toString()+")";
+      else if (type.equals("CLOB"))
+        dataType = "LONGVARCHAR";
+      else
+        dataType = type;
       rval.put(fieldName,new ColumnDescription(type,isPrimaryKey,isNull,null,null,false));
     }
 
@@ -462,8 +579,61 @@ public class DBInterfaceMySQL extends Da
   public Map<String,IndexDescription> getTableIndexes(String tableName, StringSet cacheKeys,
String queryClass)
     throws ManifoldCFException
   {
-    // MHL
-    return null;
+    Map<String,IndexDescription> rval = new HashMap<String,IndexDescription>();
+
+    String query = "SELECT index_name,column_name,non_unique,seq_in_index FROM INFORMATION_SCHEMA.STATISTICS
"+
+      "WHERE TABLE_SCHEMA=? AND TABLE_NAME=? ORDER BY index_name,seq_in_index ASC";
+    List list = new ArrayList();
+    list.add(databaseName.toUpperCase());
+    list.add(tableName.toUpperCase());
+    IResultSet result = performQuery(query,list,cacheKeys,queryClass);
+    String lastIndexName = null;
+    List<String> indexColumns = null;
+    boolean isUnique = false;
+    int i = 0;
+    while (i < result.getRowCount())
+    {
+      IResultRow row = result.getRow(i++);
+      String indexName = ((String)row.getValue("index_name")).toLowerCase();
+      String columnName = ((String)row.getValue("column_name")).toLowerCase();
+      String nonUnique = row.getValue("non_unique").toString();
+      
+      if (lastIndexName != null && !lastIndexName.equals(indexName))
+      {
+        addIndex(rval,lastIndexName,isUnique,indexColumns);
+        lastIndexName = null;
+        indexColumns = null;
+        isUnique = false;
+      }
+      
+      if (lastIndexName == null)
+      {
+        lastIndexName = indexName;
+        indexColumns = new ArrayList<String>();
+        isUnique = false;
+      }
+      indexColumns.add(columnName);
+      isUnique = nonUnique.equals("0");
+    }
+    
+    if (lastIndexName != null)
+      addIndex(rval,lastIndexName,isUnique,indexColumns);
+    
+    return rval;
+  }
+
+  protected void addIndex(Map rval, String indexName, boolean isUnique, List<String>
indexColumns)
+  {
+    if (indexName.equals("primary"))
+      return;
+    String[] columnNames = new String[indexColumns.size()];
+    int i = 0;
+    while (i < columnNames.length)
+    {
+      columnNames[i] = indexColumns.get(i);
+      i++;
+    }
+    rval.put(indexName,new IndexDescription(isUnique,columnNames));
   }
 
   /** Get a database's tables.
@@ -541,6 +711,17 @@ public class DBInterfaceMySQL extends Da
     return executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,resultSpec,returnLimit);
   }
 
+  /** Construct a count clause.
+  * On most databases this will be COUNT(col), but on some the count needs to be cast to
a BIGINT, so
+  * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+  *@param column is the column string to be counted.
+  *@return the query chunk needed.
+  */
+  public String constructCountClause(String column)
+  {
+    return "COUNT("+column+")";
+  }
+
   /** Construct a regular-expression match clause.
   * This method builds both the text part of a regular-expression match.
   *@param column is the column specifier string.

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java?rev=1221538&r1=1221537&r2=1221538&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
(original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
Wed Dec 21 00:34:15 2011
@@ -496,8 +496,9 @@ public class DBInterfacePostgreSQL exten
 
   /** Remove an index.
   *@param indexName is the name of the index to remove.
+  *@param tableName is the table the index belongs to.
   */
-  public void performRemoveIndex(String indexName)
+  public void performRemoveIndex(String indexName, String tableName)
     throws ManifoldCFException
   {
     performModification("DROP INDEX "+indexName,null,null);
@@ -865,6 +866,17 @@ public class DBInterfacePostgreSQL exten
     }
   }
 
+  /** Construct a count clause.
+  * On most databases this will be COUNT(col), but on some the count needs to be cast to
a BIGINT, so
+  * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+  *@param column is the column string to be counted.
+  *@return the query chunk needed.
+  */
+  public String constructCountClause(String column)
+  {
+    return "COUNT("+column+")";
+  }
+
   /** Construct a regular-expression match clause.
   * This method builds both the text part of a regular-expression match.
   *@param column is the column specifier string.

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java?rev=1221538&r1=1221537&r2=1221538&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
(original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
Wed Dec 21 00:34:15 2011
@@ -145,8 +145,9 @@ public interface IDBInterface
 
   /** Remove an index.
   *@param indexName is the name of the index to remove.
+  *@param tableName is the table the index belongs to.
   */
-  public void performRemoveIndex(String indexName)
+  public void performRemoveIndex(String indexName, String tableName)
     throws ManifoldCFException;
 
   /** Analyze a table.
@@ -258,6 +259,14 @@ public interface IDBInterface
     int maxResults, ResultSpecification resultSpec, ILimitChecker returnLimit)
     throws ManifoldCFException;
 
+  /** Construct a count clause.
+  * On most databases this will be COUNT(col), but on some the count needs to be cast to
a BIGINT, so
+  * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+  *@param column is the column string to be counted.
+  *@return the query chunk needed.
+  */
+  public String constructCountClause(String column);
+  
   /** Construct a regular-expression match clause.
   * This method builds a regular-expression match expression.
   *@param column is the column specifier string.



Mime
View raw message