/** * Add a table synonym to the schema. * * @param data the create synonym information * @return the created {@link TableSynonym} object */ public TableSynonym createSynonym(CreateSynonymData data) { synchronized (database) { database.lockMeta(data.session); data.schema = this; return new TableSynonym(data); } }
public synchronized void setMasterUser(User user) { lockMeta(systemSession); addDatabaseObject(systemSession, user); systemSession.commit(true); }
/** * Drop and remove the given local temporary table from this session. * * @param table the table */ public void removeLocalTempTable(Table table) { // Exception thrown in org.h2.engine.Database.removeMeta if line below // is missing with TestGeneralCommonTableQueries database.lockMeta(this); modificationId++; localTempTables.remove(table.getName()); synchronized (database) { table.removeChildrenAndResources(this); } }
private void flushInternal(Session session) { final boolean metaWasLocked = database.lockMeta(session); // just for this case, use the value with the margin try { writeWithMargin = true; database.updateMeta(session, this); } finally { writeWithMargin = false; } if (!metaWasLocked) { database.unlockMeta(session); } }
private void cleanTempTables(boolean closeSession) { if (localTempTables != null && localTempTables.size() > 0) { synchronized (database) { Iterator<Table> it = localTempTables.values().iterator(); while (it.hasNext()) { Table table = it.next(); if (closeSession || table.getOnCommitDrop()) { modificationId++; table.setModified(); it.remove(); // Exception thrown in org.h2.engine.Database.removeMeta // if line below is missing with TestDeadlock database.lockMeta(this); table.removeChildrenAndResources(this); if (closeSession) { // need to commit, otherwise recovery might // ignore the table removal database.commit(this); } } else if (table.getOnCommitTruncate()) { table.truncate(this); } } } } }
/** * Add a table to the schema. * * @param data the create table information * @return the created {@link Table} object */ public Table createTable(CreateTableData data) { synchronized (database) { if (!data.temporary || data.globalTemporary) { database.lockMeta(data.session); } data.schema = this; if (data.tableEngine == null) { DbSettings s = database.getSettings(); if (s.defaultTableEngine != null) { data.tableEngine = s.defaultTableEngine; } else if (s.mvStore) { data.tableEngine = MVTableEngine.class.getName(); } } if (data.tableEngine != null) { if (data.tableEngineParams == null) { data.tableEngineParams = this.tableEngineParams; } return database.getTableEngine(data.tableEngine).createTable(data); } return new RegularTable(data); } }
/** * 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); } } }
/** * Add a schema object to the database. * * @param session the session * @param obj the object to add */ public void addSchemaObject(Session session, SchemaObject obj) { int id = obj.getId(); if (id > 0 && !starting) { checkWritingAllowed(); } lockMeta(session); synchronized (this) { obj.getSchema().add(obj); addMeta(session, obj); } }
private void executeDrop() { // need to get the table again, because it may be dropped already // meanwhile (dependent object, or same object) table = getSchema().findTableOrView(session, tableName); if (table != null) { table.setModified(); Database db = session.getDatabase(); db.lockMeta(session); db.removeSchemaObject(session, table); } if (next != null) { next.executeDrop(); } }
/** * 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); }
/** * 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); }
/** * 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); }
database.lockMeta(session);
@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); }
database.lockMeta(session);
session.commit(true); Database db = session.getDatabase(); db.lockMeta(session);
pageStore.checkpoint(); if (!readOnly) { lockMeta(pageStore.getPageStoreSession()); pageStore.compact(compactMode); unlockMeta(pageStore.getPageStoreSession());
SearchRow r = meta.getTemplateSimpleRow(false); r.setValue(0, ValueInt.get(id)); boolean wasLocked = lockMeta(session); Cursor cursor = metaIdIndex.find(session, r, r); if (cursor.next()) {
database.lockMeta(session);
lockMeta(session); synchronized (this) { Comment comment = findComment(obj);