Search in sources :

Example 1 with Store

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);
    }
}
Also used : PropertyTypes(jetbrains.exodus.entitystore.tables.PropertyTypes) Store(jetbrains.exodus.env.Store)

Example 2 with Store

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));
        }
    });
}
Also used : Store(jetbrains.exodus.env.Store)

Example 3 with Store

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");
    }
}
Also used : Instant(java.time.Instant) EnvironmentConfig(jetbrains.exodus.env.EnvironmentConfig) Store(jetbrains.exodus.env.Store)

Example 4 with Store

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);
    });
}
Also used : ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) Store(jetbrains.exodus.env.Store)

Example 5 with Store

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);
    });
}
Also used : ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) Store(jetbrains.exodus.env.Store)

Aggregations

Store (jetbrains.exodus.env.Store)14 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)7 ByteIterable (jetbrains.exodus.ByteIterable)4 Transaction (jetbrains.exodus.env.Transaction)4 File (java.io.File)3 Cursor (jetbrains.exodus.env.Cursor)3 TransactionalExecutable (jetbrains.exodus.env.TransactionalExecutable)3 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ExodusException (jetbrains.exodus.ExodusException)1 OutOfDiskSpaceException (jetbrains.exodus.OutOfDiskSpaceException)1 Job (jetbrains.exodus.core.execution.Job)1 JobProcessor (jetbrains.exodus.core.execution.JobProcessor)1