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 */ 017package org.apache.activemq.util; 018import java.lang.reflect.Method; 019import java.util.ArrayList; 020import java.util.Locale; 021import java.util.regex.Pattern; 022 023import org.apache.activemq.store.jdbc.Statements; 024 025 026public class GenerateJDBCStatements { 027 public static String returnStatement(Object statement){ 028 return ((String)statement).replace("<", "<").replace(">", ">"); 029 030 } 031 /** 032 * @param args 033 */ 034 public static void main(String[] args) throws Exception{ 035 Statements s=new Statements(); 036 s.setTablePrefix("ACTIVEMQ."); 037 String[] stats=s.getCreateSchemaStatements(); 038 System.out.println("<bean id=\"statements\" class=\"org.apache.activemq.store.jdbc.Statements\">"); 039 System.out.println("<property name=\"createSchemaStatements\">"); 040 System.out.println("<list>"); 041 for(int i=0; i<stats.length;i++){ 042 System.out.println("<value>"+stats[i]+"</value>"); 043 } 044 System.out.println("</list>"); 045 System.out.println("</property>"); 046 047 048 Method[] methods=Statements.class.getMethods(); 049 Pattern sPattern= Pattern.compile("get.*Statement$"); 050 Pattern setPattern= Pattern.compile("set.*Statement$"); 051 ArrayList<String> setMethods=new ArrayList<String>(); 052 for(int i=0; i<methods.length;i++){ 053 if(setPattern.matcher(methods[i].getName()).find()){ 054 setMethods.add(methods[i].getName()); 055 } 056 } 057 for(int i=0; i<methods.length;i++){ 058 if(sPattern.matcher(methods[i].getName()).find()&&setMethods.contains(methods[i].getName().replace("get","set"))){ 059 System.out.println("<property name=\""+methods[i].getName().substring(3,4).toLowerCase(Locale.ENGLISH)+methods[i].getName().substring(4)+"\" value=\""+returnStatement(methods[i].invoke(s, (Object[])null))+"\" />"); 060 } 061 } 062 //for a typo is not needed if removeMessageStatment typo is corrected 063 Pattern sPattern2= Pattern.compile("get.*Statment$"); 064 for(int i=0; i<methods.length;i++){ 065 if(sPattern2.matcher(methods[i].getName()).find()){ 066 System.out.println("<property name=\""+methods[i].getName().substring(3,4).toLowerCase(Locale.ENGLISH)+methods[i].getName().substring(4)+"\" value=\""+returnStatement(methods[i].invoke(s, (Object[])null))+"\" />"); 067 } 068 } 069 //end of generating because of typo 070 071 String[] statsDrop=s.getDropSchemaStatements(); 072 System.out.println("<property name=\"dropSchemaStatements\">"); 073 System.out.println("<list>"); 074 for(int i=0; i<statsDrop.length;i++){ 075 System.out.println("<value>"+statsDrop[i]+"</value>"); 076 } 077 System.out.println("</list>"); 078 System.out.println("</property>"); 079 System.out.println("</bean>"); 080 081 082 } 083 084}