本文整理汇总了Java中org.h2.engine.Database类的典型用法代码示例。如果您正苦于以下问题:Java Database类的具体用法?Java Database怎么用?Java Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Database类属于org.h2.engine包,在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MVSecondaryIndex
import org.h2.engine.Database; //导入依赖的package包/类
public MVSecondaryIndex(Database db, MVTable table, int id, String indexName,
IndexColumn[] columns, IndexType indexType) {
this.mvTable = table;
initBaseIndex(table, id, indexName, columns, indexType);
if (!database.isStarting()) {
checkIndexColumnTypes(columns);
}
// always store the row key in the map key,
// even for unique indexes, as some of the index columns could be null
keyColumns = columns.length + 1;
mapName = "index." + getId();
int[] sortTypes = new int[keyColumns];
for (int i = 0; i < columns.length; i++) {
sortTypes[i] = columns[i].sortType;
}
sortTypes[keyColumns - 1] = SortOrder.ASCENDING;
ValueDataType keyType = new ValueDataType(
db.getCompareMode(), db, sortTypes);
ValueDataType valueType = new ValueDataType(null, null, null);
Transaction t = mvTable.getTransaction(null);
dataMap = t.openMap(mapName, keyType, valueType);
t.commit();
if (!keyType.equals(dataMap.getKeyType())) {
throw DbException.throwInternalError("Incompatible key type");
}
}
示例2: MVPrimaryIndex
import org.h2.engine.Database; //导入依赖的package包/类
public MVPrimaryIndex(Database db, MVTable table, int id,
IndexColumn[] columns, IndexType indexType) {
this.mvTable = table;
initBaseIndex(table, id, table.getName() + "_DATA", columns, indexType);
int[] sortTypes = new int[columns.length];
for (int i = 0; i < columns.length; i++) {
sortTypes[i] = SortOrder.ASCENDING;
}
ValueDataType keyType = new ValueDataType(null, null, null);
ValueDataType valueType = new ValueDataType(db.getCompareMode(), db,
sortTypes);
mapName = "table." + getId();
Transaction t = mvTable.getTransaction(null);
dataMap = t.openMap(mapName, keyType, valueType);
t.commit();
if (!table.isPersistData()) {
dataMap.map.setVolatile(true);
}
Value k = dataMap.lastKey();
lastKey = k == null ? 0 : k.getLong();
}
示例3: getValue
import org.h2.engine.Database; //导入依赖的package包/类
@Override
Value getValue(Database database, int dataType, boolean distinct) {
if (distinct) {
count = 0;
}
Value v = null;
int s = 0;
if (count == 0) {
s = 0;
} else {
m2 += distinctHashes.size();
m2 = 100 * m2 / count;
s = (int) m2;
s = s <= 0 ? 1 : s > 100 ? 100 : s;
}
v = ValueInt.get(s);
return v.convertTo(dataType);
}
示例4: add
import org.h2.engine.Database; //导入依赖的package包/类
@Override
void add(Database database, int dataType, boolean distinct, Value v) {
if (distinctValues == null) {
distinctValues = ValueHashMap.newInstance();
}
AggregateDataHistogram a = distinctValues.get(v);
if (a == null) {
if (distinctValues.size() < Constants.SELECTIVITY_DISTINCT_COUNT) {
a = new AggregateDataHistogram();
distinctValues.put(v, a);
}
}
if (a != null) {
a.count++;
}
}
示例5: getValue
import org.h2.engine.Database; //导入依赖的package包/类
@Override
Value getValue(Database database, int dataType, boolean distinct) {
if (distinct) {
count = 0;
groupDistinct(database, dataType);
}
ValueArray[] values = new ValueArray[distinctValues.size()];
int i = 0;
for (Value dv : distinctValues.keys()) {
AggregateDataHistogram d = distinctValues.get(dv);
values[i] = ValueArray.get(new Value[] { dv, ValueLong.get(d.count) });
i++;
}
final CompareMode compareMode = database.getCompareMode();
Arrays.sort(values, new Comparator<ValueArray>() {
@Override
public int compare(ValueArray v1, ValueArray v2) {
Value a1 = v1.getList()[0];
Value a2 = v2.getList()[0];
return a1.compareTo(a2, compareMode);
}
});
Value v = ValueArray.get(values);
return v.convertTo(dataType);
}
示例6: add
import org.h2.engine.Database; //导入依赖的package包/类
@Override
void add(Database database, int dataType, boolean distinct, Value v) {
if (v == ValueNull.INSTANCE) {
return;
}
if (distinct) {
if (distinctValues == null) {
distinctValues = ValueHashMap.newInstance();
}
distinctValues.put(v, this);
return;
}
if (list == null) {
list = New.arrayList();
}
list.add(v);
}
示例7: getExpressionColumns
import org.h2.engine.Database; //导入依赖的package包/类
/**
* Extracts expression columns from the given result set.
*
* @param session the session
* @param rs the result set
* @return an array of expression columns
*/
public static Expression[] getExpressionColumns(Session session, ResultSet rs) {
try {
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
Expression[] expressions = new Expression[columnCount];
Database db = session == null ? null : session.getDatabase();
for (int i = 0; i < columnCount; i++) {
String name = meta.getColumnLabel(i + 1);
int type = DataType.getValueTypeFromResultSet(meta, i + 1);
int precision = meta.getPrecision(i + 1);
int scale = meta.getScale(i + 1);
int displaySize = meta.getColumnDisplaySize(i + 1);
Column col = new Column(name, type, precision, scale, displaySize);
Expression expr = new ExpressionColumn(db, col);
expressions[i] = expr;
}
return expressions;
} catch (SQLException e) {
throw DbException.convert(e);
}
}
示例8: getFunction
import org.h2.engine.Database; //导入依赖的package包/类
/**
* Get an instance of the given function for this database.
* If no function with this name is found, null is returned.
*
* @param database the database
* @param name the function name
* @return the function object or null
*/
public static Function getFunction(Database database, String name) {
if (!database.getSettings().databaseToUpper) {
// if not yet converted to uppercase, do it now
name = StringUtils.toUpperEnglish(name);
}
FunctionInfo info = getFunctionInfo(name);
if (info == null) {
return null;
}
switch(info.type) {
case TABLE:
case TABLE_DISTINCT:
return new TableFunction(database, info, Long.MAX_VALUE);
default:
return new Function(database, info);
}
}
示例9: checkIndex
import org.h2.engine.Database; //导入依赖的package包/类
private boolean checkIndex(Session session, String value, Value indexFrom,
Value indexTo) {
if (value == null || (indexFrom == null && indexTo == null)) {
return true;
}
Database db = session.getDatabase();
Value v;
if (database.getMode().lowerCaseIdentifiers) {
v = ValueStringIgnoreCase.get(value);
} else {
v = ValueString.get(value);
}
if (indexFrom != null && db.compare(v, indexFrom) < 0) {
return false;
}
if (indexTo != null && db.compare(v, indexTo) > 0) {
return false;
}
return true;
}
示例10: stop
import org.h2.engine.Database; //导入依赖的package包/类
private void stop() {
session.endStatement();
session.setCurrentCommand(null);
if (!isTransactional()) {
session.commit(true);
} else if (session.getAutoCommit()) {
session.commit(false);
} else if (session.getDatabase().isMultiThreaded()) {
Database db = session.getDatabase();
if (db != null) {
if (db.getLockMode() == Constants.LOCK_MODE_READ_COMMITTED) {
session.unlockReadLocks();
}
}
}
if (trace.isInfoEnabled() && startTime > 0) {
long time = System.currentTimeMillis() - startTime;
if (time > Constants.SLOW_QUERY_LIMIT_MS) {
trace.info("slow query: {0} ms", time);
}
}
}
示例11: update
import org.h2.engine.Database; //导入依赖的package包/类
@Override
public int update() {
session.commit(true);
Database db = session.getDatabase();
TriggerObject trigger = getSchema().findTrigger(triggerName);
if (trigger == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.TRIGGER_NOT_FOUND_1, triggerName);
}
} else {
Table table = trigger.getTable();
session.getUser().checkRight(table, Right.ALL);
db.removeSchemaObject(session, trigger);
}
return 0;
}
示例12: checkViews
import org.h2.engine.Database; //导入依赖的package包/类
/**
* Check that all views and other dependent objects.
*/
private void checkViews(SchemaObject sourceTable, SchemaObject newTable) {
String sourceTableName = sourceTable.getName();
String newTableName = newTable.getName();
Database db = sourceTable.getDatabase();
// save the real table under a temporary name
String temp = db.getTempTableName(sourceTableName, session);
db.renameSchemaObject(session, sourceTable, temp);
try {
// have our new table impersonate the target table
db.renameSchemaObject(session, newTable, sourceTableName);
checkViewsAreValid(sourceTable);
} finally {
// always put the source tables back with their proper names
try {
db.renameSchemaObject(session, newTable, newTableName);
} finally {
db.renameSchemaObject(session, sourceTable, sourceTableName);
}
}
}
示例13: update
import org.h2.engine.Database; //导入依赖的package包/类
@Override
public int update() {
session.getUser().checkSchemaAdmin();
session.commit(true);
Database db = session.getDatabase();
User user = db.getUser(authorization);
// during DB startup, the Right/Role records have not yet been loaded
if (!db.isStarting()) {
user.checkSchemaAdmin();
}
if (db.findSchema(schemaName) != null) {
if (ifNotExists) {
return 0;
}
throw DbException.get(ErrorCode.SCHEMA_ALREADY_EXISTS_1, schemaName);
}
int id = getObjectId();
Schema schema = new Schema(db, id, schemaName, user, false);
db.addDatabaseObject(session, schema);
return 0;
}
示例14: update
import org.h2.engine.Database; //导入依赖的package包/类
@Override
public int update() {
session.commit(true);
session.getUser().checkAdmin();
Database db = session.getDatabase();
if (db.findAggregate(name) != null || schema.findFunction(name) != null) {
if (!ifNotExists) {
throw DbException.get(
ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, name);
}
} else {
int id = getObjectId();
UserAggregate aggregate = new UserAggregate(
db, id, name, javaClassMethod, force);
db.addDatabaseObject(session, aggregate);
}
return 0;
}
示例15: update
import org.h2.engine.Database; //导入依赖的package包/类
@Override
public int update() {
session.getUser().checkAdmin();
session.commit(true);
Database db = session.getDatabase();
Sequence sequence = getSchema().findSequence(sequenceName);
if (sequence == null) {
if (!ifExists) {
throw DbException.get(ErrorCode.SEQUENCE_NOT_FOUND_1, sequenceName);
}
} else {
if (sequence.getBelongsToTable()) {
throw DbException.get(ErrorCode.SEQUENCE_BELONGS_TO_A_TABLE_1, sequenceName);
}
db.removeSchemaObject(session, sequence);
}
return 0;
}