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