<commit_before>package org.rapidoid.db;

/*
 * #%L
 * rapidoid-db
 * %%
 * Copyright (C) 2014 - 2015 <NAME>
 * %%
 * 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.
 * #L%
 */
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import org.rapidoid.config.Conf;
import org.rapidoid.lambda.Callback;
import org.rapidoid.lambda.Operation;
import org.rapidoid.lambda.Predicate;
import org.rapidoid.util.Cls;
import org.rapidoid.util.U;

public class DB {

	private static final String IMPL_NAME = "org.rapidoid.db.impl.inmem.DbImpl";

	static final Class<Database> DB_IMPL_CLASS;

	private static Database db;

	static {
		String dbImplName = Conf.option("db", IMPL_NAME);

		DB_IMPL_CLASS = Cls.getClassIfExists(IMPL_NAME);

		U.must(DB_IMPL_CLASS != null, "Cannot find Db implementation (%s)!", dbImplName);
		U.must(Database.class.isAssignableFrom(DB_IMPL_CLASS), "%s must implement %s!", dbImplName,
				Database.class.getCanonicalName());

		init();
	}

	public static String path() {
		String path = Conf.option("db", "");

		if (!path.isEmpty() && !path.endsWith(File.separator)) {
			path += File.separator;
		}

		return path;
	}

	public static void init() {
		db = (Database) Cls.customizable(DB.DB_IMPL_CLASS, "default", path() + "default.db");
		db.initAndLoad();
	}

	public static Database db() {
		assert U.must(db != null, "Database not initialized!");
		return db;
	}

	public static long insert(Object record) {
		return db().insert(record);
	}

	public static void delete(long id) {
		db().delete(id);
	}
<commit_msg>Added setter of the default DB instance.<commit_after>package org.rapidoid.db;

/*
 * #%L
 * rapidoid-db
 * %%
 * Copyright (C) 2014 - 2015 <NAME>
 * %%
 * 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.
 * #L%
 */
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import org.rapidoid.config.Conf;
import org.rapidoid.lambda.Callback;
import org.rapidoid.lambda.Operation;
import org.rapidoid.lambda.Predicate;
import org.rapidoid.util.Cls;
import org.rapidoid.util.U;

public class DB {

	private static final String IMPL_NAME = "org.rapidoid.db.impl.inmem.DbImpl";

	static final Class<Database> DB_IMPL_CLASS;

	private static Database db;

	static {
		String dbImplName = Conf.option("db", IMPL_NAME);

		DB_IMPL_CLASS = Cls.getClassIfExists(IMPL_NAME);

		U.must(DB_IMPL_CLASS != null, "Cannot find Db implementation (%s)!", dbImplName);
		U.must(Database.class.isAssignableFrom(DB_IMPL_CLASS), "%s must implement %s!", dbImplName,
				Database.class.getCanonicalName());

		init();
	}

	public static String path() {
		String path = Conf.option("db", "");

		if (!path.isEmpty() && !path.endsWith(File.separator)) {
			path += File.separator;
		}

		return path;
	}

	public static void init() {
		db = (Database) Cls.customizable(DB.DB_IMPL_CLASS, "default", path() + "default.db");
		db.initAndLoad();
	}

	public static Database db() {
		assert U.must(db != null, "Database not initialized!");
		return db;
	}

	public static void setDb(Database db) {
		DB.db = db;
	}

	public static long insert(Object record) {
		return db().insert(record);
	}

	public static void delete(long id) {
		db().delete(id);
	}

{'fraction_non_alphanumeric': 0.12442817932296432, 'fraction_numerical': 0.0054894784995425435, 'mean_word_length': 4.096736596736597, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '523141', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1388, 'n_words': 419}