Search in sources :

Example 6 with TablePlaceholder

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);
}
Also used : TablePlaceholder(io.shardingjdbc.core.rewrite.placeholder.TablePlaceholder)

Example 7 with TablePlaceholder

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"));
}
Also used : TablePlaceholder(io.shardingjdbc.core.rewrite.placeholder.TablePlaceholder) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with TablePlaceholder

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"));
}
Also used : TablePlaceholder(io.shardingjdbc.core.rewrite.placeholder.TablePlaceholder) HashMap(java.util.HashMap) SchemaPlaceholder(io.shardingjdbc.core.rewrite.placeholder.SchemaPlaceholder) Test(org.junit.Test)

Aggregations

TablePlaceholder (io.shardingjdbc.core.rewrite.placeholder.TablePlaceholder)8 Test (org.junit.Test)6 IndexPlaceholder (io.shardingjdbc.core.rewrite.placeholder.IndexPlaceholder)3 SchemaPlaceholder (io.shardingjdbc.core.rewrite.placeholder.SchemaPlaceholder)3 HashMap (java.util.HashMap)3 Optional (com.google.common.base.Optional)1 ShardingJdbcException (io.shardingjdbc.core.exception.ShardingJdbcException)1 ShardingPlaceholder (io.shardingjdbc.core.rewrite.placeholder.ShardingPlaceholder)1