@Override public String toString() { return "DbObject [database=" + database + ", id=" + id + ", objectName=" + objectName + ", type=" + getType() + "]"; }
@Override public String toString() { return "#" + serialId + " (user: " + user.getName() + ")"; }
public void rename(String newName) { checkRename(); objectName = newName; }
boolean admin = session.getUser().isAdmin(); switch (type) { case TABLES: { for (Table table : getAllTables(session)) { String tableName = identifier(table.getName()); if (!checkIndex(session, tableName, indexFrom, indexTo)) { continue; String storageType = table.getTableType(); if(table instanceof TableMate) { int type2 = ((TableMate) table).getTableRule().getType(); switch (type2) { case TableRule.FIXED_NODE_TABLE: add(rows, identifier(table.getSchema().getName()), table.getTableType(), "" + table.getId(), "" + table.getRowCountApproximation() ); String tableName = identifier(indexFrom.getString()); tablesToList = getTablesByName(session, tableName); } else { tablesToList = getAllTables(session);
private synchronized void openDatabase() { User systemUser = new User(this, SYSTEM_USER_NAME); systemUser.setAdmin(true); systemUser.setPassword(SYSTEM_USER_NAME); users.put(SYSTEM_USER_NAME, systemUser); Schema mainSchema = new Schema(this, Constants.SCHEMA_MAIN, systemUser, true); Schema infoSchema = new Schema(this, "INFORMATION_SCHEMA", systemUser, true); schemas.put(mainSchema.getName(), mainSchema); schemas.put(infoSchema.getName(), infoSchema); for (TableRule tableRule : configuration.tableRules) { TableMate tableMate = repository.loadMataData(mainSchema, tableRule); tableMate.loadMataData(sysSession); if (configuration.forceLoadTableMate) { tableMate.check(); for (int type = 0, count = MetaTable.getMetaTableTypeCount(); type < count; type++) { MetaTable m = new MetaTable(infoSchema, type); infoSchema.add(m);
/** * Check that this user does not own any schema. An exception is thrown if * he owns one or more schemas. * * @throws DbException if this user owns a schema */ public void checkOwnsNoSchemas() { for (Schema s : database.getAllSchemas()) { if (this == s.getOwner()) { throw DbException.get(ErrorCode.CANNOT_DROP_2, getName(), s.getName()); } } }
/** * Rename a database object. * * @param session the session * @param obj the object * @param newName the new name */ public synchronized void renameDatabaseObject(Session session, DbObject obj, String newName) { int type = obj.getType(); HashMap<String, DbObject> map = getMap(type); if (SysProperties.CHECK) { if (!map.containsKey(obj.getName())) { DbException.throwInternalError("not found: " + obj.getName()); } if (obj.getName().equals(newName) || map.containsKey(newName)) { DbException.throwInternalError("object already exists: " + newName); } } obj.checkRename(); map.remove(obj.getName()); obj.rename(newName); map.put(newName, obj); }
@Override public Session createSession(Properties ci) { String userName = ci.getProperty("user"); String password = ci.getProperty("password"); if (userName == null) { userName = Database.SYSTEM_USER_NAME; } User user = database.findUser(userName); if (user == null) { // users is the last thing we add, so if no user is around, // the database is new (or not initialized correctly) user = new User(database, userName); user.setAdmin(true); user.setPassword(password); database.addDatabaseObject(user); } User userObject = database.getUser(userName); Session session = database.createSession(userObject); return session; }
result = ValueString.get(session.getUser().getName(), database.getMode().treatEmptyStringsAsNull); break; session.getUser().checkAdmin(); result = ValueInt.get(Utils.getMemoryFree()); break; case MEMORY_USED: session.getUser().checkAdmin(); result = ValueInt.get(Utils.getMemoryUsed()); break;
/** * Add an object to the database. * * @param obj the object to add */ public synchronized void addDatabaseObject(DbObject obj) { HashMap<String, DbObject> map = getMap(obj.getType()); String name = obj.getName(); if (SysProperties.CHECK && map.get(name) != null) { DbException.throwInternalError("object already exists"); } map.put(name, obj); }
/** * Checks that this user has the given rights for this database object. * * @param table the database object * @param rightMask the rights required * @throws DbException if this user does not have the required rights */ public void checkRight(Table table, int rightMask) { if (!hasRight(table, rightMask)) { throw DbException.get(ErrorCode.NOT_ENOUGH_RIGHTS_FOR_1, table.getSQL()); } }
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 User(Database database, String userName) { initDbObjectBase(database, userName); }
private String getUniqueName(DbObject obj, HashMap<String, ? extends SchemaObject> map, String prefix) { String hash = Integer.toHexString(obj.getName().hashCode()).toUpperCase(); String name = null; synchronized (temporaryUniqueNames) { for (int i = 1, len = hash.length(); i < len; i++) { name = prefix + hash.substring(0, i); if (!map.containsKey(name) && !temporaryUniqueNames.contains(name)) { break; } name = null; } if (name == null) { prefix = prefix + hash + "_"; for (int i = 0; ; i++) { name = prefix + i; if (!map.containsKey(name) && !temporaryUniqueNames.contains(name)) { break; } } } temporaryUniqueNames.add(name); } return name; }
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; }
/** * Remove the object from the database. * * @param session the session * @param obj the object to remove */ public synchronized void removeDatabaseObject(Session session, DbObject obj) { String objName = obj.getName(); int type = obj.getType(); HashMap<String, DbObject> map = getMap(type); if (SysProperties.CHECK && !map.containsKey(objName)) { DbException.throwInternalError("not found: " + objName); } map.remove(objName); }
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(); database.setMode(mode);
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()); } return command; }