<commit_before>package org.hcjf.layers.storage.cassandra;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import org.hcjf.layers.storage.StorageLayer;
import org.hcjf.log.Log;
import org.hcjf.names.CassandraNaming;
import org.hcjf.names.Naming;
import org.hcjf.properties.SystemProperties;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.List;

/**
 * @author javaito
 * @mail <EMAIL>
 */
public abstract class CassandraStorageLayer extends StorageLayer<CassandraStorageSession> {

    private static final String CASSANDRA_STORAGE_LAYER_LOG_TAG = "CASSANDRA_STORAGE_LAYER";

    public static final String CASSANDRA_CONTACT_POINTS = "cassandra.%s.contact.points";
    public static final String CASSANDRA_KEY_SPACE_NAME = "cassandra.%s.key.space.name";
    public static final String CASSANDRA_USER_NAME = "cassandra.%s.user.name";
    public static final String CASSANDRA_PASSWORD = "<PASSWORD>";
    public static final String CASSANDRA_NAMING_IMPL = "cassandra.%s.naming.implementation";

    private final Cluster cluster;

    public CassandraStorageLayer(String implName) {
        super(implName);
        Naming.addNamingConsumer(new CassandraNaming());
        Formatter formatter = new Formatter();
        SystemProperties.putDefaultValue(
                formatter.format(CASSANDRA_NAMING_IMPL, getImplName()).toString(),
                CassandraNaming.CASSANDRA_NAMING_IMPL);
        cluster = Cluster.builder().addContactPoints(getContactPoints()).build();
    }

    /**
     *
     * @return
     */
    protected CassandraNaming getNamingImpl() {
        return new CassandraNaming();
    }

    /**
     * Return a session with the storage implementation.
     * @return Storage implementation.
     */
    @Override
    public CassandraStorageSession begin() {
        Session session = cluster.connect(getKeySpace());
        CassandraStorageSession result = new CassandraStorageSession(getImplName(), session, this);
        return result;
    }<commit_msg>Reusing cassandra session<commit_after>package org.hcjf.layers.storage.cassandra;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import org.hcjf.layers.storage.StorageLayer;
import org.hcjf.log.Log;
import org.hcjf.names.CassandraNaming;
import org.hcjf.names.Naming;
import org.hcjf.properties.SystemProperties;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.List;

/**
 * @author javaito
 * @mail <EMAIL>
 */
public abstract class CassandraStorageLayer extends StorageLayer<CassandraStorageSession> {

    private static final String CASSANDRA_STORAGE_LAYER_LOG_TAG = "CASSANDRA_STORAGE_LAYER";

    public static final String CASSANDRA_CONTACT_POINTS = "cassandra.%s.contact.points";
    public static final String CASSANDRA_KEY_SPACE_NAME = "cassandra.%s.key.space.name";
    public static final String CASSANDRA_USER_NAME = "cassandra.%s.user.name";
    public static final String CASSANDRA_PASSWORD = "<PASSWORD>";
    public static final String CASSANDRA_NAMING_IMPL = "cassandra.%s.naming.implementation";

    private final Cluster cluster;
    private final Session session;

    public CassandraStorageLayer(String implName) {
        super(implName);
        Naming.addNamingConsumer(new CassandraNaming());
        Formatter formatter = new Formatter();
        SystemProperties.putDefaultValue(
                formatter.format(CASSANDRA_NAMING_IMPL, getImplName()).toString(),
                CassandraNaming.CASSANDRA_NAMING_IMPL);
        cluster = Cluster.builder().addContactPoints(getContactPoints()).build();
        session = cluster.connect(getKeySpace());
    }

    /**
     *
     * @return
     */
    protected CassandraNaming getNamingImpl() {
        return new CassandraNaming();
    }

    /**
     * Return a session with the storage implementation.
     * @return Storage implementation.
     */
    @Override
    public CassandraStorageSession begin() {
        CassandraStorageSession result = new CassandraStorageSession(getImplName(), session, this);
        return result;
    }
{'fraction_non_alphanumeric': 0.09565217391304348, 'fraction_numerical': 0.0, 'mean_word_length': 3.891954022988506, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5031239', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1261, 'n_words': 253}