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 org.apache.activemq.store.jdbc.Statements;
020    
021    /**
022     * Axion specific Adapter.
023     * 
024     * Axion does not seem to support ALTER statements or sub-selects.  This means:
025     * - We cannot auto upgrade the schema was we roll out new versions of ActiveMQ
026     * - We cannot delete durable sub messages that have be acknowledged by all consumers.
027     * 
028     * @org.apache.xbean.XBean element="axionJDBCAdapter"
029     * 
030     */
031    public class AxionJDBCAdapter extends StreamJDBCAdapter {
032    
033        @Override
034        public void setStatements(Statements statements) {
035            
036            String[] createStatements = new String[]{
037                "CREATE TABLE " + statements.getFullMessageTableName() + "("
038                    + "ID " + statements.getSequenceDataType() + " NOT NULL"
039                    + ", CONTAINER " + statements.getContainerNameDataType()
040                    + ", MSGID_PROD " + statements.getMsgIdDataType()
041                    + ", MSGID_SEQ " + statements.getSequenceDataType()
042                    + ", EXPIRATION " + statements.getLongDataType()
043                    + ", MSG " + (statements.isUseExternalMessageReferences() ? statements.getStringIdDataType() : statements.getBinaryDataType())
044                    + ", PRIMARY KEY ( ID ) )",                          
045                "CREATE INDEX " + statements.getFullMessageTableName() + "_MIDX ON " + statements.getFullMessageTableName() + " (MSGID_PROD,MSGID_SEQ)",
046                "CREATE INDEX " + statements.getFullMessageTableName() + "_CIDX ON " + statements.getFullMessageTableName() + " (CONTAINER)",                                       
047                "CREATE INDEX " + statements.getFullMessageTableName() + "_EIDX ON " + statements.getFullMessageTableName() + " (EXPIRATION)",                 
048                "CREATE TABLE " + statements.getFullAckTableName() + "("
049                    + "CONTAINER " + statements.getContainerNameDataType() + " NOT NULL"
050                    + ", SUB_DEST " + statements.getContainerNameDataType()
051                    + ", CLIENT_ID " + statements.getStringIdDataType() + " NOT NULL"
052                    + ", SUB_NAME " + statements.getStringIdDataType() + " NOT NULL"
053                    + ", SELECTOR " + statements.getStringIdDataType()
054                    + ", LAST_ACKED_ID " + statements.getSequenceDataType()
055                    + ", PRIMARY KEY ( CONTAINER, CLIENT_ID, SUB_NAME))"
056            };
057            statements.setCreateSchemaStatements(createStatements);
058            statements.setLongDataType("LONG");
059            statements.setSequenceDataType("LONG");
060            
061            super.setStatements(statements);
062        }
063        
064    }