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

sqlg3.runtime.QueryPiece Maven / Gradle / Ivy

Go to download

SQLG is a preprocessor and a library that uses code generation to simplify writing JDBC code

There is a newer version: 3.1
Show newest version
package sqlg3.runtime;

/**
 * Query piece encapsulating query text and query parameters.
 */
public final class QueryPiece {

    public final String sql;
    public final Parameter[] data;

    /**
     * Constructor.
     *
     * @param sql SQL text
     * @param data parameters (not null)
     */
    public QueryPiece(CharSequence sql, Parameter[] data) {
        this.sql = sql.toString();
        this.data = data;
    }

    /**
     * Concatenation of query pieces. Parameter that can contain nulls (they are ignored).
     * Line break is inserted between pieces.
     */
    public QueryPiece add(QueryPiece... that) {
        QueryBuilder buf = new QueryBuilder(this);
        for (QueryPiece piece : that) {
            buf.append(piece);
        }
        return buf.toQuery();
    }

    /**
     * Concatenation of query piece and string. Line break is inserted between them.
     */
    public QueryPiece add(CharSequence sql) {
        return new QueryPiece(QueryBuilder.add(this.sql, sql, true), data);
    }

    public String toString() {
        return sql;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy