Added the QueryBuilder

This commit is contained in:
mathias 2021-08-26 16:21:51 +02:00
parent a752a2269a
commit fb6b1d3a7d
No known key found for this signature in database
GPG Key ID: 8950DF62139C852A

View File

@ -0,0 +1,47 @@
package de.gnmyt.sqltoolkit.querybuilder;
import de.gnmyt.sqltoolkit.drivers.MySQLConnection;
import org.slf4j.Logger;
public class QueryBuilder {
private static final Logger LOG = MySQLConnection.LOG;
private AbstractQuery query;
/**
* Basic constructor of the {@link QueryBuilder}
*
* @param queryType The type of the query you want to generate
*/
public QueryBuilder(Class<? extends AbstractQuery> queryType) {
try {
query = queryType.newInstance();
} catch (Exception e) {
LOG.error("Could not initialize query: " + e.getMessage());
}
}
/**
* Adds a parameter to the building list
*
* @param type The type you want to use
* @param value The value of the type
* @return this class
*/
public QueryBuilder addParameter(QueryParameter type, Object value) {
query.addParameter(type, value);
return this;
}
/**
* Builds the query
*
* @return the built query
*/
public SQLQuery build() {
return query.build();
}
}