use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.
the class JavaFunction method exportParameters.
@Override
public String exportParameters(TableFilter filter, List<Value> container) {
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.exportParameters(filter, container));
}
return buff.append(')').toString();
}
use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.
the class TableFunction method getSQL.
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder(getName());
buff.append('(');
int i = 0;
for (Expression e : args) {
buff.appendExceptFirst(", ");
buff.append(columnList[i++].getCreateSQL()).append('=').append(e.getSQL());
}
return buff.append(')').toString();
}
use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.
the class JdbcDatabaseMetaData method getFunctions.
private String getFunctions(String section) throws SQLException {
try {
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT TOPIC " + "FROM INFORMATION_SCHEMA.HELP WHERE SECTION = ?");
prep.setString(1, section);
ResultSet rs = prep.executeQuery();
StatementBuilder buff = new StatementBuilder();
while (rs.next()) {
String s = rs.getString(1).trim();
String[] array = StringUtils.arraySplit(s, ',', true);
for (String a : array) {
buff.appendExceptFirst(",");
String f = a.trim();
if (f.indexOf(' ') >= 0) {
// remove 'Function' from 'INSERT Function'
f = f.substring(0, f.indexOf(' ')).trim();
}
buff.append(f);
}
}
rs.close();
prep.close();
return buff.toString();
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.
the class BatchUpdateWorker method error.
/**
* @param e
*/
protected void error(Throwable e) {
StatementBuilder buff = new StatementBuilder();
buff.append(shardName).append(" executing batchUpdate error:").append(sql);
for (List<Value> params : array) {
if (params != null) {
if (params != null && params.size() > 0) {
buff.appendExceptFirst(", ");
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());
}
use of com.wplatform.ddal.util.StatementBuilder in project jdbc-shards by wplatform.
the class CreateTableExecutor method doTranslate.
@Override
protected String doTranslate(TableNode tableNode) {
StatementBuilder buff = new StatementBuilder("CREATE ");
if (prepared.isTemporary()) {
buff.append("TEMPORARY ");
}
buff.append("TABLE ");
if (prepared.isIfNotExists()) {
buff.append("IF NOT EXISTS ");
}
buff.append(identifier(tableNode.getCompositeObjectName()));
if (prepared.getComment() != null) {
// buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(prepared.getComment()));
}
buff.append("(");
for (Column column : prepared.getColumns()) {
buff.appendExceptFirst(", ");
buff.append(column.getCreateSQL());
}
for (DefineCommand command : prepared.getConstraintCommands()) {
buff.appendExceptFirst(", ");
int type = command.getType();
switch(type) {
case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY:
{
AlterTableAddConstraint stmt = (AlterTableAddConstraint) command;
buff.append(" CONSTRAINT PRIMARY KEY");
if (stmt.isPrimaryKeyHash()) {
buff.append(" USING HASH");
}
buff.resetCount();
buff.append("(");
for (IndexColumn c : stmt.getIndexColumns()) {
buff.appendExceptFirst(", ");
buff.append(identifier(c.columnName));
}
buff.append(")");
break;
}
case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_UNIQUE:
{
AlterTableAddConstraint stmt = (AlterTableAddConstraint) command;
buff.append(" CONSTRAINT UNIQUE KEY");
buff.resetCount();
buff.append("(");
for (IndexColumn c : stmt.getIndexColumns()) {
buff.appendExceptFirst(", ");
buff.append(identifier(c.columnName));
}
buff.append(")");
break;
}
case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_CHECK:
{
AlterTableAddConstraint stmt = (AlterTableAddConstraint) command;
String enclose = StringUtils.enclose(stmt.getCheckExpression().getSQL());
buff.append(" CHECK").append(enclose);
break;
}
case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_REFERENTIAL:
{
AlterTableAddConstraint stmt = (AlterTableAddConstraint) command;
String refTableName = stmt.getRefTableName();
TableMate table = getTableMate(stmt.getTableName());
TableMate refTable = getTableMate(refTableName);
if (refTable != null) {
TableNode[] partitionNode = refTable.getPartitionNode();
if (partitionNode.length > 1) {
TableNode[] tableNodes = table.getPartitionNode();
TableNode[] refTableNodes = partitionNode;
Map<TableNode, TableNode> symmetryRelation = getSymmetryRelation(tableNodes, refTableNodes);
TableNode relation = symmetryRelation.get(tableNode);
if (relation == null) {
throw DbException.get(ErrorCode.CHECK_CONSTRAINT_INVALID, "The original table and reference table should be symmetrical.");
}
refTableName = relation.getCompositeObjectName();
} else if (partitionNode.length == 1) {
refTableName = partitionNode[0].getCompositeObjectName();
}
}
IndexColumn[] cols = stmt.getIndexColumns();
IndexColumn[] refCols = stmt.getRefIndexColumns();
buff.resetCount();
buff.append(" CONSTRAINT FOREIGN KEY(");
for (IndexColumn c : cols) {
buff.appendExceptFirst(", ");
buff.append(c.columnName);
}
buff.append(")");
buff.append(" REFERENCES ");
buff.append(identifier(refTableName)).append("(");
buff.resetCount();
for (IndexColumn r : refCols) {
buff.appendExceptFirst(", ");
buff.append(r.columnName);
}
buff.append(")");
break;
}
case CommandInterface.CREATE_INDEX:
{
CreateIndex stmt = (CreateIndex) command;
if (stmt.isSpatial()) {
buff.append(" SPATIAL INDEX");
} else {
buff.append(" INDEX");
if (stmt.isHash()) {
buff.append(" USING HASH");
}
}
buff.resetCount();
buff.append("(");
for (IndexColumn c : stmt.getIndexColumns()) {
buff.appendExceptFirst(", ");
buff.append(identifier(c.columnName));
}
buff.append(")");
break;
}
default:
throw DbException.throwInternalError("type=" + type);
}
}
buff.append(")");
if (prepared.getTableEngine() != null) {
buff.append(" ENGINE = ");
buff.append(prepared.getTableEngine());
}
ArrayList<String> tableEngineParams = prepared.getTableEngineParams();
if (tableEngineParams != null && tableEngineParams.isEmpty()) {
buff.append("WITH ");
buff.resetCount();
for (String parameter : tableEngineParams) {
buff.appendExceptFirst(", ");
buff.append(StringUtils.quoteIdentifier(parameter));
}
}
if (prepared.getCharset() != null) {
buff.append(" DEFAULT CHARACTER SET = ");
buff.append(prepared.getCharset());
}
return buff.toString();
}
Aggregations