Search in sources :

Example 1 with Parser

use of com.wplatform.ddal.command.Parser in project jdbc-shards by wplatform.

the class Column method getCheckConstraint.

/**
     * Get the check constraint expression for this column if set.
     *
     * @param session      the session
     * @param asColumnName the column name to use
     * @return the constraint expression
     */
public Expression getCheckConstraint(Session session, String asColumnName) {
    if (checkConstraint == null) {
        return null;
    }
    Parser parser = new Parser(session);
    String sql;
    synchronized (this) {
        String oldName = name;
        name = asColumnName;
        sql = checkConstraint.getSQL();
        name = oldName;
    }
    Expression expr = parser.parseExpression(sql);
    return expr;
}
Also used : Parser(com.wplatform.ddal.command.Parser)

Example 2 with Parser

use of com.wplatform.ddal.command.Parser in project jdbc-shards by wplatform.

the class Session method prepareLocal.

/**
     * Parse and prepare the given SQL statement. This method also checks if the
     * connection has been closed.
     *
     * @param sql the SQL statement
     * @return the prepared statement
     */
public Command prepareLocal(String sql) {
    if (closed) {
        throw DbException.get(ErrorCode.CONNECTION_BROKEN_1, "session closed");
    }
    Command command;
    if (queryCacheSize > 0) {
        if (queryCache == null) {
            queryCache = SmallLRUCache.newInstance(queryCacheSize);
        // modificationMetaID = database.getModificationMetaId();
        } else {
            // ignore table structure modification
            /*
                 * long newModificationMetaID =
                 * database.getModificationMetaId(); if (newModificationMetaID
                 * != modificationMetaID) { queryCache.clear();
                 * modificationMetaID = newModificationMetaID; }
                 */
            command = queryCache.get(sql);
            if (command != null && command.canReuse()) {
                command.reuse();
                return command;
            }
        }
    }
    Parser parser = new Parser(this);
    command = parser.prepareCommand(sql);
    if (queryCache != null) {
        if (command.isCacheable()) {
            queryCache.put(sql, command);
        }
    }
    return command;
}
Also used : Command(com.wplatform.ddal.command.Command) Parser(com.wplatform.ddal.command.Parser)

Example 3 with Parser

use of com.wplatform.ddal.command.Parser in project jdbc-shards by wplatform.

the class Session method prepare.

/**
     * Parse and prepare the given SQL statement.
     *
     * @param sql the SQL statement
     * @param rightsChecked true if the rights have already been checked
     * @return the prepared statement
     */
public Prepared prepare(String sql, boolean rightsChecked) {
    Parser parser = new Parser(this);
    parser.setRightsChecked(rightsChecked);
    return parser.prepare(sql);
}
Also used : Parser(com.wplatform.ddal.command.Parser)

Example 4 with Parser

use of com.wplatform.ddal.command.Parser in project jdbc-shards by wplatform.

the class Function method getSequence.

private Sequence getSequence(Session session, Value v0, Value v1) {
    String schemaName, sequenceName;
    if (v1 == null) {
        Parser p = new Parser(session);
        String sql = v0.getString();
        Expression expr = p.parseExpression(sql);
        if (expr instanceof ExpressionColumn) {
            ExpressionColumn seq = (ExpressionColumn) expr;
            schemaName = seq.getOriginalTableAliasName();
            if (schemaName == null) {
                schemaName = session.getCurrentSchemaName();
                sequenceName = sql;
            } else {
                sequenceName = seq.getColumnName();
            }
        } else {
            throw DbException.getSyntaxError(sql, 1);
        }
    } else {
        schemaName = v0.getString();
        sequenceName = v1.getString();
    }
    Schema s = database.findSchema(schemaName);
    if (s == null) {
        schemaName = StringUtils.toUpperEnglish(schemaName);
        s = database.getSchema(schemaName);
    }
    Sequence seq = s.findSequence(sequenceName);
    if (seq == null) {
        sequenceName = StringUtils.toUpperEnglish(sequenceName);
        seq = s.getSequence(sequenceName);
    }
    return seq;
}
Also used : Schema(com.wplatform.ddal.dbobject.schema.Schema) Sequence(com.wplatform.ddal.dbobject.schema.Sequence) Parser(com.wplatform.ddal.command.Parser)

Aggregations

Parser (com.wplatform.ddal.command.Parser)4 Command (com.wplatform.ddal.command.Command)1 Schema (com.wplatform.ddal.dbobject.schema.Schema)1 Sequence (com.wplatform.ddal.dbobject.schema.Sequence)1