use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.
the class SimpleRow method toString.
@Override
public String toString() {
StatementBuilder buff = new StatementBuilder("( /* key:");
buff.append(getKey());
if (version != 0) {
buff.append(" v:" + version);
}
buff.append(" */ ");
for (Value v : data) {
buff.appendExceptFirst(", ");
buff.append(v == null ? "null" : v.getTraceSQL());
}
return buff.append(')').toString();
}
use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.
the class JdbcQueryWorker method doWork.
@Override
public ResultSet doWork() {
Connection conn = null;
PreparedStatement stmt = null;
try {
DataSource dataSource = getDataSource();
Optional optional = Optional.build().shardName(shardName).readOnly(true);
if (trace.isDebugEnabled()) {
trace.debug("{0} Fetching connection from DataSource.", shardName);
}
conn = session.applyConnection(dataSource, optional);
attach(conn);
if (trace.isDebugEnabled()) {
trace.debug("{0} Preparing: {};", shardName, sql);
}
stmt = conn.prepareStatement(sql);
attach(stmt);
applyQueryTimeout(stmt);
applyMaxRows(stmt);
if (params != null) {
for (int i = 0, size = params.size(); i < size; i++) {
Value v = params.get(i);
v.set(stmt, i + 1);
if (trace.isDebugEnabled()) {
trace.debug("{0} setParameter: {1} -> {2};", shardName, i + 1, v.getSQL());
}
}
}
ResultSet result = stmt.executeQuery();
attach(result);
return result;
} catch (SQLException e) {
StatementBuilder buff = new StatementBuilder();
buff.append(shardName).append(" executing executeQuery error:").append(sql);
if (params != null && params.size() > 0) {
buff.append("\n{");
int i = 1;
for (Value v : params) {
buff.appendExceptFirst(", ");
buff.append(i++).append(": ").append(v.getSQL());
}
buff.append('}');
}
buff.append(';');
trace.error(e, buff.toString());
throw wrapException(sql, e);
}
}
use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.
the class AlterTableAddConstraintExecutor method doBuildUnique.
private String doBuildUnique(String forTable, String uniqueType) {
StatementBuilder buff = new StatementBuilder("ALTER TABLE ");
buff.append(identifier(forTable)).append(" ADD CONSTRAINT ");
String constraintName = prepared.getConstraintName();
// MySQL constraintName is optional
if (!StringUtils.isNullOrEmpty(constraintName)) {
buff.append(constraintName);
}
buff.append(' ').append(uniqueType);
if (prepared.isPrimaryKeyHash()) {
buff.append(" USING ").append("HASH");
}
buff.append('(');
for (IndexColumn c : prepared.getIndexColumns()) {
buff.appendExceptFirst(", ");
buff.append(identifier(c.column.getName()));
}
buff.append(')');
return buff.toString();
}
use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.
the class AlterTableAddConstraintExecutor method doBuildReferences.
private String doBuildReferences(String forTable, String forRefTable) {
StatementBuilder buff = new StatementBuilder("ALTER TABLE ");
buff.append(identifier(forTable)).append(" ADD CONSTRAINT ");
String constraintName = prepared.getConstraintName();
if (!StringUtils.isNullOrEmpty(constraintName)) {
buff.append(constraintName);
}
IndexColumn[] cols = prepared.getIndexColumns();
IndexColumn[] refCols = prepared.getRefIndexColumns();
buff.append(" FOREIGN KEY(");
for (IndexColumn c : cols) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
}
buff.append(')');
buff.append(" REFERENCES ");
buff.append(forRefTable).append('(');
buff.resetCount();
for (IndexColumn r : refCols) {
buff.appendExceptFirst(", ");
buff.append(r.getSQL());
}
buff.append(')');
if (prepared.getDeleteAction() != AlterTableAddConstraint.RESTRICT) {
buff.append(" ON DELETE ");
appendAction(buff, prepared.getDeleteAction());
}
if (prepared.getUpdateAction() != AlterTableAddConstraint.RESTRICT) {
buff.append(" ON UPDATE ");
appendAction(buff, prepared.getDeleteAction());
}
return buff.toString();
}
use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.
the class JavaFunction method getSQL.
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder();
// TODO always append the schema once FUNCTIONS_IN_SCHEMA is enabled
if (functionAlias.getDatabase().getSettings().functionsInSchema || !functionAlias.getSchema().getName().equals(Constants.SCHEMA_MAIN)) {
buff.append(Parser.quoteIdentifier(functionAlias.getSchema().getName())).append('.');
}
buff.append(Parser.quoteIdentifier(functionAlias.getName())).append('(');
for (Expression e : args) {
buff.appendExceptFirst(", ");
buff.append(e.getSQL());
}
return buff.append(')').toString();
}
Aggregations