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; }
/** * 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); }
/** * 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); }
/** * 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); }