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

io.github.wujun728.sql.node.TextSqlNode Maven / Gradle / Ivy

The newest version!
package io.github.wujun728.sql.node;

import java.util.Set;

import io.github.wujun728.sql.context.Context;
import io.github.wujun728.sql.token.TokenHandler;
import io.github.wujun728.sql.token.TokenParser;


public class TextSqlNode implements SqlNode {

    String text;

    public TextSqlNode(String text) {
        this.text = text;
    }

    @Override
    public void apply(Context context) {
        //解析常量值 ${xxx}
        TokenParser tokenParser = new TokenParser("${", "}", new TokenHandler() {
            @Override
            public String handleToken(String paramName) {
                Object value = context.getOgnlValue(paramName);
                return value == null ? "" : value.toString();
            }
        });
        String s = tokenParser.parse(text);


        context.appendSql(s);

    }

    @Override
    public void applyParameter(Set set) {
        TokenParser tokenParser = new TokenParser("${", "}", new TokenHandler() {
            @Override
            public String handleToken(String paramName) {
                set.add(paramName);
                return paramName;
            }
        });
        String s = tokenParser.parse(text);

        TokenParser tokenParser2 = new TokenParser("#{", "}", new TokenHandler() {
            @Override
            public String handleToken(String paramName) {
                set.add(paramName);
                return paramName;
            }
        });
        tokenParser2.parse(s);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy