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);
}
}
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);
}
}
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();
}
}
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);
}
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);
}
Aggregations