Search in sources :

Example 1 with FromItemVisitorAdapter

use of net.sf.jsqlparser.statement.select.FromItemVisitorAdapter in project spanner-jdbc by olavloite.

the class CloudSpannerPreparedStatement method setPlainSelectParameters.

private void setPlainSelectParameters(PlainSelect plainSelect, com.google.cloud.spanner.Statement.Builder builder) {
    if (plainSelect.getFromItem() != null) {
        plainSelect.getFromItem().accept(new FromItemVisitorAdapter() {

            private int tableCount = 0;

            @Override
            public void visit(Table table) {
                tableCount++;
                if (tableCount == 1)
                    getParameterStore().setTable(unquoteIdentifier(table.getFullyQualifiedName()));
                else
                    getParameterStore().setTable(null);
            }
        });
    }
    setWhereParameters(plainSelect.getWhere(), builder);
    if (plainSelect.getLimit() != null) {
        setWhereParameters(plainSelect.getLimit().getRowCount(), builder);
    }
    if (plainSelect.getOffset() != null && plainSelect.getOffset().isOffsetJdbcParameter()) {
        ValueBinderExpressionVisitorAdapter<com.google.cloud.spanner.Statement.Builder> binder = new ValueBinderExpressionVisitorAdapter<>(getParameterStore(), builder.bind("p" + getParameterStore().getHighestIndex()), null);
        binder.setValue(getParameterStore().getParameter(getParameterStore().getHighestIndex()));
        getParameterStore().setType(getParameterStore().getHighestIndex(), Types.BIGINT);
    }
}
Also used : Table(net.sf.jsqlparser.schema.Table) FromItemVisitorAdapter(net.sf.jsqlparser.statement.select.FromItemVisitorAdapter) WriteBuilder(com.google.cloud.spanner.Mutation.WriteBuilder)

Aggregations

WriteBuilder (com.google.cloud.spanner.Mutation.WriteBuilder)1 Table (net.sf.jsqlparser.schema.Table)1 FromItemVisitorAdapter (net.sf.jsqlparser.statement.select.FromItemVisitorAdapter)1