ActiveMQ的各种表SQL的管理

阅读更多

      ActiveMQ为了方便的切换数据库,更为了深入了解ActiveMQSQL语句的详细的信息,可以通过Statements获取各种SQL语句。在ActivMQ第一次加载的时候,通过Statements生产响应的Spring Bean,加载到内存中。在ActiveMQ的管理和监控的时候,从内容获取相关的SQL语句,简化了ActiveMQ的消息的管理和监控。

 

package com.easyway.activemq.proxy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.regex.Pattern;

import org.apache.activemq.store.jdbc.Statements;

/**
 * 获取ActiveMQ中SQL相关的各种语句
 * @author longgangbai
 *
 */
public class ActiveMQSQLManager {
	 /**
	  * 
	  * @param statement
	  * @return
	  */
	 public static String returnStatement(Object statement){
	    	return ((String)statement).replace("<", "<").replace(">", ">");
	    	
	    }
		/**
		 * 
		 * @param args
		 */
		public static void main(String[] args) throws Exception{
	    	createSQLForActiveMQ();
		}
		/**
		 * 创建ActiveMQ中语句
		 * @throws IllegalAccessException
		 * @throws InvocationTargetException
		 */
		private static void createSQLForActiveMQ() throws IllegalAccessException, InvocationTargetException {
			Statements s=new Statements();
	    	//设置表的前缀
	    	s.setTablePrefix("ACTIVEMQ.");
	    	//获取Statements中创建的语句的集合
	    	String[] stats=s.getCreateSchemaStatements();
	    	//构建Statements的Bean
	    	System.out.println("");
	    	createSQLForTableIndex(stats);
	    	
	    	createSQLForActiveMQBussine(s);
	    	//end of generating because of typo
	    	createSQLOfDropTable(s);
	    	System.out.println("");
		}
		/**
		 * 创建ActiveMQ监控和管理使用的SQL语句
		 * @param s
		 * @throws IllegalAccessException
		 * @throws InvocationTargetException
		 */
		private static void createSQLForActiveMQBussine(Statements s) throws IllegalAccessException, InvocationTargetException {
			//获取Statements的方法
	    	Method[] methods=Statements.class.getMethods();
	    	//
	    	Pattern sPattern= Pattern.compile("get.*Statement$");
	    	Pattern setPattern= Pattern.compile("set.*Statement$");
	    	//获取存储Set方法
	    	ArrayList setMethods=new ArrayList();
	    	for(int i=0; i");
	    		}
	    	}
	    	//for a typo is not needed if removeMessageStatment typo is corrected
	    	//获取get的方法
	    	Pattern sPattern2= Pattern.compile("get.*Statment$");
	    	for(int i=0; i");
	    		}
	    	}
		}
		/**
		 * 创建表的创建语句和索引语句
		 * @param stats
		 */
		private static void createSQLForTableIndex(String[] stats) {
			//获取创建表和索引的时候的Schema语句
	    	System.out.println("");
	    	System.out.println("");
	    	for(int i=0; i"+stats[i]+"");
	    	}
	    	System.out.println("");
	    	System.out.println("");
		}
		/**
		 * 获取删除语句
		 * @param s
		 */
		private static void createSQLOfDropTable(Statements s) {
			//构建删除语句
	    	String[] statsDrop=s.getDropSchemaStatements();
	    	System.out.println("");
	    	System.out.println("");
	    	for(int i=0; i"+statsDrop[i]+"");
	    	}
	    	System.out.println("");
	    	System.out.println("");
		}
}

 

 

生成的spring bean如下:




CREATE TABLE ACTIVEMQ.ACTIVEMQ_MSGS(ID BIGINT NOT NULL, CONTAINER VARCHAR(250), MSGID_PROD VARCHAR(250), MSGID_SEQ BIGINT, EXPIRATION BIGINT, MSG BLOB, PRIMARY KEY ( ID ) )
CREATE INDEX ACTIVEMQ.ACTIVEMQ_MSGS_MIDX ON ACTIVEMQ.ACTIVEMQ_MSGS (MSGID_PROD,MSGID_SEQ)
CREATE INDEX ACTIVEMQ.ACTIVEMQ_MSGS_CIDX ON ACTIVEMQ.ACTIVEMQ_MSGS (CONTAINER)
CREATE INDEX ACTIVEMQ.ACTIVEMQ_MSGS_EIDX ON ACTIVEMQ.ACTIVEMQ_MSGS (EXPIRATION)
CREATE TABLE ACTIVEMQ.ACTIVEMQ_ACKS(CONTAINER VARCHAR(250) NOT NULL, SUB_DEST VARCHAR(250), CLIENT_ID VARCHAR(250) NOT NULL, SUB_NAME VARCHAR(250) NOT NULL, SELECTOR VARCHAR(250), LAST_ACKED_ID BIGINT, PRIMARY KEY ( CONTAINER, CLIENT_ID, SUB_NAME))
CREATE TABLE ACTIVEMQ.ACTIVEMQ_LOCK( ID BIGINT NOT NULL, TIME BIGINT, BROKER_NAME VARCHAR(250), PRIMARY KEY (ID) )
INSERT INTO ACTIVEMQ.ACTIVEMQ_LOCK(ID) VALUES (1)
ALTER TABLE ACTIVEMQ.ACTIVEMQ_MSGS ADD PRIORITY BIGINT
CREATE INDEX ACTIVEMQ.ACTIVEMQ_MSGS_PIDX ON ACTIVEMQ.ACTIVEMQ_MSGS (PRIORITY)
ALTER TABLE ACTIVEMQ.ACTIVEMQ_ACKS ADD PRIORITY BIGINT DEFAULT 5 NOT NULL
ALTER TABLE ACTIVEMQ.ACTIVEMQ_ACKS DROP PRIMARY KEY
ALTER TABLE ACTIVEMQ.ACTIVEMQ_ACKS ADD PRIMARY KEY (CONTAINER, CLIENT_ID, SUB_NAME, PRIORITY)


































DROP TABLE ACTIVEMQ.ACTIVEMQ_ACKS
DROP TABLE ACTIVEMQ.ACTIVEMQ_MSGS
DROP TABLE ACTIVEMQ.ACTIVEMQ_LOCK


 

你可能感兴趣的:(ActiveMQ的各种表SQL的管理)