private void checkRights() { if (insertCommand != null) { session.getUser().checkRight(targetTable, Right.INSERT); } if (updateCommand != null) { session.getUser().checkRight(targetTable, Right.UPDATE); } if (deleteCommand != null) { session.getUser().checkRight(targetTable, Right.DELETE); } // check the underlying tables session.getUser().checkRight(targetTable, Right.SELECT); session.getUser().checkRight(sourceTableFilter.getTable(), Right.SELECT); }
/** * Create an internal connection. This connection is used when initializing * triggers, and when calling user defined functions. * * @param columnList if the url should be 'jdbc:columnlist:connection' * @return the internal connection */ public JdbcConnection createConnection(boolean columnList) { String url; if (columnList) { url = Constants.CONN_URL_COLUMNLIST; } else { url = Constants.CONN_URL_INTERNAL; } return new JdbcConnection(this, getUser().getName(), url); }
@Override public int update() { session.commit(true); if (view == null && ifExists) { return 0; } session.getUser().checkRight(view, Right.ALL); DbException e = view.recompile(session, false, true); if (e != null) { throw e; } return 0; }
@Override public int update() { String name = fileNameExpr.getValue(session).getString(); session.getUser().checkAdmin(); backupTo(name); return 0; }
@Override public int update() { session.commit(true); Constraint constraint = getSchema().findConstraint(session, constraintName); if (constraint == null) { if (!ifExists) { throw DbException.get(ErrorCode.CONSTRAINT_NOT_FOUND_1, constraintName); } } else { session.getUser().checkRight(constraint.getTable(), Right.ALL); session.getUser().checkRight(constraint.getRefTable(), Right.ALL); session.getDatabase().removeSchemaObject(session, constraint); } return 0; }
@Override public int update() { session.commit(true); Constraint constraint = getSchema().findConstraint(session, constraintName); if (constraint == null) { throw DbException.get(ErrorCode.CONSTRAINT_NOT_FOUND_1, constraintName); } if (getSchema().findConstraint(session, newConstraintName) != null || newConstraintName.equals(constraintName)) { throw DbException.get(ErrorCode.CONSTRAINT_ALREADY_EXISTS_1, newConstraintName); } session.getUser().checkRight(constraint.getTable(), Right.ALL); session.getUser().checkRight(constraint.getRefTable(), Right.ALL); session.getDatabase().renameSchemaObject(session, constraint, newConstraintName); return 0; }
private static boolean cancelStatement(Session session, int targetSessionId) { session.getUser().checkAdmin(); Session[] sessions = session.getDatabase().getSessions(false); for (Session s : sessions) { if (s.getId() == targetSessionId) { Command c = s.getCurrentCommand(); if (c == null) { return false; } c.cancel(); return true; } } return false; }
@Override public int update() { session.commit(true); session.getUser().checkAdmin(); Database db = session.getDatabase(); if (table != null) { analyzeTable(session, table, sampleRows, true); } else { for (Table table : db.getAllTablesAndViews(false)) { analyzeTable(session, table, sampleRows, true); } } return 0; }
@Override public int update() { session.getUser().checkAdmin(); session.commit(true); Database db = session.getDatabase(); UserAggregate aggregate = db.findAggregate(name); if (aggregate == null) { if (!ifExists) { throw DbException.get(ErrorCode.AGGREGATE_NOT_FOUND_1, name); } } else { db.removeDatabaseObject(session, aggregate); } return 0; }
@Override public int update() { session.getUser().checkAdmin(); session.commit(true); Database db = session.getDatabase(); UserDataType type = db.findUserDataType(typeName); if (type == null) { if (!ifExists) { throw DbException.get(ErrorCode.USER_DATA_TYPE_NOT_FOUND_1, typeName); } } else { db.removeDatabaseObject(session, type); } return 0; }
@Override public int update() { session.commit(true); if (!table.canTruncate()) { throw DbException.get(ErrorCode.CANNOT_TRUNCATE_1, table.getSQL()); } session.getUser().checkRight(table, Right.DELETE); table.lock(session, true, true); table.truncate(session); return 0; }
@Override public int update() { session.getUser().checkAdmin(); session.commit(true); Database db = session.getDatabase(); FunctionAlias functionAlias = getSchema().findFunction(aliasName); if (functionAlias == null) { if (!ifExists) { throw DbException.get(ErrorCode.FUNCTION_ALIAS_NOT_FOUND_1, aliasName); } } else { db.removeSchemaObject(session, functionAlias); } return 0; }
@Override public int update() { session.commit(true); session.getUser().checkAdmin(); TableSynonym synonym = getSchema().getSynonym(synonymName); if (synonym == null) { if (!ifExists) { throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, synonymName); } } else { session.getDatabase().removeSchemaObject(session, synonym); } return 0; }
@Override public int update() { session.getUser().checkAdmin(); session.commit(true); Database db = session.getDatabase(); Constant constant = getSchema().findConstant(constantName); if (constant == null) { if (!ifExists) { throw DbException.get(ErrorCode.CONSTANT_NOT_FOUND_1, constantName); } } else { db.removeSchemaObject(session, constant); } return 0; }
@Override public int update() { session.commit(true); Database db = session.getDatabase(); TriggerObject trigger = getSchema().findTrigger(triggerName); if (trigger == null) { if (!ifExists) { throw DbException.get(ErrorCode.TRIGGER_NOT_FOUND_1, triggerName); } } else { Table table = trigger.getTable(); session.getUser().checkRight(table, Right.ALL); db.removeSchemaObject(session, trigger); } return 0; }
@Override public int update() { session.commit(true); session.getUser().checkAdmin(); Database db = session.getDatabase(); if (db.findAggregate(name) != null || schema.findFunction(name) != null) { if (!ifNotExists) { throw DbException.get( ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, name); } } else { int id = getObjectId(); UserAggregate aggregate = new UserAggregate( db, id, name, javaClassMethod, force); db.addDatabaseObject(session, aggregate); } return 0; }
@Override public int update() { session.getUser().checkAdmin(); session.commit(true); Database db = session.getDatabase(); Sequence sequence = getSchema().findSequence(sequenceName); if (sequence == null) { if (!ifExists) { throw DbException.get(ErrorCode.SEQUENCE_NOT_FOUND_1, sequenceName); } } else { if (sequence.getBelongsToTable()) { throw DbException.get(ErrorCode.SEQUENCE_BELONGS_TO_A_TABLE_1, sequenceName); } db.removeSchemaObject(session, sequence); } return 0; }
@Override public int update() { if (!transactional) { session.commit(true); } session.getUser().checkAdmin(); Database db = session.getDatabase(); data.session = session; db.lockMeta(session); if (data.synonymForSchema.findTableOrView(session, data.synonymName) != null) { throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, data.synonymName); } if (data.synonymForSchema.findTableOrView(session, data.synonymFor) != null) { return createTableSynonym(db); } throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, data.synonymForSchema.getName() + "." + data.synonymFor); }
private CreateSchema parseCreateSchema() { CreateSchema command = new CreateSchema(session); command.setIfNotExists(readIfNotExists()); command.setSchemaName(readUniqueIdentifier()); if (readIf("AUTHORIZATION")) { command.setAuthorization(readUniqueIdentifier()); } else { command.setAuthorization(session.getUser().getName()); } if (readIf("WITH")) { command.setTableEngineParams(readTableEngineParams()); } return command; }
@Override public int update() { session.commit(true); session.getUser().checkAdmin(); Database db = session.getDatabase(); if (getSchema().findConstant(constantName) != null) { if (ifNotExists) { return 0; } throw DbException.get(ErrorCode.CONSTANT_ALREADY_EXISTS_1, constantName); } int id = getObjectId(); Constant constant = new Constant(getSchema(), id, constantName); expression = expression.optimize(session); Value value = expression.getValue(session); constant.setValue(value); db.addSchemaObject(session, constant); return 0; }