Search in sources :

Example 36 with Database

use of org.h2.engine.Database in project h2database by h2database.

the class Set method addOrUpdateSetting.

private void addOrUpdateSetting(Session session, String name, String s, int v) {
    Database database = session.getDatabase();
    if (database.isReadOnly()) {
        return;
    }
    Setting setting = database.findSetting(name);
    boolean addNew = false;
    if (setting == null) {
        addNew = true;
        int id = getObjectId();
        setting = new Setting(database, id, name);
    }
    if (s != null) {
        if (!addNew && setting.getStringValue().equals(s)) {
            return;
        }
        setting.setStringValue(s);
    } else {
        if (!addNew && setting.getIntValue() == v) {
            return;
        }
        setting.setIntValue(v);
    }
    if (addNew) {
        database.addDatabaseObject(session, setting);
    } else {
        database.updateMeta(session, setting);
    }
}
Also used : Setting(org.h2.engine.Setting) Database(org.h2.engine.Database)

Example 37 with Database

use of org.h2.engine.Database in project h2database by h2database.

the class Database method addSchemaObject.

/**
 * 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);
    }
}
Also used : Constraint(org.h2.constraint.Constraint)

Example 38 with Database

use of org.h2.engine.Database in project h2database by h2database.

the class Database method stopServer.

private void stopServer() {
    if (server != null) {
        Server s = server;
        // avoid calling stop recursively
        // because stopping the server will
        // try to close the database as well
        server = null;
        s.stop();
    }
}
Also used : Server(org.h2.tools.Server)

Example 39 with Database

use of org.h2.engine.Database in project h2database by h2database.

the class Database method addDatabaseObject.

/**
 * 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);
}
Also used : Constraint(org.h2.constraint.Constraint)

Example 40 with Database

use of org.h2.engine.Database in project h2database by h2database.

the class Database method renameDatabaseObject.

/**
 * 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);
}
Also used : Constraint(org.h2.constraint.Constraint)

Aggregations

Database (org.h2.engine.Database)79 SQLException (java.sql.SQLException)45 PreparedStatement (java.sql.PreparedStatement)38 DbException (org.h2.message.DbException)37 ResultSet (java.sql.ResultSet)34 Statement (java.sql.Statement)32 SimpleResultSet (org.h2.tools.SimpleResultSet)32 Connection (java.sql.Connection)27 Table (org.h2.table.Table)25 Value (org.h2.value.Value)25 Column (org.h2.table.Column)22 IOException (java.io.IOException)19 Constraint (org.h2.constraint.Constraint)18 Expression (org.h2.expression.Expression)17 ExpressionColumn (org.h2.expression.ExpressionColumn)17 ValueString (org.h2.value.ValueString)15 ValueExpression (org.h2.expression.ValueExpression)14 Session (org.h2.engine.Session)13 JdbcConnection (org.h2.jdbc.JdbcConnection)13 Schema (org.h2.schema.Schema)13