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: *
017: * $Header:$
018: */
019:
020: package org.apache.beehive.controls.system.jdbc.parser;
021:
022: import org.apache.beehive.controls.api.context.ControlBeanContext;
023: import org.apache.beehive.controls.system.jdbc.TypeMappingsFactory;
024:
025: import java.lang.reflect.Method;
026:
027: /**
028: * The abstract base class for fragments generated during parsing.
029: */
030: public abstract class SqlFragment {
031:
032: /**
033: * True if this fragment shouldn't be cached since the prepared statement may change on each invocation.
034: * @return true if this fragment shouldn't be cached by the parser
035: */
036: boolean isDynamicFragment() {
037: return false;
038: }
039:
040: /**
041: * Does this fragment contain a parameter value for a prepared statement
042: * @return true if this fragement doesn't contain a prepared statement value.
043: */
044: boolean hasParamValue() {
045: return false;
046: }
047:
048: /**
049: * True if this fragment evaluates to a JdbcControl.ComplexSqlFragment, i.e.
050: * a value type which needs additional evaluation after reflection.
051: *
052: * @param context Control bean context.
053: * @param method Method.
054: * @param args Method args.
055: * @return true if evaluates to a complex sql fragment.
056: */
057: protected boolean hasComplexValue(ControlBeanContext context,
058: Method method, Object[] args) {
059: return false;
060: }
061:
062: /**
063: * Get the SQL data type for the parameter value contained within this fragment.
064: * @return The SQL data type for this fragment.
065: */
066: int getParamSqlDataType() {
067: return TypeMappingsFactory.TYPE_UNKNOWN;
068: }
069:
070: /**
071: * Get the prepared statement parameter value contained within this fragment.
072: *
073: * @param context A ControlBeanContext instance
074: * @param method The annotated method
075: * @param args The method's parameters
076: * @return null if this fragment doesn't contain a parameter value.
077: */
078: Object[] getParameterValues(ControlBeanContext context,
079: Method method, Object[] args) {
080: return null;
081: }
082:
083: /**
084: * Get the text for a prepared statement generated by this fragment.
085: * @param context A ControlBeanContext instance
086: * @param method The annotated method
087: * @param args The method's parameters
088: * @return A String containing the prepared statement text generated by this fragment
089: */
090: abstract String getPreparedStatementText(
091: ControlBeanContext context, Method method, Object[] args);
092:
093: /**
094: * Must be implemented for JUnit testing.
095: * @return The String value of this fragment.
096: */
097: public String toString() {
098: assert false : "Classes which extend SqlFragment must implement toString()";
099: return null;
100: }
101: }
|