001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.activemq.store.jdbc.adapter; 018 019 import java.util.ArrayList; 020 import java.util.Arrays; 021 022 import org.apache.activemq.store.jdbc.Statements; 023 024 /** 025 * 026 * @org.apache.xbean.XBean element="mysql-jdbc-adapter" 027 * @version $Revision: 820032 $ 028 */ 029 public class MySqlJDBCAdapter extends DefaultJDBCAdapter { 030 031 // The transactional types.. 032 public static final String INNODB = "INNODB"; 033 public static final String NDBCLUSTER = "NDBCLUSTER"; 034 public static final String BDB = "BDB"; 035 036 // The non transactional types.. 037 public static final String MYISAM = "MYISAM"; 038 public static final String ISAM = "ISAM"; 039 public static final String MERGE = "MERGE"; 040 public static final String HEAP = "HEAP"; 041 042 String engineType = INNODB; 043 044 public void setStatements(Statements statements) { 045 String type = engineType.toUpperCase(); 046 if( !type.equals(INNODB) && !type.equals(NDBCLUSTER) ) { 047 // Don't use LOCK TABLE for the INNODB and NDBCLUSTER engine types... 048 statements.setLockCreateStatement("LOCK TABLE " + statements.getFullLockTableName() + " WRITE"); 049 } 050 051 statements.setBinaryDataType("LONGBLOB"); 052 053 054 String typeClause = " TYPE="+type; 055 if( type.equals(NDBCLUSTER) ) { 056 // in the NDBCLUSTER case we will create as INNODB and then alter to NDBCLUSTER 057 typeClause = " TYPE="+INNODB; 058 } 059 060 // Update the create statements so they use the right type of engine 061 String[] s = statements.getCreateSchemaStatements(); 062 for (int i = 0; i < s.length; i++) { 063 if( s[i].startsWith("CREATE TABLE")) { 064 s[i] = s[i]+typeClause; 065 } 066 } 067 068 if( type.equals(NDBCLUSTER) ) { 069 // Add the alter statements. 070 ArrayList<String> l = new ArrayList<String>(Arrays.asList(s)); 071 l.add("ALTER TABLE "+statements.getFullMessageTableName()+" ENGINE="+NDBCLUSTER); 072 l.add("ALTER TABLE "+statements.getFullAckTableName()+" ENGINE="+NDBCLUSTER); 073 l.add("ALTER TABLE "+statements.getFullLockTableName()+" ENGINE="+NDBCLUSTER); 074 l.add("FLUSH TABLES"); 075 s = l.toArray(new String[l.size()]); 076 statements.setCreateSchemaStatements(s); 077 } 078 079 super.setStatements(statements); 080 } 081 082 public String getEngineType() { 083 return engineType; 084 } 085 086 public void setEngineType(String engineType) { 087 this.engineType = engineType; 088 } 089 }