当前位置: 首页>>代码示例>>Java>>正文


Java Database类代码示例

本文整理汇总了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");
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:MVSecondaryIndex.java

示例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();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:22,代码来源:MVPrimaryIndex.java

示例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);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:19,代码来源:AggregateDataSelectivity.java

示例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++;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:AggregateDataHistogram.java

示例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);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:26,代码来源:AggregateDataHistogram.java

示例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);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:18,代码来源:AggregateDataGroupConcat.java

示例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);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:29,代码来源:Expression.java

示例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);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:26,代码来源:Function.java

示例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;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:MetaTable.java

示例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);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:Command.java

示例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;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:DropTrigger.java

示例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);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:AlterTableAlterColumn.java

示例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;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:22,代码来源:CreateSchema.java

示例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;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:19,代码来源:CreateAggregate.java

示例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;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:19,代码来源:DropSequence.java


注:本文中的org.h2.engine.Database类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。