1 19 20 package org.apache.cayenne.dba.mysql; 21 22 import java.sql.DatabaseMetaData ; 23 import java.sql.ResultSet ; 24 import java.sql.SQLException ; 25 import java.sql.Statement ; 26 27 import org.apache.cayenne.dba.DbAdapter; 28 import org.apache.cayenne.dba.DbAdapterFactory; 29 30 36 public class MySQLSniffer implements DbAdapterFactory { 37 38 public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException { 39 String dbName = md.getDatabaseProductName(); 40 if (dbName == null || dbName.toUpperCase().indexOf("MYSQL") < 0) { 41 return null; 42 } 43 44 Statement statement = md.getConnection().createStatement(); 46 boolean supportFK = false; 47 48 try { 49 ResultSet rs = statement.executeQuery("SHOW VARIABLES LIKE 'table_type'"); 50 try { 51 if (rs.next()) { 52 String tableType = rs.getString(2); 53 supportFK = tableType != null 54 && tableType.toUpperCase().equals("INNODB"); 55 } 56 } 57 finally { 58 rs.close(); 59 } 60 } 61 finally { 62 statement.close(); 63 } 64 65 MySQLAdapter adapter = new MySQLAdapter(); 66 adapter.setSupportsFkConstraints(supportFK); 67 return adapter; 68 } 69 } 70 | Popular Tags |