1 18 19 package org.apache.beehive.controls.system.jdbc.parser; 20 21 import org.apache.beehive.controls.api.context.ControlBeanContext; 22 import org.apache.beehive.controls.system.jdbc.TypeMappingsFactory; 23 24 import java.lang.reflect.Method ; 25 26 42 public class SqlSubstitutionFragment extends SqlFragmentContainer { 43 44 49 SqlSubstitutionFragment(SqlFragment child) { 50 super(); 51 addChild(child); 52 } 53 54 61 SqlSubstitutionFragment(LiteralFragment lf, ReflectionFragment rf, LiteralFragment lff) { 62 super(); 63 addChild(lf); 64 addChild(rf); 65 addChild(lff); 66 } 67 68 72 boolean isDynamicFragment() { return true; } 73 74 79 boolean hasParamValue() { return false; } 80 81 89 String getPreparedStatementText(ControlBeanContext context, Method m, Object [] args) { 90 91 StringBuilder sb = new StringBuilder (); 92 for (SqlFragment frag : _children) { 93 if (frag.hasParamValue()) { 94 Object [] pValues = frag.getParameterValues(context, m, args); 95 for (Object o : pValues) { 96 sb.append(processSqlParams(o)); 97 } 98 } else { 99 sb.append(frag.getPreparedStatementText(context, m, args)); 100 } 101 } 102 return sb.toString(); 103 } 104 105 106 108 109 116 private String processSqlParams(Object value) { 117 118 Object [] arr = null; 119 if (value != null) { 120 arr = TypeMappingsFactory.toObjectArray(value); 121 } 122 123 if (value == null || (arr != null && arr.length == 0)) { 124 return ""; 125 } else if (arr != null) { 126 StringBuilder result = new StringBuilder (); 127 for (int i = 0; i < arr.length; i++) { 128 if (i > 0) { 129 result.append(','); 130 result.append(arr[i].toString()); 131 } else { 132 result.append(arr[i].toString()); 133 } 134 } 135 return result.toString(); 136 } else { 137 return value.toString(); 138 } 139 } 140 } 141 | Popular Tags |