use of jetbrains.exodus.env.Store in project xodus by JetBrains.
the class UniqueKeyIndicesEngine method insertUniqueKey.
public void insertUniqueKey(@NotNull final PersistentStoreTransaction txn, @NotNull final Index index, @NotNull final List<Comparable> propValues, @NotNull final Entity entity) {
final PropertyTypes propertyTypes = persistentStore.getPropertyTypes();
final int propCount = index.getFields().size();
if (propCount != propValues.size()) {
throw new IllegalArgumentException("Number of fields differs from the number of property values");
}
final Store indexTable = getUniqueKeyIndex(txn, index);
if (!indexTable.add(txn.getEnvironmentTransaction(), propertyTypes.dataArrayToEntry(propValues.toArray(new Comparable[propCount])), LongBinding.longToCompressedEntry(entity.getId().getLocalId()))) {
throw new InsertConstraintException("Failed to insert unique key (already exists). Index: " + index);
}
}
use of jetbrains.exodus.env.Store in project pwm by pwm-project.
the class XodusLocalDB method removeAll.
@Override
public void removeAll(final LocalDB.DB db, final Collection<String> keys) throws LocalDBException {
checkStatus(true);
environment.executeInTransaction(transaction -> {
final Store store = getStore(db);
for (final String key : keys) {
store.delete(transaction, bindMachine.keyToEntry(key));
}
});
}
use of jetbrains.exodus.env.Store in project pwm by pwm-project.
the class XodusLocalDB method init.
@Override
public void init(final File dbDirectory, final Map<String, String> initParameters, final Map<Parameter, String> parameters) throws LocalDBException {
this.fileLocation = dbDirectory;
LOGGER.trace("begin environment open");
final Instant startTime = Instant.now();
final EnvironmentConfig environmentConfig = makeEnvironmentConfig(initParameters);
{
final boolean compressionEnabled = initParameters.containsKey(Property.Compression_Enabled.getKeyName()) ? Boolean.parseBoolean(initParameters.get(Property.Compression_Enabled.getKeyName())) : BindMachine.DEFAULT_ENABLE_COMPRESSION;
final int compressionMinLength = initParameters.containsKey(Property.Compression_MinLength.getKeyName()) ? Integer.parseInt(initParameters.get(Property.Compression_MinLength.getKeyName())) : BindMachine.DEFAULT_MIN_COMPRESSION_LENGTH;
bindMachine = new BindMachine(compressionEnabled, compressionMinLength);
}
readOnly = parameters.containsKey(Parameter.readOnly) && Boolean.parseBoolean(parameters.get(Parameter.readOnly));
LOGGER.trace("preparing to open with configuration " + JsonUtil.serializeMap(environmentConfig.getSettings()));
environment = Environments.newInstance(dbDirectory.getAbsolutePath() + File.separator + "xodus", environmentConfig);
LOGGER.trace("environment open (" + TimeDuration.fromCurrent(startTime).asCompactString() + ")");
environment.executeInTransaction(txn -> {
for (final LocalDB.DB db : LocalDB.DB.values()) {
final Store store = initStore(db, txn);
cachedStoreObjects.put(db, store);
}
});
status = LocalDB.Status.OPEN;
for (final LocalDB.DB db : LocalDB.DB.values()) {
LOGGER.trace("opened " + db + " with " + this.size(db) + " records");
}
}
use of jetbrains.exodus.env.Store in project pwm by pwm-project.
the class XodusLocalDB method put.
@Override
public boolean put(final LocalDB.DB db, final String key, final String value) throws LocalDBException {
checkStatus(true);
return environment.computeInTransaction(transaction -> {
final ByteIterable k = bindMachine.keyToEntry(key);
final ByteIterable v = bindMachine.valueToEntry(value);
final Store store = getStore(db);
return store.put(transaction, k, v);
});
}
use of jetbrains.exodus.env.Store in project pwm by pwm-project.
the class XodusLocalDB method putIfAbsent.
@LocalDB.WriteOperation
public boolean putIfAbsent(final LocalDB.DB db, final String key, final String value) throws LocalDBException {
checkStatus(true);
return environment.computeInTransaction(transaction -> {
final ByteIterable k = bindMachine.keyToEntry(key);
final ByteIterable v = bindMachine.valueToEntry(value);
final Store store = getStore(db);
final ByteIterable existingValue = store.get(transaction, k);
if (existingValue != null) {
return false;
}
return store.put(transaction, k, v);
});
}
Aggregations