Search in sources :

Example 1 with ComparablePairBinding

use of jetbrains.exodus.entitystore.custom.ComparablePairBinding in project xodus by JetBrains.

the class PropertyCustomTypeTests method testSetGet.

public void testSetGet() {
    final PersistentEntityStoreImpl store = getEntityStore();
    final PropertyTypes propertyTypes = store.getPropertyTypes();
    final PersistentStoreTransaction txn = getStoreTransaction();
    final ComparablePair<Integer, String> sample = new ComparablePair<>(0, "");
    final ComparablePairBinding customBinding = new ComparablePairBinding(propertyTypes, sample);
    // REGISTER CUSTOM TYPE HERE
    store.registerCustomPropertyType(txn, sample.getClass(), customBinding);
    Assert.assertTrue(txn.flush());
    final PersistentEntity e = txn.newEntity("CustomType");
    final int count = 1000;
    for (int i = 0; i < count; ++i) {
        e.setProperty(Integer.toString(i), new ComparablePair(i, Integer.toString(i)));
    }
    Assert.assertTrue(txn.flush());
    for (int i = 0; i < count; ++i) {
        final Comparable property = e.getProperty(Integer.toString(i));
        Assert.assertNotNull(property);
        Assert.assertEquals(property, new ComparablePair(i, Integer.toString(i)));
    }
}
Also used : PropertyTypes(jetbrains.exodus.entitystore.tables.PropertyTypes) ComparablePairBinding(jetbrains.exodus.entitystore.custom.ComparablePairBinding) ComparablePair(jetbrains.exodus.entitystore.custom.ComparablePair)

Example 2 with ComparablePairBinding

use of jetbrains.exodus.entitystore.custom.ComparablePairBinding in project xodus by JetBrains.

the class PropertyCustomTypeTests method testRegisterTwiceWithoutReinit.

@TestFor(issue = "XD-603")
public void testRegisterTwiceWithoutReinit() {
    PersistentEntityStoreImpl store = getEntityStore();
    PropertyTypes propertyTypes = store.getPropertyTypes();
    PersistentStoreTransaction txn = getStoreTransaction();
    ComparablePair<Integer, String> sample = new ComparablePair<>(0, "");
    ComparablePairBinding customBinding = new ComparablePairBinding(propertyTypes, sample);
    store.registerCustomPropertyType(txn, sample.getClass(), customBinding);
    Assert.assertTrue(txn.flush());
    store.registerCustomPropertyType(txn, sample.getClass(), customBinding);
}
Also used : PropertyTypes(jetbrains.exodus.entitystore.tables.PropertyTypes) ComparablePairBinding(jetbrains.exodus.entitystore.custom.ComparablePairBinding) ComparablePair(jetbrains.exodus.entitystore.custom.ComparablePair) TestFor(jetbrains.exodus.TestFor)

Example 3 with ComparablePairBinding

use of jetbrains.exodus.entitystore.custom.ComparablePairBinding in project xodus by JetBrains.

the class PropertyCustomTypeTests method testFind.

public void testFind() throws InterruptedException {
    final PersistentEntityStoreImpl store = getEntityStore();
    final PropertyTypes propertyTypes = store.getPropertyTypes();
    final PersistentStoreTransaction txn = getStoreTransaction();
    final ComparablePair<Integer, String> sample = new ComparablePair<>(0, "");
    final ComparablePairBinding customBinding = new ComparablePairBinding(propertyTypes, sample);
    // REGISTER CUSTOM TYPE HERE
    store.registerCustomPropertyType(txn, sample.getClass(), customBinding);
    Assert.assertTrue(txn.flush());
    final PersistentEntity e = txn.newEntity("CustomType");
    final int count = 100;
    for (int i = 0; i < count; ++i) {
        e.setProperty(Integer.toString(i), new ComparablePair(i, Integer.toString(i)));
    }
    Assert.assertTrue(txn.flush());
    for (int i = 0; i < count; ++i) {
        final EntityIterable it = txn.find("CustomType", Integer.toString(i), new ComparablePair(i, Integer.toString(i)));
        Assert.assertFalse(it.isEmpty());
        Assert.assertEquals(e, it.getFirst());
        Assert.assertTrue(txn.find("CustomType", Integer.toString(i), new ComparablePair(i, Integer.toString(i + 1))).isEmpty());
        Assert.assertTrue(txn.find("CustomType", Integer.toString(i), new ComparablePair(i + 1, Integer.toString(i))).isEmpty());
        Assert.assertTrue(txn.find("CustomType", Integer.toString(i + 1), new ComparablePair(i, Integer.toString(i))).isEmpty());
        Thread.sleep(1);
    }
}
Also used : PropertyTypes(jetbrains.exodus.entitystore.tables.PropertyTypes) ComparablePairBinding(jetbrains.exodus.entitystore.custom.ComparablePairBinding) ComparablePair(jetbrains.exodus.entitystore.custom.ComparablePair)

Example 4 with ComparablePairBinding

use of jetbrains.exodus.entitystore.custom.ComparablePairBinding in project xodus by JetBrains.

the class PropertyCustomTypeTests method testRegisterTwice.

public void testRegisterTwice() throws Exception {
    PersistentEntityStoreImpl store = getEntityStore();
    PropertyTypes propertyTypes = store.getPropertyTypes();
    PersistentStoreTransaction txn = getStoreTransaction();
    ComparablePair<Integer, String> sample = new ComparablePair<>(0, "");
    ComparablePairBinding customBinding = new ComparablePairBinding(propertyTypes, sample);
    store.registerCustomPropertyType(txn, sample.getClass(), customBinding);
    reinit();
    store = getEntityStore();
    propertyTypes = store.getPropertyTypes();
    txn = getStoreTransaction();
    sample = new ComparablePair<>(0, "");
    customBinding = new ComparablePairBinding(propertyTypes, sample);
    store.registerCustomPropertyType(txn, sample.getClass(), customBinding);
}
Also used : PropertyTypes(jetbrains.exodus.entitystore.tables.PropertyTypes) ComparablePairBinding(jetbrains.exodus.entitystore.custom.ComparablePairBinding) ComparablePair(jetbrains.exodus.entitystore.custom.ComparablePair)

Aggregations

ComparablePair (jetbrains.exodus.entitystore.custom.ComparablePair)4 ComparablePairBinding (jetbrains.exodus.entitystore.custom.ComparablePairBinding)4 PropertyTypes (jetbrains.exodus.entitystore.tables.PropertyTypes)4 TestFor (jetbrains.exodus.TestFor)1