
org.apache.beehive.controls.system.jdbc.parser.SqlSubstitutionFragment Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Header:$
*/
package org.apache.beehive.controls.system.jdbc.parser;
import org.apache.beehive.controls.api.context.ControlBeanContext;
import org.apache.beehive.controls.system.jdbc.TypeMappingsFactory;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
/**
* Represents a fragement from the SQL annotation's statement member which begins with '{sql:'.
* Substitution fragements are unique in that they are fully evaluated BEFORE a PreparedStatement
* is generated.
*
* Supported 'sql:' escapes are subst and fn. subst is the default mode, and will be used if 'sql: '
* is specified.
*
* The fn variant of this construct has a very ridgid syntax at this point. It must conform to:
*
*
* {sql:fn in(x,{y})}
*
*
* where the '{y}' could also be some literal term.
*/
public final class SqlSubstitutionFragment extends SqlFragmentContainer {
private boolean _hasParamValue = false;
/**
* Constructor for subst or function with no param substitution
*
* @param child An child which is contained in this fragment.
*/
protected SqlSubstitutionFragment(SqlFragment child) {
super();
addChild(child);
}
/**
* Constructor for a function which includes a ReflectionFragment
*
* @param lf A LiteralFragment which contains the text up to the parameter substitution.
* @param rf The ReflectionFragment containing the parameter substitution
* @param lff A LiteralFragment which contains any text which occures after the parameter substitution.
*/
protected SqlSubstitutionFragment(LiteralFragment lf, ReflectionFragment rf, LiteralFragment lff) {
super();
addChild(lf);
addChild(rf);
addChild(lff);
}
/**
* Always true for this fragment type
* @return true
*/
protected boolean isDynamicFragment() { return true; }
/**
* Will be true for this fragment type only if one of its children contains
* a complex sql fragment.
* @return true if there are param values which need to be retrieved.
*/
protected boolean hasParamValue() {
return _hasParamValue;
}
/**
* Get the parameter values from this fragment and its children. An SqlSubstitutionFragment
* only contains parameters if one of its children has a complex value type.
*
* @param context A ControlBeanContext instance
* @param m The annotated method
* @param args The method parameters
* @return Array of objects.
*/
protected Object[] getParameterValues(ControlBeanContext context, Method m, Object[] args) {
ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy