Search in sources :

Example 1 with Session

use of com.wplatform.ddal.engine.Session in project jdbc-shards by wplatform.

the class Function method cancelStatement.

private static boolean cancelStatement(Session session, int targetSessionId) {
    session.getUser().checkAdmin();
    Session[] sessions = session.getDatabase().getSessions();
    for (Session s : sessions) {
        if (s.getId() == targetSessionId) {
            Command c = s.getCurrentCommand();
            if (c == null) {
                return false;
            }
            c.cancel();
            return true;
        }
    }
    return false;
}
Also used : Command(com.wplatform.ddal.command.Command) Session(com.wplatform.ddal.engine.Session)

Example 2 with Session

use of com.wplatform.ddal.engine.Session in project jdbc-shards by wplatform.

the class ConditionInSelect method exportParameters.

@Override
public String exportParameters(TableFilter filter, List<Value> container) {
    Session session = filter.getSession();
    LocalResult rows = query(session);
    if (rows.getRowCount() > 0) {
        StatementBuilder buff = new StatementBuilder();
        buff.append('(').append(left.exportParameters(filter, container)).append(' ');
        if (all) {
            // 由于all代表全部,所以<all表示小于子查询中返回全部值中的最小值;
            // >all表示大于子查询中返回全部值中的最大值。
            buff.append(Comparison.getCompareOperator(compareType)).append(" ALL");
        } else {
            if (compareType == Comparison.EQUAL) {
                buff.append("IN");
            } else {
                // <any可以理解为小于子查询中返回的任意一个值,因此只要小于最大值即可
                // >any可以理解为大于子查询中返回的任意一个值,因此只要大于最小值即可
                buff.append(Comparison.getCompareOperator(compareType)).append(" ANY");
            }
        }
        buff.append("(");
        while (rows.next()) {
            buff.appendExceptFirst(",");
            buff.append("?");
            Value r = rows.currentRow()[0];
            container.add(r);
        }
        buff.append("))");
        return buff.toString();
    } else {
        return "1 = 0";
    }
}
Also used : LocalResult(com.wplatform.ddal.result.LocalResult) StatementBuilder(com.wplatform.ddal.util.StatementBuilder) Value(com.wplatform.ddal.value.Value) Session(com.wplatform.ddal.engine.Session)

Example 3 with Session

use of com.wplatform.ddal.engine.Session in project jdbc-shards by wplatform.

the class Command method executeUpdate.

@Override
public int executeUpdate() {
    Database database = session.getDatabase();
    Object sync = session;
    boolean callStop = true;
    synchronized (sync) {
        Session.Savepoint rollback = session.setSavepoint();
        session.setCurrentCommand(this);
        try {
            while (true) {
                try {
                    return update();
                } catch (DbException e) {
                    throw e;
                } catch (OutOfMemoryError e) {
                    callStop = false;
                    database.shutdownImmediately();
                    throw DbException.convert(e);
                } catch (Throwable e) {
                    throw DbException.convert(e);
                }
            }
        } catch (DbException e) {
            e = e.addSQL(sql);
            SQLException s = e.getSQLException();
            if (s.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
                callStop = false;
                database.shutdownImmediately();
                throw e;
            }
            if (s.getErrorCode() == ErrorCode.DEADLOCK_1) {
                session.rollback();
            } else {
                session.rollbackTo(rollback, false);
            }
            throw e;
        } finally {
            try {
                if (callStop) {
                    stop();
                }
            } finally {
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Database(com.wplatform.ddal.engine.Database) Session(com.wplatform.ddal.engine.Session) DbException(com.wplatform.ddal.message.DbException)

Aggregations

Session (com.wplatform.ddal.engine.Session)3 Command (com.wplatform.ddal.command.Command)1 Database (com.wplatform.ddal.engine.Database)1 DbException (com.wplatform.ddal.message.DbException)1 LocalResult (com.wplatform.ddal.result.LocalResult)1 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)1 Value (com.wplatform.ddal.value.Value)1 SQLException (java.sql.SQLException)1