本文整理汇总了Java中org.h2.engine.Database.getSystemSession方法的典型用法代码示例。如果您正苦于以下问题:Java Database.getSystemSession方法的具体用法?Java Database.getSystemSession怎么用?Java Database.getSystemSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.engine.Database
的用法示例。
在下文中一共展示了Database.getSystemSession方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import org.h2.engine.Database; //导入方法依赖的package包/类
@Override
public int update() {
Database db = session.getDatabase();
if (table != null) {
session.getUser().checkRight(table, Right.ALL);
}
if (cycle != null) {
sequence.setCycle(cycle);
}
if (cacheSize != null) {
long size = cacheSize.optimize(session).getValue(session).getLong();
sequence.setCacheSize(size);
}
if (start != null || minValue != null ||
maxValue != null || increment != null) {
Long startValue = getLong(start);
Long min = getLong(minValue);
Long max = getLong(maxValue);
Long inc = getLong(increment);
sequence.modify(startValue, min, max, inc);
}
// need to use the system session, so that the update
// can be committed immediately - not committing it
// would keep other transactions from using the sequence
Session sysSession = db.getSystemSession();
synchronized (sysSession) {
synchronized (db) {
db.updateMeta(sysSession, sequence);
sysSession.commit(true);
}
}
return 0;
}
示例2: create
import org.h2.engine.Database; //导入方法依赖的package包/类
/**
* Create a new in-memory database.
*
* @param factory the cursor factory
* @return a connection to this database
*/
public static H2Database create(H2Database.CursorFactory factory) {
ConnectionInfo ci = new ConnectionInfo("mem:");
Database db = new Database(ci, null);
Session s = db.getSystemSession();
return new H2Database(s, factory);
}
示例3: openDatabase
import org.h2.engine.Database; //导入方法依赖的package包/类
/**
* Open a connection to the given database.
*
* @param path the database file name
* @param factory the cursor factory
* @param flags 0, or a combination of OPEN_READONLY and CREATE_IF_NECESSARY
* @return a connection to this database
*/
public static H2Database openDatabase(String path,
H2Database.CursorFactory factory, int flags) {
ConnectionInfo ci = new ConnectionInfo(path);
if ((flags & OPEN_READWRITE) != 0) {
// TODO readonly connections
}
if ((flags & CREATE_IF_NECESSARY) == 0) {
ci.setProperty("IFEXISTS", "TRUE");
}
ci.setProperty("FILE_LOCK", "FS");
Database db = new Database(ci, null);
Session s = db.getSystemSession();
return new H2Database(s, factory);
}
示例4: update
import org.h2.engine.Database; //导入方法依赖的package包/类
@Override
public int update() {
session.commit(true);
session.getUser().checkAdmin();
Database db = session.getDatabase();
TableView view = null;
Table old = getSchema().findTableOrView(session, viewName);
if (old != null) {
if (ifNotExists) {
return 0;
}
if (!orReplace || !Table.VIEW.equals(old.getTableType())) {
throw DbException.get(ErrorCode.VIEW_ALREADY_EXISTS_1, viewName);
}
view = (TableView) old;
}
int id = getObjectId();
String querySQL;
if (select == null) {
querySQL = selectSQL;
} else {
ArrayList<Parameter> params = select.getParameters();
if (params != null && params.size() > 0) {
throw DbException.getUnsupportedException("parameters in views");
}
querySQL = select.getPlanSQL();
}
// The view creates a Prepared command object, which belongs to a
// session, so we pass the system session down.
Session sysSession = db.getSystemSession();
try {
if (view == null) {
Schema schema = session.getDatabase().getSchema(session.getCurrentSchemaName());
sysSession.setCurrentSchema(schema);
view = new TableView(getSchema(), id, viewName, querySQL, null,
columnNames, sysSession, false);
} else {
view.replace(querySQL, columnNames, sysSession, false, force);
view.setModified();
}
} finally {
sysSession.setCurrentSchema(db.getSchema(Constants.SCHEMA_MAIN));
}
if (comment != null) {
view.setComment(comment);
}
if (old == null) {
db.addSchemaObject(session, view);
} else {
db.updateMeta(session, view);
}
return 0;
}
示例5: dropTable
import org.h2.engine.Database; //导入方法依赖的package包/类
private void dropTable() {
if (table == null) {
return;
}
if (containsLob) {
// contains BLOB or CLOB: can not truncate now,
// otherwise the BLOB and CLOB entries are removed
return;
}
try {
Database database = session.getDatabase();
// Need to lock because not all of the code-paths
// that reach here have already taken this lock,
// notably via the close() paths.
synchronized (session) {
synchronized (database) {
table.truncate(session);
}
}
// This session may not lock the sys table (except if it already has
// locked it) because it must be committed immediately, otherwise
// other threads can not access the sys table. If the table is not
// removed now, it will be when the database is opened the next
// time. (the table is truncated, so this is just one record)
if (!database.isSysTableLocked()) {
Session sysSession = database.getSystemSession();
table.removeChildrenAndResources(sysSession);
if (index != null) {
// need to explicitly do this,
// as it's not registered in the system session
session.removeLocalTempTableIndex(index);
}
// the transaction must be committed immediately
// TODO this synchronization cascade is very ugly
synchronized (session) {
synchronized (sysSession) {
synchronized (database) {
sysSession.commit(false);
}
}
}
}
} finally {
table = null;
}
}