cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r654473 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/
Date Thu, 08 May 2008 11:00:05 GMT
Author: aadamchik
Date: Thu May  8 04:00:04 2008
New Revision: 654473

URL: http://svn.apache.org/viewvc?rev=654473&view=rev
Log:
CAY-1050 MySQLSniffer should configure created adapter to use MySQL default engine for tables

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSniffer.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=654473&r1=654472&r2=654473&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Thu May  8 04:00:04 2008
@@ -39,6 +39,7 @@
 CAY-1035 Replace QueryMetadata String cache policies with an enum
 CAY-1038 Upgrade to Ashwood 2.0
 CAY-1049 Refactor QueryAssembler/SelectTranslator
+CAY-1050 MySQLSniffer should configure created adapter to use MySQL default engine for tables
 
 Bug fixes since M3:
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java?rev=654473&r1=654472&r2=654473&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java
Thu May  8 04:00:04 2008
@@ -65,12 +65,18 @@
  * @author Andrus Adamchik
  */
 public class MySQLAdapter extends JdbcAdapter {
+    
+    final static String DEFAULT_STORAGE_ENGINE = "InnoDB";
+
+    protected String storageEngine;
 
     public MySQLAdapter() {
+
         // init defaults
-        this.setSupportsFkConstraints(false);
-        this.setSupportsUniqueConstraints(true);
-        this.setSupportsGeneratedKeys(true);
+        this.storageEngine = DEFAULT_STORAGE_ENGINE;
+        setSupportsFkConstraints(true);
+        setSupportsUniqueConstraints(true);
+        setSupportsGeneratedKeys(true);
     }
 
     /**
@@ -210,8 +216,11 @@
     @Override
     public String createTable(DbEntity entity) {
         String ddlSQL = super.createTable(entity);
-        // force InnoDB tables - by default constraints are enabled
-        ddlSQL += " ENGINE=InnoDB";
+        
+        if (storageEngine != null) {
+            ddlSQL += " ENGINE=" + storageEngine;
+        }
+
         return ddlSQL;
     }
 
@@ -287,7 +296,7 @@
             sqlBuffer.append(" AUTO_INCREMENT");
         }
     }
-    
+
     @Override
     public MergerFactory mergerFactory() {
         return new MySQLMergerFactory();
@@ -304,4 +313,18 @@
             }
         }
     }
+
+    /**
+     * @since 3.0
+     */
+    public String getStorageEngine() {
+        return storageEngine;
+    }
+
+    /**
+     * @since 3.0
+     */
+    public void setStorageEngine(String engine) {
+        this.storageEngine = engine;
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSniffer.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSniffer.java?rev=654473&r1=654472&r2=654473&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSniffer.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSniffer.java
Thu May  8 04:00:04 2008
@@ -44,14 +44,21 @@
         // if InnoDB is used as a default engine, allow PK
         Statement statement = md.getConnection().createStatement();
         boolean supportFK = false;
+        String adapterStorageEngine = MySQLAdapter.DEFAULT_STORAGE_ENGINE;
 
         try {
+            // http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html
+            // per link above "table type" concept is deprecated in favor of "storage
+            // engine". Not sure if we should check "storage_engine" variable and in what
+            // version of MySQL it got introduced...
             ResultSet rs = statement.executeQuery("SHOW VARIABLES LIKE 'table_type'");
             try {
                 if (rs.next()) {
-                    String tableType = rs.getString(2);
-                    supportFK = tableType != null
-                            && tableType.toUpperCase().equals("INNODB");
+                    String storageEngine = rs.getString(2);
+                    if (storageEngine != null) {
+                        adapterStorageEngine = storageEngine;
+                        supportFK = storageEngine.toUpperCase().equals("INNODB");
+                    }
                 }
             }
             finally {
@@ -64,6 +71,7 @@
 
         MySQLAdapter adapter = new MySQLAdapter();
         adapter.setSupportsFkConstraints(supportFK);
+        adapter.setStorageEngine(adapterStorageEngine);
         return adapter;
     }
 }



Mime
View raw message