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

org.nutz.plugins.sqltpl.impl.jetbrick.JetbrickSqlTpl Maven / Gradle / Ivy

There is a newer version: 1.r.69.v20220215
Show newest version
package org.nutz.plugins.sqltpl.impl.jetbrick;

import java.io.StringWriter;

import org.nutz.dao.sql.Sql;
import org.nutz.plugins.sqltpl.VarSetMap;

import jetbrick.template.JetEngine;
import jetbrick.template.JetTemplate;

/**
 * jetbrick-template实现的SqlTpl
 * @author wendal([email protected])
 *
 */
public class JetbrickSqlTpl {

    protected static JetEngine engine;
    
    public static Sql c(Sql sql) {
        JetTemplate template = engine().createTemplate(sql.getSourceSql());
        StringWriter sw = new StringWriter();
        template.render(VarSetMap.asCtx(sql), sw);
        sql.setSourceSql(sw.toString());
        return sql;
    }
    
    public static JetEngine engine() {
        if (engine == null)
            engine = JetEngine.create();
        return engine;
    }
    
    public static void setEngine(JetEngine engine) {
        JetbrickSqlTpl.engine = engine;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy