private synchronized void updateMetaAndFirstLevelChildren(Session session, DbObject obj) { ArrayList<DbObject> list = obj.getChildren(); Comment comment = findComment(obj); if (comment != null) { DbException.throwInternalError(comment.toString()); } updateMeta(session, obj); // remember that this scans only one level deep! if (list != null) { for (DbObject o : list) { if (o.getCreateSQL() != null) { updateMeta(session, o); } } } }
String createSQL = child.getCreateSQL(); if (createSQL == null) { continue; } else if (child.getType() == DbObject.TABLE_OR_VIEW) { DbException.throwInternalError(); String quotedName = Parser.quoteIdentifier(tempName + "_" + child.getName()); String sql = null; if (child instanceof ConstraintReferential) { sql = child.getCreateSQLForCopy(newTable, quotedName);
/** * 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) { checkWritingAllowed(); 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(); int id = obj.getId(); lockMeta(session); removeMeta(session, id); map.remove(obj.getName()); obj.rename(newName); map.put(newName, obj); updateMetaAndFirstLevelChildren(session, obj); }
MetaRecord(DbObject obj) { id = obj.getId(); objectType = obj.getType(); sql = obj.getCreateSQL(); }
/** * Remove the object from the database. * * @param session the session * @param obj the object to remove */ public synchronized void removeDatabaseObject(Session session, DbObject obj) { checkWritingAllowed(); 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); } Comment comment = findComment(obj); lockMeta(session); if (comment != null) { removeDatabaseObject(session, comment); } int id = obj.getId(); obj.removeChildrenAndResources(session); map.remove(objName); removeMeta(session, id); }
/** * Add an object to the database. * * @param session the session * @param obj the object to add */ public synchronized void addDatabaseObject(Session session, DbObject obj) { int id = obj.getId(); if (id > 0 && !starting) { checkWritingAllowed(); } HashMap<String, DbObject> map = getMap(obj.getType()); if (obj.getType() == DbObject.USER) { User user = (User) obj; if (user.isAdmin() && systemUser.getName().equals(SYSTEM_USER_NAME)) { systemUser.rename(user.getName()); } } String name = obj.getName(); if (SysProperties.CHECK && map.get(name) != null) { DbException.throwInternalError("object already exists"); } lockMeta(session); addMeta(session, obj); map.put(name, obj); }
private void addPrivilege(ArrayList<Row> rows, DbObject grantee, String catalog, Table table, String column, String right) { String isGrantable = "NO"; if (grantee.getType() == DbObject.USER) { User user = (User) grantee; if (user.isAdmin()) { identifier(grantee.getName()), identifier(table.getName()),
public MetaRecord(DbObject obj) { id = obj.getId(); objectType = obj.getType(); headPos = obj.getHeadPos(); sql = obj.getCreateSQL(); }
continue; String name = child.getName(); if (name == null || child.getCreateSQL() == null) { continue;
private synchronized void addMeta(Session session, DbObject obj) { int id = obj.getId(); if (id > 0 && !starting && !obj.isTemporary()) { Row r = meta.getTemplateRow(); MetaRecord rec = new MetaRecord(obj); rec.setRecord(r); objectIds.set(id); if (SysProperties.CHECK) { verifyMetaLocked(session); } meta.addRow(session, r); if (isMultiVersion()) { // TODO this should work without MVCC, but avoid risks at the // moment session.log(meta, UndoLogRecord.INSERT, r); } } }
dbObjects.addAll(db.getAllUserDataTypes()); for (DbObject obj : dbObjects) { String sql = obj.getCreateSQL();
/** * Get the comment for the given database object if one exists, or null if * not. * * @param object the database object * @return the comment or null */ public Comment findComment(DbObject object) { if (object.getType() == DbObject.COMMENT) { return null; } String key = Comment.getKey(object); return comments.get(key); }
private String getUniqueName(DbObject obj, Map<String, ? extends SchemaObject> map, String prefix) { String hash = StringUtils.toUpperEnglish(Integer.toHexString(obj.getName().hashCode())); 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; }
/** * Update an object in the system table. * * @param session the session * @param obj the database object */ public void updateMeta(Session session, DbObject obj) { lockMeta(session); synchronized (this) { int id = obj.getId(); removeMeta(session, id); addMeta(session, obj); // for temporary objects if (id > 0) { objectIds.set(id); } } }
table.getColumn(columnName).setComment(text); } else { object.setComment(text);
/** * Check that a table or view is still valid. * * @param tableOrView the table or view to check */ private void checkViewsAreValid(DbObject tableOrView) { for (DbObject view : tableOrView.getChildren()) { if (view instanceof TableView) { String sql = ((TableView) view).getQuery(); // check if the query is still valid // do not execute, not even with limit 1, because that could // have side effects or take a very long time session.prepare(sql); checkViewsAreValid(view); } } }
private String getCreateSQLForCopy(DbObject object) { StringBuilder buff = new StringBuilder(); buff.append("GRANT "); if (grantedRole != null) { buff.append(grantedRole.getSQL()); } else { buff.append(getRights()); if (object != null) { if (object instanceof Schema) { buff.append(" ON SCHEMA ").append(object.getSQL()); } else if (object instanceof Table) { buff.append(" ON ").append(object.getSQL()); } } } buff.append(" TO ").append(grantee.getSQL()); return buff.toString(); }
private synchronized void addMeta(Session session, DbObject obj) throws SQLException { if (obj.getTemporary()) { return; } Row r = meta.getTemplateRow(); MetaRecord rec = new MetaRecord(obj); rec.setRecord(r); objectIds.set(obj.getId()); meta.lock(session, true, true); meta.addRow(session, r); if (isMultiVersion()) { // TODO this should work without MVCC, but avoid risks at the moment session.log(meta, UndoLogRecord.INSERT, r); } }
public synchronized void removeDatabaseObject(Session session, DbObject obj) throws SQLException { String objName = obj.getName(); int type = obj.getType(); HashMap map = getMap(type); if (SysProperties.CHECK && !map.containsKey(objName)) { throw Message.getInternalError("not found: " + objName); } Comment comment = findComment(obj); if (comment != null) { removeDatabaseObject(session, comment); } int id = obj.getId(); obj.removeChildrenAndResources(session); map.remove(objName); removeMeta(session, id); }