<?xml version="1.0" encoding="UTF-8"?>

<!--
    Keep/Load and Save the

    1. GenericDomainEventEntry
    3. Snapshot GenericDomainEventEntry

-->

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd">



    <!-- On its Small context it should be REPLICATED and TRANSACTIONAL -->
    <bean class="org.apache.ignite.configuration.CacheConfiguration" id="AbsDomainCache" abstract="true">

        <property name="cacheMode" value="PARTITIONED"/>

        <property name="backups" value="2"/>

        <property name="storeKeepBinary" value="false"/>
        
        <property name="atomicityMode" value="ATOMIC"/>

        <property name="nodeFilter" ref="defNodeFilter"/>

        <property name="affinity">
            <bean class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction">
                <property name="partitions" value="#{T(com.tophold.trade.kafka.KafkaIgniteConstants).BOOKER_PART}"/>
            </bean>
        </property>

        <property name="dataRegionName" value="Axon_Event_Region"/>

    </bean>


    <bean id="GenericDomainEventEntry" parent="AbsDomainCache">

        <property name="name">
            <value>BookerGenericDomainEventEntry${exchanger}</value>
        </property>

        <property name="queryEntities">
            <list>
                <bean class="org.apache.ignite.cache.QueryEntity">

                    <property name="keyType" value="java.lang.String"/>
                    <property name="valueType"
                              value="org.axonframework.eventsourcing.eventstore.GenericDomainEventEntry"/>


                    <property name="keyFields">
                        <set>
                            <value>aggregateIdentifier</value>
                            <value>sequenceNumber</value>
                        </set>
                    </property>

                    <property name="fields">
                        <map>
                            <entry key="aggregateIdentifier" value="java.lang.String"/>
                            <entry key="sequenceNumber" value="java.lang.Long"/>
                        </map>
                    </property>

                    <!--


                    Creates index for a collection of fields. If index is sorted, fields will be sorted in ascending order.

                    -->
                    <property name="indexes">
                        <list>
                            <bean class="org.apache.ignite.cache.QueryIndex">
                                <constructor-arg>
                                    <list>
                                        <value>aggregateIdentifier</value>
                                        <value>sequenceNumber</value>
                                    </list>
                                </constructor-arg>
                                <constructor-arg value="SORTED"/>
                            </bean>
                        </list>
                    </property>
                </bean>
            </list>
        </property>
    </bean>

    <bean id="SnapshotGenericDomainEventEntry" parent="AbsDomainCache">
        <property name="name">
            <value>BookerSnapshotGenericDomainEventEntry${exchanger}</value>
        </property>


    </bean>

</beans>