Search in sources :

Example 1 with Builder

use of org.h2.mvstore.MVMap.Builder in project h2database by h2database.

the class TransactionStore method openMap.

/**
 * Open the map with the given name.
 *
 * @param <K> the key type
 * @param name the map name
 * @param keyType the key type
 * @param valueType the value type
 * @return the map
 */
synchronized <K> MVMap<K, VersionedValue> openMap(String name, DataType keyType, DataType valueType) {
    if (keyType == null) {
        keyType = new ObjectDataType();
    }
    if (valueType == null) {
        valueType = new ObjectDataType();
    }
    VersionedValueType vt = new VersionedValueType(valueType);
    MVMap<K, VersionedValue> map;
    MVMap.Builder<K, VersionedValue> builder = new MVMap.Builder<K, VersionedValue>().keyType(keyType).valueType(vt);
    map = store.openMap(name, builder);
    @SuppressWarnings("unchecked") MVMap<Object, VersionedValue> m = (MVMap<Object, VersionedValue>) map;
    maps.put(map.getId(), m);
    return map;
}
Also used : MVMap(org.h2.mvstore.MVMap) ObjectDataType(org.h2.mvstore.type.ObjectDataType)

Example 2 with Builder

use of org.h2.mvstore.MVMap.Builder in project h2database by h2database.

the class MVTableEngine method init.

/**
 * Initialize the MVStore.
 *
 * @param db the database
 * @return the store
 */
public static Store init(final Database db) {
    Store store = db.getMvStore();
    if (store != null) {
        return store;
    }
    byte[] key = db.getFileEncryptionKey();
    String dbPath = db.getDatabasePath();
    MVStore.Builder builder = new MVStore.Builder();
    store = new Store();
    boolean encrypted = false;
    if (dbPath != null) {
        String fileName = dbPath + Constants.SUFFIX_MV_FILE;
        MVStoreTool.compactCleanUp(fileName);
        builder.fileName(fileName);
        builder.pageSplitSize(db.getPageSize());
        if (db.isReadOnly()) {
            builder.readOnly();
        } else {
            // possibly create the directory
            boolean exists = FileUtils.exists(fileName);
            if (exists && !FileUtils.canWrite(fileName)) {
            // read only
            } else {
                String dir = FileUtils.getParent(fileName);
                FileUtils.createDirectories(dir);
            }
        }
        if (key != null) {
            encrypted = true;
            char[] password = new char[key.length / 2];
            for (int i = 0; i < password.length; i++) {
                password[i] = (char) (((key[i + i] & 255) << 16) | ((key[i + i + 1]) & 255));
            }
            builder.encryptionKey(password);
        }
        if (db.getSettings().compressData) {
            builder.compress();
            // use a larger page split size to improve the compression ratio
            builder.pageSplitSize(64 * 1024);
        }
        builder.backgroundExceptionHandler(new UncaughtExceptionHandler() {

            @Override
            public void uncaughtException(Thread t, Throwable e) {
                db.setBackgroundException(DbException.convert(e));
            }
        });
    }
    store.open(db, builder, encrypted);
    db.setMvStore(store);
    return store;
}
Also used : MVStore(org.h2.mvstore.MVStore) FileStore(org.h2.mvstore.FileStore) MVStore(org.h2.mvstore.MVStore) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)

Example 3 with Builder

use of org.h2.mvstore.MVMap.Builder in project georocket by georocket.

the class H2Store method getMVStore.

/**
 * Get or create the H2 MVStore
 * @return the MVStore
 */
protected MVStore getMVStore() {
    MVStore result = mvstore.get();
    if (result == null) {
        synchronized (mvstore) {
            MVStore.Builder builder = new MVStore.Builder().fileName(path);
            if (compress) {
                builder = builder.compress();
            }
            result = builder.open();
            mvstore.set(result);
        }
    }
    return result;
}
Also used : MVStore(org.h2.mvstore.MVStore)

Example 4 with Builder

use of org.h2.mvstore.MVMap.Builder in project ignite by apache.

the class HibernateL2CacheTransactionalSelfTest method registryBuilder.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
protected StandardServiceRegistryBuilder registryBuilder() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();
    // JTA-aware data source.
    BasicManagedDataSource dataSrc = new BasicManagedDataSource();
    dataSrc.setTransactionManager(jotm.getTransactionManager());
    dataSrc.setDefaultAutoCommit(false);
    JdbcDataSource h2DataSrc = new JdbcDataSource();
    h2DataSrc.setURL(CONNECTION_URL);
    dataSrc.setXaDataSourceInstance(h2DataSrc);
    connProvider.setDataSource(dataSrc);
    connProvider.configure(Collections.emptyMap());
    builder.addService(ConnectionProvider.class, connProvider);
    builder.addService(JtaPlatform.class, new TestJtaPlatform());
    builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName());
    return builder;
}
Also used : JtaTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) DatasourceConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) BasicManagedDataSource(org.apache.commons.dbcp.managed.BasicManagedDataSource) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with Builder

use of org.h2.mvstore.MVMap.Builder in project ignite by apache.

the class GridH2CollocationModel method toString.

/**
 * @param b String builder.
 * @param lvl Depth level.
 */
private boolean toString(SB b, int lvl) {
    boolean res = false;
    if (lvl == 0) {
        TableFilter f = filter();
        String tblAlias = f == null ? "^" : f.getTableAlias();
        b.a("[tbl=").a(tblAlias).a(", type=").a(type).a(", mul=").a(multiplier).a("]");
        res = true;
    } else if (childFilters != null) {
        assert lvl > 0;
        lvl--;
        for (int i = 0; i < childFilters.length; i++) {
            if (lvl == 0)
                b.a(" | ");
            res |= child(i, true).toString(b, lvl);
        }
        if (lvl == 0)
            b.a(" | ");
    }
    return res;
}
Also used : TableFilter(org.h2.table.TableFilter)

Aggregations

MVStore (org.h2.mvstore.MVStore)4 IOException (java.io.IOException)2 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)2 FileStore (org.h2.mvstore.FileStore)2 TableFilter (org.h2.table.TableFilter)2 SQLServerDataSource (com.microsoft.sqlserver.jdbc.SQLServerDataSource)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Closeable (java.io.Closeable)1 UncaughtExceptionHandler (java.lang.Thread.UncaughtExceptionHandler)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Arrays (java.util.Arrays)1 ScriptException (javax.script.ScriptException)1 DataSource (javax.sql.DataSource)1 OpaqueString (oracle.jdbc.internal.OpaqueString)1 OracleDataSource (oracle.jdbc.pool.OracleDataSource)1 PoolDataSource (oracle.ucp.jdbc.PoolDataSource)1