<commit_before>package org.ethereum.datasource.mapdb;

import org.ethereum.config.SystemProperties;
import org.ethereum.datasource.KeyValueDataSource;
import org.ethereum.db.ByteArrayWrapper;
import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.mapdb.HTreeMap;

import java.io.File;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static java.lang.System.getProperty;
import static org.ethereum.util.ByteUtil.wrap;

public class MapDBDataSource implements KeyValueDataSource {
    
    private DB db;
    private HTreeMap<ByteArrayWrapper, byte[]> map;
    private String name;

    @Override
    public void init() {
        File dbLocation = new File(getProperty("user.dir") + "/" + SystemProperties.CONFIG.databaseDir() + "/");
        if (!dbLocation.exists()) {
            dbLocation.mkdirs();
        }

        db = DBMaker.newFileDB(new File(dbLocation, name))
                .transactionDisable()
                .asyncWriteEnable()
                .mmapFileEnableIfSupported()
                .compressionEnable()
                .cacheSize(512)
                .closeOnJvmShutdown()
                .make();

        this.map = db.createHashMap(name).makeOrGet();
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public byte[] get(byte[] key) {
        return map.get(wrap(key));
    }

    @Override
    public byte[] put(byte[] key, byte[] value) {
        try {
            return map.put(wrap(key), value);
        } finally {
            db.commit();
        }
    }

    @Override
    public void delete(byte[] key) {
        try {
            map.remove(key);
        } finally {
            db.commit();
        }
    }

    @Override
    public Set<byte[]> keys() {
        HashSet<byte[]> result = new HashSet<>();
        for (ByteArrayWrapper key : map.keySet()) {
            result.add(key.getData());    
        }
        return result;
    }

    @Override
    public void updateBatch(Map<byte[], byte[]> rows) {
        try {
            for (byte[] key : rows.keySet()) {
                map.put(wrap(key), rows.get(key));
            }
        } finally {
            db.commit();
        }
    }

    @Override
    public void close() {
        db.close();
    }
}
<commit_msg>Enables MapDB transactions<commit_after>package org.ethereum.datasource.mapdb;

import org.ethereum.config.SystemProperties;
import org.ethereum.datasource.KeyValueDataSource;
import org.ethereum.db.ByteArrayWrapper;
import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.mapdb.HTreeMap;

import java.io.File;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static java.lang.System.getProperty;
import static org.ethereum.util.ByteUtil.wrap;

public class MapDBDataSource implements KeyValueDataSource {
    
    private DB db;
    private HTreeMap<ByteArrayWrapper, byte[]> map;
    private String name;

    @Override
    public void init() {
        File dbLocation = new File(getProperty("user.dir") + "/" + SystemProperties.CONFIG.databaseDir() + "/");
        if (!dbLocation.exists()) {
            dbLocation.mkdirs();
        }

        db = DBMaker.newFileDB(new File(dbLocation, name))
                .asyncWriteEnable()
                .mmapFileEnableIfSupported()
                .compressionEnable()
                .cacheSize(512)
                .closeOnJvmShutdown()
                .make();

        this.map = db.createHashMap(name).makeOrGet();
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public byte[] get(byte[] key) {
        return map.get(wrap(key));
    }

    @Override
    public byte[] put(byte[] key, byte[] value) {
        try {
            return map.put(wrap(key), value);
        } finally {
            db.commit();
        }
    }

    @Override
    public void delete(byte[] key) {
        try {
            map.remove(key);
        } finally {
            db.commit();
        }
    }

    @Override
    public Set<byte[]> keys() {
        HashSet<byte[]> result = new HashSet<>();
        for (ByteArrayWrapper key : map.keySet()) {
            result.add(key.getData());    
        }
        return result;
    }

    @Override
    public void updateBatch(Map<byte[], byte[]> rows) {
        try {
            for (byte[] key : rows.keySet()) {
                map.put(wrap(key), rows.get(key));
            }
        } finally {
            db.commit();
        }
    }

    @Override
    public void close() {
        db.close();
    }
}

{'fraction_non_alphanumeric': 0.12524504465258113, 'fraction_numerical': 0.001306904813766064, 'mean_word_length': 1.9454778704297626, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5714227', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1352, 'n_words': 279}