use of io.shardingjdbc.core.rewrite.placeholder.TablePlaceholder in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngine method appendTablePlaceholder.
private void appendTablePlaceholder(final SQLBuilder sqlBuilder, final TableToken tableToken, final int count, final List<SQLToken> sqlTokens) {
sqlBuilder.appendPlaceholder(new TablePlaceholder(tableToken.getTableName().toLowerCase()));
int beginPosition = tableToken.getBeginPosition() + tableToken.getOriginalLiterals().length();
appendRest(sqlBuilder, count, sqlTokens, beginPosition);
}
use of io.shardingjdbc.core.rewrite.placeholder.TablePlaceholder in project sharding-jdbc by shardingjdbc.
the class SQLBuilderTest method assertAppendTableWithTableToken.
@Test
public void assertAppendTableWithTableToken() {
SQLBuilder sqlBuilder = new SQLBuilder();
sqlBuilder.appendLiterals("SELECT ");
sqlBuilder.appendPlaceholder(new TablePlaceholder("table_x"));
sqlBuilder.appendLiterals(".id");
sqlBuilder.appendLiterals(" FROM ");
sqlBuilder.appendPlaceholder(new TablePlaceholder("table_x"));
Map<String, String> tableTokens = new HashMap<>(1, 1);
tableTokens.put("table_x", "table_x_1");
assertThat(sqlBuilder.toSQL(tableTokens, null), is("SELECT table_x_1.id FROM table_x_1"));
}
use of io.shardingjdbc.core.rewrite.placeholder.TablePlaceholder in project sharding-jdbc by shardingjdbc.
the class SQLBuilderTest method assertSchemaPlaceholderAppendTableWithTableToken.
@Test
public void assertSchemaPlaceholderAppendTableWithTableToken() {
SQLBuilder sqlBuilder = new SQLBuilder();
sqlBuilder.appendLiterals("SHOW ");
sqlBuilder.appendLiterals("CREATE TABLE ");
sqlBuilder.appendPlaceholder(new TablePlaceholder("table_0"));
sqlBuilder.appendLiterals(" ON ");
sqlBuilder.appendPlaceholder(new SchemaPlaceholder("ds", "table_0"));
Map<String, String> tableTokens = new HashMap<>(1, 1);
tableTokens.put("table_0", "table_1");
assertThat(sqlBuilder.toSQL(tableTokens, createShardingRule()), is("SHOW CREATE TABLE table_1 ON ds0"));
}
Aggregations