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

com.github.quintans.jdbc.RawSql Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.github.quintans.jdbc;

import java.util.List;
import java.util.Map;

/**
 * Class that wrapps the convertion from a SQL with named parameters to a JDBC standard SQL
 * 
 * @author paulo.quintans
 *
 */
public class RawSql {
    private ParsedSql parsedSql;
    private String sql;


	/**
	 * converts SQL with named parameters to JDBC standard sql
	 *
	 * @param sql The SQL to be converted
	 * @return The {@link RawSql} with the result
	 */
	public static RawSql of(String sql) {
		ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
		RawSql rawSql = new RawSql(parsedSql);
		return rawSql;
	}
    
	public RawSql(ParsedSql parsedSql) {
        this.parsedSql = parsedSql;
        this.sql = NamedParameterUtils.substituteNamedParameters(parsedSql, null);
    }

	/**
	 * getter for the JDBC SQL
	 * @return
	 */
	public String getSql() {
		return sql;
	}


	/**
	 * getter for the values
	 * @return
	 */
	public List getNames() {
		return parsedSql.getParameterNames();
	}

	public String getOriginalSql() {
        return parsedSql.getOriginalSql();
    }
	
    public Object[] buildValues(Map params){
        return NamedParameterUtils.buildValueArray(parsedSql, params);
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy