All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mybatis.scripting.thymeleaf.processor.BindVariableRender Maven / Gradle / Ivy

The newest version!
/*
 *    Copyright 2018-2022 the original author or authors.
 *
 *    Licensed 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
 *
 *       https://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.
 */
package org.mybatis.scripting.thymeleaf.processor;

import java.util.function.UnaryOperator;

import org.mybatis.scripting.thymeleaf.support.spring.SpringNamedParameterBindVariableRender;

/**
 * The interface for rendering a bind variable. 
* If you want to customize a default {@code BindVariableRender}, you implements class of this interface and you need to * specify the 'dialect.bind-variable-render' property of mybatis-thymeleaf.properties.
*
* e.g.) Implementation class: * *
 * package com.example;
 *
 * // ...
 * public class R2dbcMySQLBindVariableRender extends EnclosingBasedBindVariableRender {
 *   public R2dbcMySQLBindVariableRender() {
 *     super("?", ""); // Render '?...' (e.g. ?id)
 *   }
 * }
 * 
* *
* e.g.) Configuration file (mybatis-thymeleaf.properties): * *
 * dialect.bind-variable-render = com.example.MyBindVariableRender
 * 
* * @author Kazuki Shimizu * * @version 1.0.2 */ @FunctionalInterface public interface BindVariableRender extends UnaryOperator { /** * {@inheritDoc} * * @see #render(String) */ @Override default String apply(String name) { return render(name); } /** * Render a bind variable. * * @param name * a bind variable name * * @return a bind variable */ String render(String name); /** * The built-in bind variable renders. */ enum BuiltIn implements BindVariableRender { /** * The render for MyBatis core named parameter format(.e.g {@literal #{id}}). *

* This is default. *

*/ MYBATIS(name -> "#{" + name + "}"), /** * The render for Spring JDBC named parameter format(.e.g {@literal :id}). */ SPRING_NAMED_PARAMETER(new SpringNamedParameterBindVariableRender()); private final BindVariableRender delegate; BuiltIn(BindVariableRender delegate) { this.delegate = delegate; } /** * {@inheritDoc} */ @Override public String render(String name) { return delegate.render(name); } /** * Get a type of the actual {@link BindVariableRender}. * * @return a type of delegating {@link BindVariableRender} */ public Class getType() { return delegate.getClass(); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy