Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » store » jdbc » adapter » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.activemq.store.jdbc.adapter;
   18   
   19   import java.util.ArrayList;
   20   import java.util.Arrays;
   21   
   22   import org.apache.activemq.store.jdbc.Statements;
   23   
   24   /**
   25    * 
   26    * @org.apache.xbean.XBean element="mysql-jdbc-adapter"
   27    * @version $Revision: 820032 $
   28    */
   29   public class MySqlJDBCAdapter extends DefaultJDBCAdapter {
   30   
   31       // The transactional types..
   32       public static final String INNODB = "INNODB";
   33       public static final String NDBCLUSTER = "NDBCLUSTER";
   34       public static final String BDB = "BDB";
   35   
   36       // The non transactional types..
   37       public static final String MYISAM = "MYISAM";
   38       public static final String ISAM = "ISAM";
   39       public static final String MERGE = "MERGE";
   40       public static final String HEAP = "HEAP";
   41   
   42       String engineType = INNODB;
   43   
   44       public void setStatements(Statements statements) {
   45           String type = engineType.toUpperCase();
   46           if( !type.equals(INNODB) &&  !type.equals(NDBCLUSTER) ) {
   47               // Don't use LOCK TABLE for the INNODB and NDBCLUSTER engine types...
   48               statements.setLockCreateStatement("LOCK TABLE " + statements.getFullLockTableName() + " WRITE");
   49           }
   50   
   51           statements.setBinaryDataType("LONGBLOB");
   52           
   53           
   54           String typeClause = " TYPE="+type;
   55           if( type.equals(NDBCLUSTER) ) {
   56               // in the NDBCLUSTER case we will create as INNODB and then alter to NDBCLUSTER
   57               typeClause = " TYPE="+INNODB;
   58           }
   59           
   60           // Update the create statements so they use the right type of engine 
   61           String[] s = statements.getCreateSchemaStatements();
   62           for (int i = 0; i < s.length; i++) {
   63               if( s[i].startsWith("CREATE TABLE")) {
   64                   s[i] = s[i]+typeClause;
   65               }
   66           }
   67           
   68           if( type.equals(NDBCLUSTER) ) {
   69               // Add the alter statements.
   70               ArrayList<String> l = new ArrayList<String>(Arrays.asList(s));
   71               l.add("ALTER TABLE "+statements.getFullMessageTableName()+" ENGINE="+NDBCLUSTER);
   72               l.add("ALTER TABLE "+statements.getFullAckTableName()+" ENGINE="+NDBCLUSTER);
   73               l.add("ALTER TABLE "+statements.getFullLockTableName()+" ENGINE="+NDBCLUSTER);
   74               l.add("FLUSH TABLES");
   75               s = l.toArray(new String[l.size()]);
   76               statements.setCreateSchemaStatements(s);
   77           }        
   78           
   79           super.setStatements(statements);
   80       }
   81   
   82       public String getEngineType() {
   83           return engineType;
   84       }
   85   
   86       public void setEngineType(String engineType) {
   87           this.engineType = engineType;
   88       }
   89   }

Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » store » jdbc » adapter » [javadoc | source]