<commit_before>package com.tightdb.lib;

import java.nio.ByteBuffer;
import java.util.Date;

import com.tightdb.ColumnType;
import com.tightdb.Group;
import com.tightdb.Mixed;
import com.tightdb.TableBase;
import com.tightdb.TableQuery;
import com.tightdb.TableSpec;

public abstract class AbstractTable<Cursor, View, Query> extends AbstractRowset<Cursor, View, Query> {

	static {
		TightDB.loadLibrary();
	}

	protected final TableBase table;

	public AbstractTable(EntityTypes<?, View, Cursor, Query> types) {
		this(types, new TableBase());
	}

	public AbstractTable(EntityTypes<?, View, Cursor, Query> types, Group group) {
		this(types, group.getTable(types.getTableClass().getCanonicalName()));
	}

	@SuppressWarnings("unchecked")
	protected AbstractTable(EntityTypes<?, View, Cursor, Query> types, TableBase table) {
		super(types, table);
		this.table = table;
		if (table != null && table.getTableSpec().getColumnCount() <= 0) {
			// Build table schema
			final TableSpec spec = new TableSpec();
			specifyTableStructure((Class<? extends AbstractTable<?, ?, ?>>) types.getTableClass(), spec);
			table.updateFromSpec(spec);
		}
	}

	public boolean isValid() {
		return table.isValid();
	}
	
	@Override
	public String getName() {
		return getClass().getSimpleName();
	}

	@Override
	public long size() {
		return table.size();
	}

	protected static void addLongColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeInt, name);
	}

	protected static void addStringColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeString, name);
	}

	protected static void addBooleanColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeBool, name);
	}

	protected static void addBinaryColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeBinary, name);
	}

	protected static void addDateColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeDate, name);
	}

	protected static void addMixedColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeMixed, name);
	}

	@SuppressWarnings("unchecked")
	protected static void addTableColumn(TableSpec spec, String name, AbstractTable<?, ?, ?> subtable) {
		TableSpec subspec = spec.addSubtableColumn(name);
		specifyTableStructure((Class<? extends AbstractTable<?, ?, ?>>) subtable.getClass(), subspec);
	}

	protected static void specifyTableStructure(Class<? extends AbstractTable<?, ?, ?>> tableClass, TableSpec spec) {
		try {
			tableClass.getMethod("specifyStructure", TableSpec.class).invoke(tableClass, spec);
		} catch (Exception e) {
			throw new RuntimeException("Couldn't specify the table structure!", e);
		}
	}

	protected void insertLong(long columnIndex, long rowIndex, long value) {
		table.insertLong(columnIndex, rowIndex, value);
	}

	protected void insertString(long columnIndex, long rowIndex, String value) {
		table.insertString(columnIndex, rowIndex, value);
	}

	protected void insertBoolean(long columnIndex, long rowIndex, boolean value) {
		table.insertBoolean(columnIndex, rowIndex, value);
	}

	protected void insertBinary(long columnIndex, long rowIndex, byte[] value) {
		ByteBuffer buffer = ByteBuffer.allocateDirect(value.length);
		buffer.put(value);

		table.insertBinary(columnIndex, rowIndex, buffer);
	}

	protected void insertDate(long columnIndex, long rowIndex, Date value) {
		table.insertDate(columnIndex, rowIndex, value);
	}

	protected void insertMixed(long columnIndex, long rowIndex, Object value) {
		Mixed mixed = Mixed.mixedValue(value);
		table.insertMixed(columnIndex, rowIndex, mixed);
	}
<commit_msg>Added missing method for byte buffer insertion.<commit_after>package com.tightdb.lib;

import java.nio.ByteBuffer;
import java.util.Date;

import com.tightdb.ColumnType;
import com.tightdb.Group;
import com.tightdb.Mixed;
import com.tightdb.TableBase;
import com.tightdb.TableQuery;
import com.tightdb.TableSpec;

public abstract class AbstractTable<Cursor, View, Query> extends AbstractRowset<Cursor, View, Query> {

	static {
		TightDB.loadLibrary();
	}

	protected final TableBase table;

	public AbstractTable(EntityTypes<?, View, Cursor, Query> types) {
		this(types, new TableBase());
	}

	public AbstractTable(EntityTypes<?, View, Cursor, Query> types, Group group) {
		this(types, group.getTable(types.getTableClass().getCanonicalName()));
	}

	@SuppressWarnings("unchecked")
	protected AbstractTable(EntityTypes<?, View, Cursor, Query> types, TableBase table) {
		super(types, table);
		this.table = table;
		if (table != null && table.getTableSpec().getColumnCount() <= 0) {
			// Build table schema
			final TableSpec spec = new TableSpec();
			specifyTableStructure((Class<? extends AbstractTable<?, ?, ?>>) types.getTableClass(), spec);
			table.updateFromSpec(spec);
		}
	}

	public boolean isValid() {
		return table.isValid();
	}
	
	@Override
	public String getName() {
		return getClass().getSimpleName();
	}

	@Override
	public long size() {
		return table.size();
	}

	protected static void addLongColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeInt, name);
	}

	protected static void addStringColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeString, name);
	}

	protected static void addBooleanColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeBool, name);
	}

	protected static void addBinaryColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeBinary, name);
	}

	protected static void addDateColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeDate, name);
	}

	protected static void addMixedColumn(TableSpec spec, String name) {
		spec.addColumn(ColumnType.ColumnTypeMixed, name);
	}

	@SuppressWarnings("unchecked")
	protected static void addTableColumn(TableSpec spec, String name, AbstractTable<?, ?, ?> subtable) {
		TableSpec subspec = spec.addSubtableColumn(name);
		specifyTableStructure((Class<? extends AbstractTable<?, ?, ?>>) subtable.getClass(), subspec);
	}

	protected static void specifyTableStructure(Class<? extends AbstractTable<?, ?, ?>> tableClass, TableSpec spec) {
		try {
			tableClass.getMethod("specifyStructure", TableSpec.class).invoke(tableClass, spec);
		} catch (Exception e) {
			throw new RuntimeException("Couldn't specify the table structure!", e);
		}
	}

	protected void insertLong(long columnIndex, long rowIndex, long value) {
		table.insertLong(columnIndex, rowIndex, value);
	}

	protected void insertString(long columnIndex, long rowIndex, String value) {
		table.insertString(columnIndex, rowIndex, value);
	}

	protected void insertBoolean(long columnIndex, long rowIndex, boolean value) {
		table.insertBoolean(columnIndex, rowIndex, value);
	}

	protected void insertBinary(long columnIndex, long rowIndex, byte[] value) {
		ByteBuffer buffer = ByteBuffer.allocateDirect(value.length);
		buffer.put(value);

		table.insertBinary(columnIndex, rowIndex, buffer);
	}

	protected void insertBinary(long columnIndex, long rowIndex, ByteBuffer value) {
		table.insertBinary(columnIndex, rowIndex, value);
	}

	protected void insertDate(long columnIndex, long rowIndex, Date value) {
		table.insertDate(columnIndex, rowIndex, value);
	}

	protected void insertMixed(long columnIndex, long rowIndex, Object value) {
		Mixed mixed = Mixed.mixedValue(value);
		table.insertMixed(columnIndex, rowIndex, mixed);
	}

{'fraction_non_alphanumeric': 0.11483575659666129, 'fraction_numerical': 0.00026925148088314486, 'mean_word_length': 5.615316117542298, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, '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': '668728', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2200, 'n_words': 559}