Search in sources :

Example 1 with ComparableValueType

use of jetbrains.exodus.bindings.ComparableValueType in project xodus by JetBrains.

the class PropertyTypes method entryToPropertyValue.

public PropertyValue entryToPropertyValue(@NotNull final ByteIterable entry) {
    final ByteIterableBase it = (ByteIterableBase) entry;
    final byte[] bytes = it.getBytesUnsafe();
    final ComparableValueType type = getPropertyType((byte) (bytes[0] ^ 0x80));
    final Comparable data = type.getBinding().readObject(new ByteArrayInputStream(bytes, 1, it.getLength() - 1));
    return new PropertyValue(type, data);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteIterableBase(jetbrains.exodus.ByteIterableBase) ComparableValueType(jetbrains.exodus.bindings.ComparableValueType)

Example 2 with ComparableValueType

use of jetbrains.exodus.bindings.ComparableValueType in project xodus by JetBrains.

the class PropertyTypes method clear.

public void clear() {
    typesById.clear();
    typesByClass.clear();
    for (final ComparableValueType predefinedType : ComparableValueType.PREDEFINED_COMPARABLE_VALUE_TYPES) {
        typesById.put(predefinedType.getTypeId(), predefinedType);
        typesByClass.put(predefinedType.getClazz(), predefinedType);
    }
    final ComparableValueType comparableSetType = typesByClass.get(ComparableSet.class);
    final ComparableSetBinding newBinding = new ComparableSetBinding() {

        @Override
        protected ComparableValueType getType(@NotNull Class<? extends Comparable> itemClass) {
            final ComparableValueType result = super.getType(itemClass);
            return result == null ? typesByClass.get(itemClass) : result;
        }

        @Override
        protected ComparableBinding getBinding(int valueTypeId) {
            final ComparableBinding result = super.getBinding(valueTypeId);
            return result == null ? typesById.get(valueTypeId).getBinding() : result;
        }
    };
    final int typeId = comparableSetType.getTypeId();
    final ComparableValueType newComparableSetType = new ComparableValueType(typeId, newBinding, comparableSetType.getClazz());
    typesByClass.put(ComparableSet.class, newComparableSetType);
    typesById.put(typeId, newComparableSetType);
}
Also used : ComparableSetBinding(jetbrains.exodus.bindings.ComparableSetBinding) ComparableBinding(jetbrains.exodus.bindings.ComparableBinding) NotNull(org.jetbrains.annotations.NotNull) ComparableValueType(jetbrains.exodus.bindings.ComparableValueType)

Example 3 with ComparableValueType

use of jetbrains.exodus.bindings.ComparableValueType in project xodus by JetBrains.

the class PropertyTypes method registerCustomPropertyType.

public void registerCustomPropertyType(int typeId, @NotNull final Class<? extends Comparable> clazz, @NotNull final ComparableBinding binding) {
    typeId += ComparableValueType.PREDEFINED_COMPARABLE_VALUE_TYPES.length;
    final ComparableValueType propType = new ComparableValueType(typeId, binding, clazz);
    if (typesById.put(typeId, propType) != null) {
        throw new EntityStoreException("Already registered property type id " + typeId);
    }
    if (typesByClass.put(clazz, propType) != null) {
        throw new EntityStoreException("Already registered property type " + clazz);
    }
}
Also used : EntityStoreException(jetbrains.exodus.entitystore.EntityStoreException) ComparableValueType(jetbrains.exodus.bindings.ComparableValueType)

Example 4 with ComparableValueType

use of jetbrains.exodus.bindings.ComparableValueType in project xodus by JetBrains.

the class PropertyTypes method entryToPropertyValue.

public PropertyValue entryToPropertyValue(@NotNull final ByteIterable entry, @Nullable ComparableBinding binding) {
    final byte[] bytes = entry.getBytesUnsafe();
    final ComparableValueType type = getPropertyType((byte) (bytes[0] ^ 0x80));
    if (binding == null) {
        binding = type.getBinding();
    }
    final Comparable data = binding.readObject(new ByteArraySizedInputStream(bytes, 1, entry.getLength() - 1));
    return new PropertyValue(type, data);
}
Also used : ByteArraySizedInputStream(jetbrains.exodus.util.ByteArraySizedInputStream) ComparableValueType(jetbrains.exodus.bindings.ComparableValueType)

Aggregations

ComparableValueType (jetbrains.exodus.bindings.ComparableValueType)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteIterableBase (jetbrains.exodus.ByteIterableBase)1 ComparableBinding (jetbrains.exodus.bindings.ComparableBinding)1 ComparableSetBinding (jetbrains.exodus.bindings.ComparableSetBinding)1 EntityStoreException (jetbrains.exodus.entitystore.EntityStoreException)1 ByteArraySizedInputStream (jetbrains.exodus.util.ByteArraySizedInputStream)1 NotNull (org.jetbrains.annotations.NotNull)1