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 *
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 String typeStatement = "ENGINE";
044
045 public void setStatements(Statements statements) {
046 String type = engineType.toUpperCase();
047 if( !type.equals(INNODB) && !type.equals(NDBCLUSTER) ) {
048 // Don't use LOCK TABLE for the INNODB and NDBCLUSTER engine types...
049 statements.setLockCreateStatement("LOCK TABLE " + statements.getFullLockTableName() + " WRITE");
050 }
051
052 statements.setBinaryDataType("LONGBLOB");
053
054
055 String typeClause = typeStatement + "=" + type;
056 if( type.equals(NDBCLUSTER) ) {
057 // in the NDBCLUSTER case we will create as INNODB and then alter to NDBCLUSTER
058 typeClause = typeStatement + "=" + INNODB;
059 }
060
061 // Update the create statements so they use the right type of engine
062 String[] s = statements.getCreateSchemaStatements();
063 for (int i = 0; i < s.length; i++) {
064 if( s[i].startsWith("CREATE TABLE")) {
065 s[i] = s[i]+ " " + typeClause;
066 }
067 }
068
069 if( type.equals(NDBCLUSTER) ) {
070 // Add the alter statements.
071 ArrayList<String> l = new ArrayList<String>(Arrays.asList(s));
072 l.add("ALTER TABLE "+statements.getFullMessageTableName()+" ENGINE="+NDBCLUSTER);
073 l.add("ALTER TABLE "+statements.getFullAckTableName()+" ENGINE="+NDBCLUSTER);
074 l.add("ALTER TABLE "+statements.getFullLockTableName()+" ENGINE="+NDBCLUSTER);
075 l.add("FLUSH TABLES");
076 s = l.toArray(new String[l.size()]);
077 statements.setCreateSchemaStatements(s);
078 }
079
080 super.setStatements(statements);
081 }
082
083 public String getEngineType() {
084 return engineType;
085 }
086
087 public void setEngineType(String engineType) {
088 this.engineType = engineType;
089 }
090
091 public String getTypeStatement() {
092 return typeStatement;
093 }
094
095 public void setTypeStatement(String typeStatement) {
096 this.typeStatement = typeStatement;
097 }
098 }