fun refactorFixNegativeFloatAndDoubleProps()

in entity-store/src/main/kotlin/jetbrains/exodus/entitystore/PersistentEntityStoreRefactorings.kt [766:823]


    fun refactorFixNegativeFloatAndDoubleProps(settings: Store) {
        store.executeInReadonlyTransaction { tx ->
            for (entityType in store.getEntityTypes(tx as PersistentStoreTransaction).toList()) {
                store.executeInTransaction { t ->
                    val txn = t as PersistentStoreTransaction
                    val settingName = "refactorFixNegativeFloatAndDoubleProps($entityType) applied"
                    if (Settings.get(txn.environmentTransaction, settings, settingName) == "y") {
                        return@executeInTransaction
                    }
                    logInfo("Refactoring fixing negative float & double props for [$entityType]")
                    val entityTypeId = store.getEntityTypeId(txn, entityType, false)
                    val propTable = store.getPropertiesTable(txn, entityTypeId)
                    val props = HashMap<PropertyKey, Pair<PropertyValue, ByteIterable>>()
                    val propertyTypes = store.propertyTypes
                    store.getPrimaryPropertyIndexCursor(txn, propTable).use { cursor ->
                        while (cursor.next) {
                            try {
                                ArrayByteIterable(cursor.value).let {
                                    val propertyType = propertyTypes.getPropertyType(
                                        (it.iterator()
                                            .next() xor (0x80).toByte()).toInt()
                                    )
                                    when (propertyType.typeId) {
                                        ComparableValueType.FLOAT_VALUE_TYPE -> {
                                            props[PropertyKey.entryToPropertyKey(cursor.key)] =
                                                propertyTypes.entryToPropertyValue(it, FloatBinding.BINDING) to it
                                        }

                                        ComparableValueType.DOUBLE_VALUE_TYPE -> {
                                            props[PropertyKey.entryToPropertyKey(cursor.key)] =
                                                propertyTypes.entryToPropertyValue(it, DoubleBinding.BINDING) to it
                                        }

                                        else -> {
                                        }
                                    }
                                }
                            } catch (_: Throwable) {
                            }
                        }
                    }
                    if (props.isNotEmpty()) {
                        props.keys.sortedBy { it.entityLocalId }.forEach { key ->
                            props[key]?.let { (propValue, it) ->
                                propTable.put(
                                    txn, key.entityLocalId,
                                    PropertyTypes.propertyValueToEntry(propValue),
                                    it, key.propertyId, propValue.type
                                )
                            }
                        }
                        logInfo("${props.size} negative float & double props fixed.")
                    }
                    Settings.set(txn.environmentTransaction, settings, settingName, "y")
                }
            }
        }
    }