All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tvd12.ezydata.hazelcast.mapstore.EzyMongoDatabaseMapstoreCreator Maven / Gradle / Ivy

The newest version!
package com.tvd12.ezydata.hazelcast.mapstore;

import com.hazelcast.map.MapStore;
import com.mongodb.client.MongoDatabase;
import com.tvd12.ezydata.hazelcast.constant.EzyMapNames;
import com.tvd12.ezydata.mongodb.EzyMongoDatabaseAware;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class EzyMongoDatabaseMapstoreCreator
    extends EzySimpleMapstoreCreator
    implements EzyMongoDatabaseAware {

    @Setter
    protected MongoDatabase database;

    @SuppressWarnings("rawtypes")
    private final Map defaultMapstores = defaultMapstores();

    @SuppressWarnings("rawtypes")
    @Override
    public MapStore create(String mapName, Properties properties) {
        MapStore mapstore = defaultMapstores.get(mapName);
        if (mapstore == null) {
            mapstore = (MapStore) mapstoresFetcher.getMapstore(mapName);
        }
        if (mapstore instanceof EzyMongoDatabaseAware) {
            ((EzyMongoDatabaseAware) mapstore).setDatabase(database);
        }
        return mapstore;
    }

    public Set getMapNames() {
        Set mapNames = super.getMapNames();
        mapNames.addAll(defaultMapstores.keySet());
        return mapNames;
    }

    @SuppressWarnings("rawtypes")
    protected Map defaultMapstores() {
        Map suppliers = new HashMap<>();
        addDefaultMapStores(suppliers);
        return suppliers;
    }

    @SuppressWarnings("rawtypes")
    protected void addDefaultMapStores(Map suppliers) {
        suppliers.put(EzyMapNames.MAX_ID, new EzyMongoMaxIdMapstore());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy