// Path: src/main/java/org/springframework/data/hazelcast/HazelcastKeyValueAdapter.java
// public class HazelcastKeyValueAdapter
//         extends AbstractKeyValueAdapter {
// 
//     private HazelcastInstance hzInstance;
// 
//     public HazelcastKeyValueAdapter(HazelcastInstance hzInstance) {
//         super(new HazelcastQueryEngine());
//         Assert.notNull(hzInstance, "hzInstance must not be 'null'.");
//         this.hzInstance = hzInstance;
//     }
// 
//     public void setHzInstance(HazelcastInstance hzInstance) {
//         this.hzInstance = hzInstance;
//     }
// 
//     @Override
//     public Object put(Object id, Object item, String keyspace) {
//         Assert.notNull(id, "Id must not be 'null' for adding.");
//         Assert.notNull(item, "Item must not be 'null' for adding.");
// 
//         return getMap(keyspace).put(id, item);
//     }
// 
//     @Override
//     public boolean contains(Object id, String keyspace) {
//         return getMap(keyspace).containsKey(id);
//     }
// 
//     @Override
//     public Object get(Object id, String keyspace) {
//         return getMap(keyspace).get(id);
//     }
// 
//     @Override
//     public Object delete(Object id, String keyspace) {
//         return getMap(keyspace).remove(id);
//     }
// 
//     @Override
//     public Iterable<?> getAllOf(String keyspace) {
//         return getMap(keyspace).values();
//     }
// 
//     @Override
//     public void deleteAllOf(String keyspace) {
//         getMap(keyspace).clear();
//     }
// 
//     @Override
//     public void clear() {
//         this.hzInstance.shutdown();
//     }
// 
//     protected IMap<Object, Object> getMap(final String keyspace) {
//         return hzInstance.getMap(keyspace);
//     }
// 
//     @Override
//     public void destroy() {
//         this.clear();
//     }
// 
//     @Override
//     public long count(String keyspace) {
//         return getMap(keyspace).size();
//     }
// 
//     @Override
//     public CloseableIterator<Map.Entry<Object, Object>> entries(String keyspace) {
//         Iterator<Entry<Object, Object>> iterator = this.getMap(keyspace).entrySet().iterator();
//         return new ForwardingCloseableIterator<>(iterator);
//     }
// }


import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.data.hazelcast.HazelcastKeyValueAdapter;
import org.springframework.data.keyvalue.core.KeyValueTemplate;
import org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
import org.springframework.data.repository.config.RepositoryConfigurationSource;
/*
 * Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.data.hazelcast.repository.config;


/**
 * Hazelcast-specific {@link RepositoryConfigurationExtension}.
 *
 * @author Oliver Gierke
 * @author Rafal Leszko
 */
