Search in sources :

Example 51 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class EntityTests method testRawProperty.

public void testRawProperty() {
    final StoreTransaction txn = getStoreTransaction();
    final Entity entity = txn.newEntity("Issue");
    entity.setProperty("description", "it doesn't work");
    txn.flush();
    Assert.assertEquals("Issue", entity.getType());
    Entity sameEntity = txn.getEntity(entity.getId());
    Assert.assertNotNull(sameEntity);
    Assert.assertEquals(entity.getType(), sameEntity.getType());
    Assert.assertEquals(entity.getId(), sameEntity.getId());
    ByteIterable rawValue = entity.getRawProperty("description");
    Assert.assertNotNull(rawValue);
    Assert.assertEquals("it doesn't work", getEntityStore().getPropertyTypes().entryToPropertyValue(rawValue).getData());
    entity.setProperty("description", "it works");
    txn.flush();
    sameEntity = txn.getEntity(entity.getId());
    Assert.assertNotNull(sameEntity);
    Assert.assertEquals(entity.getType(), sameEntity.getType());
    Assert.assertEquals(entity.getId(), sameEntity.getId());
    rawValue = entity.getRawProperty("description");
    Assert.assertNotNull(rawValue);
    Assert.assertEquals("it works", getEntityStore().getPropertyTypes().entryToPropertyValue(rawValue).getData());
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable)

Example 52 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class PropertyValueIterable method isEmptyImpl.

@Override
public boolean isEmptyImpl(@NotNull PersistentStoreTransaction txn) {
    final ByteIterable key = getStore().getPropertyTypes().dataToPropertyValue(value).dataToEntry();
    final Cursor valueIdx = openCursor(txn);
    return valueIdx == null || new SingleKeyCursorIsEmptyChecker(valueIdx, key).isEmpty();
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) Cursor(jetbrains.exodus.env.Cursor)

Example 53 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class PropertiesTable method deleteNoFail.

public boolean deleteNoFail(@NotNull final PersistentStoreTransaction txn, final long localId, @NotNull final ByteIterable value, int propertyId, @NotNull final ComparableValueType type) {
    final ByteIterable key = PropertyKey.propertyKeyToEntry(new PropertyKey(localId, propertyId));
    final Transaction envTxn = txn.getEnvironmentTransaction();
    final ByteIterable secondaryValue = LongBinding.longToCompressedEntry(localId);
    return primaryStore.delete(envTxn, key) && deleteFromStore(envTxn, getOrCreateValueIndex(txn, propertyId), secondaryValue, createSecondaryKeys(store.getPropertyTypes(), value, type)) && deleteFromStore(envTxn, allPropsIndex, secondaryValue, IntegerBinding.intToCompressedEntry(propertyId));
}
Also used : PersistentStoreTransaction(jetbrains.exodus.entitystore.PersistentStoreTransaction) ByteIterable(jetbrains.exodus.ByteIterable)

Example 54 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class GarbageCollectorTest method updateSameKeyWithoutDuplicates.

@Test
public void updateSameKeyWithoutDuplicates() {
    set1KbFileWithoutGC();
    ByteIterable key = StringBinding.stringToEntry("key");
    final Store store = openStoreAutoCommit("updateSameKey");
    for (int i = 0; i < 1000; ++i) {
        putAutoCommit(store, key, key);
    }
    Assert.assertTrue(env.getLog().getNumberOfFiles() > 1);
    env.getGC().cleanWholeLog();
    Assert.assertEquals(1L, env.getLog().getNumberOfFiles());
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Test(org.junit.Test)

Example 55 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class GarbageCollectorTest method fillDuplicatesThenDeleteAlmostAllOfThem.

@Test
public void fillDuplicatesThenDeleteAlmostAllOfThem() {
    set1KbFileWithoutGC();
    Store store = openStoreAutoCommit("duplicates", getStoreConfig(true));
    for (int i = 0; i < 32; ++i) {
        for (int j = 0; j < 32; ++j) {
            putAutoCommit(store, IntegerBinding.intToEntry(i), IntegerBinding.intToEntry(j));
        }
    }
    for (int i = 0; i < 32; ++i) {
        final Transaction txn = env.beginTransaction();
        try {
            try (Cursor cursor = store.openCursor(txn)) {
                Assert.assertNotNull(cursor.getSearchKeyRange(IntegerBinding.intToEntry(i)));
                for (int j = 0; j < 32; ++j, cursor.getNext()) {
                    cursor.deleteCurrent();
                }
            }
            store.put(txn, IntegerBinding.intToEntry(i), IntegerBinding.intToEntry(100));
        } finally {
            txn.commit();
        }
    }
    env.getGC().cleanWholeLog();
    reopenEnvironment();
    store = openStoreAutoCommit("duplicates", getStoreConfig(true));
    for (int i = 0; i < 32; ++i) {
        final ByteIterable it = getAutoCommit(store, IntegerBinding.intToEntry(i));
        Assert.assertNotNull(it);
        Assert.assertEquals(100, IntegerBinding.entryToInt(it));
    }
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Test(org.junit.Test)

Aggregations

ByteIterable (jetbrains.exodus.ByteIterable)93 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)47 Test (org.junit.Test)26 CompressedUnsignedLongByteIterable (jetbrains.exodus.log.CompressedUnsignedLongByteIterable)16 Nullable (org.jetbrains.annotations.Nullable)11 Cursor (jetbrains.exodus.env.Cursor)8 ITreeCursor (jetbrains.exodus.tree.ITreeCursor)8 RandomAccessLoggable (jetbrains.exodus.log.RandomAccessLoggable)7 CompoundByteIterable (jetbrains.exodus.CompoundByteIterable)6 Store (jetbrains.exodus.env.Store)4 TreeSet (java.util.TreeSet)3 TokyoCabinetBenchmark (jetbrains.exodus.benchmark.TokyoCabinetBenchmark)3 PersistentStoreTransaction (jetbrains.exodus.entitystore.PersistentStoreTransaction)3 Exchange (com.persistit.Exchange)2 ExodusException (jetbrains.exodus.ExodusException)2 Pair (jetbrains.exodus.core.dataStructures.Pair)2 HashSet (jetbrains.exodus.core.dataStructures.hash.HashSet)2 PersistentLongSet (jetbrains.exodus.core.dataStructures.persistent.PersistentLongSet)2 Transaction (jetbrains.exodus.env.Transaction)2 Loggable (jetbrains.exodus.log.Loggable)2