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;
}
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";
}
}
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 {
}
}
}
}
Aggregations