class HazelcastRepositoryConfigurationExtension
        extends KeyValueRepositoryConfigurationExtension {

    private static final String HAZELCAST_ADAPTER_BEAN_NAME = "hazelcastKeyValueAdapter";

    /*
     * (non-Javadoc)
     * @see org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension
     *                          #getModuleName()
     */
    @Override
    public String getModuleName() {
        return "Hazelcast";
    }

    /*
     * (non-Javadoc)
     * @see org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension
     *                          #getModulePrefix()
     */
    @Override
    protected String getModulePrefix() {
        return "hazelcast";
    }

    /*
     * (non-Javadoc)
     * @see org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension
     *                          #getDefaultKeyValueTemplateRef()
     */
    @Override
    protected String getDefaultKeyValueTemplateRef() {
        return "keyValueTemplate";
    }

    @Override
    public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource configurationSource) {
        // register HazelcastKeyValueAdapter
        String hazelcastInstanceRef = configurationSource.getAttribute("hazelcastInstanceRef").get();

// Path: src/main/java/org/springframework/data/hazelcast/HazelcastKeyValueAdapter.java
// public class HazelcastKeyValueAdapter
//         extends AbstractKeyValueAdapter {
// 
//     private HazelcastInstance hzInstance;
// 
//     public HazelcastKeyValueAdapter(HazelcastInstance hzInstance) {
//         super(new HazelcastQueryEngine());
//         Assert.notNull(hzInstance, "hzInstance must not be 'null'.");
//         this.hzInstance = hzInstance;
//     }
// 
//     public void setHzInstance(HazelcastInstance hzInstance) {
//         this.hzInstance = hzInstance;
//     }
// 
//     @Override
//     public Object put(Object id, Object item, String keyspace) {
//         Assert.notNull(id, "Id must not be 'null' for adding.");
//         Assert.notNull(item, "Item must not be 'null' for adding.");
// 
//         return getMap(keyspace).put(id, item);
//     }
// 
//     @Override
//     public boolean contains(Object id, String keyspace) {
//         return getMap(keyspace).containsKey(id);
//     }
// 
//     @Override
//     public Object get(Object id, String keyspace) {
//         return getMap(keyspace).get(id);
//     }
// 
//     @Override
//     public Object delete(Object id, String keyspace) {
//         return getMap(keyspace).remove(id);
//     }
// 
//     @Override
//     public Iterable<?> getAllOf(String keyspace) {
//         return getMap(keyspace).values();
//     }
// 
//     @Override
//     public void deleteAllOf(String keyspace) {
//         getMap(keyspace).clear();
//     }
// 
//     @Override
//     public void clear() {
//         this.hzInstance.shutdown();
//     }
// 
//     protected IMap<Object, Object> getMap(final String keyspace) {
//         return hzInstance.getMap(keyspace);
//     }
// 
//     @Override
//     public void destroy() {
//         this.clear();
//     }
// 
//     @Override
//     public long count(String keyspace) {
//         return getMap(keyspace).size();
//     }
// 
//     @Override
//     public CloseableIterator<Map.Entry<Object, Object>> entries(String keyspace) {
//         Iterator<Entry<Object, Object>> iterator = this.getMap(keyspace).entrySet().iterator();
//         return new ForwardingCloseableIterator<>(iterator);
//     }
// }


// Path: src/main/java/org/springframework/data/hazelcast/repository/config/HazelcastRepositoryConfigurationExtension.java
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.data.hazelcast.HazelcastKeyValueAdapter;
import org.springframework.data.keyvalue.core.KeyValueTemplate;
import org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension;
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
import org.springframework.data.repository.config.RepositoryConfigurationSource;

/*
 * Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.data.hazelcast.repository.config;


/**
 * Hazelcast-specific {@link RepositoryConfigurationExtension}.
 *
 * @author Oliver Gierke
 * @author Rafal Leszko
 */
class HazelcastRepositoryConfigurationExtension
        extends KeyValueRepositoryConfigurationExtension {

    private static final String HAZELCAST_ADAPTER_BEAN_NAME = "hazelcastKeyValueAdapter";

    /*
     * (non-Javadoc)
     * @see org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension
     *                          #getModuleName()
     */
    @Override
    public String getModuleName() {
        return "Hazelcast";
    }

    /*
     * (non-Javadoc)
     * @see org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension
     *                          #getModulePrefix()
     */
    @Override
    protected String getModulePrefix() {
        return "hazelcast";
    }

    /*
     * (non-Javadoc)
     * @see org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension
     *                          #getDefaultKeyValueTemplateRef()
     */
    @Override
    protected String getDefaultKeyValueTemplateRef() {
        return "keyValueTemplate";
    }

    @Override
    public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource configurationSource) {
        // register HazelcastKeyValueAdapter
        String hazelcastInstanceRef = configurationSource.getAttribute("hazelcastInstanceRef").get();

        RootBeanDefinition hazelcastKeyValueAdapterDefinition = new RootBeanDefinition(HazelcastKeyValueAdapter.class);