Added the StatementBuilder

This commit is contained in:
mathias 2021-08-26 17:59:06 +02:00
parent d41de8cfcc
commit 0772017633
No known key found for this signature in database
GPG Key ID: 8950DF62139C852A

View File

@ -0,0 +1,47 @@
package de.gnmyt.sqltoolkit.querybuilder;
public class StatementBuilder {
private StringBuilder query = new StringBuilder();
/**
* Basic constructor of the {@link StatementBuilder} with a prefilled text
* @param text The text you want to add
*/
public StatementBuilder(String text) {
append(text);
}
/**
* Basic constructor of the {@link StatementBuilder}
*/
public StatementBuilder() {
}
/**
* Adds a text to the query with spaces
* @param text The text you want to add
* @return this class
*/
public StatementBuilder append(String text) {
if (text.isEmpty()) return this;
if (!query.toString().isEmpty()) query.append(" ");
query.append(text);
return this;
}
/**
* Builds the query string
* @return the built string
*/
public String build() {
return query.toString();
}
@Override
public String toString() {
return build();
}
}