1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package org.apache.synapse.mediators.db; 21 22 import org.apache.synapse.SynapseException; 23 import org.apache.synapse.util.xpath.SynapseXPath; 24 25 import java.sql.Types; 26 import java.util.ArrayList; 27 import java.util.HashMap; 28 import java.util.List; 29 import java.util.Map; 30 31 /** 32 * Encapsulates an SQL statement, one or more parameters for it and optionally some information 33 * about results that one would like to read. 34 */ 35 public class Statement { 36 37 String rawStatement = null; 38 List parameters = new ArrayList(); 39 Map resultsMap = new HashMap(); 40 41 public Statement(String rawStatement) { 42 this.rawStatement = rawStatement; 43 } 44 45 public String getRawStatement() { 46 return rawStatement; 47 } 48 49 public void addParameter(String propertyName, SynapseXPath xpath, String type){ 50 parameters.add(new Parameter(propertyName, xpath, type)); 51 } 52 53 public void addResult(String propertyName, String column) { 54 resultsMap.put(propertyName, column); 55 } 56 57 public List getParameters() { 58 return parameters; 59 } 60 61 public Map getResultsMap() { 62 return resultsMap; 63 } 64 65 public class Parameter { 66 String propertyName = null; 67 SynapseXPath xpath = null; 68 int type = 0; 69 70 Parameter(String value, SynapseXPath xpath, String type) { 71 72 this.propertyName = value; 73 this.xpath = xpath; 74 if ("CHAR".equals(type)) { 75 this.type = Types.CHAR; 76 } else if ("VARCHAR".equals(type)) { 77 this.type = Types.VARCHAR; 78 } else if ("LONGVARCHAR".equals(type)) { 79 this.type = Types.LONGVARCHAR; 80 } else if ("NUMERIC".equals(type)) { 81 this.type = Types.NUMERIC; 82 } else if ("DECIMAL".equals(type)) { 83 this.type = Types.DECIMAL; 84 } else if ("BIT".equals(type)) { 85 this.type = Types.BIT; 86 } else if ("TINYINT".equals(type)) { 87 this.type = Types.TINYINT; 88 } else if ("SMALLINT".equals(type)) { 89 this.type = Types.SMALLINT; 90 } else if ("INTEGER".equals(type)) { 91 this.type = Types.INTEGER; 92 } else if ("BIGINT".equals(type)) { 93 this.type = Types.BIGINT; 94 } else if ("REAL".equals(type)) { 95 this.type = Types.REAL; 96 } else if ("FLOAT".equals(type)) { 97 this.type = Types.FLOAT; 98 } else if ("DOUBLE".equals(type)) { 99 this.type = Types.DOUBLE; 100 } else if ("DATE".equals(type)) { 101 this.type = Types.DATE; 102 } else if ("TIME".equals(type)) { 103 this.type = Types.TIME; 104 } else if ("TIMESTAMP".equals(type)) { 105 this.type = Types.TIMESTAMP; 106 } else { 107 throw new SynapseException("Unknown or unsupported JDBC type : " + type); 108 } 109 } 110 111 public String getPropertyName() { 112 return propertyName; 113 } 114 115 public SynapseXPath getXpath() { 116 return xpath; 117 } 118 119 public int getType() { 120 return type; 121 } 122 } 123 } 124