public Parser(Session session) { this.database = session.getDatabase(); this.identifiersToUpper = database.getSettings().databaseToUpper; this.session = session; }
/** {@inheritDoc} */ @Override public boolean lock(Session ses, boolean exclusive, boolean force) { // In accordance with base method semantics, we'll return true if we were already exclusively locked. Boolean res = sessions.get(ses); if (res != null) return res; // Acquire the lock. lock(exclusive); if (destroyed) { unlock(exclusive); throw new IllegalStateException("Table " + identifierString() + " already destroyed."); } // Mutate state. sessions.put(ses, exclusive); ses.addLock(this); return false; }
@Override public Row get() { if (values == null) { return null; } if (row == null) { row = session.createRow(values, 1); } return row; }
private static Query prepareSubQuery(String sql, Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder) { Prepared p; session.pushSubQueryInfo(masks, filters, filter, sortOrder); try { p = session.prepare(sql, true, true); } finally { session.popSubQueryInfo(); } return (Query) p; }
private Query compileViewQuery(Session session, String sql, boolean literalsChecked, String viewName) { Prepared p; session.setParsingCreateView(true, viewName); try { p = session.prepare(sql, false, literalsChecked); } finally { session.setParsingCreateView(false, viewName); } if (!(p instanceof Query)) { throw DbException.getSyntaxError(sql, 0); } Query q = (Query) p; // only potentially recursive cte queries need to be non-lazy if (isTableExpression && allowRecursive) { q.setNeverLazy(true); } return q; }
@Override public int update() { Database database = session.getDatabase(); String name = SetTypes.getTypeName(type); switch (type) { case SetTypes.ALLOW_LITERALS: { session.getUser().checkAdmin(); int value = getIntValue(); if (value < 0 || value > 2) { session.getUser().checkAdmin(); database.setCacheSize(getIntValue()); addOrUpdateSetting(name, null, getIntValue()); session.getUser().checkAdmin(); synchronized (database) { addOrUpdateSetting(sysSession, name, value, 0); sysSession.commit(true); session.getUser().checkAdmin(); final boolean binaryUnsigned = database. getCompareMode().isBinaryUnsigned(); session.getUser().checkAdmin(); Table table = database.getFirstUserTable(); if (table != null) { session.getUser().checkAdmin(); int algo = CompressTool.getCompressAlgorithm(stringValue);
int id = transfer.readInt(); String sql = transfer.readString(); int old = session.getModificationId(); Command command = session.prepareLocal(sql); boolean readonly = command.isReadOnly(); cache.addObject(id, command); commit = session.prepareLocal("COMMIT"); int old = session.getModificationId(); commit.executeUpdate(false); transfer.writeInt(getState(old)).flush(); Command command = (Command) cache.getObject(id, false); setParameters(command); int old = session.getModificationId(); ResultInterface result; synchronized (session) { int old = session.getModificationId(); ResultWithGeneratedKeys result; synchronized (session) { if (session.isClosed()) { status = SessionRemote.STATUS_CLOSED; stop = true; writeBoolean(session.getAutoCommit()); if (writeGeneratedKeys) {
Database database = session.getDatabase(); String name = SetTypes.getTypeName(type); switch (type) { case SetTypes.MAX_LOG_SIZE: session.getUser().checkAdmin(); session.getDatabase().setMaxLogSize((long) getIntValue() * 1024 * 1024); addOrUpdateSetting(name, null, getIntValue()); break; case SetTypes.LOCK_TIMEOUT: session.setLockTimeout(getIntValue()); break; case SetTypes.LOCK_MODE: session.getUser().checkAdmin(); database.setLockMode(getIntValue()); addOrUpdateSetting(name, null, getIntValue()); break; case SetTypes.DEFAULT_LOCK_TIMEOUT: session.getUser().checkAdmin(); addOrUpdateSetting(name, null, getIntValue()); break; case SetTypes.DEFAULT_TABLE_TYPE: session.getUser().checkAdmin(); addOrUpdateSetting(name, null, getIntValue()); break; case SetTypes.TRACE_LEVEL_SYSTEM_OUT: session.getUser().checkAdmin(); if (getCurrentObjectId() == 0) { session.getUser().checkAdmin();
session.setAllowLiterals(true); DbSettings defaultSettings = DbSettings.getDefaultSettings(); for (String setting : ci.getKeys()) { CommandInterface command = session.prepareCommand( "SET " + Parser.quoteIdentifier(setting) + " " + value, Integer.MAX_VALUE); } catch (DbException e) { if (e.getErrorCode() == ErrorCode.ADMIN_RIGHTS_REQUIRED) { session.getTrace().error(e, "admin rights required; user: \"" + ci.getUserName() + "\""); } else { session.getTrace().error(e, ""); session.close(); throw e; CommandInterface command = session.prepareCommand(init, Integer.MAX_VALUE); command.executeUpdate(false); } catch (DbException e) { if (!ignoreUnknownSetting) { session.close(); throw e; session.setAllowLiterals(false); session.commit(true);
session.setAllowLiterals(true); for (int i = 0; i < keys.length; i++) { String setting = keys[i]; String value = ci.getProperty(setting); try { CommandInterface command = session.prepareCommand("SET " + Parser.quoteIdentifier(setting) + " " + value, Integer.MAX_VALUE); command.executeUpdate(); } catch (SQLException e) { if (!ignoreUnknownSetting) { session.close(); throw e; session.setAllowLiterals(false); session.commit(true); session.getDatabase().getTrace(Trace.SESSION).info("connected #" + session.getId()); return session;
indexType); } else if (indexType.isSpatial()) { index = new MVSpatialIndex(session.getDatabase(), this, indexId, indexName, cols, indexType); } else { index = new MVSecondaryIndex(session.getDatabase(), this, indexId, indexName, cols, indexType); index.setComment(indexComment); if (isSessionTemporary) { session.addLocalTempTableIndex(index); } else { database.addSchemaObject(session, index);
@Override public Expression optimize(Session session) { if (columnResolver == null) { Schema schema = session.getDatabase().findSchema( tableAlias == null ? session.getCurrentSchemaName() : tableAlias); if (schema != null) { Constant constant = schema.findConstant(columnName); if (constant != null) { return constant.getValue(); } } String name = columnName; if (tableAlias != null) { name = tableAlias + "." + name; if (schemaName != null) { name = schemaName + "." + name; } } throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, name); } return columnResolver.optimize(this, column); }
/** * Create a session for the given user. * * @param user the user * @return the session, or null if the database is currently closing * @throws DbException if the database is in exclusive mode */ synchronized Session createSession(User user) { if (closing) { return null; } if (exclusiveSession.get() != null) { throw DbException.get(ErrorCode.DATABASE_IS_IN_EXCLUSIVE_MODE); } Session session = new Session(this, user, ++nextSessionId); userSessions.add(session); trace.info("connecting session #{0} to {1}", session.getId(), databaseName); if (delayedCloser != null) { delayedCloser.reset(); delayedCloser = null; } return session; }
roles.put(Constants.PUBLIC_ROLE_NAME, publicRole); systemUser.setAdmin(true); systemSession = new Session(this, systemUser, ++nextSessionId); lobSession = new Session(this, systemUser, ++nextSessionId); CreateTableData data = new CreateTableData(); ArrayList<Column> cols = data.columns; systemSession.commit(true);
index.setComment(indexComment); if (isSessionTemporary) { session.addLocalTempTableIndex(index); } else { database.addSchemaObject(session, index);
private Schema getSchemaWithDefault() { if (schemaName == null) { schemaName = session.getCurrentSchemaName(); } return getSchema(schemaName); }
private void execute(String sql) { try { Prepared command = session.prepare(sql); if (command.isQuery()) { command.query(0); } else { command.update(); } if (session.getAutoCommit()) { session.commit(false); } } catch (DbException e) { throw e.addSQL(sql); } }
@Override public void checkExistingData(Session session) { if (session.getDatabase().isStarting()) { session.startStatementWithinTransaction(); StatementBuilder buff = new StatementBuilder("SELECT 1 FROM (SELECT "); for (IndexColumn c : columns) { ResultInterface r = session.prepare(sql).query(1); if (r.next()) { throw DbException.get(ErrorCode.REFERENTIAL_INTEGRITY_VIOLATED_PARENT_MISSING_1,
/** * Parse and prepare the given SQL statement. This method also checks the * rights. * * @param sql the SQL statement * @return the prepared statement */ public Prepared prepare(String sql) { return prepare(sql, false, false); }