database.addSchemaObject(ses, idx); database.addSchemaObject(ses, cloneIdx);
/** * Construct a local result object. * * @param session the session * @param expressions the expression array * @param visibleColumnCount the number of visible columns */ public LocalResult(Session session, Expression[] expressions, int visibleColumnCount) { this.session = session; if (session == null) { this.maxMemoryRows = Integer.MAX_VALUE; } else { Database db = session.getDatabase(); if (db.isPersistent() && !db.isReadOnly()) { this.maxMemoryRows = session.getDatabase().getMaxMemoryRows(); } else { this.maxMemoryRows = Integer.MAX_VALUE; } } rows = New.arrayList(); this.visibleColumnCount = visibleColumnCount; rowId = -1; this.expressions = expressions; }
/** * Notifies query progress via the DatabaseEventListener */ private void setProgress() { if ((currentRowNumber & 127) == 0) { session.getDatabase().setProgress( DatabaseEventListener.STATE_STATEMENT_PROGRESS, sqlStatement, currentRowNumber, 0); } }
public CompareLike(Database db, Expression left, Expression right, Expression escape, boolean regexp) { this(db.getCompareMode(), db.getSettings().defaultEscape, left, right, escape, regexp); }
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); } }
public synchronized void setMasterUser(User user) { lockMeta(systemSession); addDatabaseObject(systemSession, user); systemSession.commit(true); }
String catalog = identifier(database.getShortName()); boolean admin = session.getUser().isAdmin(); switch (type) { String collation = database.getCompareMode().getName(); for (int j = 0; j < cols.length; j++) { Column c = cols[j]; for (Setting s : database.getAllSettings()) { String value = s.getStringValue(); if (value == null) { add(rows, "EXCLUSIVE", database.getExclusiveSession() == null ? "FALSE" : "TRUE"); add(rows, "MODE", database.getMode().getName()); add(rows, "MULTI_THREADED", database.isMultiThreaded() ? "1" : "0"); add(rows, "MVCC", database.isMultiVersion() ? "TRUE" : "FALSE"); add(rows, "QUERY_TIMEOUT", "" + session.getQueryTimeout()); add(rows, "RETENTION_TIME", "" + database.getRetentionTime()); add(rows, "LOG", "" + database.getLogMode()); HashMap<String, String> s = database.getSettings().getSettings(); settingNames.addAll(s.keySet()); Collections.sort(settingNames); if (database.isPersistent()) { PageStore store = database.getPageStore(); if (store != null) { add(rows, "info.FILE_WRITE_TOTAL",
if (ifExists && !Database.exists(name)) { throw DbException.get(ErrorCode.DATABASE_NOT_FOUND_1, name); database = new Database(ci, cipher); opened = true; if (database.getAllUsers().isEmpty()) { user = new User(database, database.allocateObjectId(), ci.getUserName(), false); user.setAdmin(true); user.setUserPasswordHash(ci.getUserPasswordHash()); database.setMasterUser(user); database.opened(); if (database.isClosing()) { return null; if (database.validateFilePasswordHash(cipher, ci.getFilePasswordHash())) { user = database.findUser(ci.getUserName()); if (user != null) { if (!user.validateUserPasswordHash(ci.getUserPasswordHash())) { database.setEventListener(null); database.getTrace(Trace.DATABASE).error(er, "wrong user or password; user: \"" + ci.getUserName() + "\""); database.removeSession(null); throw er;
session.commit(true); Database db = session.getDatabase(); db.lockMeta(session); ArrayList<Table> tables = db.getAllTablesAndViews(false); ArrayList<Table> toRemove = New.arrayList(); for (Table t : tables) { } else if (db.getDependentTable(t, t) == null) { db.removeSchemaObject(session, t); } else { runLoopAgain = true; for (Schema schema : db.getAllSchemas()) { if (schema.canDrop()) { db.removeDatabaseObject(session, schema); for (SchemaObject obj : db.getAllSchemaObjects(DbObject.SEQUENCE)) { list.addAll(db.getAllSchemaObjects(DbObject.CONSTRAINT)); list.addAll(db.getAllSchemaObjects(DbObject.TRIGGER)); list.addAll(db.getAllSchemaObjects(DbObject.CONSTANT)); list.addAll(db.getAllSchemaObjects(DbObject.FUNCTION_ALIAS)); for (SchemaObject obj : list) { if (obj.isHidden()) { continue; db.removeSchemaObject(session, obj);
if (schemaNames != null) { for (String schemaName : schemaNames) { Schema schema = db.findSchema(schemaName); if (schema == null) { throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, for (Setting setting : db.getAllSettings()) { if (setting.getName().equals(SetTypes.getTypeName( SetTypes.CREATE_BUILD))) { for (User user : db.getAllUsers()) { add(user.getCreateSQL(passwords), false); for (Role role : db.getAllRoles()) { add(role.getCreateSQL(true), false); for (Schema schema : db.getAllSchemas()) { if (excludeSchema(schema)) { continue; for (UserDataType datatype : db.getAllUserDataTypes()) { if (drop) { add(datatype.getDropSQL(), false); for (SchemaObject obj : db.getAllSchemaObjects( DbObject.CONSTANT)) { if (excludeSchema(obj.getSchema())) { final ArrayList<Table> tables = db.getAllTablesAndViews(false);
boolean opened = false; if (database == null) { if (ifExists && !Database.exists(name)) { throw Message.getSQLException(ErrorCode.DATABASE_NOT_FOUND_1, name); database = new Database(name, ci, cipher); opened = true; if (database.getAllUsers().size() == 0) { user = new User(database, database.allocateObjectId(false, true), ci.getUserName(), false); user.setAdmin(true); user.setUserPasswordHash(ci.getUserPasswordHash()); database.setMasterUser(user); database.opened(); if (database.isClosing()) { return null; if (database.validateFilePasswordHash(cipher, ci.getFilePasswordHash())) { user = database.findUser(ci.getUserName()); if (user != null) { if (!user.validateUserPasswordHash(ci.getUserPasswordHash())) { database.setEventListener(null); database.removeSession(null); throw Message.getSQLException(ErrorCode.WRONG_USER_OR_PASSWORD);
database.lockMeta(session); if (database.isStarting() && database.getPageStore().getRootPageId(indexId) != 0) { mainIndexColumn = -1; } else if (!database.isStarting() && mainIndex.getRowCount(session) != 0) { mainIndexColumn = -1; } else { if (database.isMultiVersion()) { index = new MultiVersionIndex(index, this); Cursor cursor = scan.find(session, null, null); long i = 0; int bufferSize = (int) Math.min(rowCount, database.getMaxMemoryRows()); ArrayList<Row> buffer = new ArrayList<>(bufferSize); String n = getName() + ":" + index.getName(); int t = MathUtils.convertLongToInt(total); while (cursor.next()) { database.setProgress(DatabaseEventListener.STATE_CREATE_INDEX, n, MathUtils.convertLongToInt(i++), t); Row row = cursor.get(); session.addLocalTempTableIndex(index); } else { database.addSchemaObject(session, index);
database.getLobStorage().removeAllForTable(getId()); database.lockMeta(session); Index index = indexes.get(1); if (index.getName() != null) { database.removeSchemaObject(session, index); for (SchemaObject obj : database.getAllSchemaObjects(DbObject.INDEX)) { Index index = (Index) obj; if (index.getTable() == this) { database.removeMeta(session, getId()); scanIndex = null; lockExclusiveSession = null;
/** * 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); }
Cursor cursor = scan.find(session, null, null); long i = 0; Store store = session.getDatabase().getMvStore(); int bufferSize = database.getMaxMemoryRows() / 2; ArrayList<Row> buffer = new ArrayList<>(bufferSize); String n = getName() + ":" + index.getName(); Row row = cursor.get(); buffer.add(row); database.setProgress(DatabaseEventListener.STATE_CREATE_INDEX, n, MathUtils.convertLongToInt(i++), t); if (buffer.size() >= bufferSize) {
throwLastBackgroundException(); if (fileLockMethod == FileLockMethod.SERIALIZED && !reconnectChangePending) { closeOpenFilesAndUnlock(false); } catch (DbException e) { stopServer(); if (!userSessions.isEmpty()) { if (!fromShutdownHook) { closeAllSessionsException(null); removeOrphanedLobs(); try { if (systemSession != null) { if (powerOffCount != -1) { for (Table table : getAllTablesAndViews(false)) { if (table.isGlobalTemporary()) { table.removeChildrenAndResources(systemSession); for (SchemaObject obj : getAllSchemaObjects( DbObject.SEQUENCE)) { Sequence sequence = (Sequence) obj; for (SchemaObject obj : getAllSchemaObjects( DbObject.TRIGGER)) { TriggerObject trigger = (TriggerObject) obj;
private void rebuildIndexBuffered(Session session, Index index) { Index scan = getScanIndex(session); long remaining = scan.getRowCount(session); long total = remaining; Cursor cursor = scan.find(session, null, null); long i = 0; int bufferSize = (int) Math.min(total, database.getMaxMemoryRows()); ArrayList<Row> buffer = new ArrayList<>(bufferSize); String n = getName() + ":" + index.getName(); int t = MathUtils.convertLongToInt(total); while (cursor.next()) { Row row = cursor.get(); buffer.add(row); database.setProgress(DatabaseEventListener.STATE_CREATE_INDEX, n, MathUtils.convertLongToInt(i++), t); if (buffer.size() >= bufferSize) { addRowsToIndex(session, buffer, index); } remaining--; } addRowsToIndex(session, buffer, index); if (SysProperties.CHECK && remaining != 0) { DbException.throwInternalError("rowcount remaining=" + remaining + " " + getName()); } }
Database db = targetSession.getDatabase(); Schema schema = getSchemaWithDefault(); int id = db.allocateObjectId(); Column[] columnTemplateArray = columnTemplateList.toArray(new Column[0]); if (!view.isRecursiveQueryDetected() && allowRecursiveQueryDetection) { if (isPersistent) { db.addSchemaObject(targetSession, view); view.lock(targetSession, true, true); targetSession.getDatabase().removeSchemaObject(targetSession, view); } else { session.removeLocalTempTable(view); targetSession.getDatabase().unlockMeta(targetSession); if (addViewToSession) { if (isPersistent) { db.addSchemaObject(targetSession, view); view.unlock(targetSession); db.unlockMeta(targetSession); } else { targetSession.addLocalTempTable(view);
ConnectionInfo ci = new ConnectionInfo("jdbc:h2:" + testDatabase + ";FILE_LOCK=NO;TRACE_LEVEL_FILE=0", p); Database database = new Database(ci, null); Session sysSession = database.getSystemSession(); sysSession.prepare("script to '" + testDatabase + ".sql'").query(0); sysSession.prepare("shutdown immediately").update(); database.removeSession(null); ConnectionInfo ci = new ConnectionInfo("jdbc:h2:" + testDatabase + ";FILE_LOCK=NO", p); Database database = new Database(ci, null); database.removeSession(null); } catch (Exception e) { int errorCode = 0;
/** * 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); }