Search in sources :

Example 1 with ReadOnlyException

use of io.crate.exceptions.ReadOnlyException in project crate by crate.

the class SimplePortal method bind.

@Override
public Portal bind(String statementName, String query, Statement statement, List<Object> params, @Nullable FormatCodes.FormatCode[] resultFormatCodes) {
    if (statement.equals(this.statement)) {
        if (portalContext.isReadOnly()) {
            // Cannot have a bulk operation in read only mode
            throw new ReadOnlyException();
        }
        assert consumer == null : "Existing portal must not have a consumer";
        BulkPortal portal = new BulkPortal(name, this.query, this.statement, outputTypes, fields(), resultReceiver, maxRows, this.params, sessionContext, portalContext);
        return portal.bind(statementName, query, statement, params, resultFormatCodes);
    } else if (this.statement != null) {
        assert consumer == null : "Existing portal must not have a consumer";
        if (portalContext.isReadOnly()) {
            // Cannot have a batch operation in read only mode
            throw new ReadOnlyException();
        }
        BatchPortal portal = new BatchPortal(name, this.query, analysis, outputTypes, resultReceiver, this.params, sessionContext, portalContext);
        return portal.bind(statementName, query, statement, params, resultFormatCodes);
    }
    this.query = query;
    this.statement = statement;
    this.params = params;
    this.rowParams = new RowN(params.toArray());
    this.resultFormatCodes = resultFormatCodes;
    if (analysis == null) {
        analysis = portalContext.getAnalyzer().boundAnalyze(statement, sessionContext, new ParameterContext(this.rowParams, Collections.<Row>emptyList()));
        AnalyzedRelation rootRelation = analysis.rootRelation();
        if (rootRelation != null) {
            this.outputTypes = new ArrayList<>(Symbols.extractTypes(rootRelation.fields()));
        }
    }
    return this;
}
Also used : RowN(io.crate.data.RowN) ParameterContext(io.crate.analyze.ParameterContext) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) ReadOnlyException(io.crate.exceptions.ReadOnlyException)

Aggregations

ParameterContext (io.crate.analyze.ParameterContext)1 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)1 RowN (io.crate.data.RowN)1 ReadOnlyException (io.crate.exceptions.ReadOnlyException)1