NamedParamObject.java

  1. /*
  2. Copyright (c) 2015 James Ahlborn

  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at

  6.     http://www.apache.org/licenses/LICENSE-2.0

  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */

  13. package com.healthmarketscience.sqlbuilder.custom;

  14. import java.io.IOException;
  15. import com.healthmarketscience.common.util.AppendableExt;
  16. import com.healthmarketscience.sqlbuilder.ValidationContext;
  17. import com.healthmarketscience.sqlbuilder.Expression;

  18. /**
  19.  * SqlObject expression which inserts a "named" parameter like {@code
  20.  * ":<name>"}.  This syntax is used by various custom SQL or SQL-like
  21.  * frameworks (e.g. Hibernate's HQL).
  22.  *
  23.  * @author James Ahlborn
  24.  */
  25. public class NamedParamObject extends Expression
  26. {
  27.   private String _name;

  28.   public NamedParamObject(String name)
  29.   {
  30.     _name = name;
  31.   }

  32.   @Override
  33.   protected void collectSchemaObjects(ValidationContext vContext) {
  34.   }
  35.  
  36.   @Override
  37.   public void appendTo(AppendableExt app) throws IOException {
  38.     app.append(':').append(_name);
  39.   }
  40. }