switch (type) { case CommandInterface.SET_AUTOCOMMIT_TRUE: session.setAutoCommit(true); break; case CommandInterface.SET_AUTOCOMMIT_FALSE: session.setAutoCommit(false); break; case CommandInterface.BEGIN: session.begin(); break; case CommandInterface.COMMIT: session.commit(); break; case CommandInterface.ROLLBACK: session.rollback(); break; case CommandInterface.SAVEPOINT: session.addSavepoint(savepointName); break; case CommandInterface.ROLLBACK_TO_SAVEPOINT: session.rollbackToSavepoint(savepointName); break; case CommandInterface.RELEASE_SAVEPOINT: session.releaseSavepoint(savepointName); break; default:
/** * Close the database. */ public synchronized void close() { if (closing) { return; } if (userSessions.size() > 0) { Session[] all = new Session[userSessions.size()]; userSessions.toArray(all); for (Session s : all) { try { s.rollback(); s.close(); } catch (DbException e) { trace.error(e, "disconnecting session #{0}", s.getId()); } } } repository.close(); if (queryExecutor != null) { Threads.shutdownGracefully(queryExecutor, 1000, 1000, TimeUnit.MILLISECONDS); } closing = true; }
/** * @param options * @return * @throws SQLException */ private Connection getRawConnection(Options options) throws DbException { Connection conn = target.getConnection(options); try { if (conn.getAutoCommit() != session.getAutoCommit()) { conn.setAutoCommit(session.getAutoCommit()); } if (session.getIsolation() != 0) { if (conn.getTransactionIsolation() != session.getIsolation()) { conn.setTransactionIsolation(session.getIsolation()); } } if (conn.isReadOnly() != session.isReadOnly()) { conn.setReadOnly(session.isReadOnly()); } } catch (Exception e) { throw DbException.convert(e); } return conn; }
public void setAutoCommit(boolean b) { if (autoCommit == b) { return; } if (!getAutoCommit()) { commit(); } autoCommit = b; }
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; }
public Comparison(Session session, int compareType, Expression left, Expression right) { this.database = session.getDatabase(); this.left = left; this.right = right; this.compareType = compareType; }
boolean admin = session.getUser().isAdmin(); switch (type) { case TABLES: { add(rows, "QUERY_TIMEOUT", "" + session.getQueryTimeout()); if (admin || session.getUser() == u) { add(rows, for (Session s : database.getSessions()) { if (admin || s == session) { Command command = s.getCurrentCommand(); long start = s.getCurrentCommandStart(); if (start == 0) { start = now; "" + s.getId(), s.getUser().getName(), new Timestamp(s.getSessionStart()).toString(), "" + s.isReadOnly() ); for (String name : session.getVariableNames()) { Value v = session.getVariable(name); add(rows,
case RAND: { if (v0 != null) { session.getRandom().setSeed(v0.getInt()); result = ValueDouble.get(session.getRandom().nextDouble()); break; case CURDATE: case CURRENT_DATE: { long now = session.getTransactionStart(); long now = session.getTransactionStart(); long now = session.getTransactionStart(); ValueTimestamp vt = ValueTimestamp.fromMillis(now); if (v0 != null) { result = ValueString.get(session.getUser().getName(), database.getMode().treatEmptyStringsAsNull); break; case IDENTITY: result = session.getLastIdentity(); break; case SCOPE_IDENTITY: result = session.getLastScopeIdentity(); break; case AUTOCOMMIT: result = ValueBoolean.get(session.getAutoCommit()); break;
@Override public int update() { Database database = session.getDatabase(); switch (type) { case SetTypes.ALLOW_LITERALS: { session.getUser().checkAdmin(); int value = getIntValue(); if (value < 0 || value > 2) { session.getUser().checkAdmin(); final boolean binaryUnsigned = database.getCompareMode().isBinaryUnsigned(); CompareMode compareMode; session.getUser().checkAdmin(); CompareMode currentMode = database.getCompareMode(); CompareMode newMode; session.getUser().checkAdmin(); database.setIgnoreCase(getIntValue() == 1); break; session.getUser().checkAdmin(); database.setMaxMemoryRows(getIntValue()); break; session.getUser().checkAdmin(); int value = getIntValue(); database.setMaxOperationMemory(value); session.getUser().checkAdmin();
@Override public void close() { if (!closed) { try { if (!getAutoCommit()) { rollback(); } transaction.close(); database.removeSession(this); } finally { closed = true; } } }
@Override public int executeUpdate() { Database database = session.getDatabase(); Object sync = session; synchronized (sync) { session.setCurrentCommand(this); try { while (true) {
public JdbcWorker(Session session, String shardName, String sql, List<Value> params) { super(); this.session = session; this.shardName = shardName; this.sql = sql; this.params = params; this.trace = session.getDatabase().getTrace(Trace.EXECUTOR); this.tx = (JdbcTransaction)session.getTransaction(); this.connProvider = tx.getConnectionProvider(); }
protected final void prepare(Session s) { if (isPrepared) { return; } this.session = s; this.database = session.getDatabase(); this.queryExecutor = database.getQueryExecutor(); this.routingHandler = database.getRoutingHandler(); this.queryHandlerFactory = session.getQueryHandlerFactory(); doPrepare(); isPrepared = true; }
@Override public synchronized CommandInterface prepareCommand(String sql, int fetchSize) { return prepareLocal(sql); }
private boolean initValue(SQLMethodInvokeExpr expr) { Session session = target.getSession().getDbSession(); List<SQLExpr> parameters = expr.getParameters(); if (!parameters.isEmpty()) { return false; } String name = expr.getMethodName().toLowerCase(); if ("user".equals(name) || "current_user".equals(name)) { expr.putAttribute(EVAL_VALUE, session.getUser().getName()); return true; } else if ("connection_id".equals(name)) { long threadId = target.getSession().getThreadId(); expr.putAttribute(EVAL_VALUE, threadId); return true; } else if ("version_comment".equals(name)) { expr.putAttribute(EVAL_VALUE, MySQLServer.VERSION_COMMENT); return true; } return false; }
/** * Print information about the statement executed if info trace level is * enabled. * * @param startTime when the statement was started * @param rowCount the query or update row count */ void trace(long startTime, int rowCount) { if (session.getTrace().isInfoEnabled() && startTime > 0) { long deltaTime = System.currentTimeMillis() - startTime; String params = Trace.formatParams(parameters); session.getTrace().infoSQL(sqlStatement, params, rowCount, deltaTime); } if (session.getDatabase().getQueryStatistics()) { long deltaTime = System.currentTimeMillis() - startTime; session.getDatabase().getQueryStatisticsData(). update(toString(), deltaTime, rowCount); } }
query.init(); Session s = session; alias = session.getNextSystemIdentifier(sqlCommand); table = TableView.createTempView(s, session.getUser(), alias, query, currentSelect); } else {
@Override public void closeConnection(Connection connection, Options options) { if (session.getAutoCommit()) { target.closeConnection(connection, options); } else { Connection contains = connectionMap.get(options.shardName); if (connection != contains) { target.closeConnection(connection, options); } } }
public void close() { dbSession.close(); server.removeSession(threadId); if (channel != null && channel.isOpen()) { channel.attr(CHANNEL_SESSION_KEY).remove(); channel.close(); } }
private Connection getRawConnectionForReadOnly(Options options) { try { Connection conn = target.getConnection(options); conn.setAutoCommit(true); conn.setReadOnly(true); if (session.getIsolation() != 0) { if (conn.getTransactionIsolation() != session.getIsolation()) { conn.setTransactionIsolation(session.getIsolation()); } } return conn; } catch (SQLException e) { throw DbException.convert(e); } }